The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

CmapSubtableFormat0.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/CmapSubtableFormat0.vala.
Cache overview items
1 /* 2 Copyright (C) 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 0 cmap subtable */ 18 public class CmapSubtableFormat0 : CmapSubtable { 19 FontData cmap_data = new FontData (); 20 21 public CmapSubtableFormat0 () { 22 } 23 24 public override ushort get_platform () { 25 return 1; 26 } 27 28 public override ushort get_encoding () { 29 return 0; 30 } 31 32 public override FontData get_cmap_data () { 33 return cmap_data; 34 } 35 36 public override void generate_cmap_data (GlyfTable glyf_table) 37 throws GLib.Error { 38 FontData fd = new FontData (); 39 40 fd.add_u16 (0); // Format 41 fd.add_u16 (262); // Length 42 fd.add_u16 (0); // Language 43 44 for (uint i = 0; i < 256; i++) { 45 fd.add (get_gid_for_unichar ((unichar) i, glyf_table)); 46 } 47 48 cmap_data = fd; 49 } 50 51 uint8 get_gid_for_unichar (unichar c, GlyfTable glyf_table) { 52 uint32 index = 0; 53 foreach (GlyphCollection g in glyf_table.glyphs) { 54 if (g.get_unicode_character () == c && !g.is_unassigned ()) { 55 return (index <= uint8.MAX) ? (uint8) index : 0; 56 } 57 index++; 58 } 59 return 0; 60 } 61 } 62 63 } 64 65