Clone in a terminal:
Commit e79b09c
Johan Mattsson - 2014-10-30T20:43:07+00:00
e79b09c7467045a9ec3fe3929296c1c982e82190johan.mattsson.m@gmail.com

Calculate max extent

Changed files (3)

Diff

diff --git a/libbirdfont/Ligatures.vala b/libbirdfont/Ligatures.valaindex 215e857..dcd8364 100644--- a/libbirdfont/Ligatures.vala+++ b/libbirdfont/Ligatures.vala@@ -162,7 +162,6 @@ public class Ligatures : GLib.Object { 				 	public void set_ligature (int index) { 		Ligature lig;-		TextListener listener; 		 		return_if_fail (0 <= index < ligatures.size); 		@@ -172,7 +171,6 @@ public class Ligatures : GLib.Object { 	 	public void set_substitution (int index) { 		Ligature lig;-		TextListener listener; 		 		return_if_fail (0 <= index < ligatures.size); 		diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex c479f3a..d08e769 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -796,12 +796,6 @@ public class OverView : FontDisplay { 		return false; 	} 	-	bool select_visible_character (unichar c) {-		StringBuilder s = new StringBuilder ();-		s.append_unichar (c);-		return select_visible_glyph (s.str);-	}-	 	public void scroll_to_char (unichar c) { 		StringBuilder s = new StringBuilder (); diff --git a/libbirdfont/Renderer/TextArea.vala b/libbirdfont/Renderer/TextArea.valaindex 7c34c45..f1abbb6 100644--- a/libbirdfont/Renderer/TextArea.vala+++ b/libbirdfont/Renderer/TextArea.vala@@ -24,6 +24,7 @@ public class TextArea { 	string text; 	GlyphSequence glyph_sequence; 	double line_gap = 20;+	public delegate void Iterator (Glyph glyph, double kerning); 	 	public TextArea () { 		font = new Font ();@@ -50,43 +51,23 @@ public class TextArea { 			name = font.get_name_for_character (c); 			g = font.get_glyph_by_name (name); 			glyph_sequence.glyph.add (g);-		}		+		}	 	}-	-	public bool load_font (string file) {-		Font? f = font_cache.get_font (file);-		-		if (f != null) {-			font = (!) f;-		}-		-		return f != null;-	}-	-	public void draw (Context cr, int px, int py, int width, int height, double font_size_in_pixels) {++	public void iterate (Iterator iter) { 		Glyph glyph;-		double x, y, w, kern;-		int i, wi;+		double w, kern;+		int wi; 		Glyph? prev; 		GlyphSequence word_with_ligatures; 		GlyphRange? gr_left, gr_right; 		double row_height; 		GlyphSequence word;-		double center_x, center_y;-		double ratio; 		-		i = 0; 		row_height = get_row_height (); 		-		ratio = font_size_in_pixels / row_height;-		-		cr.save ();-		cr.scale (ratio, ratio);-		 		glyph = new Glyph ("", '\0'); -		y = get_row_height () + font.base_line + py;-		x = px; 		w = 0; 		prev = null; 		kern = 0;@@ -109,32 +90,62 @@ public class TextArea { 				kern = KerningDisplay.get_kerning_for_pair (((!)prev).get_name (), ((!)g).get_name (), gr_left, gr_right); 			} 					-			// draw glyph+			// process glyph 			glyph = (g == null) ? font.get_not_def_character ().get_current () : (!) g;+			iter (glyph, kern);+			+			prev = g;+			wi++;+		}+	}++	public double get_max_extent_x (double font_size_in_pixels) {+		double x = 0;+		+		iterate ((glyph, kerning) => {+			x += glyph.get_width () + kerning;+		});+		+		return x;+	}+	+	public bool load_font (string file) {+		Font? f = font_cache.get_font (file);+		+		if (f != null) {+			font = (!) f;+		}+		+		return f != null;+	}+	+	public void draw (Context cr, int px, int py, int width, int height, double font_size_in_pixels) {+		double x, y;+		double row_height, ratio; -			center_x = glyph.allocation.width / 2.0;-			center_y = glyph.allocation.height / 2.0;+		row_height = get_row_height ();		+		ratio = font_size_in_pixels / row_height;+		+		cr.save ();+		cr.scale (ratio, ratio);++		y = get_row_height () + font.base_line + py;+		x = px;+		+		iterate ((glyph, kerning) => {+			double center_x = glyph.allocation.width / 2.0;+			double center_y = glyph.allocation.height / 2.0;  			cr.save (); 			glyph.add_help_lines ();-			cr.translate (kern + x - center_x - glyph.get_lsb (), y - center_y + glyph.get_baseline ());+			cr.translate (kerning + x - center_x - glyph.get_lsb (), y - center_y + glyph.get_baseline ()); 			glyph.draw_paths (cr); 			cr.restore (); 			-			w = glyph.get_width ();--			x += w + kern;--			prev = g;-			-			wi++;-			i++;-		}-					-		y += row_height + line_gap;-		x = 20;-			-		cr.restore ();		+			x += glyph.get_width () + kerning;+		});+		+		cr.restore ();	 	}	  	double get_row_height () {

Contact

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