The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Merge branch 'master' of github.com:johanmattssonm/birdfont

These changes was commited to the Birdfont repository Sun, 15 Mar 2015 19:15:23 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 15 Mar 2015 19:15:23 +0000 (20:15 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 15 Mar 2015 19:15:23 +0000 (20:15 +0100)
commit 6288f9734dc336398b895f8612bd4fdb0f77580b
tree 18187419d15d3f4e0fecd5b87aeb4ae759edbcf2
parent af08afa2610a5aa89cb1d421e37c4eaaa8a52ce4
parent b8a114477d9f73a2634da90af9c7d5b909ce9666
Merge branch 'master' of github.com:johanmattssonm/birdfont

libbirdfont/Glyph.vala
libbirdfont/Renderer/Text.vala
libbirdfont/Renderer/TextArea.vala
resources/roboto.bf
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -101,28 +101,7 @@ Line right_line; /** Cache for Cairo rendering */ - HashMap<int64?, Surface> glyph_cache = new HashMap<int64?, Surface> ((v) => { - int? t = (int?) v; - int i = (!) t; - - if (i == 0) { - return 0; - } - - return (int) (0xFFFFFFFF & i); - }, (a, b) => { - int64? i1; - int64? i2; - - i1 = (int64?) a; - i2 = (int64?) b; - - if (i1 == null || i1 == null) { - return false; - } - - return (!) i1 == (!) i2; - }); + HashMap<string, Surface> glyph_cache = new HashMap<string, Surface> (); public Glyph (string name, unichar unichar_code = 0) { this.name = name; @@ -2109,21 +2088,21 @@ } } - public void set_cache (int64 font_size, Surface cache) { - glyph_cache.set (font_size, cache); + public void set_cache (string key, Surface cache) { + glyph_cache.set (key, cache); } - public bool has_cache (int64 font_size) { - return glyph_cache.has_key (font_size); + public bool has_cache (string key) { + return glyph_cache.has_key (key); } - public Surface get_cache (int64 font_size) { - if (unlikely (!has_cache (font_size))) { + public Surface get_cache (string key) { + if (unlikely (!has_cache (key))) { warning ("No cache for glyph."); return new ImageSurface (Cairo.Format.ARGB32, 1, 1); } - return glyph_cache.get (font_size); + return glyph_cache.get (key); } public void add_custom_guide () {
--- a/libbirdfont/Renderer/Text.vala +++ b/libbirdfont/Renderer/Text.vala @@ -318,7 +318,7 @@ draw_at_baseline (cr, widget_x, y); } - public void draw_at_top (Context cr, double px, double py, int64 cacheid = -1) { + public void draw_at_top (Context cr, double px, double py, string cacheid = "") { double s = get_scale (); double y = py + s * (font.top_limit - font.base_line); draw_at_baseline (cr, px, y, cacheid); @@ -331,22 +331,31 @@ this.a = a; } - public int64 get_cache_id () { - int64 s = (((int64) font_size) << 32) - | (((int64) (r * 255)) << 24) + public string get_cache_id (int offset_x, int offset_y) { + string key; + int64 c; + + c = (((int64) (r * 255)) << 24) | (((int64) (g * 255)) << 16) | (((int64) (b * 255)) << 8) | (((int64) (a * 255)) << 0); - return s; + + // FIXME: use binary key + key = @"$font_size $c $offset_x $offset_y"; + + return key; } - public void draw_at_baseline (Context cr, double px, double py, int64 cacheid = -1) { + public void draw_at_baseline (Context cr, double px, double py, string cacheid = "") { double x, y; double ratio; double cc_y; - int64 cache_id; + string cache_id; + int offset_x, offset_y; - cache_id = (cacheid < 0) ? get_cache_id () : cacheid; + offset_x = (int) (10 * (px - (int) px)); + offset_y = (int) (10 * (py - (int) py)); + cache_id = (cacheid == "") ? get_cache_id (offset_x, offset_y) : cacheid; ratio = get_scale (); cc_y = (font.top_limit - font.base_line) * ratio; @@ -366,7 +375,9 @@ return; } - draw_chached (cr ,glyph, kerning, last, x, y, cc_y, cache_id, ratio); + draw_chached (cr ,glyph, kerning, last, x, y, cc_y, + cache_id, ratio, offset_x, offset_y); + x = end; }); } else { @@ -381,14 +392,14 @@ return; } - draw_without_cache (cr, glyph, kerning, last, x, y, cc_y, cache_id, ratio); + draw_without_cache (cr, glyph, kerning, last, x, y, cc_y, ratio); x = end; }); } } void draw_without_cache (Context cr, Glyph glyph, double kerning, bool last, - double x, double y, double cc_y, int64 cache_id, double ratio) { + double x, double y, double cc_y, double ratio) { double lsb; @@ -408,7 +419,8 @@ } void draw_chached (Context cr, Glyph glyph, double kerning, bool last, - double x, double y, double cc_y,int64 cache_id, double ratio) { + double x, double y, double cc_y, string cache_id, double ratio, + int offset_x, int offset_y) { double lsb; Surface cache; @@ -425,7 +437,7 @@ cc.new_path (); foreach (Path path in glyph.path_list) { - draw_path (cc, path, lsb, 0, cc_y, ratio); + draw_path (cc, path, lsb, offset_x / 10.0, cc_y + offset_y / 10.0, ratio); } cc.fill (); @@ -434,7 +446,7 @@ glyph.set_cache (cache_id, cache); } - cr.set_source_surface (glyph.get_cache (cache_id), x, y - cc_y); + cr.set_source_surface (glyph.get_cache (cache_id), (int) x, (int) (y - cc_y)); cr.paint (); }
--- a/libbirdfont/Renderer/TextArea.vala +++ b/libbirdfont/Renderer/TextArea.vala @@ -52,8 +52,6 @@ Gee.ArrayList<Paragraph> paragraphs = new Gee.ArrayList<Paragraph> (); private static const int DONE = -2; - - int64 cache_id = -1; int last_paragraph = 0; string text; @@ -1133,10 +1131,9 @@ tx = paragraph.start_x; ty = paragraph.start_y; - if (cache_id == -1 && paragraphs.size > 0 && paragraphs.get (0).words.size > 0) { + if (paragraphs.size > 0 && paragraphs.get (0).words.size > 0) { Text t = paragraphs.get (0).words.get (0); Theme.text_color (t, "Foreground 1"); - cache_id = t.get_cache_id (); } for (int i = first_visible; i < last_visible; i++) { @@ -1153,7 +1150,7 @@ Theme.text_color (next_word, "Foreground 1"); if (next_word.text != "\n") { - next_word.draw_at_top (cc, next_word.widget_x, next_word.widget_y - ty, cache_id); + next_word.draw_at_top (cc, next_word.widget_x, next_word.widget_y - ty); } } }
--- a/resources/roboto.bf +++ b/resources/roboto.bf @@ -22,6 +22,10 @@ <bottom_position>-21.3378910000</bottom_position> <bottom_limit>-27.0996090000</bottom_limit> </horizontal> + + <grid width="1.0000"/> + <grid width="2.0000"/> + <grid width="4.0000"/> <background scale="1.0000" /> @@ -6186,5 +6190,6 @@ + <kerning left="T" right="e" hadjustment="-11.3891448975" /> </font>