Commit 02f2850
small ttf fixes
Changed files (3)
modifiedsrc/OpenFontFormatReader.valamodifiedsrc/OpenFontFormatWriter.valamodifiedsrc/OverView.vala
Diff
@@ -94,9 +94,7 @@ class OpenFontFormatReader : Object { directory_table = new DirectoryTable (); directory_table.set_offset_table (offset_table);- directory_table.parse (dis, file);- - set_limits ();+ directory_table.parse (dis, file, this); } public void set_limits () {@@ -108,6 +106,7 @@ class OpenFontFormatReader : Object { f.base_line = 0; f.top_position = -get_ascender (); f.top_limit = f.top_position - 5;+ f.xheight_position = f.top_position - 5; f.bottom_position = -get_descender (); f.bottom_limit = f.bottom_position + 5; @@ -600,8 +600,6 @@ class LocaTable : Table { foreach (uint32 o in glyf_table.location_offsets) { fd.add_u16 ((uint16) (o / 2)); - printd (@"o0: $(o)\n"); - if (o < last) { warning (@"Loca table must be sorted. ($o < $last)"); } @@ -612,9 +610,7 @@ class LocaTable : Table { } else if (head_table.loca_offset_size == 1) { foreach (uint32 o in glyf_table.location_offsets) { fd.add_u32 (o); - - printd (@"o1: $(o)\n"); - + if (o < last) { warning (@"Loca table must be sorted. ($o < $last)"); } @@ -1447,12 +1443,11 @@ class CmapSubtableWindowsUnicode : CmapSubtable { return_if_fail (seg_count_x2 % 2 == 0); seg_count = seg_count_x2 / 2; - - printd (@"seg_count: $seg_count\n"); - + end_char = new uint16[seg_count]; for (int i = 0; i < seg_count; i++) { end_char[i] = dis.read_ushort (); + print (@"end_char[i] $(end_char[i])\n"); } if (end_char[seg_count - 1] != 0xFFFF) { @@ -1482,8 +1477,6 @@ class CmapSubtableWindowsUnicode : CmapSubtable { } gid_len = (length - 16 - 8 * seg_count) / 2; - printd (@"length: $length\n"); - printd (@"gid_len: $gid_len\n"); glyph_id_array = new uint16[gid_len]; for (int i = 0; i < gid_len; i++) { glyph_id_array[i] = dis.read_ushort (); @@ -1546,6 +1539,19 @@ class CmapSubtableWindowsUnicode : CmapSubtable { // print (@"New range $(s.str) - $(e.str) delta: $delta_offset, range: $range_offset\n"); } + /** Largest power of two less than max. */ + public static uint16 largest_pow2 (uint16 max) { + uint16 x = 1; + uint16 l = 0; + + while (x < max) { + l = x; + x = x << 1; + } + + return l; + } + public void process (FontData fd, GlyfTable glyf_table) { GlyphRange glyph_range = new GlyphRange (); unowned List<UniRange> ranges; @@ -1584,7 +1590,7 @@ class CmapSubtableWindowsUnicode : CmapSubtable { ranges = glyph_range.get_ranges (); seg_count = (uint16) ranges.length () + 1; seg_count_2 = seg_count * 2; - search_range = 2 * ((uint16) Math.pow (2, (Math.log (seg_count) / Math.log (2)))); + search_range = 2 * largest_pow2 (seg_count); entry_selector = (uint16) (Math.log (search_range / 2) / Math.log (2)); range_shift = seg_count_2 - search_range; @@ -1639,7 +1645,7 @@ class CmapSubtableWindowsUnicode : CmapSubtable { fd.add_ushort ((uint16) (indice - u.start)); indice += u.length (); } - fd.add_ushort (0xFFFF); + fd.add_ushort (1); // range offset foreach (UniRange u in ranges) { @@ -4129,15 +4135,15 @@ class DirectoryTable : Table { if (tables.length () == 0) { tables.append (offset_table); tables.append (this); - - tables.append (head_table); + tables.append (cmap_table); + tables.append (head_table); tables.append (glyf_table); tables.append (hhea_table); tables.append (hmtx_table); tables.append (loca_table); - tables.append (name_table); tables.append (maxp_table); + tables.append (name_table); tables.append (os_2_table); tables.append (post_table); } @@ -4149,7 +4155,7 @@ class DirectoryTable : Table { offset_table = ot; } - public void parse (OtfInputStream dis, File file) throws Error { + public void parse (OtfInputStream dis, File file, OpenFontFormatReader reader_callback) throws Error { StringBuilder tag = new StringBuilder (); uint32 checksum; uint32 offset; @@ -4242,10 +4248,12 @@ class DirectoryTable : Table { return; } + hhea_table.parse (dis); + reader_callback.set_limits (); + name_table.parse (dis); post_table.parse (dis); os_2_table.parse (dis); - hhea_table.parse (dis); maxp_table.parse (dis); loca_table.parse (dis, head_table, maxp_table); hmtx_table.parse (dis, hhea_table, loca_table); @@ -418,7 +418,7 @@ class OverView : FontDisplay { scrollbar.draw (cr, allocation); - n_items = ((allocation.width - 10) / nail_width);+ n_items = ((allocation.width - 15) / nail_width); rows = (allocation.height / nail_height); if (items_per_row != n_items) { @@ -513,8 +513,6 @@ class OverView : FontDisplay { public void scroll_to (double percent) { int64 r; - print (@"percent $percent\n");- r = (int64) (percent * glyph_range.length () / rows); r *= items_per_row;