Behdad Esfahbod | 15232e2 | 2009-08-13 17:13:25 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2009 Red Hat, Inc. |
Behdad Esfahbod | 15232e2 | 2009-08-13 17:13:25 -0400 | [diff] [blame] | 3 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 4 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | 15232e2 | 2009-08-13 17:13:25 -0400 | [diff] [blame] | 5 | * |
| 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. |
| 11 | * |
| 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 |
| 16 | * DAMAGE. |
| 17 | * |
| 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. |
| 23 | * |
| 24 | * Red Hat Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
Behdad Esfahbod | c57d454 | 2011-04-20 18:50:27 -0400 | [diff] [blame] | 27 | #include "hb-private.hh" |
Behdad Esfahbod | 15232e2 | 2009-08-13 17:13:25 -0400 | [diff] [blame] | 28 | |
| 29 | #include "hb-shape.h" |
| 30 | |
Behdad Esfahbod | 22da7fd | 2010-05-12 18:23:21 -0400 | [diff] [blame] | 31 | #include "hb-buffer-private.hh" |
Behdad Esfahbod | 2f50d87 | 2009-11-04 21:07:03 -0500 | [diff] [blame] | 32 | |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 33 | #ifdef HAVE_UNISCRIBE |
| 34 | # include "hb-uniscribe.h" |
Behdad Esfahbod | 305ba86 | 2010-05-21 14:02:20 +0100 | [diff] [blame] | 35 | #endif |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 36 | #ifdef HAVE_OT |
| 37 | # include "hb-ot-shape.h" |
| 38 | #endif |
| 39 | #include "hb-fallback-shape-private.hh" |
Behdad Esfahbod | 26d7a75 | 2009-12-20 17:58:25 +0100 | [diff] [blame] | 40 | |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 41 | typedef hb_bool_t (*hb_shape_func_t) (hb_font_t *font, |
| 42 | hb_buffer_t *buffer, |
| 43 | const hb_feature_t *features, |
| 44 | unsigned int num_features, |
Behdad Esfahbod | 0501573 | 2011-08-10 16:25:56 +0200 | [diff] [blame^] | 45 | const char * const *shaper_options); |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 46 | |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 47 | #define HB_SHAPER_IMPLEMENT(name) {#name, hb_##name##_shape} |
Behdad Esfahbod | 670c873 | 2011-08-08 21:36:24 +0200 | [diff] [blame] | 48 | static struct hb_shaper_pair_t { |
| 49 | char name[16]; |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 50 | hb_shape_func_t func; |
| 51 | } shapers[] = { |
| 52 | /* v--- Add new shapers in the right place here */ |
| 53 | #ifdef HAVE_UNISCRIBE |
| 54 | HB_SHAPER_IMPLEMENT (uniscribe), |
| 55 | #endif |
| 56 | #ifdef HAVE_OT |
| 57 | HB_SHAPER_IMPLEMENT (ot), |
| 58 | #endif |
| 59 | HB_SHAPER_IMPLEMENT (fallback) /* should be last */ |
| 60 | }; |
| 61 | #undef HB_SHAPER_IMPLEMENT |
Behdad Esfahbod | 26d7a75 | 2009-12-20 17:58:25 +0100 | [diff] [blame] | 62 | |
Behdad Esfahbod | c62a8f1 | 2011-08-05 18:02:30 -0400 | [diff] [blame] | 63 | static struct static_shaper_list_t |
| 64 | { |
Behdad Esfahbod | c4d63ef | 2011-08-05 17:54:25 -0400 | [diff] [blame] | 65 | static_shaper_list_t (void) |
| 66 | { |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 67 | char *env = getenv ("HB_SHAPER_LIST"); |
Behdad Esfahbod | 670c873 | 2011-08-08 21:36:24 +0200 | [diff] [blame] | 68 | if (env && *env) |
| 69 | { |
| 70 | /* Reorder shaper list to prefer requested shaper list. */ |
| 71 | unsigned int i = 0; |
| 72 | char *end, *p = env; |
| 73 | for (;;) { |
| 74 | end = strchr (p, ','); |
| 75 | if (!end) |
| 76 | end = p + strlen (p); |
| 77 | |
| 78 | for (unsigned int j = i; j < ARRAY_LENGTH (shapers); j++) |
Behdad Esfahbod | 33ccc77 | 2011-08-09 00:43:24 +0200 | [diff] [blame] | 79 | if (end - p == (int) strlen (shapers[j].name) && |
Behdad Esfahbod | 670c873 | 2011-08-08 21:36:24 +0200 | [diff] [blame] | 80 | 0 == strncmp (shapers[j].name, p, end - p)) |
| 81 | { |
| 82 | /* Reorder this shaper to position i */ |
| 83 | struct hb_shaper_pair_t t = shapers[j]; |
| 84 | memmove (&shapers[i + 1], &shapers[i], sizeof (shapers[i]) * (j - i)); |
| 85 | shapers[i] = t; |
| 86 | i++; |
| 87 | } |
| 88 | |
| 89 | if (!*end) |
| 90 | break; |
| 91 | else |
| 92 | p = end + 1; |
| 93 | } |
Behdad Esfahbod | 9da5545 | 2011-08-05 19:48:49 -0400 | [diff] [blame] | 94 | } |
Behdad Esfahbod | c4d63ef | 2011-08-05 17:54:25 -0400 | [diff] [blame] | 95 | |
Behdad Esfahbod | 670c873 | 2011-08-08 21:36:24 +0200 | [diff] [blame] | 96 | ASSERT_STATIC ((ARRAY_LENGTH (shapers) + 1) * sizeof (*shaper_list) <= sizeof (shaper_list)); |
| 97 | unsigned int i; |
| 98 | for (i = 0; i < ARRAY_LENGTH (shapers); i++) |
| 99 | shaper_list[i] = shapers[i].name; |
| 100 | shaper_list[i] = NULL; |
Behdad Esfahbod | c4d63ef | 2011-08-05 17:54:25 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Behdad Esfahbod | 670c873 | 2011-08-08 21:36:24 +0200 | [diff] [blame] | 103 | const char *shaper_list[ARRAY_LENGTH (shapers) + 1]; |
Behdad Esfahbod | 9da5545 | 2011-08-05 19:48:49 -0400 | [diff] [blame] | 104 | } static_shaper_list; |
| 105 | |
| 106 | const char ** |
| 107 | hb_shape_list_shapers (void) |
| 108 | { |
| 109 | return static_shaper_list.shaper_list; |
| 110 | } |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 111 | |
| 112 | hb_bool_t |
Behdad Esfahbod | 0501573 | 2011-08-10 16:25:56 +0200 | [diff] [blame^] | 113 | hb_shape_full (hb_font_t *font, |
| 114 | hb_buffer_t *buffer, |
| 115 | const hb_feature_t *features, |
| 116 | unsigned int num_features, |
| 117 | const char * const *shaper_options, |
| 118 | const char * const *shaper_list) |
Behdad Esfahbod | 15232e2 | 2009-08-13 17:13:25 -0400 | [diff] [blame] | 119 | { |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 120 | if (likely (!shaper_list)) { |
| 121 | for (unsigned int i = 0; i < ARRAY_LENGTH (shapers); i++) |
| 122 | if (likely (shapers[i].func (font, buffer, |
| 123 | features, num_features, |
| 124 | shaper_options))) |
| 125 | return TRUE; |
| 126 | } else { |
| 127 | while (*shaper_list) { |
| 128 | for (unsigned int i = 0; i < ARRAY_LENGTH (shapers); i++) |
Behdad Esfahbod | ff199ba | 2011-08-07 03:43:46 -0400 | [diff] [blame] | 129 | if (0 == strcmp (*shaper_list, shapers[i].name)) { |
| 130 | if (likely (shapers[i].func (font, buffer, |
| 131 | features, num_features, |
| 132 | shaper_options))) |
| 133 | return TRUE; |
| 134 | break; |
| 135 | } |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 136 | shaper_list++; |
Behdad Esfahbod | 3286fc0 | 2011-03-16 14:53:32 -0300 | [diff] [blame] | 137 | } |
| 138 | } |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 139 | return FALSE; |
Behdad Esfahbod | 3286fc0 | 2011-03-16 14:53:32 -0300 | [diff] [blame] | 140 | } |
Behdad Esfahbod | 3ca6c4e | 2011-08-05 17:22:19 -0400 | [diff] [blame] | 141 | |
| 142 | void |
| 143 | hb_shape (hb_font_t *font, |
| 144 | hb_buffer_t *buffer, |
| 145 | const hb_feature_t *features, |
| 146 | unsigned int num_features) |
| 147 | { |
| 148 | hb_shape_full (font, buffer, features, num_features, NULL, NULL); |
| 149 | } |