Clone in a terminal:
Commit 4eb323f
Johan Mattsson - 2014-11-16T20:24:25+00:00
4eb323fa8f8b79c879184753418590b3a2a6c1cejohan.mattsson.m@gmail.com

Text area

Changed files (18)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 3c093e1..8b9dd1e 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -107,12 +107,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { 			 			scrollbar.set_visible (fd.has_scrollbar ()); 			-			if (fd.get_name () == "Description") {-				description.update_fields ();-				description.canvas.set_visible (true);-				html_box.set_visible (false);-				glyph_canvas_area.set_visible (false);-			} else if (fd.get_name () == "Preview") {+			if (fd.get_name () == "Preview") { 				uri = Preview.get_uri (); 				html = Preview.get_html_with_absolute_paths (); 										diff --git a/libbirdfont/BackgroundSelectionTool.vala b/libbirdfont/BackgroundSelectionTool.valaindex c65b728..288d1b1 100644--- a/libbirdfont/BackgroundSelectionTool.vala+++ b/libbirdfont/BackgroundSelectionTool.vala@@ -70,11 +70,13 @@ public class BackgroundSelectionTool : CutBackgroundTool { 						font_height = 18; 						cr.set_source_rgba (1, 1, 1, 1); 						label.set_text ((!) bs.assigned_glyph);-						tx = x  + w - label.get_width (font_height) / 2.0;+						label.set_font_size (font_height);+						tx = x  + w - label.get_width () / 2.0; 						ty = y + h;-						ty += label.get_height (font_height) / 2.0;+						ty += label.get_height () / 2.0; 						ty -= label.get_decender (font_height);-						label.draw (cr, tx, ty, font_height);+						label.set_font_size (font_height);+						label.draw_at_baseline (cr, tx, ty); 					} 				} 				diff --git a/libbirdfont/DescriptionDisplay.vala b/libbirdfont/DescriptionDisplay.valanew file mode 100644index 0000000..bd1f17c--- /dev/null+++ b/libbirdfont/DescriptionDisplay.vala@@ -0,0 +1,185 @@+/*+    Copyright (C) 2014 Johan Mattsson++    This library is free software; you can redistribute it and/or modify +    it under the terms of the GNU Lesser General Public License as +    published by the Free Software Foundation; either version 3 of the +    License, or (at your option) any later version.++    This library is distributed in the hope that it will be useful, but +    WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +    Lesser General Public License for more details.+*/++using Cairo;+using Math;++namespace BirdFont {++public class DescriptionDisplay : FontDisplay {+	+	double scroll = 0;+	double content_height = 1;+	WidgetAllocation allocation;+	+	TextArea version;+	TextArea description;+	TextArea copyright;+	+	Gee.ArrayList<Widget> widgets;+	+	public DescriptionDisplay () {+		double margin = 20 * MainWindow.units;+		double label_size = 22 * MainWindow.units;+		double label_margin = 4 * MainWindow.units;+		+		allocation = new WidgetAllocation ();+		+		widgets = new Gee.ArrayList<Widget> ();+		+		copyright = new TextArea (label_size);+		description = new TextArea (label_size);+		version = new TextArea (label_size);++		widgets.add (new Text (t_("Version"),label_size, label_margin));+		version.margin_bottom = margin;+		widgets.add (version);++		widgets.add (new Text (t_("Description"), label_size, label_margin));+		description.margin_bottom = margin;+		widgets.add (description);+		+		widgets.add (new Text (t_("Copyright"), label_size, label_margin));+		copyright.margin_bottom = margin;+		widgets.add (copyright);+	}++	public override void draw (WidgetAllocation allocation, Context cr) {+		this.allocation = allocation;+		+		layout ();+		+		// background+		cr.save ();+		cr.rectangle (0, 0, allocation.width, allocation.height);+		cr.set_line_width (0);+		cr.set_source_rgba (51 / 255.0, 54 / 255.0, 59 / 255.0, 1);+		cr.fill ();+		cr.stroke ();+		cr.restore ();++		foreach (Widget w in widgets) {+			if (w is Text) {+				cr.save ();+				cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);+				w.draw (cr);+				cr.restore ();+			} else {+				w.draw (cr);+			}+		}+	}	++	void layout () {+		double y = 10 * MainWindow.units;+		double margin;+		+		foreach (Widget w in widgets) {+			w.widget_x = 17 * MainWindow.units;+			w.widget_y = y;+			y += w.get_height () + w.margin_bottom;+		}+	}++	public override void key_press (uint keyval) {+		unichar c = (unichar) keyval;+		string s;+		+		if (!KeyBindings.has_alt () && !KeyBindings.has_ctrl ()) {+			switch (c) {+				case Key.BACK_SPACE:+					copyright.remove_last_character ();+					break;+				case Key.ENTER:+					copyright.insert_text ("\n");+					break;				+				default:+					if (!is_modifier_key (keyval)) {+						s = (!) c.to_string ();+						if (s.validate ()) {+							copyright.insert_text (s);+							print (@"keyval: $keyval\n");+						}+					}+					break;+			}+		}+		+		GlyphCanvas.redraw ();+	}++	public override void button_press (uint button, double x, double y) {+		GlyphCanvas.redraw ();+	}+	+	public override void button_release (int button, double x, double y) {+		GlyphCanvas.redraw ();+	}++	public override void motion_notify (double x, double y) {+	}++	public override string get_label () {+		return t_("Name and Description");+	}++	public override string get_name () {+		return "Description";+	}++	public override bool has_scrollbar () {+		return true;+	}+	+	public override void scroll_wheel_down (double x, double y) {+		scroll += 25 * MainWindow.units;++		if (scroll + allocation.height >=  content_height) {+			scroll = content_height - allocation.height;+		}+		+		update_scrollbar ();+		GlyphCanvas.redraw ();+	}+	+	public override void scroll_wheel_up (double x, double y) {+		scroll -= 25 * MainWindow.units;+		+		if (scroll < 0) {+			scroll = 0;+		}+		+		update_scrollbar ();+		GlyphCanvas.redraw ();+	}++	public override void selected_canvas () {+		update_scrollbar ();+		GlyphCanvas.redraw ();+	}+	+	public void update_scrollbar () {+		double h = content_height - allocation.height;+		MainWindow.set_scrollbar_size (allocation.height / content_height);+		MainWindow.set_scrollbar_position (scroll /  h);+	}++	public override void scroll_to (double percent) {+		double h = content_height - allocation.height;+		scroll = percent * h;+		GlyphCanvas.redraw ();+	}+}++}diff --git a/libbirdfont/DescriptionTab.vala b/libbirdfont/DescriptionTab.valadeleted file mode 100644index c140c91..0000000--- a/libbirdfont/DescriptionTab.vala+++ /dev/null@@ -1,33 +0,0 @@-/*-    Copyright (C) 2012 2013 Johan Mattsson--    This library is free software; you can redistribute it and/or modify -    it under the terms of the GNU Lesser General Public License as -    published by the Free Software Foundation; either version 3 of the -    License, or (at your option) any later version.--    This library is distributed in the hope that it will be useful, but -    WITHOUT ANY WARRANTY; without even the implied warranty of -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -    Lesser General Public License for more details.-*/--namespace BirdFont {--/** Names and description for the TTF Name table.- * The actual tab is implemented in the GTK window.- */-public class DescriptionTab : FontDisplay {	-	public DescriptionTab () {-	}-	-	public override string get_name () {-		return "Description";-	}--	public override string get_label () {-		return t_("Description");-	}-}--}diff --git a/libbirdfont/Expander.vala b/libbirdfont/Expander.valaindex ef27ad3..5cf1614 100644--- a/libbirdfont/Expander.vala+++ b/libbirdfont/Expander.vala@@ -233,7 +233,8 @@ public class Expander : GLib.Object { 				title = new Text (); 				title.set_text ((!) headline); 				cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);-				title.draw (cr, x, yt + HEADLINE_MARGIN + 7, 14);+				title.set_font_size (14);+				title.draw_at_baseline (cr, x, yt + HEADLINE_MARGIN + 7); 			} else if (draw_separator) {		 				cr.save (); 				cr.set_line_width (0.5);diff --git a/libbirdfont/FontName.vala b/libbirdfont/FontName.valaindex 7821e78..ea80afb 100644--- a/libbirdfont/FontName.vala+++ b/libbirdfont/FontName.vala@@ -44,13 +44,15 @@ public class FontName : Tool { 		text_height = 22; 		 		max_width = (width - 2 * x * Toolbox.get_scale ());-		extent = font_name.get_extent (text_height) * Toolbox.get_scale ();+		font_name.set_font_size (text_height);+		extent = font_name.get_extent () * Toolbox.get_scale (); 		if (extent > max_width) { 			text_height *= max_width / extent; 		} 		 		cr.set_source_rgba (234 / 255.0, 77 / 255.0, 26 / 255.0, 1);-		font_name.draw (cr, x, y + 13 * Toolbox.get_scale (), text_height);+		font_name.set_font_size (text_height);+		font_name.draw_at_baseline (cr, x, y + 13 * Toolbox.get_scale ()); 		cr.restore (); 	} }diff --git a/libbirdfont/KerningDisplay.vala b/libbirdfont/KerningDisplay.valaindex 93f892c..091983f 100644--- a/libbirdfont/KerningDisplay.vala+++ b/libbirdfont/KerningDisplay.vala@@ -94,7 +94,7 @@ public class KerningDisplay : FontDisplay { 		cr.restore (); 	} 	-	double get_row_height () {+	public double get_row_height () { 		return current_font.top_limit - current_font.bottom_limit; 	} diff --git a/libbirdfont/KeyBindings.vala b/libbirdfont/KeyBindings.valaindex ab2f484..e6568b8 100644--- a/libbirdfont/KeyBindings.vala+++ b/libbirdfont/KeyBindings.vala@@ -72,7 +72,8 @@ bool is_modifier_key (uint i) { 		Key.LOGO_RIGHT == i ||  		Key.TAB == i ||  		Key.CAPS_LOCK == i || -		Key.LOGO_RIGHT == i;+		Key.LOGO_RIGHT == i ||+		Key.ENTER == i; }  /** Modifier flags */diff --git a/libbirdfont/LabelTool.vala b/libbirdfont/LabelTool.valaindex 63f21a0..1eeb4b2 100644--- a/libbirdfont/LabelTool.vala+++ b/libbirdfont/LabelTool.vala@@ -73,7 +73,8 @@ public class LabelTool : Tool { 			cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 		} 		-		label_text.draw (cr, x + 14, y + h - 1.5, text_height);+		label_text.set_font_size (text_height);+		label_text.draw_at_baseline (cr, x + 14, y + h - 1.5); 		cr.restore ();  		// glyph count@@ -92,7 +93,8 @@ public class LabelTool : Tool { 			glyph_count.set_text (@"$(this.number)"); 			text_height = 12 / scale; 			-			center_x = bgx + ((!) counter_background).get_width () / 2.0  - glyph_count.get_extent (text_height) / 2.0;+			glyph_count.set_font_size (text_height);+			center_x = bgx + ((!) counter_background).get_width () / 2.0  - glyph_count.get_extent () / 2.0; 			center_y = bgy + ((!) counter_background).get_height () / 2.0 + 4 / scale; 			 			if (is_selected ()) {@@ -101,7 +103,8 @@ public class LabelTool : Tool { 				cr.set_source_rgba (51 / 255.0, 54 / 255.0, 59 / 255.0, 1); 			} 			-			glyph_count.draw (cr, center_x, center_y, text_height);+			glyph_count.set_font_size (text_height);+			glyph_count.draw_at_baseline (cr, center_x, center_y); 									 			cr.restore (); 		}diff --git a/libbirdfont/Menu.vala b/libbirdfont/Menu.valaindex 927a141..c4e096d 100644--- a/libbirdfont/Menu.vala+++ b/libbirdfont/Menu.vala@@ -33,7 +33,7 @@ public class Menu : GLib.Object { 			 			if (menu_visibility) { 				tab_name = MainWindow.get_tab_bar ().get_selected_tab ().get_display ().get_name ();-				if (tab_name == "Description" || tab_name == "Preview") {+				if (tab_name == "Preview") { 					MenuTab.select_overview (); 				} 			}@@ -597,8 +597,11 @@ public class Menu : GLib.Object { 		foreach (MenuItem item in current_menu.items) { 			key_binding.set_text (item.get_key_bindings ()); 			-			w = item.label.get_extent (font_size);-			w += key_binding.get_extent (font_size);+			item.label.set_font_size (font_size);+			key_binding.set_font_size (font_size);+			+			w = item.label.get_extent ();+			w += key_binding.get_extent (); 			w += 3 * height * MainWindow.units; 			 			if (w > width) {@@ -638,12 +641,14 @@ public class Menu : GLib.Object { 			cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 			label_x = allocation.width - width + 0.7 * height * MainWindow.units; 			label_y = y + font_size - 1 * MainWindow.units;-			item.label.draw (cr, label_x, label_y, font_size);+			item.label.draw_at_baseline (cr, label_x, label_y); 			 			key_binding.set_text (item.get_key_bindings ());-			binding_extent = key_binding.get_extent (font_size);+			key_binding.set_font_size (font_size);+			binding_extent = key_binding.get_extent (); 			label_x = x + width - binding_extent - 0.6 * height * MainWindow.units;-			key_binding.draw (cr, label_x, label_y, font_size);+			key_binding.set_font_size (font_size);+			key_binding.draw_at_baseline (cr, label_x, label_y); 			 			y += height; 		}diff --git a/libbirdfont/MenuTab.vala b/libbirdfont/MenuTab.valaindex 7b57fc1..0506b0a 100644--- a/libbirdfont/MenuTab.vala+++ b/libbirdfont/MenuTab.vala@@ -251,7 +251,7 @@ public class MenuTab : FontDisplay { 	}  	 	public static void show_description () {-		MainWindow.get_tab_bar ().add_unique_tab (new DescriptionTab ());+		MainWindow.get_tab_bar ().add_unique_tab (new DescriptionDisplay ()); 	} 	 	public static void show_kerning_context () {diff --git a/libbirdfont/OverViewItem.vala b/libbirdfont/OverViewItem.valaindex 3868b88..d28df9f 100644--- a/libbirdfont/OverViewItem.vala+++ b/libbirdfont/OverViewItem.vala@@ -187,9 +187,11 @@ public class OverViewItem : GLib.Object { 			c.set_source_rgba (219 / 255.0, 221 / 255.0, 233 / 255.0, 1); 			fallback.set_text ((!) character.to_string ()); 			font_size = height * 0.8;-			gx = (width - fallback.get_extent (font_size)) / 2.0;+			fallback.set_font_size (font_size);+			gx = (width - fallback.get_extent ()) / 2.0; 			gy = height - 30;-			fallback.draw (c, gx, gy, font_size);+			fallback.set_font_size (font_size);+			fallback.draw_at_baseline (c, gx, gy); 			c.restore (); 		} 		diff --git a/libbirdfont/Renderer/Text.vala b/libbirdfont/Renderer/Text.valaindex bc636c8..483724b 100644--- a/libbirdfont/Renderer/Text.vala+++ b/libbirdfont/Renderer/Text.vala@@ -17,9 +17,9 @@ using Cairo; namespace BirdFont {  /** Test implementation of a birdfont rendering engine. */-public class Text {+public class Text : Widget { -	Font font {+	public Font font { 		get { 			if (current_font == null) { 				File path = SearchPaths.find_file (null, "roboto.bf");@@ -42,12 +42,20 @@ public class Text { 	public string text; 	GlyphSequence glyph_sequence; 	public delegate void Iterator (Glyph glyph, double kerning, bool last);+	double font_size; 	-	public Text () {+	public Text (string text = "", double size = 17, double margin_bottom = 0) { 		current_font = null;-		text = "";+		this.margin_bottom = margin_bottom; 		glyph_sequence = new GlyphSequence (); 		font_cache = FontCache.get_default_cache ();+		+		set_text (text);+		set_font_size (size);+	}++	public void set_font_size (double height_in_pixels) {+		font_size = height_in_pixels; 	}  	public void set_font_cache (FontCache font_cache) {@@ -83,12 +91,9 @@ public class Text { 		Glyph? prev; 		GlyphSequence word_with_ligatures; 		GlyphRange? gr_left, gr_right;-		double row_height; 		GlyphSequence word; 		Glyph? g; 		-		row_height = get_row_height ();-		 		glyph = new Glyph ("", '\0');  		w = 0;@@ -125,9 +130,9 @@ public class Text { 	}  	// FIXME: some fonts doesn't have on curve extrema-	public double get_extent (double font_size_in_pixels) {+	public double get_extent () { 		double x = 0;-		double ratio = font_size_in_pixels / get_row_height ();+		double ratio = get_scale ();  		iterate ((glyph, kerning, last) => { 			double x1, y1, x2, y2;@@ -147,26 +152,45 @@ public class Text { 		return x; 	} -	public double get_height (double font_size_in_pixels) {-		double ratio = font_size_in_pixels / get_row_height ();-		double max_y = 0;+	public double get_sidebearing_extent () {+		double x = 0;+		double ratio = get_scale ();++		iterate ((glyph, kerning, last) => {+			double lsb;+			+			glyph.add_help_lines ();+			lsb = glyph.left_limit;+			x += (glyph.get_width () + kerning) * ratio;+		});+		+		return x;+	}++	public override double get_height () {+		return font_size;+	}++	public double get_glyph_height () {+		double ratio = get_scale ();+		double max_height = 0;  		iterate ((glyph, kerning, last) => { 			double x1, y1, x2, y2;-			double y;+			double h; 			glyph.boundaries (out x1, out y1, out x2, out y2);-			y = Math.fmax (y1, y2) - Math.fmin (y1, y2) ;-			if (y > max_y) {-				max_y = y;+			h = Math.fmax (y1, y2) - Math.fmin (y1, y2) ;+			if (h > max_height) {+				max_height = h; 			} 		}); 		-		return max_y * ratio;+		return max_height * ratio; 	}	 -	public double get_width (double font_size_in_pixels) {+	public override double get_width () { 		double x = 0;-		double ratio = font_size_in_pixels / get_row_height ();+		double ratio = get_scale (); 		bool first = true; 		 		iterate ((glyph, kerning, last) => {@@ -192,7 +216,7 @@ public class Text { 	}  	public double get_decender (double font_size_in_pixels) {-		double ratio = font_size_in_pixels / get_row_height ();+		double ratio = get_scale (); 		double min_y = 0; 		double decender; 		@@ -219,13 +243,17 @@ public class Text { 		 		return f != null; 	}-		-	public void draw (Context cr, double px, double py, double font_size_in_pixels) {+	+	public override void draw (Context cr) {+		double y = widget_y + get_height () + get_scale () * (font.bottom_limit + font.base_line);+		draw_at_baseline (cr, widget_x, y);+	}+	+	public void draw_at_baseline (Context cr, double px, double py) { 		double x, y;-		double row_height, ratio;+		double ratio; -		row_height = get_row_height ();		-		ratio = font_size_in_pixels / row_height;+		ratio = get_scale (); 		 		cr.save (); @@ -233,7 +261,7 @@ public class Text { 		x = px; 					 		iterate ((glyph, kerning, last) => {-			double lsb;;+			double lsb; 			 			glyph.add_help_lines (); 			@@ -305,8 +333,8 @@ public class Text { 		} 	} -	double get_row_height () {-		return font.top_limit - font.bottom_limit;+	public double get_scale () {+		return font_size / (font.top_limit - font.bottom_limit); 	} } diff --git a/libbirdfont/Renderer/TextArea.vala b/libbirdfont/Renderer/TextArea.valanew file mode 100644index 0000000..a12be9c--- /dev/null+++ b/libbirdfont/Renderer/TextArea.vala@@ -0,0 +1,290 @@+/*+    Copyright (C) 2014 Johan Mattsson++    This library is free software; you can redistribute it and/or modify +    it under the terms of the GNU Lesser General Public License as +    published by the Free Software Foundation; either version 3 of the +    License, or (at your option) any later version.++    This library is distributed in the hope that it will be useful, but +    WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +    Lesser General Public License for more details.+*/++using Cairo;+using Math;++namespace BirdFont {++public class TextArea : Widget {+	+	public double min_width = 500;+	public double min_height = 100;+	public double font_size;+	public double margin = 10;+	+	public bool draw_carret = true;+	public bool draw_border = true;++	private double width;+	private double height;++	int carret = 0;+	string text = "";+	int text_length = 0;+		+	int iter_pos;+	+	public TextArea (double font_size = 14) {+		this.font_size = font_size;+		width = min_width;+		height = min_height;+	}++	public override double get_height () {+		return height;+	}++	public override double get_width () {+		return width;+	}++	public void set_font_size (double z) {+		font_size = z;+	}+	+	public void set_text (string t) {+		int tl = t.length;+		text = t;+		carret = tl;+		text_length += tl;+	}+	+	public void remove_last_character () {+		int last_index = 0;+		int index = 0;+		unichar c;+		+		while (text.get_next_char (ref index, out c) && index < carret) {+			last_index = index;+		}+		+		set_text (text.substring (0, last_index) + text.substring (carret));+	}+	+	public void insert_text (string t) {+		string nt = text.substring (0, carret);+		int tl = t.length;+		nt += t;+		nt += text.substring (carret);+		carret += tl;+		text = nt;+		text_length += tl;+	}+	+	void layout () {+		Text word;+		double p;+		double tx, ty;+		string w;+		double xmax = 0;+		double width = this.width - 2 * margin;+		double height = this.height - 2 * margin;+		+		iter_pos = 0;+		word = new Text ();+		word.set_font_size (font_size);+		+		tx = 0;+		ty = 0;+		while (iter_pos < text_length) {+			w = get_next_word (out draw_carret);+			+			if (w == "") {+				break;+			}++			word.set_text (w);+			+			p = word.get_sidebearing_extent ();+			+			if (tx + p > width || w == "\n") {+				tx = 0;+				ty += font_size;+			}+			+			if (w != "\n") {+				tx += p;+			}+			+			if (tx > xmax) {+				xmax = tx;+			}+		}+		+		this.width = min_width;+		+		if (xmax > width) {+			this.width = xmax + 2 * margin;+		}+		+		this.height = fmax (min_height, ty + 2 * margin);+	}+	+	public override void draw (Context cr) {+		Text word;+		double p;+		double tx, ty;+		string w;+		bool draw_carret;+		double carret_y;+		double scale;+		double width;+		double x = widget_x;+		double y = widget_y;+		+		layout ();++		if (draw_border) {+			// background+			cr.save ();+			cr.set_line_width (1);+			cr.set_source_rgba (1, 1, 1, 1);+			create_border (cr, x, y);+			cr.fill ();+			cr.restore ();+			+			// border+			cr.save ();+			cr.set_line_width (1);+			create_border (cr, x, y);+			cr.stroke ();+			cr.restore ();+		}+		+		cr.save ();+		cr.set_source_rgba (38 / 255.0, 39 / 255.0, 43 / 255.0, 1);+		+		iter_pos = 0;+		word = new Text ();+		+		width = this.width - margin;+		x += margin;+		word.set_font_size (font_size);+		scale = word.get_scale ();+		//y += font_size - scale * (word.font.bottom_limit - word.font.base_line);+		y += font_size;+		+		tx = 0;+		ty = 0;+		while (iter_pos < text_length) {+			w = get_next_word (out draw_carret);+			+			if (w == "") {+				break;+			}+			+			word.set_text (w);+			p = word.get_sidebearing_extent ();+			+			if (tx + p > width || w == "\n") {+				tx = 0;+				ty += font_size;+			}+			+			if (w != "\n") {+				word.draw_at_baseline (cr, x + tx, y + ty);+				tx += p;+			}+			+			if (draw_carret && this.draw_carret) {+				cr.save ();+				cr.set_line_width (1);+				carret_y = y + ty;+				carret_y += scale * -word.font.bottom_limit;+				cr.move_to (x + tx, carret_y);+				cr.line_to (x + tx, carret_y - font_size);+				cr.stroke ();+				cr.restore ();+			}+		}+		cr.restore ();+	}+	+	string get_next_word (out bool draw_carret) {+		int i;+		int ni;+		int pi;+		string n;+		int nl;+		+		draw_carret = false;+		+		if (iter_pos >= text_length) {+			draw_carret = true;+			return "".dup ();+		}+		+		if (text.get_char (iter_pos) == '\n') {+			iter_pos += "\n".length;+			draw_carret = (iter_pos == carret);+			return "\n".dup ();+		}+		+		i = text.index_of (" ", iter_pos);+		pi = i + " ".length;+		+		ni = text.index_of ("\t", iter_pos);+		if (ni != -1 && ni < pi || i == -1) {+			i = ni;+			pi = i  + "\t".length;+		}+		+		ni = text.index_of ("\n", iter_pos);+		if (ni != -1 && ni < pi || i == -1) {+			i = ni;+			pi = i;+		}+		+		if (iter_pos + iter_pos - pi > text_length || i == -1) {+			n = text.substring (iter_pos);+		} else {+			n = text.substring (iter_pos, pi - iter_pos);+		}+		+		nl = n.length;+		if (iter_pos < carret < iter_pos + nl) {+			n = text.substring (iter_pos, carret - iter_pos);+			nl = n.length;+			draw_carret = true;+		}+		+		iter_pos += nl;+		+		if (iter_pos == carret) {+			draw_carret = true;+		}+		+		return n;+	}++	void create_border (Context cr, double x, double y) {+		double radius = margin;		+		double w = width;+		double h = height;+		+		cr.move_to (x, y + radius);+		cr.arc (x + radius, y + radius, radius, 2 * (PI / 2), 3 * (PI / 2));+		cr.line_to (x + w - radius, y);+		cr.arc (x + w - radius, y + radius, radius, 3 * (PI / 2), 4 * (PI / 2));+		cr.line_to (x + w, y + h);		+		cr.arc (x + w - radius, y + h, radius, 4 * (PI / 2), 5 * (PI / 2));+		cr.line_to (x + radius, y + h + radius);+		cr.arc (x + radius, y + h, radius, 5 * (PI / 2), 6 * (PI / 2));+		cr.line_to (x, y + radius);+		cr.close_path ();		+	}+}++}diff --git a/libbirdfont/Renderer/TextTab.vala b/libbirdfont/Renderer/TextTab.valadeleted file mode 100644index 5742b39..0000000--- a/libbirdfont/Renderer/TextTab.vala+++ /dev/null@@ -1,45 +0,0 @@-/*-    Copyright (C) 2014 Johan Mattsson--    This library is free software; you can redistribute it and/or modify -    it under the terms of the GNU Lesser General Public License as -    published by the Free Software Foundation; either version 3 of the -    License, or (at your option) any later version.--    This library is distributed in the hope that it will be useful, but -    WITHOUT ANY WARRANTY; without even the implied warranty of -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -    Lesser General Public License for more details.-*/--using Cairo;--namespace BirdFont {--/** Testing class for an experimental implementation of a birdfont rendering engine. */-public class TextTab : FontDisplay {--	Text text_area;-	Text text_area2;-	Text text_area3;--	public TextTab () {	-		text_area = new Text ();-		text_area.set_text ("Test");--		text_area2 = new Text ();-		text_area2.set_text ("Birdfont ÅÄÖ");--		text_area3 = new Text ();-		text_area3.load_font ("testfont.bf");-		text_area3.set_text ("TEST 3");-	}--	public override void draw (WidgetAllocation allocation, Context cr) {		-		text_area.draw (cr, 0, 0, 16);-		text_area2.draw (cr, 0, 100, 16);-		text_area3.draw (cr, 0, 200, 16);-	}	-}--}diff --git a/libbirdfont/SettingsItem.vala b/libbirdfont/SettingsItem.valaindex 75e205a..fcc7a28 100644--- a/libbirdfont/SettingsItem.vala+++ b/libbirdfont/SettingsItem.vala@@ -67,7 +67,8 @@ class SettingsItem : GLib.Object { 				 			cr.save (); 			cr.set_source_rgba (1, 1, 1, 1);-			label.draw (cr, 21 * MainWindow.units, y + 25 * MainWindow.units, 20 * MainWindow.units);+			label.set_font_size (20 * MainWindow.units);+			label.draw_at_baseline (cr, 21 * MainWindow.units, y + 25 * MainWindow.units); 			cr.restore (); 		} else { 			if (active) {@@ -88,7 +89,8 @@ class SettingsItem : GLib.Object { 			 			cr.save (); 			cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);-			label.draw (cr, label_x, y + 20 * MainWindow.units, 17 * MainWindow.units);+			label.set_font_size (17 * MainWindow.units);+			label.draw_at_baseline (cr, label_x, y + 20 * MainWindow.units); 			cr.restore (); 			 			if (key_bindings) {@@ -102,8 +104,9 @@ class SettingsItem : GLib.Object { 					cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 				} 				-				label_x += label.get_extent (17 * MainWindow.units) + 20 * MainWindow.units;-				key_binding_text.draw (cr, label_x, y + 20 * MainWindow.units, 17 * MainWindow.units);+				key_binding_text.set_font_size (17 * MainWindow.units);+				label_x += label.get_extent () + 20 * MainWindow.units;+				key_binding_text.draw_at_baseline (cr, label_x, y + 20 * MainWindow.units); 				cr.restore (); 			}	 		}diff --git a/libbirdfont/TabBar.vala b/libbirdfont/TabBar.valaindex 25e41b8..c5918c3 100644--- a/libbirdfont/TabBar.vala+++ b/libbirdfont/TabBar.vala@@ -774,7 +774,8 @@ public class TabBar : GLib.Object { 			label = new Text (); 			label.set_text (t.get_label ()); 			text_height = 16 / scale;-			text_width = label.get_extent (text_height);+			label.set_font_size (text_height);+			text_width = label.get_extent (); 			center_x = tab_width / 2.0 - text_width / 2.0; 			center_y = tab_height / 2.0 + 4 / scale; 			@@ -784,7 +785,8 @@ public class TabBar : GLib.Object { 				cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 			} 			-			label.draw (cr, center_x, center_y, text_height);+			label.set_font_size (text_height);+			label.draw_at_baseline (cr, center_x, center_y); 						 			// edges 			if (tab_index != selected) { // don't draw edges for the selected tabdiff --git a/libbirdfont/Widget.vala b/libbirdfont/Widget.valanew file mode 100644index 0000000..9e8b316--- /dev/null+++ b/libbirdfont/Widget.vala@@ -0,0 +1,31 @@+/*+    Copyright (C) 2014 Johan Mattsson++    This library is free software; you can redistribute it and/or modify +    it under the terms of the GNU Lesser General Public License as +    published by the Free Software Foundation; either version 3 of the +    License, or (at your option) any later version.++    This library is distributed in the hope that it will be useful, but +    WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +    Lesser General Public License for more details.+*/++using Cairo;+using Math;++namespace BirdFont {++public abstract class Widget : GLib.Object {++	public double margin_bottom = 0;+	public double widget_x = 0;+	public double widget_y = 0;++	public abstract double get_height ();+	public abstract double get_width ();+	public abstract void draw (Context cr);+}++}

Contact

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