Clone in a terminal:
Commit 5bd47f4
unknown - 2012-08-05T11:31:32+00:00
5bd47f4d07dde69edcea1598b7852a7433b54e4ajohan.mattsson.m@gmail.com

Merge branch 'master' of gitorious.org:supplement/supplement

Changed files (7)

Diff

diff --git a/src/EditPoint.vala b/src/EditPoint.valaindex e6e9776..20c0dfc 100644--- a/src/EditPoint.vala+++ b/src/EditPoint.vala@@ -23,6 +23,7 @@ using Math; namespace Supplement {  enum PointType {+	NONE, 	NORMAL, 	LINE, 	CURVE,diff --git a/src/ExportTool.vala b/src/ExportTool.valaindex baa2f09..a195eaa 100644--- a/src/ExportTool.vala+++ b/src/ExportTool.vala@@ -178,7 +178,7 @@ class ExportTool : Tool {  		@font-face{ 			font-family: '"""); os.put_string (@"$(name)");              os.put_string ("""';-			src: url('""");     os.put_string (@"$(name).svg#$(name)");  os.put_string ("""') format('svg');+			src: url('""");     os.put_string (@"$(name).svg#$(name)");  os.put_string ("""') format('svg'), url('""");     os.put_string (@"$(name).ttf"); os.put_string ("""') format('truetype'); 		}  		h1 {diff --git a/src/OpenFontFormatReader.vala b/src/OpenFontFormatReader.valaindex 83ae51b..e492588 100644--- a/src/OpenFontFormatReader.vala+++ b/src/OpenFontFormatReader.vala@@ -94,9 +94,7 @@ class OpenFontFormatReader : Object { 		 		directory_table = new DirectoryTable (); 		directory_table.set_offset_table (offset_table);-		directory_table.parse (dis, file);-		-		set_limits ();+		directory_table.parse (dis, file, this); 	}  	public void set_limits () {@@ -108,6 +106,7 @@ class OpenFontFormatReader : Object { 			f.base_line = 0; 			f.top_position = -get_ascender (); 			f.top_limit = f.top_position - 5;+			f.xheight_position = f.top_position - 5; 			f.bottom_position = -get_descender (); 			f.bottom_limit = f.bottom_position + 5;	 diff --git a/src/OpenFontFormatWriter.vala b/src/OpenFontFormatWriter.valaindex 4c60382..8176fa4 100644--- a/src/OpenFontFormatWriter.vala+++ b/src/OpenFontFormatWriter.vala@@ -600,8 +600,6 @@ class LocaTable : Table { 			foreach (uint32 o in glyf_table.location_offsets) {
 				fd.add_u16 ((uint16) (o / 2));
 				
-				printd (@"o0: $(o)\n");
-				
 				if (o < last) {
 					warning (@"Loca table must be sorted. ($o < $last)");
 				}
@@ -612,9 +610,7 @@ class LocaTable : Table { 		} else if (head_table.loca_offset_size == 1) {
 			foreach (uint32 o in glyf_table.location_offsets) {
 				fd.add_u32 (o);
-				
-				printd (@"o1: $(o)\n");
-				
+
 				if (o < last) {
 					warning (@"Loca table must be sorted. ($o < $last)");
 				}
@@ -1075,8 +1071,8 @@ class GlyfTable : Table { 					path.add_point (edit_point);
 					
 					if (prev_is_curve) {
-						edit_point.get_left_handle ().set_point_type (PointType.CURVE);
-						edit_point.get_left_handle ().length = 0;						
+						edit_point.get_left_handle ().set_point_type (PointType.NONE);
+						edit_point.get_left_handle ().length = 0;
 					} else {
 						edit_point.recalculate_linear_handles ();
 					}
@@ -1096,7 +1092,7 @@ class GlyfTable : Table { 					x = xcoordinates[j] * 1000.0 / units_per_em; // in proportion to em width
 					y = ycoordinates[j] * 1000.0 / units_per_em;
 
-					edit_point.get_left_handle ().set_point_type (PointType.CURVE);
+					edit_point.get_left_handle ().set_point_type (PointType.NONE);
 					edit_point.get_left_handle ().length = 0;
 						
 					edit_point.type = PointType.CURVE;
@@ -1448,12 +1444,11 @@ class CmapSubtableWindowsUnicode : CmapSubtable { 		return_if_fail (seg_count_x2 % 2 == 0);
 
 		seg_count = seg_count_x2 / 2;
-		
-		printd (@"seg_count: $seg_count\n");
-		
+
 		end_char = new uint16[seg_count];
 		for (int i = 0; i < seg_count; i++) {
 			end_char[i] = dis.read_ushort ();
+			print (@"end_char[i] $(end_char[i])\n");
 		}
 		
 		if (end_char[seg_count - 1] != 0xFFFF) {
@@ -1483,8 +1478,6 @@ class CmapSubtableWindowsUnicode : CmapSubtable { 		}
 
 		gid_len = (length - 16 - 8 * seg_count) / 2;
-		printd (@"length: $length\n");
-		printd (@"gid_len: $gid_len\n");
 		glyph_id_array = new uint16[gid_len];
 		for (int i = 0; i < gid_len; i++) {
 			glyph_id_array[i] = dis.read_ushort ();
@@ -1547,6 +1540,19 @@ class CmapSubtableWindowsUnicode : CmapSubtable { 		// print (@"New range $(s.str) - $(e.str) delta: $delta_offset, range: $range_offset\n");
 	}
 	
+	/** Largest power of two less than max. */
+	public static uint16 largest_pow2 (uint16 max) {
+		uint16 x = 1;
+		uint16 l = 0;
+		
+		while (x < max) {
+			l = x;
+			x = x << 1;
+		}
+		
+		return l;
+	}
+	
 	public void process (FontData fd, GlyfTable glyf_table) {
 		GlyphRange glyph_range = new GlyphRange ();
 		unowned List<UniRange> ranges;
@@ -1585,7 +1591,7 @@ class CmapSubtableWindowsUnicode : CmapSubtable { 		ranges = glyph_range.get_ranges ();
 		seg_count = (uint16) ranges.length () + 1;
 		seg_count_2 =  seg_count * 2;
-		search_range = 2 * ((uint16) Math.pow (2, (Math.log (seg_count) / Math.log (2))));
+		search_range = 2 * largest_pow2 (seg_count);
 		entry_selector = (uint16) (Math.log (search_range / 2) / Math.log (2));
 		range_shift = seg_count_2 - search_range;
 		
@@ -1640,7 +1646,7 @@ class CmapSubtableWindowsUnicode : CmapSubtable { 			fd.add_ushort ((uint16) (indice - u.start));
 			indice += u.length ();
 		}
-		fd.add_ushort (0xFFFF);
+		fd.add_ushort (1);
 		
 		// range offset
 		foreach (UniRange u in ranges) {
@@ -2461,8 +2467,10 @@ class NameTable : Table { 		text.append (font.get_name ());
 		type.append (FULL_FONT_NAME);
 
-		text.append ("Version 1.0;");
-		type.append (VERSION);
+		// This does for some reason cause an internal error in ms fontvalidatior utility
+		// put it back when you have figured out how to solve the validation issue.
+		// text.append ("Version 1.0");
+		// type.append (VERSION);
 						
 		num_records = (uint16) text.length ();
 		
@@ -4128,15 +4136,15 @@ class DirectoryTable : Table { 		if (tables.length () == 0) {
 			tables.append (offset_table);
 			tables.append (this);
-
-			tables.append (head_table);
+			
 			tables.append (cmap_table);
+			tables.append (head_table);
 			tables.append (glyf_table);
 			tables.append (hhea_table);
 			tables.append (hmtx_table);
 			tables.append (loca_table);
-			tables.append (name_table);
 			tables.append (maxp_table);
+			tables.append (name_table);
 			tables.append (os_2_table);
 			tables.append (post_table);
 		}
@@ -4148,7 +4156,7 @@ class DirectoryTable : Table { 		offset_table = ot;
 	}
 	
-	public void parse (OtfInputStream dis, File file) throws Error {
+	public void parse (OtfInputStream dis, File file, OpenFontFormatReader reader_callback) throws Error {
 		StringBuilder tag = new StringBuilder ();
 		uint32 checksum;
 		uint32 offset;
@@ -4241,10 +4249,12 @@ class DirectoryTable : Table { 			return;
 		}
 		
+		hhea_table.parse (dis);
+		reader_callback.set_limits ();
+		
 		name_table.parse (dis);
 		post_table.parse (dis);
 		os_2_table.parse (dis);
-		hhea_table.parse (dis);
 		maxp_table.parse (dis);
 		loca_table.parse (dis, head_table, maxp_table);
 		hmtx_table.parse (dis, hhea_table, loca_table);
diff --git a/src/OverView.vala b/src/OverView.valaindex c3bdf41..ee9e0fd 100644--- a/src/OverView.vala+++ b/src/OverView.vala@@ -418,7 +418,7 @@ class OverView : FontDisplay { 		 		scrollbar.draw (cr, allocation); 		-		n_items = ((allocation.width - 10) / nail_width);+		n_items = ((allocation.width - 15) / nail_width); 		rows = (allocation.height / nail_height); 		 		if (items_per_row != n_items) { 	@@ -513,8 +513,6 @@ class OverView : FontDisplay { 	public void scroll_to (double percent) { 		int64 r; 		-		print (@"percent $percent\n");-		 		r = (int64) (percent * glyph_range.length () / rows); 		r *= items_per_row; 		diff --git a/src/Path.vala b/src/Path.valaindex 138c7c6..a3b4761 100644--- a/src/Path.vala+++ b/src/Path.vala@@ -180,32 +180,6 @@ class Path { 		cr.curve_to (xb, yb, xc, yc, xd, yd); 	} 	-	private static void print_curve (EditPoint e, EditPoint en) {-		double xa, ya, xb, yb, xc, yc, xd, yd;-		-		get_bezier_points (e, en, out xa, out ya, out xb, out yb, out xc, out yc, out xd, out yd);--		stdout.printf ("L");-		-		stdout.printf ("%s ",  round (xa));-		stdout.printf ("%s ",  round (ya));	-		-		stdout.printf ("\n");--		stdout.printf ("C");--		stdout.printf ("%s ", round (xb));-		stdout.printf ("%s ", round (yb));-		-		stdout.printf ("%s ", round (xc));-		stdout.printf ("%s ", round (yc));	-		-		stdout.printf ("%s ", round (xd));-		stdout.printf ("%s ", round (yd));	-		-		stdout.printf ("\n");-	}-	 	/** Curve relative to window center. */ 	public static void get_bezier_points (EditPoint e, EditPoint en, out double xa, out double ya, out double xb, out double yb, out double xc, out double yc, out double xd, out double yd) { 		Glyph g = MainWindow.get_current_glyph ();diff --git a/src/Svg.vala b/src/Svg.valaindex b7b413e..b19efa7 100644--- a/src/Svg.vala+++ b/src/Svg.vala@@ -85,8 +85,10 @@ class Svg { 	private static void add_abs_next (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool do_glyph, double scale = 1) { 		if (start.right_handle.type == PointType.LINE && end.left_handle.type == PointType.LINE) { 			add_abs_line_to (end, start, svg, g, do_glyph, scale);+		} else if (end.get_left_handle ().type == PointType.NONE) {+			add_quadratic_abs_path (end, start, svg, g, do_glyph, scale); 		} else {-			add_abs_path (end, start, svg, g, do_glyph, scale);+			add_cubic_abs_path (end, start, svg, g, do_glyph, scale); 		} 	} @@ -141,9 +143,40 @@ class Svg { 		} 	} 	-	private static void add_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g,  bool to_glyph, double scale = 1) {-		// Just like Path.print_curve (e, m, svg);+	private static void add_quadratic_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g,  bool to_glyph, double scale = 1) {+		double left = g.left_limit;+		double baseline = Supplement.get_current_font ().base_line;+		double height = Supplement.get_current_font ().get_height (); // no probably not 		+		double xa, ya, xb, yb, xc, yc, xd, yd;+		+		Path.get_bezier_points (start, end, out xa, out ya, out xb, out yb, out xc, out yc, out xd, out yd);++		double center_x = Glyph.xc ();+		double center_y = Glyph.yc ();+		+		// cubic path+		if (!to_glyph) {+			svg.append_printf ("Q");++			svg.append_printf ("%s ", round ((xb - center_x - left) * scale));+			svg.append_printf ("%s ", round ((yb - center_y - baseline + height) * scale));+			+			svg.append_printf ("%s ", round ((xc - center_x - left) * scale));+			svg.append_printf ("%s ", round ((yc - center_y - baseline + height) * scale));++		} else {		+			svg.append_printf ("Q");++			svg.append_printf ("%s ", round ((xb - center_x - left) * scale));+			svg.append_printf ("%s ", round ((-yb + center_y + baseline) * scale));+			+			svg.append_printf ("%s ", round ((xc - center_x - left) * scale));+			svg.append_printf ("%s ", round ((-yc + center_y + baseline) * scale));	+		}+	}+			+	private static void add_cubic_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g,  bool to_glyph, double scale = 1) { 		double left = g.left_limit; 		double baseline = Supplement.get_current_font ().base_line; 		double height = Supplement.get_current_font ().get_height (); // no probably not@@ -155,6 +188,7 @@ class Svg { 		double center_x = Glyph.xc (); 		double center_y = Glyph.yc (); 		+		// cubic path 		if (!to_glyph) { 			svg.append_printf ("C"); @@ -218,6 +252,23 @@ class Svg { 				continue; 			} +			if (d[i].index_of ("Q") == 0) {+				x1 = double.parse (d[i].substring (1)) + x;+				y1 = -double.parse (d[i+1]) + y;++				x2 = double.parse (d[i+2]) + x;+				y2 = -double.parse (d[i+3]) + y;++				x1 *= scale;+				y1 *= scale;++				x2 *= scale;+				y2 *= scale;+																+				cr.curve_to (x1, y1, x2, y2, x2, y2);+				continue;+			}+			 			if (d[i].index_of ("C") == 0) { 				x1 = double.parse (d[i].substring (1)) + x; 				y1 = -double.parse (d[i+1]) + y;

Contact

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