2 * Copyright (C) 2007,2008 Red Hat, Inc.
4 * This is part of HarfBuzz, an OpenType Layout engine library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Red Hat Author(s): Behdad Esfahbod
27 #define HB_OT_LAYOUT_CC
29 #include "hb-ot-layout.h"
30 #include "hb-ot-layout-private.h"
32 #include "hb-ot-layout-open-private.h"
33 #include "hb-ot-layout-gdef-private.h"
34 #include "hb-ot-layout-gsub-private.h"
41 hb_ot_layout_create (const char *font_data,
44 HB_OT_Layout *layout = (HB_OT_Layout *) calloc (1, sizeof (HB_OT_Layout));
46 const OpenTypeFontFile &font = OpenTypeFontFile::get_for_data (font_data);
47 const OpenTypeFontFace &face = font.get_face (face_index);
49 layout->gdef = &GDEF::get_for_data (font.get_table_data (face.get_table (GDEF::Tag)));
50 layout->gsub = &GSUB::get_for_data (font.get_table_data (face.get_table (GSUB::Tag)));
51 //layout->gpos = &GPOS::get_for_data (font.get_table_data (face.get_table (GPOS::Tag)));
57 hb_ot_layout_destroy (HB_OT_Layout *layout)
62 static hb_ot_layout_glyph_properties_t
63 _hb_ot_layout_get_glyph_properties (HB_OT_Layout *layout,
64 hb_ot_layout_glyph_t glyph)
66 hb_ot_layout_class_t klass;
68 /* TODO old harfbuzz doesn't always parse mark attachments as it says it was
69 * introduced without a version bump, so it may not be safe */
70 klass = layout->gdef->get_mark_attachment_type (glyph);
74 klass = layout->gdef->get_glyph_class (glyph);
76 if (!klass && glyph < layout->new_gdef.len)
77 klass = layout->new_gdef.klasses[glyph];
81 case GDEF::UnclassifiedGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED;
82 case GDEF::BaseGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH;
83 case GDEF::LigatureGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE;
84 case GDEF::MarkGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_MARK;
85 case GDEF::ComponentGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT;
89 hb_ot_layout_glyph_class_t
90 hb_ot_layout_get_glyph_class (HB_OT_Layout *layout,
91 hb_ot_layout_glyph_t glyph)
93 hb_ot_layout_glyph_properties_t properties;
94 hb_ot_layout_class_t klass;
96 properties = _hb_ot_layout_get_glyph_properties (layout, glyph);
98 if (properties & 0xFF)
99 return HB_OT_LAYOUT_GLYPH_CLASS_MARK;
101 return (hb_ot_layout_glyph_class_t) properties;
105 hb_ot_layout_set_glyph_class (HB_OT_Layout *layout,
106 hb_ot_layout_glyph_t glyph,
107 hb_ot_layout_glyph_class_t klass)
109 /* TODO optimize this, similar to old harfbuzz code for example */
110 /* TODO our semantics are a bit different from old harfbuzz code too */
112 hb_ot_layout_class_t gdef_klass;
113 int len = layout->new_gdef.len;
117 uint8_t *new_klasses;
119 new_len = len == 0 ? 120 : 2 * len;
122 new_klasses = (uint8_t *) realloc (layout->new_gdef.klasses, new_len * sizeof (uint8_t));
124 if (G_UNLIKELY (!new_klasses))
127 memset (new_klasses + len, 0, new_len - len);
129 layout->new_gdef.klasses = new_klasses;
130 layout->new_gdef.len = new_len;
135 case HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED: gdef_klass = GDEF::UnclassifiedGlyph; break;
136 case HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH: gdef_klass = GDEF::BaseGlyph; break;
137 case HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE: gdef_klass = GDEF::LigatureGlyph; break;
138 case HB_OT_LAYOUT_GLYPH_CLASS_MARK: gdef_klass = GDEF::MarkGlyph; break;
139 case HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT: gdef_klass = GDEF::ComponentGlyph; break;
142 layout->new_gdef.klasses[glyph] = gdef_klass;