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.
Merge ../birdfont-2.x
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 (int units_per_em) { 26 directory_table = new DirectoryTable (); 27 HeadTable.init (units_per_em); 28 } 29 30 public static Font get_current_font () { 31 return font; 32 } 33 34 public void open (File ttf, File ttf_mac) throws Error { 35 if (ttf.query_exists () || ttf_mac.query_exists ()) { 36 warning ("File exists in export."); 37 throw new FileError.EXIST("OpenFontFormatWriter: file exists."); 38 } 39 40 os = new DataOutputStream(ttf.create (FileCreateFlags.REPLACE_DESTINATION)); 41 os_mac = new DataOutputStream(ttf_mac.create (FileCreateFlags.REPLACE_DESTINATION)); 42 } 43 44 public void write_ttf_font (Font nfont) throws Error { 45 long dl; 46 uint8* data; 47 Gee.ArrayList<OtfTable> tables; 48 FontData fd; 49 uint l; 50 51 font = nfont; 52 53 directory_table.process (); 54 tables = directory_table.get_tables (); 55 56 dl = directory_table.get_font_file_size (); 57 58 if (dl == 0) { 59 warning ("font size is zero"); 60 return; 61 } 62 63 foreach (OtfTable t in tables) { 64 fd = t.get_font_data (); 65 data = fd.table_data; 66 l = fd.length_with_padding (); 67 68 for (int j = 0; j < l; j++) { 69 os.put_byte (data[j]); 70 } 71 } 72 73 directory_table.process_mac (); 74 75 foreach (OtfTable t in tables) { 76 fd = t.get_font_data (); 77 data = fd.table_data; 78 l = fd.length_with_padding (); 79 80 for (int j = 0; j < l; j++) { 81 os_mac.put_byte (data[j]); 82 } 83 } 84 } 85 86 public void close () throws Error { 87 os.close (); 88 os_mac.close (); 89 } 90 } 91 92 } 93