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