The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

CmapSubtableFormat12.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/CmapSubtableFormat12.vala.
Fix errors in cmap subtable 4
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 namespace BirdFont { 16 17 /** Format 12 cmap subtable */ 18 public class CmapSubtableFormat12 : CmapSubtable { 19 20 FontData cmap_data; 21 22 public CmapSubtableFormat12 () { 23 } 24 25 public override ushort get_platform () { 26 return 3; 27 } 28 29 public override ushort get_encoding () { 30 return 10; 31 } 32 33 public override FontData get_cmap_data () { 34 return cmap_data; 35 } 36 37 public override void generate_cmap_data (GlyfTable glyf_table) throws GLib.Error { 38 GlyphRange glyph_range = new GlyphRange (); 39 Gee.ArrayList<UniRange> ranges; 40 FontData fd = new FontData (); 41 uint32 first_assigned; 42 uint32 index; 43 44 first_assigned = 1; 45 46 foreach (GlyphCollection g in glyf_table.glyphs) { 47 if (!g.is_unassigned () && g.get_unicode_character () < 0xFFFFFFFF) { 48 glyph_range.add_single (g.get_unicode_character ()); 49 } 50 } 51 52 ranges = glyph_range.get_ranges (); 53 54 fd.add_u16 (12); // Format 55 fd.add_u16 (0); // Reserved 56 57 fd.add_u32 (16 + ranges.size * 12); // length 58 59 fd.add_u32 (0); // Language 60 fd.add_u32 ((uint32) ranges.size); // Number of groupings 61 62 index = first_assigned; 63 foreach (UniRange u in ranges) { 64 65 if (u.start >= 0xFFFFFFFF || u.stop >= 0xFFFFFFFF) { 66 warning ("Glyph range not supported by CmapSubtableFormat12."); 67 } else { 68 fd.add_u32 (u.start); 69 fd.add_u32 (u.stop); 70 fd.add_u32 (index); 71 72 index += u.length (); 73 } 74 } 75 76 cmap_data = fd; 77 } 78 } 79 80 } 81