The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Os2Table.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/Os2Table.vala.
Fix compile time error
1 /* 2 Copyright (C) 2012, 2013, 2014 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 using Math; 16 17 namespace BirdFont { 18 19 public class Os2Table : OtfTable { 20 21 public static const uint16 ITALIC = 1; 22 public static const uint16 UNDERSCORE = 1 << 1; 23 public static const uint16 NEGATIVE = 1 << 2; 24 public static const uint16 OUTLINED = 1 << 3; 25 public static const uint16 STRIKEOUT = 1 << 4; 26 public static const uint16 BOLD = 1 << 5; 27 public static const uint16 REGULAR = 1 << 6; 28 public static const uint16 TYPO_METRICS = 1 << 7; 29 public static const uint16 WWS = 1 << 8; 30 public static const uint16 OBLIQUE = 1 << 9; 31 32 public Os2Table () { 33 id = "OS/2"; 34 } 35 36 public override void parse (FontData dis) throws Error { 37 } 38 39 public void process (GlyfTable glyf_table, HmtxTable hmtx_table) { 40 process_table (glyf_table, hmtx_table, false); 41 } 42 43 public void process_mac (GlyfTable glyf_table, HmtxTable hmtx_table) { 44 process_table (glyf_table, hmtx_table, true); 45 } 46 47 public void process_table (GlyfTable glyf_table, HmtxTable hmtx_table, bool mac) { 48 FontData fd = new FontData (); 49 Font font = OpenFontFormatWriter.get_current_font (); 50 int16 ascender; 51 int16 descender; 52 uint16 style = 0; 53 UnicodeRangeBits ranges = new UnicodeRangeBits (); 54 CodePageBits pages = new CodePageBits (); 55 uint32 unicodeRange1, unicodeRange2, unicodeRange3, unicodeRange4; 56 uint32 codepage1, codepage2; 57 58 fd.add_u16 (0x0004); // version 59 60 fd.add_16 (hmtx_table.get_average_width ()); // xAvgCharWidth 61 62 fd.add_u16 ((uint16) font.weight); // usWeightClass (400 is normal, 700 is bold) 63 64 fd.add_u16 (5); // usWidthClass (5 is normal) 65 fd.add_u16 (0); // fsType 66 67 //FIXME: 68 fd.add_16 (40); // ySubscriptXSize 69 fd.add_16 (40); // ySubscriptYSize 70 fd.add_16 (40); // ySubscriptXOffset 71 fd.add_16 (40); // ySubscriptYOffset 72 fd.add_16 (40); // ySuperscriptXSize 73 fd.add_16 (40); // ySuperscriptYSize 74 fd.add_16 (40); // ySuperscriptXOffset 75 fd.add_16 (40); // ySuperscriptYOffset 76 fd.add_16 (40); // yStrikeoutSize 77 fd.add_16 (200); // yStrikeoutPosition 78 fd.add_16 (0); // sFamilyClass 79 80 // FIXME: PANOSE 81 // Panose, zero means anything will fit. 82 fd.add (0); 83 fd.add (0); 84 fd.add (0); 85 fd.add (0); 86 fd.add (0); 87 fd.add (0); 88 fd.add (0); 89 fd.add (0); 90 fd.add (0); 91 fd.add (0); 92 93 ranges.get_ranges (font, out unicodeRange1, out unicodeRange2, out unicodeRange3, out unicodeRange4); 94 95 if (mac) { 96 fd.add_u32 (unicodeRange1); // ulUnicodeRange1 Bits 0-31 97 fd.add_u32 (0); // ulUnicodeRange2 Bits 32-63 98 fd.add_u32 (0); // ulUnicodeRange3 Bits 64-95 99 fd.add_u32 (0); // ulUnicodeRange4 Bits 96-127 100 } else { 101 fd.add_u32 (unicodeRange1); // ulUnicodeRange1 Bits 0-31 102 fd.add_u32 (unicodeRange2); // ulUnicodeRange2 Bits 32-63 103 fd.add_u32 (unicodeRange3); // ulUnicodeRange3 Bits 64-95 104 fd.add_u32 (unicodeRange4); // ulUnicodeRange4 Bits 96-127 105 } 106 107 fd.add_tag ("Bird"); // VendID 108 109 // fsSelection (1 for italic 0 for upright) 110 111 if (!font.bold && !font.italic) { 112 style |= REGULAR; 113 } 114 115 if (font.bold) { 116 style |= BOLD; 117 } 118 119 if (font.italic) { 120 style |= ITALIC; 121 } 122 123 fd.add_u16 (style); 124 125 fd.add_u16 (glyf_table.get_first_char ()); // usFirstCharIndex 126 fd.add_u16 (glyf_table.get_last_char ()); // usLastCharIndex 127 128 ascender = (int16) rint (font.top_limit * HeadTable.UNITS); 129 descender = (int16) rint (font.bottom_limit * HeadTable.UNITS); 130 131 fd.add_16 (ascender); // sTypoAscender 132 fd.add_16 (descender); // sTypoDescender 133 fd.add_16 (100); // sTypoLineGap 134 135 fd.add_u16 (ascender); // usWinAscent 136 137 if (descender > 0) { 138 warning (@"usWinDescent is unsigned, can not write $(-descender) to the field."); 139 fd.add_u16 (0); 140 } else { 141 fd.add_u16 (-descender); // usWinDescent (not like sTypoDescender) 142 } 143 144 pages.get_pages (font, out codepage1, out codepage2); 145 146 if (mac) { 147 fd.add_u32 (1); // ulCodePageRange1 Bits 0-31 (this value is only used fontbook) 148 fd.add_u32 (0); // ulCodePageRange2 Bits 32-63 149 } else { 150 fd.add_u32 (codepage1); // ulCodePageRange1 Bits 0-31 (this value is used by Word on Windows) 151 fd.add_u32 (codepage2); // ulCodePageRange2 Bits 32-63 152 } 153 154 fd.add_16 (ascender); // sHeight 155 fd.add_16 (ascender); // sCapHeight 156 157 fd.add_16 (0); // usDefaultChar 158 fd.add_16 (0x0020); // usBreakChar, also known as space 159 160 fd.add_16 (2); // usMaxContext (two, becase the font has kerning but not ligatures). 161 162 // padding 163 fd.pad (); 164 165 this.font_data = fd; 166 } 167 } 168 169 } 170