The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

HheaTable.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/HheaTable.vala.
Merge ../birdfont-2.x
1 /* 2 Copyright (C) 2012 2013 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 HheaTable : OtfTable { 20 21 public int16 ascender; 22 public int16 descender; 23 public int16 line_gap; 24 25 Fixed version; 26 27 uint16 max_advance; 28 int16 min_lsb; 29 int16 min_rsb; 30 int16 xmax_extent; 31 int16 carret_slope; 32 int16 carret_slope_run; 33 int16 carret_offset; 34 35 int16 metric_format; 36 public int16 num_horizontal_metrics; 37 38 GlyfTable glyf_table; 39 HeadTable head_table; 40 HmtxTable hmtx_table; 41 42 int16 winAscent = 0; 43 int16 winDescent = 0; 44 45 public HheaTable (GlyfTable g, HeadTable h, HmtxTable hm) { 46 glyf_table = g; 47 head_table = h; 48 hmtx_table = hm; 49 id = "hhea"; 50 } 51 52 public int16 get_winascent () { 53 if (winAscent != 0) { 54 return winAscent; 55 } 56 57 foreach (GlyfData glyph in glyf_table.glyf_data) { 58 if (glyph.bounding_box_ymax > winAscent) { 59 winAscent = glyph.bounding_box_ymax; 60 } 61 } 62 63 return winAscent; 64 } 65 66 public int16 get_windescent () { 67 if (winDescent != 0) { 68 return winDescent; 69 } 70 71 foreach (GlyfData glyph in glyf_table.glyf_data) { 72 if (glyph.bounding_box_ymin < winDescent) { 73 winDescent = -glyph.bounding_box_ymin; 74 } 75 } 76 77 return winDescent; 78 } 79 80 public override void parse (FontData dis) throws GLib.Error { 81 dis.seek (offset); 82 83 version = dis.read_fixed (); 84 85 if (!version.equals (1, 0)) { 86 warning (@"wrong version in hhea table $(version.get_string ())"); 87 } 88 89 ascender = dis.read_short (); 90 descender = dis.read_short (); 91 line_gap = dis.read_short (); 92 max_advance = dis.read_ushort (); 93 min_lsb = dis.read_short (); 94 min_rsb = dis.read_short (); 95 xmax_extent = dis.read_short (); 96 carret_slope = dis.read_short (); 97 carret_slope_run = dis.read_short (); 98 carret_offset = dis.read_short (); 99 100 // reserved x 4 101 dis.read_short (); 102 dis.read_short (); 103 dis.read_short (); 104 dis.read_short (); 105 106 metric_format = dis.read_short (); 107 num_horizontal_metrics = dis.read_short (); 108 } 109 110 public void process () throws GLib.Error { 111 FontData fd = new FontData (); 112 Fixed version = 1 << 16; 113 Font font = OpenFontFormatWriter.get_current_font (); 114 115 fd.add_fixed (version); // table version 116 117 ascender = (int16) rint (font.top_limit * HeadTable.UNITS); 118 ascender -= (int16) rint (font.base_line * HeadTable.UNITS); 119 120 descender = (int16) rint (font.bottom_limit * HeadTable.UNITS); 121 descender -= (int16) rint (font.base_line * HeadTable.UNITS); 122 123 fd.add_16 (ascender); // Ascender 124 fd.add_16 (descender); // Descender 125 fd.add_16 (0); // LineGap 126 127 fd.add_u16 (hmtx_table.max_advance); // maximum advance width value in 'hmtx' table. 128 129 fd.add_16 (hmtx_table.min_lsb); // min left side bearing 130 fd.add_16 (hmtx_table.min_rsb); // min right side bearing 131 fd.add_16 (hmtx_table.max_extent); // x max extent Max(lsb + (xMax - xMin)) 132 133 fd.add_16 (1); // caretSlopeRise 134 fd.add_16 (0); // caretSlopeRun 135 fd.add_16 (0); // caretOffset 136 137 // reserved 138 fd.add_16 (0); 139 fd.add_16 (0); 140 fd.add_16 (0); 141 fd.add_16 (0); 142 143 fd.add_16 (0); // metricDataFormat 0 for current format. 144 145 // numberOfHMetrics Number of hMetric entries in 'hmtx' table 146 fd.add_u16 ((uint16) glyf_table.glyphs.size); 147 148 // padding 149 fd.pad (); 150 this.font_data = fd; 151 } 152 } 153 154 } 155