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 Cmap tables
1 /* 2 Copyright (C) 2012, 2013, 2014 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 : GLib.Object { 19 20 public CmapSubtableFormat12 () { 21 } 22 23 public FontData get_cmap_data (GlyfTable glyf_table) throws GLib.Error { 24 GlyphRange glyph_range = new GlyphRange (); 25 Gee.ArrayList<UniRange> ranges; 26 FontData fd = new FontData (); 27 uint32 first_assigned; 28 uint32 indice; 29 30 first_assigned = 0; 31 foreach (GlyphCollection g in glyf_table.glyphs) { 32 if (!g.is_unassigned () && g.get_unicode_character () == '\0') { 33 first_assigned++; 34 } 35 } 36 37 foreach (GlyphCollection g in glyf_table.glyphs) { 38 if (!g.is_unassigned () && g.get_unicode_character () < 0xFFFFFFFF) { 39 glyph_range.add_single (g.get_unicode_character ()); 40 } 41 } 42 43 ranges = glyph_range.get_ranges (); 44 45 fd.add_u16 (12); // Format 46 fd.add_u16 (0); // Reserved 47 48 fd.add_u32 (16 + ranges.size * 12); // length 49 50 fd.add_u32 (0); // Language 51 fd.add_u32 ((uint32) ranges.size); // Number of groupings 52 53 indice = first_assigned; 54 foreach (UniRange u in ranges) { 55 56 if (u.start >= 0xFFFFFFFF || u.stop >= 0xFFFFFFFF) { 57 warning ("Glyph range not supported by CmapSubtableFormat12."); 58 } else { 59 fd.add_u32 (u.start); 60 fd.add_u32 (u.stop); 61 fd.add_u32 (indice); 62 63 indice += u.length (); 64 } 65 } 66 67 return fd; 68 } 69 } 70 71 } 72