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 DirectoryTable directory_table; 21 22 public static Font font; 23 24 public OpenFontFormatWriter () { 25 directory_table = new DirectoryTable (); 26 } 27 28 public static Font get_current_font () { 29 return font; 30 } 31 32 public void open (File file) throws Error { 33 assert (!is_null (file)); 34 35 if (file.query_exists ()) { 36 warning ("File exists in export."); 37 throw new FileError.EXIST("OpenFontFormatWriter: file exists."); 38 } 39 40 os = new DataOutputStream(file.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 73 public void close () throws Error { 74 os.close (); 75 } 76 } 77 78 } 79