The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

OpenFontFormatWriter.vala in libbirdfont/OpenFontFormat

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala.
Generate mac specific truetype fonts
1 /* 2 Copyright (C) 2012, 2013 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 public class OpenFontFormatWriter : Object { 18 19 DataOutputStream os; 20 DataOutputStream os_mac; 21 DirectoryTable directory_table; 22 23 public static Font font; 24 25 public OpenFontFormatWriter () { 26 directory_table = new DirectoryTable (); 27 } 28 29 public static Font get_current_font () { 30 return font; 31 } 32 33 public void open (File ttf, File ttf_mac) throws Error { 34 if (ttf.query_exists () || ttf_mac.query_exists ()) { 35 warning ("File exists in export."); 36 throw new FileError.EXIST("OpenFontFormatWriter: file exists."); 37 } 38 39 os = new DataOutputStream(ttf.create (FileCreateFlags.REPLACE_DESTINATION)); 40 os_mac = new DataOutputStream(ttf_mac.create (FileCreateFlags.REPLACE_DESTINATION)); 41 } 42 43 public void write_ttf_font (Font nfont) throws Error { 44 long dl; 45 uint8* data; 46 Gee.ArrayList<OtfTable> tables; 47 FontData fd; 48 uint l; 49 50 font = nfont; 51 52 directory_table.process (); 53 tables = directory_table.get_tables (); 54 55 dl = directory_table.get_font_file_size (); 56 57 if (dl == 0) { 58 warning ("font size is zero"); 59 return; 60 } 61 62 foreach (OtfTable t in tables) { 63 fd = t.get_font_data (); 64 data = fd.table_data; 65 l = fd.length_with_padding (); 66 67 for (int j = 0; j < l; j++) { 68 os.put_byte (data[j]); 69 } 70 } 71 72 directory_table.process_mac (); 73 74 foreach (OtfTable t in tables) { 75 fd = t.get_font_data (); 76 data = fd.table_data; 77 l = fd.length_with_padding (); 78 79 for (int j = 0; j < l; j++) { 80 os_mac.put_byte (data[j]); 81 } 82 } 83 } 84 85 public void close () throws Error { 86 os.close (); 87 os_mac.close (); 88 } 89 } 90 91 } 92