Clone in a terminal:
Commit 7e367f8
Johan Mattsson - 2014-10-03T18:34:56+00:00
7e367f830822a94d609a44bf2d43e0b8caa5d75djohan.mattsson.m@gmail.com

Add abstract table class

Changed files (31)

Diff

diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex bb3c011..289b1e7 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -969,7 +969,6 @@ public class Glyph : FontDisplay { 		double xt, yt; 		Path np; 		EditPoint inserted;-		PathList pl; 		 		if (path_list.size == 0) { 			np = new Path ();diff --git a/libbirdfont/GlyphSequence.vala b/libbirdfont/GlyphSequence.valaindex 9339a0e..0a6ab7b 100644--- a/libbirdfont/GlyphSequence.vala+++ b/libbirdfont/GlyphSequence.vala@@ -58,7 +58,7 @@ public class GlyphSequence { 		}); 		 		ligature_sequence.ranges.clear ();-		foreach (Glyph? g in ligature_sequence.glyph) {+		for (int i = 0; i < ligature_sequence.glyph.size; i++) { 			ligature_sequence.ranges.add (null); 		} 		diff --git a/libbirdfont/GridTool.vala b/libbirdfont/GridTool.valaindex 15a8b32..50bda3f 100644--- a/libbirdfont/GridTool.vala+++ b/libbirdfont/GridTool.vala@@ -90,17 +90,6 @@ class GridTool : Tool { 		 		update_lines (); 	}-	-	public static void ttf_grid (ref int pixel_x, ref int pixel_y) {-		double coordinate_x = Glyph.path_coordinate_x (pixel_x);-		double coordinate_y = Glyph.path_coordinate_y (pixel_y);-		-		coordinate_x = GlyfData.tie_to_ttf_grid_x (MainWindow.get_current_glyph (), coordinate_x);-		coordinate_y = GlyfData.tie_to_ttf_grid_y (BirdFont.get_current_font (), coordinate_y);-		-		pixel_x = Glyph.reverse_path_coordinate_x (coordinate_x);-		pixel_y = Glyph.reverse_path_coordinate_y (coordinate_y);-	}  	public static void ttf_grid_coordinate (ref double x, ref double y) { 		x = GlyfData.tie_to_ttf_grid_x (MainWindow.get_current_glyph (), x);diff --git a/libbirdfont/KerningList.vala b/libbirdfont/KerningList.valaindex 66b243d..1302bcc 100644--- a/libbirdfont/KerningList.vala+++ b/libbirdfont/KerningList.vala@@ -177,27 +177,28 @@ public class KerningList : FontDisplay { 		glyph_range_first = new GlyphRange (); 		glyph_range_next = new GlyphRange (); 		-		glyph_range_first.parse_ranges (left);-		glyph_range_next.parse_ranges (right);-							 		try {-			if (left != "" && right != "") {-				if (glyph_range_first.is_class () || glyph_range_next.is_class ()) {-					-					kerning = classes.get_kerning_for_range (glyph_range_first, glyph_range_next);-					class_index = classes.get_kerning_item_index (glyph_range_first, glyph_range_next);-					-					classes.delete_kerning_for_class (left, right);-				} else {-					kerning = classes.get_kerning (left, right);-					classes.delete_kerning_for_pair (left, right);-				}+			glyph_range_first.parse_ranges (left);+			glyph_range_next.parse_ranges (right);+		} catch (GLib.MarkupError e) {+			warning (e.message);+			return;+		}++		if (left != "" && right != "") {+			if (glyph_range_first.is_class () || glyph_range_next.is_class ()) {+				+				kerning = classes.get_kerning_for_range (glyph_range_first, glyph_range_next);+				class_index = classes.get_kerning_item_index (glyph_range_first, glyph_range_next); 				-				undo_items.add (new UndoItem (left, right, kerning, class_index));-				font.touch ();+				classes.delete_kerning_for_class (left, right);+			} else {+				kerning = classes.get_kerning (left, right);+				classes.delete_kerning_for_pair (left, right); 			}-		} catch (MarkupError e) {-			warning (e.message);+			+			undo_items.add (new UndoItem (left, right, kerning, class_index));+			font.touch (); 		} 	} diff --git a/libbirdfont/LigatureList.vala b/libbirdfont/LigatureList.valaindex 5c49276..fc81e04 100644--- a/libbirdfont/LigatureList.vala+++ b/libbirdfont/LigatureList.vala@@ -17,134 +17,77 @@ using Math;  namespace BirdFont { -public class LigatureList : FontDisplay {-	-	int scroll = 0;-	int visible_rows = 0;-	WidgetAllocation allocation;+public class LigatureList : Table {+	Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> ();++	public const int NEW_LIGATURE = -1; 	 	public LigatureList () {-		allocation = new WidgetAllocation (); 	} -	public override void draw (WidgetAllocation allocation, Context cr) {-		Ligatures ligatures = BirdFont.get_current_font ().get_ligatures ();-		int y = 20;-		int s = 0;-		bool color = (scroll % 2) == 0;-		-		this.allocation = allocation;-		-		visible_rows = (int) (allocation.height / 18.0);-		-		cr.save ();-		cr.set_source_rgba (1, 1, 1, 1);-		cr.rectangle (0, 0, allocation.width, allocation.height);-		cr.fill ();-		cr.restore ();-		-		cr.save ();-		cr.set_source_rgba (0.3, 0.3, 0.3, 1);-		cr.set_font_size (12);--		ligatures.get_ligatures ((substitution, ligature) => {-			if (s++ >= scroll) {-				draw_row (allocation, cr, substitution, ligature, y, color);-				y += 18;-				color = !color;-			}-		});-		-		cr.restore ();-	}	--	private static void draw_row (WidgetAllocation allocation, Context cr,-		string substitution, string ligature, int y, bool color) {--		if (color) {-			cr.save ();-			cr.set_source_rgba (224/255.0, 224/255.0, 224/255.0, 1);-			cr.rectangle (0, y - 14, allocation.width, 18);-			cr.fill ();-			cr.restore ();-		}-		-		cr.move_to (30, y);-		cr.show_text (substitution);-		cr.move_to (230, y);-		cr.show_text (ligature);+	public override Gee.ArrayList<Row> get_rows () {+		return rows; 	} -	public override string get_label () {-		return t_("Ligatures");+	void add_ligature (string subst, string liga) {+		Font font = BirdFont.get_current_font ();+		Ligatures ligatures = font.get_ligatures ();+		ligatures.add_ligature (subst, liga); 	} -	public override string get_name () {-		return "Ligatures";-	}+	public override void selected_row (Row row, int column, bool delete_button) {+		Font font = BirdFont.get_current_font ();+		Ligatures ligatures = font.get_ligatures ();+		+		if (row.get_index () == NEW_LIGATURE) {+			add_ligature (t_("substitute"), t_("ligature"));+			MainWindow.native_window.hide_text_input ();+		} else if (ligatures.count () != 0) {+			if (delete_button) {+				return_if_fail (0 <= row.get_index () < ligatures.count ());+				ligatures.remove_at (row.get_index ());+				MainWindow.native_window.hide_text_input ();+			} else if (column == 0) {+				if (!(0 <= row.get_index () < ligatures.count ())) {+					warning (@"Index: $(row.get_index ()) ligatures.count (): $(ligatures.count ())");+					return;+				}+				ligatures.set_ligature (row.get_index ());+			} else if (column == 2) {+				return_if_fail (0 <= row.get_index () < ligatures.count ());+				ligatures.set_substitution (row.get_index ());+			}+		} -	public override bool has_scrollbar () {-		return true;+		update_rows ();+		update_scrollbar ();+		font.touch (); 	}-	-	public override void scroll_wheel_down (double x, double y) {-		Ligatures ligatures = BirdFont.get_current_font ().get_ligatures ();-		uint liga = ligatures.count ();-		scroll += 3; -		if (scroll > liga - visible_rows) {-			scroll = (int) (liga - visible_rows);-		}-		-		if (visible_rows > liga) {-			scroll = 0;-		} +	public override void update_rows () {+		int i;+		Font font = BirdFont.get_current_font ();+		Ligatures ligatures = font.get_ligatures (); 		-		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);-	}-	-	public override void scroll_wheel_up (double x, double y) {-		scroll -= 3;+		rows.clear ();+		rows.add (new Row (t_("New Ligature"), NEW_LIGATURE, false)); 		-		if (scroll < 0) {-			scroll = 0;-		}+		i = 0;+		ligatures.get_ligatures ((subst, liga) => {+			rows.add (new Row.columns_3 (@"$subst", "->",  @"$liga", i));+			i++;+		}); 		-		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);-	}--	public override void selected_canvas () {-		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	}-	-	public void update_scrollbar () {-		Ligatures ligatures = BirdFont.get_current_font ().get_ligatures ();-		uint rows = ligatures.count (); -		if (rows == 0 || visible_rows == 0) {-			MainWindow.set_scrollbar_size (0);-			MainWindow.set_scrollbar_position (0);-		} else {-			MainWindow.set_scrollbar_size ((double) visible_rows / rows);-			MainWindow.set_scrollbar_position ((double) scroll /  rows);-		}+	public override string get_label () {+		return t_("Ligatures"); 	} -	public override void scroll_to (double percent) {-		Ligatures ligatures = BirdFont.get_current_font ().get_ligatures ();-		uint liga = ligatures.count ();-		scroll = (int) (percent * liga);-		-		if (scroll > liga - visible_rows) {-			scroll = (int) (liga - visible_rows);-		}-		-		redraw_area (0, 0, allocation.width, allocation.height);+	public override string get_name () {+		return "Ligatures"; 	} }  }-diff --git a/libbirdfont/Ligatures.vala b/libbirdfont/Ligatures.valaindex 81e2713..d545956 100644--- a/libbirdfont/Ligatures.vala+++ b/libbirdfont/Ligatures.vala@@ -19,6 +19,9 @@ namespace BirdFont {  public class Ligatures : GLib.Object { 	+	public Gee.ArrayList<string> ligature = new Gee.ArrayList<string> ();+	public Gee.ArrayList<string> substitution = new Gee.ArrayList<string> ();+	 	public delegate void LigatureIterator (string substitution, string ligature); 	public delegate void SingleLigatureIterator (GlyphSequence substitution, GlyphCollection ligature); @@ -64,10 +67,26 @@ public class Ligatures : GLib.Object { 	} 		 	public int count () {-		return 1;+		return ligature.size;+	}+	+	public void remove_at (int i) {+		return_if_fail (0 <= i < ligature.size);+		return_if_fail (0 <= i < substitution.size);+		ligature.remove_at (i);+		substitution.remove_at (i); 	} 	+	public void set_ligature (int index) {+	} 	+	public void set_substitution (int index) {+	}	++	public void add_ligature (string subst, string liga) {+		substitution.insert (0, subst);+		ligature.insert (0, liga);+	} }  }diff --git a/libbirdfont/OpenFontFormat/CffTable.vala b/libbirdfont/OpenFontFormat/CffTable.valaindex 901c07d..d64dcdd 100644--- a/libbirdfont/OpenFontFormat/CffTable.vala+++ b/libbirdfont/OpenFontFormat/CffTable.vala@@ -15,7 +15,7 @@ namespace BirdFont {  /** Type2, PostScript outlines */-public class CffTable : Table {+public class CffTable : OtfTable {  	static const uint8 HSTEM = 1; 	static const uint8 VSTEM = 3;diff --git a/libbirdfont/OpenFontFormat/Cmap.vala b/libbirdfont/OpenFontFormat/Cmap.valaindex e3a505b..dc669b6 100644--- a/libbirdfont/OpenFontFormat/Cmap.vala+++ b/libbirdfont/OpenFontFormat/Cmap.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class CmapTable : Table { +public class CmapTable : OtfTable {  	 	GlyfTable glyf_table;	 	CmapSubtableFormat4 cmap_format4 = new CmapSubtableFormat4 ();diff --git a/libbirdfont/OpenFontFormat/CvtTable.vala b/libbirdfont/OpenFontFormat/CvtTable.valaindex 423fbad..3fd85f3 100644--- a/libbirdfont/OpenFontFormat/CvtTable.vala+++ b/libbirdfont/OpenFontFormat/CvtTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class CvtTable : Table {+public class CvtTable : OtfTable { 	 	public CvtTable () { 		id = "cvt ";diff --git a/libbirdfont/OpenFontFormat/DirectoryTable.vala b/libbirdfont/OpenFontFormat/DirectoryTable.valaindex 5097cad..f42bbd3 100644--- a/libbirdfont/OpenFontFormat/DirectoryTable.vala+++ b/libbirdfont/OpenFontFormat/DirectoryTable.vala@@ -15,7 +15,7 @@ namespace BirdFont {  /** Table with list of tables sorted by table tag. */-public class DirectoryTable : Table {+public class DirectoryTable : OtfTable { 	 	public CmapTable cmap_table; 	public CvtTable  cvt_table;@@ -36,7 +36,7 @@ public class DirectoryTable : Table { 	 	public OffsetTable offset_table; 	-	Gee.ArrayList<Table> tables;+	Gee.ArrayList<OtfTable> tables; 	 	public DirectoryTable () { 		offset_table = new OffsetTable (this);@@ -60,7 +60,7 @@ public class DirectoryTable : Table { 		 		id = "Directory table"; 		-		tables = new Gee.ArrayList<Table> ();+		tables = new Gee.ArrayList<OtfTable> (); 	}  	public void process () throws GLib.Error {@@ -86,7 +86,7 @@ public class DirectoryTable : Table { 		process_directory (); // this table 	} -	public Gee.ArrayList<Table> get_tables () {+	public Gee.ArrayList<OtfTable> get_tables () { 		if (tables.size == 0) { 			tables.add (offset_table); 			tables.add (this);@@ -393,7 +393,7 @@ public class DirectoryTable : Table { 	public long get_font_file_size () { 		long length = 0; 		-		foreach (Table t in tables) {+		foreach (OtfTable t in tables) { 			length += t.get_font_data ().length_with_padding (); 		} 		@@ -408,7 +408,7 @@ public class DirectoryTable : Table { 	// Check sum adjustment for the entire font 	public uint32 get_font_file_checksum () { 		uint32 check_sum = 0;-		foreach (Table t in tables) {+		foreach (OtfTable t in tables) { 			t.get_font_data ().continous_check_sum (ref check_sum); 		} 		return check_sum;@@ -436,7 +436,7 @@ public class DirectoryTable : Table { 		head_table.process (); 		 		// write the directory -		foreach (Table t in tables) {+		foreach (OtfTable t in tables) { 						 			if (t is DirectoryTable || t is OffsetTable) { 				continue;diff --git a/libbirdfont/OpenFontFormat/FontData.vala b/libbirdfont/OpenFontFormat/FontData.valaindex bb93f5a..8ad2391 100644--- a/libbirdfont/OpenFontFormat/FontData.vala+++ b/libbirdfont/OpenFontFormat/FontData.vala@@ -102,7 +102,7 @@ public class FontData : Object { 		uint l; 		 		if (length_with_padding () % 4 != 0) {-			warning ("Table is not padded to correct size.");+			warning ("OtfTable is not padded to correct size."); 		} 				 		seek (0);diff --git a/libbirdfont/OpenFontFormat/GaspTable.vala b/libbirdfont/OpenFontFormat/GaspTable.valaindex 0c57490..3c6b198 100644--- a/libbirdfont/OpenFontFormat/GaspTable.vala+++ b/libbirdfont/OpenFontFormat/GaspTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class GaspTable : Table {+public class GaspTable : OtfTable {  	public const uint16 NONE = 0; 	public const uint16 GASP_GRIDFIT = 1;diff --git a/libbirdfont/OpenFontFormat/GdefTable.vala b/libbirdfont/OpenFontFormat/GdefTable.valaindex 94a897f..031b779 100644--- a/libbirdfont/OpenFontFormat/GdefTable.vala+++ b/libbirdfont/OpenFontFormat/GdefTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class GdefTable : Table {+public class GdefTable : OtfTable { 	 	public GdefTable () { 		id = "GDEF";diff --git a/libbirdfont/OpenFontFormat/GlyfTable.vala b/libbirdfont/OpenFontFormat/GlyfTable.valaindex 68aa713..1c796aa 100644--- a/libbirdfont/OpenFontFormat/GlyfTable.vala+++ b/libbirdfont/OpenFontFormat/GlyfTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class GlyfTable : Table {+public class GlyfTable : OtfTable { 	// Flags for composite glyph 	static const uint16 BOTH_ARE_WORDS = 1 << 0; 	static const uint16 BOTH_ARE_XY_VALUES = 1 << 1;diff --git a/libbirdfont/OpenFontFormat/GposTable.vala b/libbirdfont/OpenFontFormat/GposTable.valaindex 7ac8653..c19c7ca 100644--- a/libbirdfont/OpenFontFormat/GposTable.vala+++ b/libbirdfont/OpenFontFormat/GposTable.vala@@ -15,7 +15,7 @@ using Math;  namespace BirdFont { -public class GposTable : Table {+public class GposTable : OtfTable { 	 	GlyfTable glyf_table; 	KernList pairs;diff --git a/libbirdfont/OpenFontFormat/GsubTable.vala b/libbirdfont/OpenFontFormat/GsubTable.valaindex 3a23bd9..a584f9e 100644--- a/libbirdfont/OpenFontFormat/GsubTable.vala+++ b/libbirdfont/OpenFontFormat/GsubTable.vala@@ -15,7 +15,7 @@ using Math;  namespace BirdFont { -public class GsubTable : Table {+public class GsubTable : OtfTable { 	 	GlyfTable glyf_table; 	@@ -155,7 +155,7 @@ public class GsubTable : Table { 			warning (@"Bad identifier expecting 1 found $identifier"); 		} 		-		uint16 coverage_offset = fd.read_ushort ();+		uint16 coverage_offset = fd.read_ushort (); // TODO: read coverage 		uint16 num_sets = fd.read_ushort (); 		 		Gee.ArrayList<int> liga_set_offsets = new Gee.ArrayList<int> ();diff --git a/libbirdfont/OpenFontFormat/HeadTable.vala b/libbirdfont/OpenFontFormat/HeadTable.valaindex 71853bd..c32004e 100644--- a/libbirdfont/OpenFontFormat/HeadTable.vala+++ b/libbirdfont/OpenFontFormat/HeadTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class HeadTable : Table {+public class HeadTable : OtfTable {  	public int16 xmin = int16.MIN; 	public int16 ymin = int16.MIN;diff --git a/libbirdfont/OpenFontFormat/HheaTable.vala b/libbirdfont/OpenFontFormat/HheaTable.valaindex 20c4ca3..07376b7 100644--- a/libbirdfont/OpenFontFormat/HheaTable.vala+++ b/libbirdfont/OpenFontFormat/HheaTable.vala@@ -16,7 +16,7 @@ using Math;  namespace BirdFont { -public class HheaTable : Table {+public class HheaTable : OtfTable {  	Fixed version; 	int16 ascender;diff --git a/libbirdfont/OpenFontFormat/HmtxTable.vala b/libbirdfont/OpenFontFormat/HmtxTable.valaindex c68d11b..f460b0d 100644--- a/libbirdfont/OpenFontFormat/HmtxTable.vala+++ b/libbirdfont/OpenFontFormat/HmtxTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class HmtxTable : Table {+public class HmtxTable : OtfTable { 	 	uint32 nmetrics; 	uint32 nmonospaced;diff --git a/libbirdfont/OpenFontFormat/KernTable.vala b/libbirdfont/OpenFontFormat/KernTable.valaindex 73555c3..d942110 100644--- a/libbirdfont/OpenFontFormat/KernTable.vala+++ b/libbirdfont/OpenFontFormat/KernTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class KernTable : Table {+public class KernTable : OtfTable { 	 	public static const uint16 HORIZONTAL = 1; 	public static const uint16 MINIMUM = 1 << 1;diff --git a/libbirdfont/OpenFontFormat/LigatureSet.vala b/libbirdfont/OpenFontFormat/LigatureSet.valaindex 1bc638c..d8c4629 100644--- a/libbirdfont/OpenFontFormat/LigatureSet.vala+++ b/libbirdfont/OpenFontFormat/LigatureSet.vala@@ -43,7 +43,7 @@ public class LigatureSet : GLib.Object { 		return (!) ligatures.get (0).substitution.get (0).to_string (); 	} 	-	public FontData get_set_data () {+	public FontData get_set_data () throws GLib.Error { 		FontData fd, ligature_data; 		uint16 o, pos; 		diff --git a/libbirdfont/OpenFontFormat/LocaTable.vala b/libbirdfont/OpenFontFormat/LocaTable.valaindex a8c34b7..eaf7ca6 100644--- a/libbirdfont/OpenFontFormat/LocaTable.vala+++ b/libbirdfont/OpenFontFormat/LocaTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class LocaTable : Table {+public class LocaTable : OtfTable { 	 	uint32* glyph_offsets = null; 	public uint32 size = 0;diff --git a/libbirdfont/OpenFontFormat/MaxpTable.vala b/libbirdfont/OpenFontFormat/MaxpTable.valaindex 99bbbf7..e4c5054 100644--- a/libbirdfont/OpenFontFormat/MaxpTable.vala+++ b/libbirdfont/OpenFontFormat/MaxpTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class MaxpTable : Table {+public class MaxpTable : OtfTable { 	 	GlyfTable glyf_table; 	diff --git a/libbirdfont/OpenFontFormat/NameTable.vala b/libbirdfont/OpenFontFormat/NameTable.valaindex c2b51a6..f382a10 100644--- a/libbirdfont/OpenFontFormat/NameTable.vala+++ b/libbirdfont/OpenFontFormat/NameTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class NameTable : Table {+public class NameTable : OtfTable {  	public static const uint16 COPYRIGHT_NOTICE = 0; 	public static const uint16 FONT_NAME = 1;diff --git a/libbirdfont/OpenFontFormat/OffsetTable.vala b/libbirdfont/OpenFontFormat/OffsetTable.valaindex eb0bd80..5e06f8d 100644--- a/libbirdfont/OpenFontFormat/OffsetTable.vala+++ b/libbirdfont/OpenFontFormat/OffsetTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class OffsetTable : Table {+public class OffsetTable : OtfTable { 	DirectoryTable directory_table; 		 	public uint16 num_tables = 0;diff --git a/libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala b/libbirdfont/OpenFontFormat/OpenFontFormatWriter.valaindex b13f88a..5783eb9 100644--- a/libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala+++ b/libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala@@ -43,7 +43,7 @@ public class OpenFontFormatWriter : Object  { 	public void write_ttf_font (Font nfont) throws Error { 		long dl; 		uint8* data;-		Gee.ArrayList<Table> tables;+		Gee.ArrayList<OtfTable> tables; 		FontData fd; 		uint l; 		@@ -59,7 +59,7 @@ public class OpenFontFormatWriter : Object  { 			return; 		} 		-		foreach (Table t in tables) {+		foreach (OtfTable t in tables) { 			fd = t.get_font_data (); 			data = fd.table_data; 			l = fd.length_with_padding ();diff --git a/libbirdfont/OpenFontFormat/Os2Table.vala b/libbirdfont/OpenFontFormat/Os2Table.valaindex b5647a2..4d1ff1e 100644--- a/libbirdfont/OpenFontFormat/Os2Table.vala+++ b/libbirdfont/OpenFontFormat/Os2Table.vala@@ -16,7 +16,7 @@ using Math;  namespace BirdFont { -public class Os2Table : Table {+public class Os2Table : OtfTable { 	 	public static const uint16 ITALIC = 1; 	public static const uint16 UNDERSCORE = 1 << 1;diff --git a/libbirdfont/OpenFontFormat/OtfTable.vala b/libbirdfont/OpenFontFormat/OtfTable.valanew file mode 100644index 0000000..ed6cdff--- /dev/null+++ b/libbirdfont/OpenFontFormat/OtfTable.vala@@ -0,0 +1,113 @@++/*+    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 {++public class OtfTable : Object {++	public string id = "NO_ID";++	public uint32 checksum = 0;+	public uint32 offset = 0;+	public uint32 length = 0;++	protected FontData? font_data = null;++	public virtual string get_id () {+		return id;+	}+	+	public FontData get_font_data () {+		if (font_data == null) {+			warning (@"No font data for $(id).");+			font_data = new FontData ();+		}+		+		return (!) font_data;+	}++	public bool has_data () {+		return length > 0;+	}++	public virtual void parse (FontData dis) throws GLib.Error {+		warning (@"Parse is not implemented for $(id).");+	}++	/** Validate table checksum. */+	public bool validate (FontData dis) {+		bool valid;+		+		if (length == 0) {+			stderr.printf (@"OtfTable $id is of zero length.\n");			+			valid = false;+		} else {+			valid = OtfTable.validate_table (dis, checksum, offset, length, id);+		}+		+		if (!valid) {+			stderr.printf (@"OtfTable $id is invalid.\n");+		}+		+		return valid;+	}++	public static bool validate_table (FontData dis, uint32 checksum, uint32 offset, uint32 length, string name) {+		uint32 ch = calculate_checksum (dis, offset, length, name);+		bool c;+		+		c = (ch == checksum);+	+		if (!c) {+			stderr.printf(@"Checksum does not match data for $(name).\n");+			stderr.printf(@"name: $name, checksum: $checksum, offset: $offset, length: $length\n");+			stderr.printf(@"calculated checksum $(ch)\n");+		}+		+		return c;	+	}+	+	public static uint32 calculate_checksum (FontData dis, uint32 offset, uint32 length, string name) {+		uint32 checksum = 0;+		uint32 l;+			 +		dis.seek (offset);++		l = (length % 4 > 0) ? length / 4 + 1 : length / 4; ++		for (uint32 i = 0; i < l; i++) {+			checksum += dis.read_ulong ();+		}+		+		return checksum;+	}+	+	public static uint16 max_pow_2_less_than_i (uint16 ind) {+		uint16 last = 0;+		uint16 i = 1;+		+		while ((i <<= 1) < ind) {+			last = i;+		}+		+		return last;+	}++	public static uint16 max_log_2_less_than_i (uint16 ind) {+		return (uint16) (Math.log (ind) / Math.log (2));+	}+}++}diff --git a/libbirdfont/OpenFontFormat/PostTable.vala b/libbirdfont/OpenFontFormat/PostTable.valaindex 13c178e..aa08dce 100644--- a/libbirdfont/OpenFontFormat/PostTable.vala+++ b/libbirdfont/OpenFontFormat/PostTable.vala@@ -14,7 +14,7 @@  namespace BirdFont { -public class PostTable : Table {+public class PostTable : OtfTable { 	 	GlyfTable glyf_table; 	diff --git a/libbirdfont/OpenFontFormat/Table.vala b/libbirdfont/OpenFontFormat/Table.valadeleted file mode 100644index 1f23b7e..0000000--- a/libbirdfont/OpenFontFormat/Table.vala+++ /dev/null@@ -1,113 +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 {--public class Table : Object {--	public string id = "NO_ID";--	public uint32 checksum = 0;-	public uint32 offset = 0;-	public uint32 length = 0;--	protected FontData? font_data = null;--	public virtual string get_id () {-		return id;-	}-	-	public FontData get_font_data () {-		if (font_data == null) {-			warning (@"No font data for $(id).");-			font_data = new FontData ();-		}-		-		return (!) font_data;-	}--	public bool has_data () {-		return length > 0;-	}--	public virtual void parse (FontData dis) throws GLib.Error {-		warning (@"Parse is not implemented for $(id).");-	}--	/** Validate table checksum. */-	public bool validate (FontData dis) {-		bool valid;-		-		if (length == 0) {-			stderr.printf (@"Table $id is of zero length.\n");			-			valid = false;-		} else {-			valid = Table.validate_table (dis, checksum, offset, length, id);-		}-		-		if (!valid) {-			stderr.printf (@"Table $id is invalid.\n");-		}-		-		return valid;-	}--	public static bool validate_table (FontData dis, uint32 checksum, uint32 offset, uint32 length, string name) {-		uint32 ch = calculate_checksum (dis, offset, length, name);-		bool c;-		-		c = (ch == checksum);-	-		if (!c) {-			stderr.printf(@"Checksum does not match data for $(name).\n");-			stderr.printf(@"name: $name, checksum: $checksum, offset: $offset, length: $length\n");-			stderr.printf(@"calculated checksum $(ch)\n");-		}-		-		return c;	-	}-	-	public static uint32 calculate_checksum (FontData dis, uint32 offset, uint32 length, string name) {-		uint32 checksum = 0;-		uint32 l;-			 -		dis.seek (offset);--		l = (length % 4 > 0) ? length / 4 + 1 : length / 4; --		for (uint32 i = 0; i < l; i++) {-			checksum += dis.read_ulong ();-		}-		-		return checksum;-	}-	-	public static uint16 max_pow_2_less_than_i (uint16 ind) {-		uint16 last = 0;-		uint16 i = 1;-		-		while ((i <<= 1) < ind) {-			last = i;-		}-		-		return last;-	}--	public static uint16 max_log_2_less_than_i (uint16 ind) {-		return (uint16) (Math.log (ind) / Math.log (2));-	}-}--}diff --git a/libbirdfont/SpacingClassTab.vala b/libbirdfont/SpacingClassTab.valaindex 7d3c921..5ba2439 100644--- a/libbirdfont/SpacingClassTab.vala+++ b/libbirdfont/SpacingClassTab.vala@@ -16,22 +16,20 @@ using Math;  namespace BirdFont { -public class SpacingClassTab : FontDisplay {--	int scroll = 0;-	int visible_rows = 0;-	WidgetAllocation allocation = new WidgetAllocation ();-	Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> ();+public class SpacingClassTab : Table { 	 	public Gee.ArrayList<SpacingClass> classes = new Gee.ArrayList<SpacingClass> ();-	 	public static int NEW_CLASS = -1;-	 	Gee.ArrayList<string> connections = new Gee.ArrayList<string> ();+	Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> (); 	 	public SpacingClassTab () { 	} +	public override Gee.ArrayList<Row> get_rows () {+		return rows;+	}+ 	public static void remove_all_spacing_classes () { 		if (!is_null (MainWindow.spacing_class_tab)) { 			MainWindow.spacing_class_tab.classes.clear ();@@ -109,7 +107,7 @@ public class SpacingClassTab : FontDisplay { 		KerningTools.update_spacing_classes (); 	} -	public void selected_row (Row row, int column, bool delete_button) {+	public override void selected_row (Row row, int column, bool delete_button) { 		Font font = BirdFont.get_current_font (); 		 		if (row.get_index () == -1) {@@ -140,17 +138,12 @@ public class SpacingClassTab : FontDisplay { 			} 		} 	}--	public override void selected_canvas () {-		update_rows ();-		update_scrollbar ();-	} 	 	void update_all_rows (SpacingClass s) { 		update_rows (); 	} 	-	void update_rows () {+	public override void update_rows () { 		int i = 0; 		 		rows.clear ();@@ -163,109 +156,6 @@ public class SpacingClassTab : FontDisplay { 		 		GlyphCanvas.redraw (); 	}-	-	public override void draw (WidgetAllocation allocation, Context cr) {-		double y = 20 * MainWindow.units;-		int s = 0;-		bool color = (scroll + 1 % 2) == 0;-		-		if (allocation.width != this.allocation.width-				|| allocation.height != this.allocation.height) {-			this.allocation = allocation;-			update_rows ();-			update_scrollbar ();-		}-		-		visible_rows = (int) (allocation.height / 18.0);-		-		cr.save ();-		cr.set_source_rgba (1, 1, 1, 1);-		cr.rectangle (0, 0, allocation.width, allocation.height);-		cr.fill ();-		cr.restore ();-		-		cr.save ();-		cr.set_source_rgba (0.3, 0.3, 0.3, 1);-		cr.set_font_size (12);--		foreach (Row r in rows) {-			if (s++ >= scroll) {-				draw_row (allocation, cr, r, y, color, true);-				y += 18 * MainWindow.units;-				color = !color;-			}-		}-		-		cr.restore ();-	}	--	private static void draw_row (WidgetAllocation allocation, Context cr,-			Row row, double y, bool color, bool dark) {-		-		double margin;-	-		if (color) {-			cr.save ();-			cr.set_source_rgba (224/255.0, 224/255.0, 224/255.0, 1);-			cr.rectangle (0, y - 14 * MainWindow.units, allocation.width, 18 * MainWindow.units);-			cr.fill ();-			cr.restore ();-		}--		if (row.has_delete_button ()) {-			cr.save ();-			cr.set_line_width (1);-			cr.move_to (10 * MainWindow.units, y - 8 * MainWindow.units);-			cr.line_to (15 * MainWindow.units, y - 3 * MainWindow.units);-			cr.move_to (10 * MainWindow.units, y - 3 * MainWindow.units);-			cr.line_to (15 * MainWindow.units, y - 8 * MainWindow.units);		-			cr.stroke ();-			cr.restore ();-		}-		-		for (int i = 0; i < row.columns; i++) {-			cr.save ();-			margin = (row.has_delete_button ()) ? 120 * MainWindow.units : 3* MainWindow.units;-			cr.move_to (margin + i * 120 * MainWindow.units, y);-			cr.set_font_size (12 * MainWindow.units);-			cr.show_text (row.get_column (i));-			cr.restore ();-		}-	}--	public override void button_release (int button, double ex, double ey) {-		int s = 0;-		double y = 0;-		int colum = -1;-		Row? selected = null;-		bool over_delete = false;--		foreach (Row r in rows) {-			if (s++ >= scroll) {-				y += 18 * MainWindow.units;-				-				if (y - 10 * MainWindow.units <= ey * MainWindow.units <= y + 5 * MainWindow.units) {-					-					if (r.has_delete_button ()) {-						colum = (int) ((ex - 120) / 120 * MainWindow.units);-					} else {-						colum = (int) ((ex) / 120 * MainWindow.units);-					}-					-					over_delete = (ex < 18 && r.has_delete_button ());-					selected = r;-					break;-				}-			}-		}-		-		if (selected != null) {-			selected_row ((!) selected, colum, over_delete);	-		}-		-		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);-	}  	public override string get_label () { 		return t_("Spacing Classes");@@ -274,60 +164,6 @@ public class SpacingClassTab : FontDisplay { 	public override string get_name () { 		return "SpacingClasses"; 	}--	public override bool has_scrollbar () {-		return true;-	}-	-	public override void scroll_wheel_down (double x, double y) {-		int nrows = rows.size;-		scroll += 3;--		if (scroll > nrows - visible_rows) {-			scroll = (int) (nrows - visible_rows);-		}-		-		if (visible_rows > nrows) {-			scroll = 0;-		} -		-		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);-	}-	-	public override void scroll_wheel_up (double x, double y) {-		scroll -= 3;-		-		if (scroll < 0) {-			scroll = 0;-		}-		-		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);-	}-	-	public void update_scrollbar () {-		uint rows = rows.size;--		if (rows == 0 || visible_rows == 0) {-			MainWindow.set_scrollbar_size (0);-			MainWindow.set_scrollbar_position (0);-		} else {-			MainWindow.set_scrollbar_size ((double) visible_rows / rows);-			MainWindow.set_scrollbar_position ((double) scroll /  rows);-		}-	}--	public override void scroll_to (double percent) {-		uint rows = rows.size;-		scroll = (int) (percent * rows);-		-		if (scroll > rows - visible_rows) {-			scroll = (int) (rows - visible_rows);-		}-		-		redraw_area (0, 0, allocation.width, allocation.height);-	} }  }

Contact

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