Clone in a terminal:
Commit c667aba
Johan Mattsson - 2015-12-13T17:30:42+00:00
c667aba38ac548c6e96f75f998bcc437c9e46f18johan.mattsson.m@gmail.com

Faster text and icon rendering This commit makes switching tools many times faster.

Changed files (8)

Diff

diff --git a/libbirdfont/CharacterInfo.vala b/libbirdfont/CharacterInfo.valaindex 3f5c6b7..acbc715 100644--- a/libbirdfont/CharacterInfo.vala+++ b/libbirdfont/CharacterInfo.vala@@ -36,7 +36,6 @@ public class CharacterInfo : GLib.Object { 			ligature = ((!) gc).is_unassigned (); 			name = ((!) gc).get_name (); 			icon.load_font ("icons.bf");-			icon.use_cache (true); 		} 	} 	diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 14b6522..e204ad8 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -108,7 +108,11 @@ public class DrawingTools : ToolCollection  { 	static Tool line_cap_butt; 	static Tool line_cap_round; 	static Tool line_cap_square;-			++	private Text backgrounds_headline = new Text (t_("Background Tools"));+	private Text control_points_headline = new Text (t_("Control Points"));+	private Text object_tools_headline = new Text (t_("Object Tools"));+		 	public DrawingTools (GlyphCanvas main_glyph_canvas) { 		bool selected_line; 		@@ -1324,7 +1328,7 @@ public class DrawingTools : ToolCollection  { 	}  	void show_background_tool_modifiers () {-		draw_tool_modifiers.set_headline (t_("Background Tools"));+		draw_tool_modifiers.set_headline (backgrounds_headline); 		 		cut_background.set_tool_visibility (true); 		show_bg.set_tool_visibility (true);@@ -1339,7 +1343,7 @@ public class DrawingTools : ToolCollection  { 	} 			 	void show_point_tool_modifiers () {-		draw_tool_modifiers.set_headline (t_("Control Points"));+		draw_tool_modifiers.set_headline (control_points_headline); 		 		tie_handles.set_tool_visibility (true); 		reflect_handle.set_tool_visibility (true);@@ -1355,7 +1359,7 @@ public class DrawingTools : ToolCollection  { 	} 	 	void show_object_tool_modifiers () {-		draw_tool_modifiers.set_headline (t_("Object Tools"));+		draw_tool_modifiers.set_headline (object_tools_headline); 		 		x_coordinate.set_tool_visibility (true); 		y_coordinate.set_tool_visibility (true);diff --git a/libbirdfont/Expander.vala b/libbirdfont/Expander.valaindex cc4a861..8ac6238 100644--- a/libbirdfont/Expander.vala+++ b/libbirdfont/Expander.vala@@ -53,7 +53,7 @@ public class Expander : GLib.Object { 		title = new Text ();  		if (headline != null) {-			set_headline(headline);+			title.set_text ((!) headline); 		} 				 		tool = new Gee.ArrayList<Tool> ();@@ -63,13 +63,13 @@ public class Expander : GLib.Object { 		cached = null; 	} -	public void set_headline (string? h) {-		headline = h;-		title.set_text ((!) headline);+	public void set_headline (Text h) {+		headline = h.get_text ();+		title = h; 	}  	public double get_content_height () {-		return content_height;+		return content_height;
 	}  	/** Returns true if tools can be used with the current canvas after@@ -217,7 +217,6 @@ public class Expander : GLib.Object { 	} 	 	public void redraw () {-		cached = null; 		Toolbox.redraw_tool_box (); 	} 	@@ -290,11 +289,12 @@ public class Expander : GLib.Object { 			} 			 			draw_content (cc, offset_y);-			cached = (!) cache;+			cached = (!) cache;			 		} 		 		if (cached != null) { 			cache = (!) cached;+			cr.set_antialias (Cairo.Antialias.NONE); 			Screen.paint_background_surface (cr, cache, 0, (int) (y + scroll)); 		} 	}diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 70c20bb..d05c541 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -320,7 +320,7 @@ public class Path : GLib.Object { 		double max = Glyph.CANVAS_MIN; 		Text arrow; 		double x, y, angle;-		double size = 50 * Glyph.ivz ();+		double size = 50 * Screen.get_scale (); 		 		foreach (EditPoint e in points) { 			if (e.y > max) {@@ -331,7 +331,6 @@ public class Path : GLib.Object { 		 		arrow = new Text ("orientation_arrow", size); 		arrow.load_font ("icons.bf");-		arrow.use_cache (false); 		 		Theme.text_color_opacity (arrow, "Highlighted 1", opacity); @@ -342,6 +341,8 @@ public class Path : GLib.Object { 		if (points.size > 0) { 			cr.save (); 			cr.translate (x, y);+			double inverted_zoom = Glyph.ivz ();+			cr.scale (inverted_zoom, inverted_zoom); 			cr.rotate (-angle); 			cr.translate (-x, -y);  			diff --git a/libbirdfont/Renderer/Text.vala b/libbirdfont/Renderer/Text.valaindex 0955bd3..6eb703e 100644--- a/libbirdfont/Renderer/Text.vala+++ b/libbirdfont/Renderer/Text.vala@@ -20,7 +20,9 @@ namespace BirdFont { public class Text : Widget { 	FontCache font_cache; 	public CachedFont cached_font;-+	+	Surface? cache = null;+	 	public string text; 	 	GlyphSequence glyph_sequence {@@ -44,8 +46,6 @@ public class Text : Widget { 	public double g = 0; 	public double b = 0; 	public double a = 1;-	-	bool use_cached_glyphs = true; 	double truncated_width = -1; 	 	public Text (string text = "", double size = 17, double margin_bottom = 0) {@@ -57,8 +57,8 @@ public class Text : Widget { 		set_font_size (size); 	} 	-	public void use_cache (bool cache) {-		use_cached_glyphs = cache;+	public string get_text () {+		return text; 	} 	 	/** Set font for this text area.@@ -332,49 +332,61 @@ public class Text : Widget { 		double ratio; 		double cc_y; +		if (cache == null) {+			cache = draw_on_cache_surface (cacheid);+		}+		+		double s = get_font_scale ();+		double cache_y = py - s * (cached_font.top_limit - cached_font.base_line);+		cr.set_source_surface ((!) cache, (int) px, (int) cache_y);+		cr.paint ();+	}+	+	Surface draw_on_cache_surface (string cacheid) {+		double x, y;+		double ratio;+		double cc_y;+		Context cr;+		Surface cache_surface;+		double screen_scale = Screen.get_scale();+		double h = font_size * screen_scale + 1;+		double w = get_sidebearing_extent () * screen_scale + 1;+		+		cache_surface = Screen.create_background_surface ((int) w, (int) h);+		cr = new Context (cache_surface);+		cr.scale(screen_scale, screen_scale);+ 		ratio = get_font_scale (); 		cc_y = (cached_font.top_limit - cached_font.base_line) * ratio; -		y = py;-		x = px;+		double px = 0;+		double py = cc_y;+		+		y = cc_y;+		x = 0;  		if (unlikely (cached_font.base_line != 0)) { 			warning ("Base line not zero."); 		} 		-		if (use_cached_glyphs) {-			iterate ((glyph, kerning, last) => {-				double end;-				-				x += kerning * ratio;-				end = x + glyph.get_width () * ratio;-				-				// truncation-				if (truncated_width > 0 && end - px > truncated_width) {-					return;-				}+		iterate ((glyph, kerning, last) => {+			double end;+			+			x += kerning * ratio;+			end = x + glyph.get_width () * ratio;+			+			// truncation+			if (truncated_width > 0 && end - px > truncated_width) {+				return;+			} -				draw_chached (cr, glyph, kerning, last, x, y, cc_y, -					ratio, cacheid);-				-				x = end;-			});-		} else {-			iterate ((glyph, kerning, last) => {-				double end;-				-				x += kerning * ratio;-				end = x + glyph.get_width () * ratio;-				-				// truncation-				if (truncated_width > 0 && end - px > truncated_width) {-					return;-				}-				-				draw_without_cache (cr, glyph, kerning, last, x, y, cc_y, ratio);-				x = end;-			});-		}+			draw_chached (cr, glyph, kerning, last, x, y, cc_y, +				ratio, cacheid);+			+			x = end;+		});+		+		return cache_surface; 	} 	 	void draw_without_cache (Context cr, Glyph glyph, double kerning, bool last, diff --git a/libbirdfont/Renderer/TextArea.vala b/libbirdfont/Renderer/TextArea.valaindex d919a56..797c52c 100644--- a/libbirdfont/Renderer/TextArea.vala+++ b/libbirdfont/Renderer/TextArea.vala@@ -64,7 +64,6 @@ public class TextArea : Widget { 	bool store_undo_state_at_next_event = false; 	 	public bool editable;-	public bool use_cache = true; 	 	public TextArea (double font_size = 20, Color? c = null) { 		this.font_size = font_size;@@ -1068,7 +1067,6 @@ public class TextArea : Widget { 		cr.save ();  		word = new Text ();-		word.use_cache (use_cache); 		 		width = this.width - padding; 		x += padding;diff --git a/libbirdfont/TabBar.vala b/libbirdfont/TabBar.valaindex f701d2d..ad0d1bc 100644--- a/libbirdfont/TabBar.vala+++ b/libbirdfont/TabBar.vala@@ -682,8 +682,6 @@ public class TabBar : GLib.Object { 			wheel.widget_x = middlex; 			wheel.widget_y = middley; 			-			wheel.use_cache (false);-			 			cr.save (); 			if (!has_stop_button ()) { 				cr.translate (middlex, middley);@@ -801,7 +799,6 @@ public class TabBar : GLib.Object { 			 			// tab label 			label = new Text ();-			label.use_cache (false); 			label.set_text (t.get_label ()); 			text_height = (int) (16 / scale); 			label.set_font_size (text_height);diff --git a/libbirdfont/Tool.vala b/libbirdfont/Tool.valaindex d1701d4..fc4e756 100644--- a/libbirdfont/Tool.vala+++ b/libbirdfont/Tool.vala@@ -240,7 +240,6 @@ public class Tool : Widget { 		icon_file = Theme.get_icon_file (); 		icon_font = new Text ((!) name); 		found = icon_font.load_font (icon_file);-		icon_font.use_cache (true); 		icon_font.set_font_size (40 * Toolbox.get_scale ()); 		 		if (!found) {

Contact

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