Commit e9cbfa5
Set units per em in export settings
Changed files (7)
modifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/ExportSettings.valamodifiedlibbirdfont/ExportTool.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/OpenFontFormat/HeadTable.valamodifiedlibbirdfont/OpenFontFormat/OpenFontFormatWriter.vala
Diff
@@ -527,7 +527,7 @@ public class BirdFont { DefaultCharacterSet.create_default_character_sets (); DefaultCharacterSet.get_characters_for_prefered_language (); - HeadTable.init ();+ HeadTable.init (1024); if (TestBirdFont.get_singleton ().test_cases_to_run != "All") { TestBirdFont.run_tests ();@@ -1,5 +1,5 @@ /*- Copyright (C) 2013, 2014 Johan Mattsson+ Copyright (C) 2013 2014 2015 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 @@ -341,6 +341,7 @@ class BirdFontFile : GLib.Object { os.put_string (@"<description>$(Markup.escape_text (font.description))</description>\n"); os.put_string (@"<copyright>$(Markup.escape_text (font.copyright))</copyright>\n"); os.put_string (@"<weight>$(font.weight)</weight>\n");+ os.put_string (@"<units_per_em>$(font.units_per_em)</units_per_em>\n"); } public void write_lines (DataOutputStream os) throws GLib.Error {@@ -762,7 +763,11 @@ class BirdFontFile : GLib.Object { if (t.get_name () == "weight") { font.weight = int.parse (t.get_content ()); }- ++ if (t.get_name () == "units_per_em") {+ font.units_per_em = int.parse (t.get_content ());+ }+ if (t.get_name () == "images") { parse_images (t); }@@ -20,6 +20,7 @@ namespace BirdFont { public class ExportSettings : TableLayout { TextArea file_name; TextArea file_name_mac;+ TextArea units_per_em; CheckBox ttf; CheckBox eot; CheckBox svg;@@ -71,6 +72,24 @@ public class ExportSettings : TableLayout { widgets.add (file_name_mac); focus_ring.add (file_name_mac); + widgets.add (new Text (t_("Units Per Em"), label_size, label_margin));+ + units_per_em = new LineTextArea (label_size);+ units_per_em.margin_bottom = margin;+ + units_per_em.set_text (@"$(font.units_per_em)");+ units_per_em.text_changed.connect ((t) => {+ Font f = BirdFont.get_current_font ();+ int u = int.parse (t);+ if (u > 0) {+ f.units_per_em = u;+ f.touch ();+ }+ });+ + widgets.add (units_per_em);+ focus_ring.add (units_per_em);+ folder = (!) font.get_folder ().get_path (); Text folder_row = new Text (t_("Folder") + ": " + folder, label_size, label_margin); folder_row.margin_bottom = 20 * MainWindow.units;@@ -474,8 +474,9 @@ os.put_string ( } static void write_ttf (string ttf, string ttf_mac) {- OpenFontFormatWriter fo = new OpenFontFormatWriter (); Font f = BirdFont.get_current_font ();+ OpenFontFormatWriter fo = new OpenFontFormatWriter (f.units_per_em);+ File file = (!) File.new_for_path (ttf); File file_mac = (!) File.new_for_path (ttf_mac); @@ -112,6 +112,8 @@ public class Font : GLib.Object { public int format_major = 0; public int format_minor = 0; + public int units_per_em = 1024;+ public Font () { KerningClasses kerning_classes; @@ -53,13 +53,17 @@ public class HeadTable : OtfTable { public HeadTable (GlyfTable gt) { glyf_table = gt; id = "head";- init (); } /** Set default value for unit. */- public static void init () {- units_per_em = 1024;- UNITS = 10 * (units_per_em / 1000.0);+ public static void init (int units_per_em) {+ if (units_per_em <= 0 || units_per_em > uint16.MAX) {+ HeadTable.units_per_em = 1024;+ } else {+ HeadTable.units_per_em = (uint16) units_per_em;+ }+ + UNITS = 10 * (HeadTable.units_per_em / 1000.0); } public uint32 get_adjusted_checksum () {@@ -22,8 +22,9 @@ public class OpenFontFormatWriter : Object { public static Font font; - public OpenFontFormatWriter () {+ public OpenFontFormatWriter (int units_per_em) { directory_table = new DirectoryTable ();+ HeadTable.init (units_per_em); } public static Font get_current_font () {