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.h"
29 #include "hb-buffer-private.h"
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'),
47 add_feature (hb_face_t *face,
49 unsigned int feature_index,
50 unsigned int *lookups,
51 unsigned int *num_lookups,
52 unsigned int room_lookups)
54 unsigned int i = room_lookups - *num_lookups;
55 hb_ot_layout_feature_get_lookup_indexes (face, table_tag, feature_index, 0,
57 lookups + *num_lookups);
62 cmp_lookups (const void *p1, const void *p2)
64 unsigned int a = * (const unsigned int *) p1;
65 unsigned int b = * (const unsigned int *) p2;
71 setup_lookups (hb_face_t *face,
73 hb_feature_t *features,
74 unsigned int num_features,
76 unsigned int *lookups,
77 unsigned int *num_lookups)
79 unsigned int i, j, script_index, language_index, feature_index, room_lookups;
81 room_lookups = *num_lookups;
84 hb_ot_layout_table_choose_script (face, table_tag,
85 hb_ot_tags_from_script (buffer->script),
87 hb_ot_layout_script_find_language (face, table_tag, script_index,
88 hb_ot_tag_from_language (buffer->language),
91 if (hb_ot_layout_language_get_required_feature_index (face, table_tag, script_index, language_index,
93 add_feature (face, table_tag, feature_index, lookups, num_lookups, room_lookups);
95 for (i = 0; i < ARRAY_LENGTH (default_features); i++)
97 if (hb_ot_layout_language_find_feature (face, table_tag, script_index, language_index,
100 add_feature (face, table_tag, feature_index, lookups, num_lookups, room_lookups);
103 qsort (lookups, *num_lookups, sizeof (lookups[0]), cmp_lookups);
107 for (i = 1, j = 0; i < *num_lookups; i++)
108 if (lookups[i] != lookups[j])
109 lookups[++j] = lookups[i];
110 lookups[j++] = lookups[i - 1];
117 _hb_ot_substitute_complex (hb_font_t *font HB_GNUC_UNUSED,
120 hb_feature_t *features,
121 unsigned int num_features)
123 unsigned int lookups[1000];
124 unsigned int num_lookups = ARRAY_LENGTH (lookups);
127 if (!hb_ot_layout_has_substitution (face))
130 setup_lookups (face, buffer, features, num_features,
132 lookups, &num_lookups);
134 for (i = 0; i < num_lookups; i++)
135 hb_ot_layout_substitute_lookup (face, buffer, lookups[i], 0xFFFF);
141 _hb_ot_position_complex (hb_font_t *font,
144 hb_feature_t *features,
145 unsigned int num_features)
147 unsigned int lookups[1000];
148 unsigned int num_lookups = ARRAY_LENGTH (lookups);
151 if (!hb_ot_layout_has_positioning (face))
154 setup_lookups (face, buffer, features, num_features,
156 lookups, &num_lookups);
158 for (i = 0; i < num_lookups; i++)
159 hb_ot_layout_position_lookup (font, face, buffer, lookups[i], 0xFFFF);
161 hb_ot_layout_position_finish (font, face, buffer);