Clone in a terminal:
Commit bcc9843
Johan Mattsson - 2012-07-29T10:44:29+00:00
bcc9843e0c0db7e053430b911462b1d29380e36fjohan.mattsson.m@gmail.com

load nice curve from last to first point in ttf files

Changed files (4)

Diff

diff --git a/src/Font.vala b/src/Font.valaindex 870bfc3..fc6d62e 100644--- a/src/Font.vala+++ b/src/Font.vala@@ -257,8 +257,6 @@ class Font : GLib.Object { 			gr.add_single (((!) g).get_unichar ()); 		} 		-		gr.sort ();-		 		gr.set_unassigned (unassigned_glyphs); 		 		return gr;@@ -653,23 +651,19 @@ class Font : GLib.Object { 		gcl = get_glyph_collection (g.get_name ()); 		 		if (gcl != null) {-			warning ("glyph does already exist");+			warning (@"glyph \"$(g.get_name ())\"does already exist"); 		} 		 		if (g.is_unassigned ()) { 			gc = new GlyphCollection (g);+			 			if (g.name == "") { 				g.name = @"($(++next_unindexed))"; 			}+			 			unassigned_glyphs.insert ((!) gc); 		} else if (gcl == null) {-			-			print (@"g.name $(g.name)\n");-			 			gc = new GlyphCollection (g);-			-			print (@"gc.get_name () $(((!)gc).get_name ())\n");-			 			glyph_cache.insert ((!) gc); 		} else { 			stderr.printf (@"Glyph collection does already have an entry for $(g.get_name ()) char $((uint64) g.unichar_code).\n");diff --git a/src/Glyph.vala b/src/Glyph.valaindex 2c531b5..8d07ee9 100644--- a/src/Glyph.vala+++ b/src/Glyph.vala@@ -38,7 +38,7 @@ class Glyph : FontDisplay { 	int zoom_list_index = 0; 	 	// Paths-	public List<Path> path_list;	// outline // FIXME: make private+	public List<Path> path_list;	// outline // FIXME: private 	public Path? active_path = null; 	Path? union_path = null; 		// add this to active path 	bool move_edit_point = false;diff --git a/src/GlyphRange.vala b/src/GlyphRange.valaindex c135925..de827b8 100644--- a/src/GlyphRange.vala+++ b/src/GlyphRange.vala@@ -20,16 +20,15 @@ namespace Supplement { class GlyphRange { 	 	List<UniRange> ranges;-	List<unichar> index_start; -	GlyphTable? unassigned = null;+	GlyphTable unassigned = new GlyphTable (); 	-	unichar len = 0;+	uint32 len = 0; 	 	public GlyphRange () { 	} 	-	public void set_unassigned (GlyphTable? unassigned) {+	public void set_unassigned (GlyphTable unassigned) { 		this.unassigned = unassigned; 	} 	@@ -98,11 +97,7 @@ class GlyphRange { 	 	public unichar get_length () { 		unichar l = len;-		-		if (unassigned != null) {-			l += ((!) unassigned).length ();-		}-		+		l += unassigned.length (); 		return l; 	} 	@@ -177,41 +172,44 @@ class GlyphRange { 		} 	} -	public string get_char (unichar index) {-		int i = 0;-		unichar next = 0;--		foreach (unichar s in index_start) {-			StringBuilder sbt = new StringBuilder ();+	public string get_char (uint32 index) {+		uint i = 0;+		uint next = 0;+		int64 ti;+		string chr;+		UniRange r;+		StringBuilder sb;+		unichar c;+		+		if (index > len + unassigned.length ()) { +			return "\0".dup();+		}+		+		if (index >= len) { 			-			if (!s.validate () && s >= index) {-				sbt.append_unichar (s);-				break;-			} else if (s >= index) {-				sbt.append_unichar (s);-				break;-			}+			if (index - len >= unassigned.length ()) {+				return "\0".dup();+			}  			-			next = s;-			i++;+			chr = ((!) unassigned.nth (index - len)).get_name ();+			return chr; 		} -		if (index == 0 || !(0 <= i < ranges.length ())) {-			if (index > ranges.length ()) {-				i = (int) (index - ranges.length ());-				-				if (unassigned == null || i >= ((!) unassigned).length ()) {-					return "\0".dup();-				}-				-				return ((!) ((!) unassigned).nth (i)).get_name ();+		r = ranges.first ().data;++		ti = (index < r.length ()) ? index - 1: index;++		foreach (UniRange u in ranges) {+			ti -= u.length ();+			+			if (ti < 0) {+				r = u;+				break; 			} 		}--		UniRange u = ranges.nth_data (i);-		StringBuilder sb = new StringBuilder ();-		unichar c = u.get_char (index - next - 1);-		+				+		sb = new StringBuilder ();+		c = r.get_char ((unichar) (ti + r.length ())); 		sb.append_unichar (c);  		return sb.str;@@ -246,7 +244,6 @@ class GlyphRange { 		 		UniRange ur = new UniRange (start, stop); 		len += ur.length ();-		index_start.append (len); 		ranges.append (ur); 		 		return ur;diff --git a/src/OpenFontFormatWriter.vala b/src/OpenFontFormatWriter.valaindex ea694cc..4f8361a 100644--- a/src/OpenFontFormatWriter.vala+++ b/src/OpenFontFormatWriter.vala@@ -643,7 +643,12 @@ class GlyfTable : Table { 			try {
 				character = cmap.get_char (i);
 				name = new StringBuilder ();
-				name.append_unichar (character);
+				
+				if (character == '\0') {
+					name.append ("null");
+				} else {
+					name.append_unichar (character);
+				}
 				
 				print (@"name: $(name.str)\n");
 				
@@ -809,8 +814,8 @@ class GlyfTable : Table { 		for (int i = 0; i < ncontours; i++) {
 			end_points[i] = dis.read_ushort (); // FIXA: mind shot vector is negative
 			
-			if (i > 0 && end_points[i] > end_points[i -1]) {
-				warning (@"Next endpoint has bad value. (end_points[i] > end_points[i -1])  ($(end_points[i]) > $(end_points[i -1]))");
+			if (i > 0 && end_points[i] < end_points[i -1]) {
+				warning (@"Next endpoint has bad value in $(name.str). (end_points[i] > end_points[i -1])  ($(end_points[i]) > $(end_points[i -1])) i: $i ncontours: $ncontours");
 			}
 		}
 		
@@ -912,6 +917,8 @@ class GlyfTable : Table { 		}
 		
 		int j = 0;
+		int first_point;
+		int last_point = 0;
 		Glyph glyph;
 		double startx, starty;
 		double x, y, rx, ry, lx, ly, nx, ny;
@@ -929,13 +936,15 @@ class GlyfTable : Table { 			EditPoint edit_point = new EditPoint ();
 			bool prev_is_curve = false;
 			
+			first_point = j;
+			last_point = end_points[i];
 			for (; j <= end_points[i]; j++) {
 
 				if (j >= npoints) {
 					warning (@"j >= npoints in glyph $(name.str). (j: $j, end_points[i]: $(end_points[i]), npoints: $npoints)");
 					break;
 				}
-				
+								
 				x = xcoordinates[j] * 1000.0 / units_per_em; // in proportion to em width
 				y = ycoordinates[j] * 1000.0 / units_per_em;
 				
@@ -973,18 +982,43 @@ class GlyfTable : Table { 					edit_point.type = PointType.CURVE;
 					edit_point.get_right_handle ().set_point_type (PointType.CURVE);
 					edit_point.get_right_handle ().move_to_coordinate (x, y);
-										
+					
 					prev_is_curve = true;
 				} 
 			}
 			
-			path.close ();
-			
-			if (path.points.length () > 0 && path.points.last ().data.type == PointType.CURVE) {
-				path.points.first ().data.get_left_handle ().set_point_type (PointType.CURVE);
-				path.points.first ().data.get_left_handle ().length = 0;
+			// last to first point
+			if (prev_is_curve) {
+				x = xcoordinates[first_point] * 1000.0 / units_per_em; // in proportion to em width
+				y = ycoordinates[first_point] * 1000.0 / units_per_em;
+				
+				x = x - (x - edit_point.right_handle.x ()) / 2;
+				y = y - (y - edit_point.right_handle.y ()) / 2;
+				
+				edit_point = new EditPoint ();
+				edit_point.set_position (x, y);
+				path.add_point (edit_point);
+				
+				x = xcoordinates[first_point] * 1000.0 / units_per_em; // in proportion to em width
+				y = ycoordinates[first_point] * 1000.0 / units_per_em;
+
+				edit_point.get_left_handle ().set_point_type (PointType.CURVE);
+				edit_point.get_left_handle ().length = 0;
+					
+				edit_point.type = PointType.CURVE;
+				edit_point.get_right_handle ().set_point_type (PointType.CURVE);
+				edit_point.get_right_handle ().move_to_coordinate (x, y);
 			}
 			
+			// curve last to first
+			x = xcoordinates[first_point] * 1000.0 / units_per_em; // in proportion to em width
+			y = ycoordinates[first_point] * 1000.0 / units_per_em;
+			edit_point.type = PointType.CURVE;
+			edit_point.get_right_handle ().set_point_type (PointType.CURVE);
+			edit_point.get_right_handle ().move_to_coordinate (x, y);
+			
+			path.close ();
+			
 			glyph.add_path (path);
 		}
 		
@@ -1062,10 +1096,10 @@ class GlyfTable : Table { 		
 		g.boundries (out gxmin, out gymin, out gxmax, out gymax);
 		
-		xmin = (int16) gxmin;
-		ymin = (int16) gymin;
-		xmax = (int16) gxmax;
-		ymax = (int16) gymax;
+		xmin = (int16) (gxmin - g.left_limit);
+		ymin = (int16) (gymin + font.base_line);
+		xmax = (int16) (gxmax - g.left_limit);
+		ymax = (int16) (gymax + font.base_line);
 		
 		fd.add_16 (xmin);
 		fd.add_16 (ymin);
@@ -1324,7 +1358,7 @@ class CmapSubtableWindowsUnicode : CmapSubtable { 		uint32 id;
 		for (uint16 i = 0; i < seg_count && start_char[i] != 0xFFFF; i++) {
 			
-			print_range (start_char[i], end_char[i], id_delta[i], id_range_offset[i]);
+			// print_range (start_char[i], end_char[i], id_delta[i], id_range_offset[i]);
 			
 			uint16 j = 0;
 			do {
@@ -1332,7 +1366,6 @@ class CmapSubtableWindowsUnicode : CmapSubtable { 				indice = start_char[i] + id_delta[i] + j;
 				
 				if (id_range_offset[i] == 0) {
-					print (@"table.insert ($indice, $((uint32) character));\n");
 					table.insert (indice, character);
 				} else {
 					// the awkward indexing trick:
@@ -1373,7 +1406,7 @@ class CmapSubtableWindowsUnicode : CmapSubtable { 		s.append_unichar (start_char);
 		e.append_unichar (end_char);
 		
-		print (@"New range $(s.str) - $(e.str) delta: $delta_offset, range: $range_offset\n");
+		// print (@"New range $(s.str) - $(e.str) delta: $delta_offset, range: $range_offset\n");
 	}
 	
 	public void process (FontData fd) {
@@ -1595,7 +1628,7 @@ class CmapTable : Table { 		
 		foreach (CmapSubtable t in subtables) {
 			t.parse (dis);
-			t.print_cmap ();
+			// t.print_cmap ();
 		}
 
 	}
@@ -2277,9 +2310,9 @@ class DirectoryTable : Table { 			tables.append (hhea_table);
 			tables.append (hmtx_table);
 			tables.append (maxp_table);
-			tables.append (os_2_table);
-			tables.append (name_table);
-			tables.append (post_table);
+			//tables.append (os_2_table);
+			//tables.append (name_table);
+			//tables.append (post_table);
 		}
 
 		return tables;

Contact

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