OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Red Hat, Inc. | 2 * Copyright © 2009 Red Hat, Inc. |
3 * | 3 * |
4 * This is part of HarfBuzz, a text shaping library. | 4 * This is part of HarfBuzz, a text shaping library. |
5 * | 5 * |
6 * Permission is hereby granted, without written agreement and without | 6 * Permission is hereby granted, without written agreement and without |
7 * license or royalty fees, to use, copy, modify, and distribute this | 7 * license or royalty fees, to use, copy, modify, and distribute this |
8 * software and its documentation for any purpose, provided that the | 8 * software and its documentation for any purpose, provided that the |
9 * above copyright notice and the following two paragraphs appear in | 9 * above copyright notice and the following two paragraphs appear in |
10 * all copies of this software. | 10 * all copies of this software. |
11 * | 11 * |
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR | 12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES | 13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN | 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 | 15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
16 * DAMAGE. | 16 * DAMAGE. |
17 * | 17 * |
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | 18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | 19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS | 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 | 21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
23 * | 23 * |
24 * Red Hat Author(s): Behdad Esfahbod | 24 * Red Hat Author(s): Behdad Esfahbod |
25 */ | 25 */ |
26 | 26 |
27 #include "hb-private.h" | 27 #include "hb-private.hh" |
28 | 28 |
29 #include "hb-shape.h" | 29 #include "hb-shape.h" |
30 | 30 |
31 #include "hb-buffer-private.hh" | 31 #include "hb-buffer-private.hh" |
32 | 32 |
33 #include "hb-ot-shape.h" | 33 #ifdef HAVE_GRAPHITE |
| 34 #include "hb-graphite2.h" |
| 35 #endif |
| 36 #ifdef HAVE_UNISCRIBE |
| 37 # include "hb-uniscribe.h" |
| 38 #endif |
| 39 #ifdef HAVE_OT |
| 40 # include "hb-ot-shape.h" |
| 41 #endif |
| 42 #include "hb-fallback-shape-private.hh" |
34 | 43 |
| 44 typedef hb_bool_t (*hb_shape_func_t) (hb_font_t *font, |
| 45 hb_buffer_t *buffer, |
| 46 const hb_feature_t *features, |
| 47 unsigned int num_features, |
| 48 const char * const *shaper_options); |
| 49 |
| 50 #define HB_SHAPER_IMPLEMENT(name) {#name, hb_##name##_shape} |
| 51 static struct hb_shaper_pair_t { |
| 52 char name[16]; |
| 53 hb_shape_func_t func; |
| 54 } shapers[] = { |
| 55 /* v--- Add new shapers in the right place here */ |
35 #ifdef HAVE_GRAPHITE | 56 #ifdef HAVE_GRAPHITE |
36 #include "hb-graphite.h" | 57 HB_SHAPER_IMPLEMENT (graphite), |
37 #endif | 58 #endif |
| 59 #ifdef HAVE_UNISCRIBE |
| 60 HB_SHAPER_IMPLEMENT (uniscribe), |
| 61 #endif |
| 62 #ifdef HAVE_OT |
| 63 HB_SHAPER_IMPLEMENT (ot), |
| 64 #endif |
| 65 HB_SHAPER_IMPLEMENT (fallback) /* should be last */ |
| 66 }; |
| 67 #undef HB_SHAPER_IMPLEMENT |
38 | 68 |
39 HB_BEGIN_DECLS | 69 static struct static_shaper_list_t |
| 70 { |
| 71 static_shaper_list_t (void) |
| 72 { |
| 73 char *env = getenv ("HB_SHAPER_LIST"); |
| 74 if (env && *env) |
| 75 { |
| 76 /* Reorder shaper list to prefer requested shaper list. */ |
| 77 unsigned int i = 0; |
| 78 char *end, *p = env; |
| 79 for (;;) { |
| 80 end = strchr (p, ','); |
| 81 if (!end) |
| 82 end = p + strlen (p); |
40 | 83 |
| 84 for (unsigned int j = i; j < ARRAY_LENGTH (shapers); j++) |
| 85 if (end - p == (int) strlen (shapers[j].name) && |
| 86 0 == strncmp (shapers[j].name, p, end - p)) |
| 87 { |
| 88 /* Reorder this shaper to position i */ |
| 89 struct hb_shaper_pair_t t = shapers[j]; |
| 90 memmove (&shapers[i + 1], &shapers[i], sizeof (shapers[i]) * (j - i))
; |
| 91 shapers[i] = t; |
| 92 i++; |
| 93 } |
| 94 |
| 95 if (!*end) |
| 96 break; |
| 97 else |
| 98 p = end + 1; |
| 99 } |
| 100 } |
| 101 |
| 102 ASSERT_STATIC ((ARRAY_LENGTH (shapers) + 1) * sizeof (*shaper_list) <= sizeo
f (shaper_list)); |
| 103 unsigned int i; |
| 104 for (i = 0; i < ARRAY_LENGTH (shapers); i++) |
| 105 shaper_list[i] = shapers[i].name; |
| 106 shaper_list[i] = NULL; |
| 107 } |
| 108 |
| 109 const char *shaper_list[ARRAY_LENGTH (shapers) + 1]; |
| 110 } static_shaper_list; |
| 111 |
| 112 const char ** |
| 113 hb_shape_list_shapers (void) |
| 114 { |
| 115 return static_shaper_list.shaper_list; |
| 116 } |
| 117 |
| 118 hb_bool_t |
| 119 hb_shape_full (hb_font_t *font, |
| 120 hb_buffer_t *buffer, |
| 121 const hb_feature_t *features, |
| 122 unsigned int num_features, |
| 123 const char * const *shaper_options, |
| 124 const char * const *shaper_list) |
| 125 { |
| 126 if (likely (!shaper_list)) { |
| 127 for (unsigned int i = 0; i < ARRAY_LENGTH (shapers); i++) |
| 128 if (likely (shapers[i].func (font, buffer, |
| 129 features, num_features, |
| 130 shaper_options))) |
| 131 return TRUE; |
| 132 } else { |
| 133 while (*shaper_list) { |
| 134 for (unsigned int i = 0; i < ARRAY_LENGTH (shapers); i++) |
| 135 if (0 == strcmp (*shaper_list, shapers[i].name)) { |
| 136 if (likely (shapers[i].func (font, buffer, |
| 137 features, num_features, |
| 138 shaper_options))) |
| 139 return TRUE; |
| 140 break; |
| 141 } |
| 142 shaper_list++; |
| 143 } |
| 144 } |
| 145 return FALSE; |
| 146 } |
41 | 147 |
42 void | 148 void |
43 hb_shape (hb_font_t *font, | 149 hb_shape (hb_font_t *font, |
44 » hb_face_t *face, | 150 » hb_buffer_t *buffer, |
45 » hb_buffer_t *buffer, | 151 » const hb_feature_t *features, |
46 » hb_feature_t *features, | 152 » unsigned int num_features) |
47 » unsigned int num_features) | |
48 { | 153 { |
49 #if 0 && defined(HAVE_GRAPHITE) | 154 hb_shape_full (font, buffer, features, num_features, NULL, NULL); |
50 hb_blob_t *silf_blob; | |
51 silf_blob = hb_face_get_table (face, HB_GRAPHITE_TAG_Silf); | |
52 if (hb_blob_get_length(silf_blob)) | |
53 { | |
54 hb_graphite_shape(font, face, buffer, features, num_features); | |
55 hb_blob_destroy(silf_blob); | |
56 return; | |
57 } | |
58 hb_blob_destroy(silf_blob); | |
59 #endif | |
60 | |
61 hb_ot_shape (font, face, buffer, features, num_features); | |
62 } | 155 } |
63 | |
64 | |
65 HB_END_DECLS | |
OLD | NEW |