Clone in a terminal:
Commit 6288f97
Johan Mattsson - 2015-03-15T19:15:23+00:00
6288f9734dc336398b895f8612bd4fdb0f77580bjohan.mattsson.m@gmail.com

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

Changed files (4)

Diff

diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 889686b..9efb52a 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -101,28 +101,7 @@ public class Glyph : FontDisplay { 	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 class Glyph : FontDisplay { 		}	 	} -	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 () {diff --git a/libbirdfont/Renderer/Text.vala b/libbirdfont/Renderer/Text.valaindex 988a753..8801eb1 100644--- a/libbirdfont/Renderer/Text.vala+++ b/libbirdfont/Renderer/Text.vala@@ -318,7 +318,7 @@ public class Text : Widget { 		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 @@ public class Text : Widget { 		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 @@ public class Text : Widget { 					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 @@ public class Text : Widget { 					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 @@ public class Text : Widget { 	} 	 	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 @@ public class Text : Widget { 			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 @@ public class Text : Widget { 			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 (); 	} 	diff --git a/libbirdfont/Renderer/TextArea.vala b/libbirdfont/Renderer/TextArea.valaindex 8a25540..9bf34b5 100644--- a/libbirdfont/Renderer/TextArea.vala+++ b/libbirdfont/Renderer/TextArea.vala@@ -53,8 +53,6 @@ public class TextArea : Widget { 	Gee.ArrayList<Paragraph> paragraphs = new Gee.ArrayList<Paragraph>  (); 	private static const int DONE = -2;  	-	int64 cache_id = -1;-	 	int last_paragraph = 0; 	string text; 	int text_length;@@ -1133,10 +1131,9 @@ public class TextArea : Widget { 		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 @@ public class TextArea : Widget { 					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); 					} 				} 			}diff --git a/resources/roboto.bf b/resources/roboto.bfindex 7bfabfd..abd0060 100644--- a/resources/roboto.bf+++ b/resources/roboto.bf@@ -23,6 +23,10 @@ 	<bottom_limit>-27.0996090000</bottom_limit> </horizontal> +<grid width="1.0000"/>+<grid width="2.0000"/>+<grid width="4.0000"/>+ <background scale="1.0000" />  <collection unicode="U+20">@@ -6186,4 +6190,5 @@   +<kerning left="T" right="e" hadjustment="-11.3891448975" /> </font>

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112