The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Generate Mac specific TTF fonts

These changes was commited to the Birdfont repository Mon, 15 Jun 2015 18:40:01 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Mon, 15 Jun 2015 18:40:01 +0000]

Updated Files

libbirdfont/ExportSettings.vala
libbirdfont/ExportTool.vala
libbirdfont/OpenFontFormat/DirectoryTable.vala
libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala
libbirdfont/OpenFontFormat/Os2Table.vala
--- a/libbirdfont/ExportSettings.vala +++ b/libbirdfont/ExportSettings.vala @@ -19,6 +19,7 @@ public class ExportSettings : TableLayout { TextArea file_name; + TextArea file_name_mac; CheckBox ttf; CheckBox eot; CheckBox svg; @@ -54,7 +55,22 @@ widgets.add (file_name); focus_ring.add (file_name); + + widgets.add (new Text (t_("File Name") + " Mac", label_size, label_margin)); + file_name_mac = new LineTextArea (label_size); + file_name_mac.margin_bottom = margin; + + fn = get_file_name_mac (font); + file_name_mac.set_text (fn); + file_name_mac.text_changed.connect ((t) => { + Font f = BirdFont.get_current_font (); + f.settings.set_setting ("file_name_mac", t); + }); + + widgets.add (file_name_mac); + focus_ring.add (file_name_mac); + 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; @@ -120,6 +136,16 @@ return n; } + public static string get_file_name_mac (Font font) { + string n = font.settings.get_setting ("file_name_mac"); + + if (n == "") { + n = font.full_name + " Mac"; + } + + return n; + } + public static bool export_ttf_setting (Font f) { return f.settings.get_setting ("export_ttf") != "false"; }
--- a/libbirdfont/ExportTool.vala +++ b/libbirdfont/ExportTool.vala @@ -391,11 +391,13 @@ public static bool export_ttf_font_path (File folder, bool use_export_settings = true) { Font current_font = BirdFont.get_current_font (); File ttf_file; + File ttf_file_mac; File eot_file; bool done = true; try { ttf_file = get_child (folder, ExportSettings.get_file_name (current_font) + ".ttf"); + ttf_file_mac = get_child (folder, ExportSettings.get_file_name_mac (current_font) + ".ttf"); eot_file = get_child (folder, ExportSettings.get_file_name (current_font) + ".eot"); printd (@"Writing TTF fonts to $((!) ttf_file.get_path ())\n"); @@ -404,11 +406,15 @@ ttf_file.delete (); } + if (ttf_file_mac.query_exists ()) { + ttf_file_mac.delete (); + } + if (eot_file.query_exists ()) { eot_file.delete (); } - write_ttf ((!) ttf_file.get_path ()); + write_ttf ((!) ttf_file.get_path (), (!) ttf_file_mac.get_path ()); if (!use_export_settings || ExportSettings.export_eot_setting (current_font)) { write_eot ((!) ttf_file.get_path (), (!) eot_file.get_path ()); @@ -457,13 +463,14 @@ return true; } - static void write_ttf (string ttf) { + static void write_ttf (string ttf, string ttf_mac) { OpenFontFormatWriter fo = new OpenFontFormatWriter (); Font f = BirdFont.get_current_font (); File file = (!) File.new_for_path (ttf); + File file_mac = (!) File.new_for_path (ttf_mac); try { - fo.open (file); + fo.open (file, file_mac); fo.write_ttf_font (f); fo.close (); } catch (Error e) {
--- a/libbirdfont/OpenFontFormat/DirectoryTable.vala +++ b/libbirdfont/OpenFontFormat/DirectoryTable.vala @@ -1,5 +1,5 @@ /* - Copyright (C) 2012, 2013, 2014 Johan Mattsson + Copyright (C) 2012 2013 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 @@ -82,6 +82,12 @@ kern_table.process (); gpos_table.process (glyf_table); + offset_table.process (); + process_directory (); // this table + } + + public void process_mac () throws GLib.Error { + os_2_table.process_mac (glyf_table, hmtx_table); offset_table.process (); process_directory (); // this table }
--- a/libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala +++ b/libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala @@ -17,6 +17,7 @@ public class OpenFontFormatWriter : Object { DataOutputStream os; + DataOutputStream os_mac; DirectoryTable directory_table; public static Font font; @@ -29,15 +30,14 @@ return font; } - public void open (File file) throws Error { - assert (!is_null (file)); - - if (file.query_exists ()) { + public void open (File ttf, File ttf_mac) throws Error { + if (ttf.query_exists () || ttf_mac.query_exists ()) { warning ("File exists in export."); throw new FileError.EXIST("OpenFontFormatWriter: file exists."); } - os = new DataOutputStream(file.create (FileCreateFlags.REPLACE_DESTINATION)); + os = new DataOutputStream(ttf.create (FileCreateFlags.REPLACE_DESTINATION)); + os_mac = new DataOutputStream(ttf_mac.create (FileCreateFlags.REPLACE_DESTINATION)); } public void write_ttf_font (Font nfont) throws Error { @@ -49,7 +49,7 @@ font = nfont; - directory_table.process (); + directory_table.process (); tables = directory_table.get_tables (); dl = directory_table.get_font_file_size (); @@ -66,14 +66,27 @@ for (int j = 0; j < l; j++) { os.put_byte (data[j]); + } + } + + directory_table.process_mac (); + + foreach (OtfTable t in tables) { + fd = t.get_font_data (); + data = fd.table_data; + l = fd.length_with_padding (); + + for (int j = 0; j < l; j++) { + os_mac.put_byte (data[j]); } } } public void close () throws Error { os.close (); + os_mac.close (); } } }
--- a/libbirdfont/OpenFontFormat/Os2Table.vala +++ b/libbirdfont/OpenFontFormat/Os2Table.vala @@ -35,8 +35,16 @@ public override void parse (FontData dis) throws Error { } - + public void process (GlyfTable glyf_table, HmtxTable hmtx_table) { + process_table (glyf_table, hmtx_table, false); + } + + public void process_mac (GlyfTable glyf_table, HmtxTable hmtx_table) { + process_table (glyf_table, hmtx_table, true); + } + + public void process_table (GlyfTable glyf_table, HmtxTable hmtx_table, bool mac) { FontData fd = new FontData (); Font font = OpenFontFormatWriter.get_current_font (); int16 ascender; @@ -112,8 +120,7 @@ ascender = (int16) rint (font.top_limit * HeadTable.UNITS); descender = (int16) rint (font.bottom_limit * HeadTable.UNITS); - - + fd.add_16 (ascender); // sTypoAscender fd.add_16 (descender); // sTypoDescender fd.add_16 (100); // sTypoLineGap @@ -128,9 +135,15 @@ } pages.get_pages (font, out codepage1, out codepage2); - fd.add_u32 (codepage1); // ulCodePageRange1 Bits 0-31 - fd.add_u32 (codepage2); // ulCodePageRange2 Bits 32-63 - + + if (mac) { + fd.add_u32 (1); // ulCodePageRange1 Bits 0-31 (this value is only used fontbook) + fd.add_u32 (0); // ulCodePageRange2 Bits 32-63 + } else { + fd.add_u32 (codepage1); // ulCodePageRange1 Bits 0-31 (this value is used by Word on Windows) + fd.add_u32 (codepage2); // ulCodePageRange2 Bits 32-63 + } + fd.add_16 (ascender); // sHeight fd.add_16 (ascender); // sCapHeight @@ -144,8 +157,7 @@ this.font_data = fd; } - } }