2 * Copyright (C) 2009 Red Hat, Inc.
4 * This is part of HarfBuzz, a text shaping 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 #include "hb-ot-shape-private.hh"
29 #include "hb-buffer-private.hh"
31 #include "hb-ot-layout.h"
33 hb_tag_t default_features[] = {
35 HB_TAG('c','c','m','p'),
36 HB_TAG('l','o','c','l'),
37 HB_TAG('l','i','g','a'),
38 HB_TAG('c','l','i','g'),
40 HB_TAG('k','e','r','n'),
41 HB_TAG('m','a','r','k'),
42 HB_TAG('m','k','m','k'),
52 add_feature (hb_face_t *face,
54 unsigned int feature_index,
57 unsigned int *num_lookups,
58 unsigned int room_lookups)
60 unsigned int i = room_lookups - *num_lookups;
61 lookups += *num_lookups;
63 unsigned int *lookup_indices = (unsigned int *) lookups;
65 hb_ot_layout_feature_get_lookup_indexes (face, table_tag, feature_index, 0,
72 lookups[i].mask = mask;
73 lookups[i].index = lookup_indices[i];
78 cmp_lookups (const void *p1, const void *p2)
80 const lookup_map *a = (const lookup_map *) p1;
81 const lookup_map *b = (const lookup_map *) p2;
83 return a->index - b->index;
87 setup_lookups (hb_face_t *face,
89 hb_feature_t *features,
90 unsigned int num_features,
93 unsigned int *num_lookups)
95 unsigned int i, j, script_index, language_index, feature_index, room_lookups;
97 room_lookups = *num_lookups;
100 hb_ot_layout_table_choose_script (face, table_tag,
101 hb_ot_tags_from_script (buffer->script),
103 hb_ot_layout_script_find_language (face, table_tag, script_index,
104 hb_ot_tag_from_language (buffer->language),
107 if (hb_ot_layout_language_get_required_feature_index (face, table_tag, script_index, language_index,
109 add_feature (face, table_tag, feature_index, 1, lookups, num_lookups, room_lookups);
111 for (i = 0; i < ARRAY_LENGTH (default_features); i++)
113 if (hb_ot_layout_language_find_feature (face, table_tag, script_index, language_index,
116 add_feature (face, table_tag, feature_index, 1, lookups, num_lookups, room_lookups);
119 for (i = 0; i < num_features; i++)
121 if (hb_ot_layout_language_find_feature (face, table_tag, script_index, language_index,
124 add_feature (face, table_tag, feature_index, 1, lookups, num_lookups, room_lookups);
127 qsort (lookups, *num_lookups, sizeof (lookups[0]), cmp_lookups);
131 for (i = 1, j = 0; i < *num_lookups; i++)
132 if (lookups[i].index != lookups[j].index)
133 lookups[++j] = lookups[i];
135 lookups[j].mask |= lookups[i].mask;
143 _hb_ot_substitute_complex (hb_font_t *font HB_UNUSED,
146 hb_feature_t *features,
147 unsigned int num_features)
149 lookup_map lookups[1000];
150 unsigned int num_lookups = ARRAY_LENGTH (lookups);
153 if (!hb_ot_layout_has_substitution (face))
156 setup_lookups (face, buffer, features, num_features,
158 lookups, &num_lookups);
160 for (i = 0; i < num_lookups; i++)
161 hb_ot_layout_substitute_lookup (face, buffer, lookups[i].index, lookups[i].mask);
167 _hb_ot_position_complex (hb_font_t *font,
170 hb_feature_t *features,
171 unsigned int num_features)
173 lookup_map lookups[1000];
174 unsigned int num_lookups = ARRAY_LENGTH (lookups);
177 if (!hb_ot_layout_has_positioning (face))
180 setup_lookups (face, buffer, features, num_features,
182 lookups, &num_lookups);
184 for (i = 0; i < num_lookups; i++)
185 hb_ot_layout_position_lookup (font, face, buffer, lookups[i].index, lookups[i].mask);
187 hb_ot_layout_position_finish (font, face, buffer);