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.
Language fix heads/multimaster
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 = 1; 31 32 foreach (GlyphCollection g in glyf_table.glyphs) { 33 if (!g.is_unassigned () && g.get_unicode_character () < 0xFFFFFFFF) { 34 glyph_range.add_single (g.get_unicode_character ()); 35 } 36 } 37 38 ranges = glyph_range.get_ranges (); 39 40 fd.add_u16 (12); // Format 41 fd.add_u16 (0); // Reserved 42 43 fd.add_u32 (16 + ranges.size * 12); // length 44 45 fd.add_u32 (0); // Language 46 fd.add_u32 ((uint32) ranges.size); // Number of groupings 47 48 indice = first_assigned; 49 foreach (UniRange u in ranges) { 50 51 if (u.start >= 0xFFFFFFFF || u.stop >= 0xFFFFFFFF) { 52 warning ("Glyph range not supported by CmapSubtableFormat12."); 53 } else { 54 fd.add_u32 (u.start); 55 fd.add_u32 (u.stop); 56 fd.add_u32 (indice); 57 58 indice += u.length (); 59 } 60 } 61 62 return fd; 63 } 64 } 65 66 } 67