Clone in a terminal:
Commit a9f382c
Johan Mattsson - 2014-04-22T11:28:51+00:00
a9f382c981db459ff594a7d0055a709a05bc17fbjohan.mattsson.m@gmail.com

Kerning in SVG font

Changed files (2)

Diff

diff --git a/libbirdfont/GlyphCanvas.vala b/libbirdfont/GlyphCanvas.valaindex c7a2d68..0324d15 100644--- a/libbirdfont/GlyphCanvas.vala+++ b/libbirdfont/GlyphCanvas.vala@@ -1,20 +1,16 @@ /*
     Copyright (C) 2012 Johan Mattsson
 
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU 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 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 program 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 General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+    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;
 
diff --git a/libbirdfont/SvgFontFormatWriter.vala b/libbirdfont/SvgFontFormatWriter.valaindex be20aee..d6b0276 100644--- a/libbirdfont/SvgFontFormatWriter.vala+++ b/libbirdfont/SvgFontFormatWriter.vala@@ -1,5 +1,5 @@ /*-    Copyright (C) 2012 Johan Mattsson+    Copyright (C) 2012 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 @@ -58,7 +58,7 @@ class SvgFontFormatWriter : Object  { 		put ("<defs>");  		put (@"<font id=\"$font_name\" horiz-adv-x=\"250\" >");-		put (@"<font-face units-per-em=\"$units_per_em\" ascent=\"$ascent\" descent=\"$descent\" />");+		put (@"<font-face units-per-em=\"$(to_float (units_per_em))\" ascent=\"$(to_float (ascent))\" descent=\"$(to_float (descent))\" />");  		// (missing-glyph goes here) @@ -78,42 +78,30 @@ class SvgFontFormatWriter : Object  { 			if (glyph.get_unichar () >= ' ' && b.str.validate ()) { 				if (b.str == "\"" || b.str == "&" || b.str == "<" || b.str == ">") { 					uni = Font.to_hex_code (glyph.get_unichar ());-					put (@"<glyph unicode=\"&#x$(uni);\" horiz-adv-x=\"$(glyph.get_width ())\" d=\"$(glyph.get_svg_data ())\" />");			+					put (@"<glyph unicode=\"&#x$(uni);\" horiz-adv-x=\"$(to_float (glyph.get_width ()))\" d=\"$(glyph.get_svg_data ())\" />");			 				} else {-					put (@"<glyph unicode=\"$(b.str)\" horiz-adv-x=\"$(glyph.get_width ())\" d=\"$(glyph.get_svg_data ())\" />");+					put (@"<glyph unicode=\"$(b.str)\" horiz-adv-x=\"$(to_float (glyph.get_width ()))\" d=\"$(glyph.get_svg_data ())\" />"); 				} 			}--			Tool.yield (); 		} 		 		// FIXME: ligatures-		KerningClasses.get_instance ().each_pair ((left, right, k) => {+		KerningClasses.get_instance ().all_pairs ((kerning) => { 			string l, r;-			Font f = BirdFont.get_current_font ();-			Glyph? gr = f.get_glyph (right);-			Glyph? gl = f.get_glyph (left);-			Glyph glyph_right;-			Glyph glyph_left;-			-			if (gr == null || gl == null) {-				warning ("kerning glyph that does not exist.");-				return;-			}-			-			glyph_right = (!) gr;-			glyph_left = (!) gl;-			-			l = Font.to_hex_code (glyph_left.unichar_code);-			r = Font.to_hex_code (glyph_right.unichar_code); 			-			try {			-				os.put_string (@"<hkern u1=\"&#x$l;\" u2=\"&#x$r;\" k=\"$(-k)\"/>\n");-			} catch (GLib.Error e) {-				warning (e.message);+			foreach (Kerning k in kerning.kerning) {+				try {+					if (k.glyph != null) {+						l = Font.to_hex_code (kerning.character.unichar_code);+						r = Font.to_hex_code (((!)k.glyph).unichar_code);	+						os.put_string (@"<hkern u1=\"&#x$l;\" u2=\"&#x$r;\" k=\"$(to_float (-k.val))\"/>\n");+					} else {+						warning ("No glyph.");+					}+				} catch (GLib.Error e) {+					warning (e.message);+				} 			}-			-			Tool.yield (); 		});	  		put ("</font>");@@ -121,6 +109,14 @@ class SvgFontFormatWriter : Object  { 		put ("</svg>"); 	} +	string to_float (double d) {+		string s = @"$d";+		if (s.index_of ("e") != -1) {+			return "0".dup ();+		}+		return s.replace (",", ".");+	}+ 	/** Write a new line */ 	private void put (string line) throws Error { 		os.put_string (line);

Contact

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