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.
Fix compile time error
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 using Math; 16 17 namespace BirdFont { 18 19 public class HheaTable : OtfTable { 20 21 Fixed version; 22 int16 ascender; 23 int16 descender; 24 int16 linegap; 25 uint16 max_advance; 26 int16 min_lsb; 27 int16 min_rsb; 28 int16 xmax_extent; 29 int16 carret_slope; 30 int16 carret_slope_run; 31 int16 carret_offset; 32 33 int16 metric_format; 34 public int16 num_horizontal_metrics; 35 36 GlyfTable glyf_table; 37 HeadTable head_table; 38 HmtxTable hmtx_table; 39 40 public HheaTable (GlyfTable g, HeadTable h, HmtxTable hm) { 41 glyf_table = g; 42 head_table = h; 43 hmtx_table = hm; 44 id = "hhea"; 45 } 46 47 public double get_ascender () { 48 return ascender * 1000 / head_table.get_units_per_em (); 49 } 50 51 public double get_descender () { 52 return descender * 1000 / head_table.get_units_per_em (); 53 } 54 55 public override void parse (FontData dis) throws GLib.Error { 56 dis.seek (offset); 57 58 version = dis.read_fixed (); 59 60 if (!version.equals (1, 0)) { 61 warning (@"wrong version in hhea table $(version.get_string ())"); 62 } 63 64 ascender = dis.read_short (); 65 descender = dis.read_short (); 66 linegap = dis.read_short (); 67 max_advance = dis.read_ushort (); 68 min_lsb = dis.read_short (); 69 min_rsb = dis.read_short (); 70 xmax_extent = dis.read_short (); 71 carret_slope = dis.read_short (); 72 carret_slope_run = dis.read_short (); 73 carret_offset = dis.read_short (); 74 75 // reserved x 4 76 dis.read_short (); 77 dis.read_short (); 78 dis.read_short (); 79 dis.read_short (); 80 81 metric_format = dis.read_short (); 82 num_horizontal_metrics = dis.read_short (); 83 } 84 85 public void process () throws GLib.Error { 86 int16 ascender, descender; 87 FontData fd = new FontData (); 88 Fixed version = 1 << 16; 89 Font font = BirdFont.get_current_font (); 90 91 fd.add_fixed (version); // table version 92 93 ascender = (int16) rint (font.top_limit * HeadTable.UNITS); 94 ascender -= (int16) rint (font.base_line * HeadTable.UNITS); 95 96 descender = (int16) rint (font.bottom_limit * HeadTable.UNITS); 97 descender -= (int16) rint (font.base_line * HeadTable.UNITS); 98 99 fd.add_16 (ascender); // Ascender 100 fd.add_16 (descender); // Descender 101 fd.add_16 (0); // LineGap 102 103 fd.add_u16 (hmtx_table.max_advance); // maximum advance width value in 'hmtx' table. 104 105 fd.add_16 (hmtx_table.min_lsb); // min left side bearing 106 fd.add_16 (hmtx_table.min_rsb); // min right side bearing 107 fd.add_16 (hmtx_table.max_extent); // x max extent Max(lsb + (xMax - xMin)) 108 109 fd.add_16 (1); // caretSlopeRise 110 fd.add_16 (0); // caretSlopeRun 111 fd.add_16 (0); // caretOffset 112 113 // reserved 114 fd.add_16 (0); 115 fd.add_16 (0); 116 fd.add_16 (0); 117 fd.add_16 (0); 118 119 fd.add_16 (0); // metricDataFormat 0 for current format. 120 121 fd.add_u16 ((uint16) glyf_table.glyphs.size); // numberOfHMetrics Number of hMetric entries in 'hmtx' table 122 123 // padding 124 fd.pad (); 125 this.font_data = fd; 126 } 127 } 128 129 } 130