Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 3613696 | 2013-08-12 00:33:28 -0400 | [diff] [blame] | 2 | * Copyright © 2011,2012,2013 Google, Inc. |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 3 | * |
| 4 | * This is part of HarfBuzz, a text shaping library. |
| 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 | * Google Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 27 | #define HB_SHAPER uniscribe |
| 28 | #include "hb-shaper-impl-private.hh" |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 29 | |
Behdad Esfahbod | b492299 | 2011-08-05 20:34:50 -0400 | [diff] [blame] | 30 | #include <windows.h> |
| 31 | #include <usp10.h> |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 32 | #include <rpc.h> |
Behdad Esfahbod | b492299 | 2011-08-05 20:34:50 -0400 | [diff] [blame] | 33 | |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 34 | #include "hb-uniscribe.h" |
| 35 | |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 36 | #include "hb-open-file-private.hh" |
Behdad Esfahbod | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 37 | #include "hb-ot-name-table.hh" |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 38 | #include "hb-ot-tag.h" |
| 39 | |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 40 | |
| 41 | #ifndef HB_DEBUG_UNISCRIBE |
| 42 | #define HB_DEBUG_UNISCRIBE (HB_DEBUG+0) |
| 43 | #endif |
| 44 | |
| 45 | |
Behdad Esfahbod | 666b42f | 2014-10-14 21:24:59 -0700 | [diff] [blame] | 46 | static inline uint16_t hb_uint16_swap (const uint16_t v) |
| 47 | { return (v >> 8) | (v << 8); } |
| 48 | static inline uint32_t hb_uint32_swap (const uint32_t v) |
| 49 | { return (hb_uint16_swap (v) << 16) | hb_uint16_swap (v >> 16); } |
| 50 | |
| 51 | |
Chun-wei Fan | 93a04b8 | 2013-06-03 17:49:37 +0800 | [diff] [blame] | 52 | typedef HRESULT (WINAPI *SIOT) /*ScriptItemizeOpenType*/( |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 53 | const WCHAR *pwcInChars, |
| 54 | int cInChars, |
| 55 | int cMaxItems, |
| 56 | const SCRIPT_CONTROL *psControl, |
| 57 | const SCRIPT_STATE *psState, |
| 58 | SCRIPT_ITEM *pItems, |
| 59 | OPENTYPE_TAG *pScriptTags, |
| 60 | int *pcItems |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 61 | ); |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 62 | |
Chun-wei Fan | 93a04b8 | 2013-06-03 17:49:37 +0800 | [diff] [blame] | 63 | typedef HRESULT (WINAPI *SSOT) /*ScriptShapeOpenType*/( |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 64 | HDC hdc, |
| 65 | SCRIPT_CACHE *psc, |
| 66 | SCRIPT_ANALYSIS *psa, |
| 67 | OPENTYPE_TAG tagScript, |
| 68 | OPENTYPE_TAG tagLangSys, |
| 69 | int *rcRangeChars, |
| 70 | TEXTRANGE_PROPERTIES **rpRangeProperties, |
| 71 | int cRanges, |
| 72 | const WCHAR *pwcChars, |
| 73 | int cChars, |
| 74 | int cMaxGlyphs, |
| 75 | WORD *pwLogClust, |
| 76 | SCRIPT_CHARPROP *pCharProps, |
| 77 | WORD *pwOutGlyphs, |
| 78 | SCRIPT_GLYPHPROP *pOutGlyphProps, |
| 79 | int *pcGlyphs |
| 80 | ); |
| 81 | |
Chun-wei Fan | 93a04b8 | 2013-06-03 17:49:37 +0800 | [diff] [blame] | 82 | typedef HRESULT (WINAPI *SPOT) /*ScriptPlaceOpenType*/( |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 83 | HDC hdc, |
| 84 | SCRIPT_CACHE *psc, |
| 85 | SCRIPT_ANALYSIS *psa, |
| 86 | OPENTYPE_TAG tagScript, |
| 87 | OPENTYPE_TAG tagLangSys, |
| 88 | int *rcRangeChars, |
| 89 | TEXTRANGE_PROPERTIES **rpRangeProperties, |
| 90 | int cRanges, |
| 91 | const WCHAR *pwcChars, |
| 92 | WORD *pwLogClust, |
| 93 | SCRIPT_CHARPROP *pCharProps, |
| 94 | int cChars, |
| 95 | const WORD *pwGlyphs, |
| 96 | const SCRIPT_GLYPHPROP *pGlyphProps, |
| 97 | int cGlyphs, |
| 98 | int *piAdvance, |
| 99 | GOFFSET *pGoffset, |
| 100 | ABC *pABC |
| 101 | ); |
| 102 | |
| 103 | |
| 104 | /* Fallback implementations. */ |
| 105 | |
| 106 | static HRESULT WINAPI |
| 107 | hb_ScriptItemizeOpenType( |
| 108 | const WCHAR *pwcInChars, |
| 109 | int cInChars, |
| 110 | int cMaxItems, |
| 111 | const SCRIPT_CONTROL *psControl, |
| 112 | const SCRIPT_STATE *psState, |
| 113 | SCRIPT_ITEM *pItems, |
| 114 | OPENTYPE_TAG *pScriptTags, |
| 115 | int *pcItems |
| 116 | ) |
| 117 | { |
| 118 | { |
| 119 | return ScriptItemize (pwcInChars, |
| 120 | cInChars, |
| 121 | cMaxItems, |
| 122 | psControl, |
| 123 | psState, |
| 124 | pItems, |
| 125 | pcItems); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | static HRESULT WINAPI |
| 130 | hb_ScriptShapeOpenType( |
| 131 | HDC hdc, |
| 132 | SCRIPT_CACHE *psc, |
| 133 | SCRIPT_ANALYSIS *psa, |
| 134 | OPENTYPE_TAG tagScript, |
| 135 | OPENTYPE_TAG tagLangSys, |
| 136 | int *rcRangeChars, |
| 137 | TEXTRANGE_PROPERTIES **rpRangeProperties, |
| 138 | int cRanges, |
| 139 | const WCHAR *pwcChars, |
| 140 | int cChars, |
| 141 | int cMaxGlyphs, |
| 142 | WORD *pwLogClust, |
| 143 | SCRIPT_CHARPROP *pCharProps, |
| 144 | WORD *pwOutGlyphs, |
| 145 | SCRIPT_GLYPHPROP *pOutGlyphProps, |
| 146 | int *pcGlyphs |
| 147 | ) |
| 148 | { |
| 149 | SCRIPT_VISATTR *psva = (SCRIPT_VISATTR *) pOutGlyphProps; |
| 150 | return ScriptShape (hdc, |
| 151 | psc, |
| 152 | pwcChars, |
| 153 | cChars, |
| 154 | cMaxGlyphs, |
| 155 | psa, |
| 156 | pwOutGlyphs, |
| 157 | pwLogClust, |
| 158 | psva, |
| 159 | pcGlyphs); |
| 160 | } |
| 161 | |
| 162 | static HRESULT WINAPI |
| 163 | hb_ScriptPlaceOpenType( |
| 164 | HDC hdc, |
| 165 | SCRIPT_CACHE *psc, |
| 166 | SCRIPT_ANALYSIS *psa, |
| 167 | OPENTYPE_TAG tagScript, |
| 168 | OPENTYPE_TAG tagLangSys, |
| 169 | int *rcRangeChars, |
| 170 | TEXTRANGE_PROPERTIES **rpRangeProperties, |
| 171 | int cRanges, |
| 172 | const WCHAR *pwcChars, |
| 173 | WORD *pwLogClust, |
| 174 | SCRIPT_CHARPROP *pCharProps, |
| 175 | int cChars, |
| 176 | const WORD *pwGlyphs, |
| 177 | const SCRIPT_GLYPHPROP *pGlyphProps, |
| 178 | int cGlyphs, |
| 179 | int *piAdvance, |
| 180 | GOFFSET *pGoffset, |
| 181 | ABC *pABC |
| 182 | ) |
| 183 | { |
| 184 | SCRIPT_VISATTR *psva = (SCRIPT_VISATTR *) pGlyphProps; |
| 185 | return ScriptPlace (hdc, |
| 186 | psc, |
| 187 | pwGlyphs, |
| 188 | cGlyphs, |
| 189 | psva, |
| 190 | psa, |
| 191 | piAdvance, |
| 192 | pGoffset, |
| 193 | pABC); |
| 194 | } |
| 195 | |
| 196 | |
| 197 | struct hb_uniscribe_shaper_funcs_t { |
| 198 | SIOT ScriptItemizeOpenType; |
| 199 | SSOT ScriptShapeOpenType; |
| 200 | SPOT ScriptPlaceOpenType; |
| 201 | |
| 202 | inline void init (void) |
| 203 | { |
Chun-wei Fan | 93a04b8 | 2013-06-03 17:49:37 +0800 | [diff] [blame] | 204 | HMODULE hinstLib; |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 205 | this->ScriptItemizeOpenType = NULL; |
| 206 | this->ScriptShapeOpenType = NULL; |
| 207 | this->ScriptPlaceOpenType = NULL; |
| 208 | |
Behdad Esfahbod | 757a7a9 | 2013-08-28 12:35:13 -0400 | [diff] [blame] | 209 | hinstLib = GetModuleHandle (TEXT ("usp10.dll")); |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 210 | if (hinstLib) |
| 211 | { |
| 212 | this->ScriptItemizeOpenType = (SIOT) GetProcAddress (hinstLib, "ScriptItemizeOpenType"); |
| 213 | this->ScriptShapeOpenType = (SSOT) GetProcAddress (hinstLib, "ScriptShapeOpenType"); |
| 214 | this->ScriptPlaceOpenType = (SPOT) GetProcAddress (hinstLib, "ScriptPlaceOpenType"); |
| 215 | } |
| 216 | if (!this->ScriptItemizeOpenType || |
| 217 | !this->ScriptShapeOpenType || |
| 218 | !this->ScriptPlaceOpenType) |
| 219 | { |
| 220 | DEBUG_MSG (UNISCRIBE, NULL, "OpenType versions of functions not found; falling back."); |
| 221 | this->ScriptItemizeOpenType = hb_ScriptItemizeOpenType; |
| 222 | this->ScriptShapeOpenType = hb_ScriptShapeOpenType; |
| 223 | this->ScriptPlaceOpenType = hb_ScriptPlaceOpenType; |
| 224 | } |
| 225 | } |
| 226 | }; |
| 227 | static hb_uniscribe_shaper_funcs_t *uniscribe_funcs; |
| 228 | |
| 229 | static inline void |
| 230 | free_uniscribe_funcs (void) |
| 231 | { |
| 232 | free (uniscribe_funcs); |
| 233 | } |
| 234 | |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 235 | static hb_uniscribe_shaper_funcs_t * |
| 236 | hb_uniscribe_shaper_get_funcs (void) |
| 237 | { |
| 238 | retry: |
| 239 | hb_uniscribe_shaper_funcs_t *funcs = (hb_uniscribe_shaper_funcs_t *) hb_atomic_ptr_get (&uniscribe_funcs); |
| 240 | |
| 241 | if (unlikely (!funcs)) |
| 242 | { |
| 243 | funcs = (hb_uniscribe_shaper_funcs_t *) calloc (1, sizeof (hb_uniscribe_shaper_funcs_t)); |
| 244 | if (unlikely (!funcs)) |
| 245 | return NULL; |
| 246 | |
| 247 | funcs->init (); |
| 248 | |
| 249 | if (!hb_atomic_ptr_cmpexch (&uniscribe_funcs, NULL, funcs)) { |
| 250 | free (funcs); |
| 251 | goto retry; |
| 252 | } |
| 253 | |
Behdad Esfahbod | 38fb30d | 2014-08-06 13:34:49 -0400 | [diff] [blame] | 254 | #ifdef HB_USE_ATEXIT |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 255 | atexit (free_uniscribe_funcs); /* First person registers atexit() callback. */ |
| 256 | #endif |
| 257 | } |
| 258 | |
| 259 | return funcs; |
| 260 | } |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 261 | |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 262 | |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 263 | struct active_feature_t { |
| 264 | OPENTYPE_FEATURE_RECORD rec; |
| 265 | unsigned int order; |
| 266 | |
| 267 | static int cmp (const active_feature_t *a, const active_feature_t *b) { |
| 268 | return a->rec.tagFeature < b->rec.tagFeature ? -1 : a->rec.tagFeature > b->rec.tagFeature ? 1 : |
| 269 | a->order < b->order ? -1 : a->order > b->order ? 1 : |
| 270 | a->rec.lParameter < b->rec.lParameter ? -1 : a->rec.lParameter > b->rec.lParameter ? 1 : |
| 271 | 0; |
| 272 | } |
| 273 | bool operator== (const active_feature_t *f) { |
| 274 | return cmp (this, f) == 0; |
| 275 | } |
| 276 | }; |
| 277 | |
| 278 | struct feature_event_t { |
| 279 | unsigned int index; |
| 280 | bool start; |
| 281 | active_feature_t feature; |
| 282 | |
| 283 | static int cmp (const feature_event_t *a, const feature_event_t *b) { |
| 284 | return a->index < b->index ? -1 : a->index > b->index ? 1 : |
| 285 | a->start < b->start ? -1 : a->start > b->start ? 1 : |
| 286 | active_feature_t::cmp (&a->feature, &b->feature); |
| 287 | } |
| 288 | }; |
| 289 | |
| 290 | struct range_record_t { |
| 291 | TEXTRANGE_PROPERTIES props; |
| 292 | unsigned int index_first; /* == start */ |
| 293 | unsigned int index_last; /* == end - 1 */ |
| 294 | }; |
| 295 | |
Behdad Esfahbod | cfe9882 | 2012-07-27 03:06:30 -0400 | [diff] [blame] | 296 | HB_SHAPER_DATA_ENSURE_DECLARE(uniscribe, face) |
| 297 | HB_SHAPER_DATA_ENSURE_DECLARE(uniscribe, font) |
Behdad Esfahbod | cfe9882 | 2012-07-27 03:06:30 -0400 | [diff] [blame] | 298 | |
| 299 | |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 300 | /* |
| 301 | * shaper face data |
| 302 | */ |
Behdad Esfahbod | 71388b3 | 2011-08-24 02:09:04 +0200 | [diff] [blame] | 303 | |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 304 | struct hb_uniscribe_shaper_face_data_t { |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 305 | HANDLE fh; |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 306 | hb_uniscribe_shaper_funcs_t *funcs; |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 307 | wchar_t face_name[LF_FACESIZE]; |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 308 | }; |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 309 | |
Behdad Esfahbod | bdeea60 | 2013-07-21 16:22:10 -0400 | [diff] [blame] | 310 | /* face_name should point to a wchar_t[LF_FACESIZE] object. */ |
| 311 | static void |
| 312 | _hb_generate_unique_face_name (wchar_t *face_name, unsigned int *plen) |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 313 | { |
| 314 | /* We'll create a private name for the font from a UUID using a simple, |
| 315 | * somewhat base64-like encoding scheme */ |
| 316 | const char *enc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-"; |
| 317 | UUID id; |
| 318 | UuidCreate ((UUID*) &id); |
Behdad Esfahbod | d7c850f | 2014-08-02 17:46:38 -0400 | [diff] [blame] | 319 | ASSERT_STATIC (2 + 3 * (16/2) < LF_FACESIZE); |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 320 | unsigned int name_str_len = 0; |
Behdad Esfahbod | bdeea60 | 2013-07-21 16:22:10 -0400 | [diff] [blame] | 321 | face_name[name_str_len++] = 'F'; |
| 322 | face_name[name_str_len++] = '_'; |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 323 | unsigned char *p = (unsigned char *) &id; |
| 324 | for (unsigned int i = 0; i < 16; i += 2) |
| 325 | { |
| 326 | /* Spread the 16 bits from two bytes of the UUID across three chars of face_name, |
| 327 | * using the bits in groups of 5,5,6 to select chars from enc. |
| 328 | * This will generate 24 characters; with the 'F_' prefix we already provided, |
| 329 | * the name will be 26 chars (plus the NUL terminator), so will always fit within |
| 330 | * face_name (LF_FACESIZE = 32). */ |
Behdad Esfahbod | bdeea60 | 2013-07-21 16:22:10 -0400 | [diff] [blame] | 331 | face_name[name_str_len++] = enc[p[i] >> 3]; |
| 332 | face_name[name_str_len++] = enc[((p[i] << 2) | (p[i + 1] >> 6)) & 0x1f]; |
| 333 | face_name[name_str_len++] = enc[p[i + 1] & 0x3f]; |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 334 | } |
Behdad Esfahbod | bdeea60 | 2013-07-21 16:22:10 -0400 | [diff] [blame] | 335 | face_name[name_str_len] = 0; |
| 336 | if (plen) |
| 337 | *plen = name_str_len; |
| 338 | } |
| 339 | |
| 340 | /* Destroys blob. */ |
| 341 | static hb_blob_t * |
| 342 | _hb_rename_font (hb_blob_t *blob, wchar_t *new_name) |
| 343 | { |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 344 | /* Create a copy of the font data, with the 'name' table replaced by a |
| 345 | * table that names the font with our private F_* name created above. |
| 346 | * For simplicity, we just append a new 'name' table and update the |
| 347 | * sfnt directory; the original table is left in place, but unused. |
| 348 | * |
| 349 | * The new table will contain just 5 name IDs: family, style, unique, |
| 350 | * full, PS. All of them point to the same name data with our unique name. |
| 351 | */ |
| 352 | |
Behdad Esfahbod | 8b427c7 | 2013-07-22 10:57:05 -0400 | [diff] [blame] | 353 | blob = OT::Sanitizer<OT::OpenTypeFontFile>::sanitize (blob); |
| 354 | |
Behdad Esfahbod | bdeea60 | 2013-07-21 16:22:10 -0400 | [diff] [blame] | 355 | unsigned int length, new_length, name_str_len; |
| 356 | const char *orig_sfnt_data = hb_blob_get_data (blob, &length); |
| 357 | |
| 358 | _hb_generate_unique_face_name (new_name, &name_str_len); |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 359 | |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 360 | static const uint16_t name_IDs[] = { 1, 2, 3, 4, 6 }; |
| 361 | |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 362 | unsigned int name_table_length = OT::name::min_size + |
| 363 | ARRAY_LENGTH (name_IDs) * OT::NameRecord::static_size + |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 364 | name_str_len * 2; /* for name data in UTF16BE form */ |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 365 | unsigned int name_table_offset = (length + 3) & ~3; |
| 366 | |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 367 | new_length = name_table_offset + ((name_table_length + 3) & ~3); |
| 368 | void *new_sfnt_data = calloc (1, new_length); |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 369 | if (!new_sfnt_data) |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 370 | { |
| 371 | hb_blob_destroy (blob); |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 372 | return NULL; |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 373 | } |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 374 | |
| 375 | memcpy(new_sfnt_data, orig_sfnt_data, length); |
| 376 | |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 377 | OT::name &name = OT::StructAtOffset<OT::name> (new_sfnt_data, name_table_offset); |
| 378 | name.format.set (0); |
| 379 | name.count.set (ARRAY_LENGTH (name_IDs)); |
| 380 | name.stringOffset.set (name.get_size ()); |
| 381 | for (unsigned int i = 0; i < ARRAY_LENGTH (name_IDs); i++) |
| 382 | { |
| 383 | OT::NameRecord &record = name.nameRecord[i]; |
| 384 | record.platformID.set (3); |
| 385 | record.encodingID.set (1); |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 386 | record.languageID.set (0x0409u); /* English */ |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 387 | record.nameID.set (name_IDs[i]); |
| 388 | record.length.set (name_str_len * 2); |
| 389 | record.offset.set (0); |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 390 | } |
| 391 | |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 392 | /* Copy string data from new_name, converting wchar_t to UTF16BE. */ |
| 393 | unsigned char *p = &OT::StructAfter<unsigned char> (name); |
| 394 | for (unsigned int i = 0; i < name_str_len; i++) |
| 395 | { |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 396 | *p++ = new_name[i] >> 8; |
| 397 | *p++ = new_name[i] & 0xff; |
| 398 | } |
| 399 | |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 400 | /* Adjust name table entry to point to new name table */ |
Behdad Esfahbod | 12ff69d | 2013-07-22 10:52:12 -0400 | [diff] [blame] | 401 | const OT::OpenTypeFontFile &file = * (OT::OpenTypeFontFile *) (new_sfnt_data); |
| 402 | unsigned int face_count = file.get_face_count (); |
| 403 | for (unsigned int face_index = 0; face_index < face_count; face_index++) |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 404 | { |
Behdad Esfahbod | 8b427c7 | 2013-07-22 10:57:05 -0400 | [diff] [blame] | 405 | /* Note: doing multiple edits (ie. TTC) can be unsafe. There may be |
| 406 | * toe-stepping. But we don't really care. */ |
Behdad Esfahbod | 12ff69d | 2013-07-22 10:52:12 -0400 | [diff] [blame] | 407 | const OT::OpenTypeFontFace &face = file.get_face (face_index); |
| 408 | unsigned int index; |
| 409 | if (face.find_table_index (HB_OT_TAG_name, &index)) |
| 410 | { |
| 411 | OT::TableRecord &record = const_cast<OT::TableRecord &> (face.get_table (index)); |
| 412 | record.checkSum.set_for_data (&name, name_table_length); |
| 413 | record.offset.set (name_table_offset); |
| 414 | record.length.set (name_table_length); |
| 415 | } |
| 416 | else if (face_index == 0) /* Fail if first face doesn't have 'name' table. */ |
| 417 | { |
| 418 | free (new_sfnt_data); |
| 419 | hb_blob_destroy (blob); |
| 420 | return NULL; |
| 421 | } |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /* The checkSumAdjustment field in the 'head' table is now wrong, |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 425 | * but that doesn't actually seem to cause any problems so we don't |
| 426 | * bother. */ |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 427 | |
Behdad Esfahbod | 73f947e | 2013-07-21 16:16:35 -0400 | [diff] [blame] | 428 | hb_blob_destroy (blob); |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 429 | return hb_blob_create ((const char *) new_sfnt_data, new_length, |
| 430 | HB_MEMORY_MODE_WRITABLE, NULL, free); |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 433 | hb_uniscribe_shaper_face_data_t * |
| 434 | _hb_uniscribe_shaper_face_data_create (hb_face_t *face) |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 435 | { |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 436 | hb_uniscribe_shaper_face_data_t *data = (hb_uniscribe_shaper_face_data_t *) calloc (1, sizeof (hb_uniscribe_shaper_face_data_t)); |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 437 | if (unlikely (!data)) |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 438 | return NULL; |
Behdad Esfahbod | a3bd8a0 | 2011-08-24 03:22:49 +0200 | [diff] [blame] | 439 | |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 440 | data->funcs = hb_uniscribe_shaper_get_funcs (); |
| 441 | if (unlikely (!data->funcs)) |
| 442 | { |
| 443 | free (data); |
| 444 | return NULL; |
| 445 | } |
| 446 | |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 447 | hb_blob_t *blob = hb_face_reference_blob (face); |
Behdad Esfahbod | 73f947e | 2013-07-21 16:16:35 -0400 | [diff] [blame] | 448 | if (unlikely (!hb_blob_get_length (blob))) |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 449 | DEBUG_MSG (UNISCRIBE, face, "Face has empty blob"); |
| 450 | |
Behdad Esfahbod | 73f947e | 2013-07-21 16:16:35 -0400 | [diff] [blame] | 451 | blob = _hb_rename_font (blob, data->face_name); |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 452 | if (unlikely (!blob)) |
| 453 | { |
| 454 | free (data); |
| 455 | return NULL; |
| 456 | } |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 457 | |
| 458 | DWORD num_fonts_installed; |
Behdad Esfahbod | 73f947e | 2013-07-21 16:16:35 -0400 | [diff] [blame] | 459 | data->fh = AddFontMemResourceEx ((void *) hb_blob_get_data (blob, NULL), |
| 460 | hb_blob_get_length (blob), |
| 461 | 0, &num_fonts_installed); |
Behdad Esfahbod | 05bad3b | 2013-07-21 17:05:02 -0400 | [diff] [blame] | 462 | if (unlikely (!data->fh)) |
| 463 | { |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 464 | DEBUG_MSG (UNISCRIBE, face, "Face AddFontMemResourceEx() failed"); |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 465 | free (data); |
| 466 | return NULL; |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | return data; |
| 470 | } |
| 471 | |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 472 | void |
| 473 | _hb_uniscribe_shaper_face_data_destroy (hb_uniscribe_shaper_face_data_t *data) |
| 474 | { |
Behdad Esfahbod | 713914d | 2012-07-30 17:54:38 -0400 | [diff] [blame] | 475 | RemoveFontMemResourceEx (data->fh); |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 476 | free (data); |
| 477 | } |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 478 | |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 479 | |
| 480 | /* |
| 481 | * shaper font data |
| 482 | */ |
| 483 | |
| 484 | struct hb_uniscribe_shaper_font_data_t { |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 485 | HDC hdc; |
Behdad Esfahbod | d666035 | 2011-08-10 22:08:36 +0200 | [diff] [blame] | 486 | LOGFONTW log_font; |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 487 | HFONT hfont; |
| 488 | SCRIPT_CACHE script_cache; |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 489 | }; |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 490 | |
Behdad Esfahbod | b6b7ba1 | 2012-07-27 01:26:11 -0400 | [diff] [blame] | 491 | static bool |
| 492 | populate_log_font (LOGFONTW *lf, |
| 493 | hb_font_t *font) |
| 494 | { |
| 495 | memset (lf, 0, sizeof (*lf)); |
| 496 | lf->lfHeight = -font->y_scale; |
| 497 | lf->lfCharSet = DEFAULT_CHARSET; |
| 498 | |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 499 | hb_face_t *face = font->face; |
| 500 | hb_uniscribe_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); |
Behdad Esfahbod | b6b7ba1 | 2012-07-27 01:26:11 -0400 | [diff] [blame] | 501 | |
Behdad Esfahbod | 8ac2e88 | 2013-07-21 16:06:49 -0400 | [diff] [blame] | 502 | memcpy (lf->lfFaceName, face_data->face_name, sizeof (lf->lfFaceName)); |
Behdad Esfahbod | b6b7ba1 | 2012-07-27 01:26:11 -0400 | [diff] [blame] | 503 | |
| 504 | return true; |
| 505 | } |
| 506 | |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 507 | hb_uniscribe_shaper_font_data_t * |
| 508 | _hb_uniscribe_shaper_font_data_create (hb_font_t *font) |
| 509 | { |
Behdad Esfahbod | 713914d | 2012-07-30 17:54:38 -0400 | [diff] [blame] | 510 | if (unlikely (!hb_uniscribe_shaper_face_data_ensure (font->face))) return NULL; |
| 511 | |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 512 | hb_uniscribe_shaper_font_data_t *data = (hb_uniscribe_shaper_font_data_t *) calloc (1, sizeof (hb_uniscribe_shaper_font_data_t)); |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 513 | if (unlikely (!data)) |
| 514 | return NULL; |
| 515 | |
| 516 | data->hdc = GetDC (NULL); |
| 517 | |
| 518 | if (unlikely (!populate_log_font (&data->log_font, font))) { |
| 519 | DEBUG_MSG (UNISCRIBE, font, "Font populate_log_font() failed"); |
| 520 | _hb_uniscribe_shaper_font_data_destroy (data); |
| 521 | return NULL; |
| 522 | } |
| 523 | |
| 524 | data->hfont = CreateFontIndirectW (&data->log_font); |
| 525 | if (unlikely (!data->hfont)) { |
| 526 | DEBUG_MSG (UNISCRIBE, font, "Font CreateFontIndirectW() failed"); |
| 527 | _hb_uniscribe_shaper_font_data_destroy (data); |
| 528 | return NULL; |
| 529 | } |
| 530 | |
| 531 | if (!SelectObject (data->hdc, data->hfont)) { |
| 532 | DEBUG_MSG (UNISCRIBE, font, "Font SelectObject() failed"); |
| 533 | _hb_uniscribe_shaper_font_data_destroy (data); |
| 534 | return NULL; |
| 535 | } |
| 536 | |
| 537 | return data; |
| 538 | } |
| 539 | |
| 540 | void |
| 541 | _hb_uniscribe_shaper_font_data_destroy (hb_uniscribe_shaper_font_data_t *data) |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 542 | { |
| 543 | if (data->hdc) |
| 544 | ReleaseDC (NULL, data->hdc); |
| 545 | if (data->hfont) |
| 546 | DeleteObject (data->hfont); |
| 547 | if (data->script_cache) |
| 548 | ScriptFreeCache (&data->script_cache); |
| 549 | free (data); |
| 550 | } |
| 551 | |
Behdad Esfahbod | 0ae6dbf | 2012-12-09 18:37:38 -0500 | [diff] [blame] | 552 | LOGFONTW * |
| 553 | hb_uniscribe_font_get_logfontw (hb_font_t *font) |
| 554 | { |
| 555 | if (unlikely (!hb_uniscribe_shaper_font_data_ensure (font))) return NULL; |
| 556 | hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font); |
| 557 | return &font_data->log_font; |
| 558 | } |
| 559 | |
| 560 | HFONT |
| 561 | hb_uniscribe_font_get_hfont (hb_font_t *font) |
| 562 | { |
| 563 | if (unlikely (!hb_uniscribe_shaper_font_data_ensure (font))) return NULL; |
| 564 | hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font); |
| 565 | return font_data->hfont; |
| 566 | } |
| 567 | |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 568 | |
| 569 | /* |
| 570 | * shaper shape_plan data |
| 571 | */ |
| 572 | |
| 573 | struct hb_uniscribe_shaper_shape_plan_data_t {}; |
| 574 | |
| 575 | hb_uniscribe_shaper_shape_plan_data_t * |
Behdad Esfahbod | 45c1383 | 2012-08-14 09:33:18 -0400 | [diff] [blame] | 576 | _hb_uniscribe_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, |
| 577 | const hb_feature_t *user_features HB_UNUSED, |
| 578 | unsigned int num_user_features HB_UNUSED) |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 579 | { |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 580 | return (hb_uniscribe_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; |
| 581 | } |
| 582 | |
| 583 | void |
Behdad Esfahbod | 45c1383 | 2012-08-14 09:33:18 -0400 | [diff] [blame] | 584 | _hb_uniscribe_shaper_shape_plan_data_destroy (hb_uniscribe_shaper_shape_plan_data_t *data HB_UNUSED) |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 585 | { |
| 586 | } |
| 587 | |
| 588 | |
| 589 | /* |
| 590 | * shaper |
| 591 | */ |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 592 | |
| 593 | |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 594 | hb_bool_t |
Behdad Esfahbod | bd26b4d | 2012-07-26 22:05:39 -0400 | [diff] [blame] | 595 | _hb_uniscribe_shape (hb_shape_plan_t *shape_plan, |
| 596 | hb_font_t *font, |
Behdad Esfahbod | 6bd9b47 | 2012-04-12 14:53:53 -0400 | [diff] [blame] | 597 | hb_buffer_t *buffer, |
| 598 | const hb_feature_t *features, |
| 599 | unsigned int num_features) |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 600 | { |
Behdad Esfahbod | b6b7ba1 | 2012-07-27 01:26:11 -0400 | [diff] [blame] | 601 | hb_face_t *face = font->face; |
| 602 | hb_uniscribe_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); |
| 603 | hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font); |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 604 | hb_uniscribe_shaper_funcs_t *funcs = face_data->funcs; |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 605 | |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 606 | /* |
| 607 | * Set up features. |
| 608 | */ |
| 609 | hb_auto_array_t<OPENTYPE_FEATURE_RECORD> feature_records; |
| 610 | hb_auto_array_t<range_record_t> range_records; |
| 611 | if (num_features) |
| 612 | { |
| 613 | /* Sort features by start/end events. */ |
| 614 | hb_auto_array_t<feature_event_t> feature_events; |
| 615 | for (unsigned int i = 0; i < num_features; i++) |
| 616 | { |
| 617 | active_feature_t feature; |
| 618 | feature.rec.tagFeature = hb_uint32_swap (features[i].tag); |
| 619 | feature.rec.lParameter = features[i].value; |
| 620 | feature.order = i; |
| 621 | |
| 622 | feature_event_t *event; |
| 623 | |
| 624 | event = feature_events.push (); |
| 625 | if (unlikely (!event)) |
| 626 | goto fail_features; |
| 627 | event->index = features[i].start; |
| 628 | event->start = true; |
| 629 | event->feature = feature; |
| 630 | |
| 631 | event = feature_events.push (); |
| 632 | if (unlikely (!event)) |
| 633 | goto fail_features; |
| 634 | event->index = features[i].end; |
| 635 | event->start = false; |
| 636 | event->feature = feature; |
| 637 | } |
Behdad Esfahbod | fb8cc86 | 2014-06-19 15:30:18 -0400 | [diff] [blame] | 638 | feature_events.qsort (); |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 639 | /* Add a strategic final event. */ |
| 640 | { |
| 641 | active_feature_t feature; |
| 642 | feature.rec.tagFeature = 0; |
| 643 | feature.rec.lParameter = 0; |
| 644 | feature.order = num_features + 1; |
| 645 | |
| 646 | feature_event_t *event = feature_events.push (); |
| 647 | if (unlikely (!event)) |
| 648 | goto fail_features; |
| 649 | event->index = 0; /* This value does magic. */ |
| 650 | event->start = false; |
| 651 | event->feature = feature; |
| 652 | } |
| 653 | |
| 654 | /* Scan events and save features for each range. */ |
| 655 | hb_auto_array_t<active_feature_t> active_features; |
| 656 | unsigned int last_index = 0; |
| 657 | for (unsigned int i = 0; i < feature_events.len; i++) |
| 658 | { |
| 659 | feature_event_t *event = &feature_events[i]; |
| 660 | |
| 661 | if (event->index != last_index) |
| 662 | { |
| 663 | /* Save a snapshot of active features and the range. */ |
| 664 | range_record_t *range = range_records.push (); |
| 665 | if (unlikely (!range)) |
| 666 | goto fail_features; |
| 667 | |
| 668 | unsigned int offset = feature_records.len; |
| 669 | |
Behdad Esfahbod | fb8cc86 | 2014-06-19 15:30:18 -0400 | [diff] [blame] | 670 | active_features.qsort (); |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 671 | for (unsigned int j = 0; j < active_features.len; j++) |
| 672 | { |
| 673 | if (!j || active_features[j].rec.tagFeature != feature_records[feature_records.len - 1].tagFeature) |
| 674 | { |
| 675 | OPENTYPE_FEATURE_RECORD *feature = feature_records.push (); |
| 676 | if (unlikely (!feature)) |
| 677 | goto fail_features; |
| 678 | *feature = active_features[j].rec; |
| 679 | } |
| 680 | else |
| 681 | { |
| 682 | /* Overrides value for existing feature. */ |
| 683 | feature_records[feature_records.len - 1].lParameter = active_features[j].rec.lParameter; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | /* Will convert to pointer after all is ready, since feature_records.array |
| 688 | * may move as we grow it. */ |
| 689 | range->props.potfRecords = reinterpret_cast<OPENTYPE_FEATURE_RECORD *> (offset); |
| 690 | range->props.cotfRecords = feature_records.len - offset; |
| 691 | range->index_first = last_index; |
| 692 | range->index_last = event->index - 1; |
| 693 | |
| 694 | last_index = event->index; |
| 695 | } |
| 696 | |
| 697 | if (event->start) { |
| 698 | active_feature_t *feature = active_features.push (); |
| 699 | if (unlikely (!feature)) |
| 700 | goto fail_features; |
| 701 | *feature = event->feature; |
| 702 | } else { |
| 703 | active_feature_t *feature = active_features.find (&event->feature); |
| 704 | if (feature) |
| 705 | active_features.remove (feature - active_features.array); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | if (!range_records.len) /* No active feature found. */ |
| 710 | goto fail_features; |
| 711 | |
| 712 | /* Fixup the pointers. */ |
| 713 | for (unsigned int i = 0; i < range_records.len; i++) |
| 714 | { |
| 715 | range_record_t *range = &range_records[i]; |
Jonathan Kew | 62cb28d | 2014-01-20 14:23:08 +0000 | [diff] [blame] | 716 | range->props.potfRecords = feature_records.array + reinterpret_cast<uintptr_t> (range->props.potfRecords); |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | else |
| 720 | { |
| 721 | fail_features: |
| 722 | num_features = 0; |
| 723 | } |
| 724 | |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 725 | #define FAIL(...) \ |
| 726 | HB_STMT_START { \ |
| 727 | DEBUG_MSG (UNISCRIBE, NULL, __VA_ARGS__); \ |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 728 | return false; \ |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 729 | } HB_STMT_END; |
| 730 | |
Behdad Esfahbod | bf3eef5 | 2011-08-09 00:13:24 +0200 | [diff] [blame] | 731 | HRESULT hr; |
| 732 | |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 733 | retry: |
| 734 | |
| 735 | unsigned int scratch_size; |
Behdad Esfahbod | 68c372e | 2013-11-13 14:44:01 -0500 | [diff] [blame] | 736 | hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size); |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 737 | |
Behdad Esfahbod | 68c372e | 2013-11-13 14:44:01 -0500 | [diff] [blame] | 738 | #define ALLOCATE_ARRAY(Type, name, len) \ |
| 739 | Type *name = (Type *) scratch; \ |
| 740 | { \ |
| 741 | unsigned int _consumed = DIV_CEIL ((len) * sizeof (Type), sizeof (*scratch)); \ |
| 742 | assert (_consumed <= scratch_size); \ |
| 743 | scratch += _consumed; \ |
| 744 | scratch_size -= _consumed; \ |
| 745 | } |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 746 | |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 747 | #define utf16_index() var1.u32 |
| 748 | |
Behdad Esfahbod | 68c372e | 2013-11-13 14:44:01 -0500 | [diff] [blame] | 749 | ALLOCATE_ARRAY (WCHAR, pchars, buffer->len * 2); |
| 750 | |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 751 | unsigned int chars_len = 0; |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 752 | for (unsigned int i = 0; i < buffer->len; i++) |
| 753 | { |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 754 | hb_codepoint_t c = buffer->info[i].codepoint; |
| 755 | buffer->info[i].utf16_index() = chars_len; |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 756 | if (likely (c <= 0xFFFFu)) |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 757 | pchars[chars_len++] = c; |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 758 | else if (unlikely (c > 0x10FFFFu)) |
| 759 | pchars[chars_len++] = 0xFFFDu; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 760 | else { |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 761 | pchars[chars_len++] = 0xD800u + ((c - 0x10000u) >> 10); |
| 762 | pchars[chars_len++] = 0xDC00u + ((c - 0x10000u) & ((1 << 10) - 1)); |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 766 | ALLOCATE_ARRAY (WORD, log_clusters, chars_len); |
| 767 | ALLOCATE_ARRAY (SCRIPT_CHARPROP, char_props, chars_len); |
| 768 | |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 769 | if (num_features) |
| 770 | { |
| 771 | /* Need log_clusters to assign features. */ |
| 772 | chars_len = 0; |
| 773 | for (unsigned int i = 0; i < buffer->len; i++) |
| 774 | { |
| 775 | hb_codepoint_t c = buffer->info[i].codepoint; |
| 776 | unsigned int cluster = buffer->info[i].cluster; |
| 777 | log_clusters[chars_len++] = cluster; |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 778 | if (hb_in_range (c, 0x10000u, 0x10FFFFu)) |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 779 | log_clusters[chars_len++] = cluster; /* Surrogates. */ |
| 780 | } |
| 781 | } |
| 782 | |
Behdad Esfahbod | 3216e44 | 2013-12-23 14:39:23 -0500 | [diff] [blame] | 783 | /* The -2 in the following is to compensate for possible |
| 784 | * alignment needed after the WORD array. sizeof(WORD) == 2. */ |
| 785 | unsigned int glyphs_size = (scratch_size * sizeof (int) - 2) |
| 786 | / (sizeof (WORD) + |
| 787 | sizeof (SCRIPT_GLYPHPROP) + |
| 788 | sizeof (int) + |
| 789 | sizeof (GOFFSET) + |
| 790 | sizeof (uint32_t)); |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 791 | |
| 792 | ALLOCATE_ARRAY (WORD, glyphs, glyphs_size); |
| 793 | ALLOCATE_ARRAY (SCRIPT_GLYPHPROP, glyph_props, glyphs_size); |
| 794 | ALLOCATE_ARRAY (int, advances, glyphs_size); |
| 795 | ALLOCATE_ARRAY (GOFFSET, offsets, glyphs_size); |
| 796 | ALLOCATE_ARRAY (uint32_t, vis_clusters, glyphs_size); |
| 797 | |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 798 | /* Note: |
| 799 | * We can't touch the contents of glyph_props. Our fallback |
| 800 | * implementations of Shape and Place functions use that buffer |
| 801 | * by casting it to a different type. It works because they |
| 802 | * both agree about it, but if we want to access it here we |
| 803 | * need address that issue first. |
| 804 | */ |
| 805 | |
Behdad Esfahbod | 91e721e | 2012-07-25 19:20:34 -0400 | [diff] [blame] | 806 | #undef ALLOCATE_ARRAY |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 807 | |
Behdad Esfahbod | 8729691 | 2012-06-08 14:18:30 -0400 | [diff] [blame] | 808 | #define MAX_ITEMS 256 |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 809 | |
| 810 | SCRIPT_ITEM items[MAX_ITEMS + 1]; |
Behdad Esfahbod | 5c29934 | 2011-09-19 14:53:26 -0400 | [diff] [blame] | 811 | SCRIPT_CONTROL bidi_control = {0}; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 812 | SCRIPT_STATE bidi_state = {0}; |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 813 | ULONG script_tags[MAX_ITEMS]; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 814 | int item_count; |
| 815 | |
Behdad Esfahbod | 5c29934 | 2011-09-19 14:53:26 -0400 | [diff] [blame] | 816 | /* MinGW32 doesn't define fMergeNeutralItems, so we bruteforce */ |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 817 | //bidi_control.fMergeNeutralItems = true; |
Behdad Esfahbod | 5c29934 | 2011-09-19 14:53:26 -0400 | [diff] [blame] | 818 | *(uint32_t*)&bidi_control |= 1<<24; |
| 819 | |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 820 | bidi_state.uBidiLevel = HB_DIRECTION_IS_FORWARD (buffer->props.direction) ? 0 : 1; |
Behdad Esfahbod | 29eac8f | 2012-06-08 09:26:17 -0400 | [diff] [blame] | 821 | bidi_state.fOverrideDirection = 1; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 822 | |
Behdad Esfahbod | 68c372e | 2013-11-13 14:44:01 -0500 | [diff] [blame] | 823 | hr = funcs->ScriptItemizeOpenType (pchars, |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 824 | chars_len, |
| 825 | MAX_ITEMS, |
| 826 | &bidi_control, |
| 827 | &bidi_state, |
| 828 | items, |
| 829 | script_tags, |
| 830 | &item_count); |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 831 | if (unlikely (FAILED (hr))) |
Behdad Esfahbod | 2eb474a | 2011-08-07 00:59:38 -0400 | [diff] [blame] | 832 | FAIL ("ScriptItemizeOpenType() failed: 0x%08xL", hr); |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 833 | |
| 834 | #undef MAX_ITEMS |
| 835 | |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 836 | OPENTYPE_TAG language_tag = hb_uint32_swap (hb_ot_tag_from_language (buffer->props.language)); |
Behdad Esfahbod | 38d5c58 | 2013-08-06 14:45:36 -0400 | [diff] [blame] | 837 | hb_auto_array_t<TEXTRANGE_PROPERTIES*> range_properties; |
| 838 | hb_auto_array_t<int> range_char_counts; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 839 | |
| 840 | unsigned int glyphs_offset = 0; |
| 841 | unsigned int glyphs_len; |
Behdad Esfahbod | b069c3c | 2012-06-08 10:10:29 -0400 | [diff] [blame] | 842 | bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction); |
Behdad Esfahbod | 3409fb1 | 2013-08-21 17:22:21 -0400 | [diff] [blame] | 843 | for (unsigned int i = 0; i < item_count; i++) |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 844 | { |
Behdad Esfahbod | 0dd86f9 | 2012-06-08 10:23:03 -0400 | [diff] [blame] | 845 | unsigned int chars_offset = items[i].iCharPos; |
| 846 | unsigned int item_chars_len = items[i + 1].iCharPos - chars_offset; |
Behdad Esfahbod | 1c1233e | 2012-06-08 09:20:53 -0400 | [diff] [blame] | 847 | |
Behdad Esfahbod | 38d5c58 | 2013-08-06 14:45:36 -0400 | [diff] [blame] | 848 | if (num_features) |
| 849 | { |
Behdad Esfahbod | 38d5c58 | 2013-08-06 14:45:36 -0400 | [diff] [blame] | 850 | range_properties.shrink (0); |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 851 | range_char_counts.shrink (0); |
Behdad Esfahbod | 38d5c58 | 2013-08-06 14:45:36 -0400 | [diff] [blame] | 852 | |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 853 | range_record_t *last_range = &range_records[0]; |
Behdad Esfahbod | 38d5c58 | 2013-08-06 14:45:36 -0400 | [diff] [blame] | 854 | |
Behdad Esfahbod | 9a17591 | 2013-08-07 17:26:13 -0400 | [diff] [blame] | 855 | for (unsigned int k = chars_offset; k < chars_offset + item_chars_len; k++) |
| 856 | { |
| 857 | range_record_t *range = last_range; |
| 858 | while (log_clusters[k] < range->index_first) |
| 859 | range--; |
| 860 | while (log_clusters[k] > range->index_last) |
| 861 | range++; |
| 862 | if (!range_properties.len || |
| 863 | &range->props != range_properties[range_properties.len - 1]) |
| 864 | { |
| 865 | TEXTRANGE_PROPERTIES **props = range_properties.push (); |
| 866 | int *c = range_char_counts.push (); |
| 867 | if (unlikely (!props || !c)) |
| 868 | { |
| 869 | range_properties.shrink (0); |
| 870 | range_char_counts.shrink (0); |
| 871 | break; |
| 872 | } |
| 873 | *props = &range->props; |
| 874 | *c = 1; |
| 875 | } |
| 876 | else |
| 877 | { |
| 878 | range_char_counts[range_char_counts.len - 1]++; |
| 879 | } |
| 880 | |
| 881 | last_range = range; |
| 882 | } |
Behdad Esfahbod | 38d5c58 | 2013-08-06 14:45:36 -0400 | [diff] [blame] | 883 | } |
| 884 | |
Behdad Esfahbod | 3409fb1 | 2013-08-21 17:22:21 -0400 | [diff] [blame] | 885 | /* Asking for glyphs in logical order circumvents at least |
| 886 | * one bug in Uniscribe. */ |
| 887 | items[i].a.fLogicalOrder = true; |
| 888 | |
Behdad Esfahbod | e9c0f15 | 2012-07-20 17:05:46 -0400 | [diff] [blame] | 889 | retry_shape: |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 890 | hr = funcs->ScriptShapeOpenType (font_data->hdc, |
| 891 | &font_data->script_cache, |
| 892 | &items[i].a, |
| 893 | script_tags[i], |
| 894 | language_tag, |
Behdad Esfahbod | 38d5c58 | 2013-08-06 14:45:36 -0400 | [diff] [blame] | 895 | range_char_counts.array, |
| 896 | range_properties.array, |
| 897 | range_properties.len, |
Behdad Esfahbod | 68c372e | 2013-11-13 14:44:01 -0500 | [diff] [blame] | 898 | pchars + chars_offset, |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 899 | item_chars_len, |
| 900 | glyphs_size - glyphs_offset, |
| 901 | /* out */ |
| 902 | log_clusters + chars_offset, |
| 903 | char_props + chars_offset, |
| 904 | glyphs + glyphs_offset, |
| 905 | glyph_props + glyphs_offset, |
| 906 | (int *) &glyphs_len); |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 907 | |
Behdad Esfahbod | 0dd86f9 | 2012-06-08 10:23:03 -0400 | [diff] [blame] | 908 | if (unlikely (items[i].a.fNoGlyphIndex)) |
| 909 | FAIL ("ScriptShapeOpenType() set fNoGlyphIndex"); |
| 910 | if (unlikely (hr == E_OUTOFMEMORY)) |
| 911 | { |
Behdad Esfahbod | 15c633d | 2014-08-11 13:42:42 -0400 | [diff] [blame] | 912 | if (unlikely (!buffer->ensure (buffer->allocated * 2))) |
Behdad Esfahbod | 0dd86f9 | 2012-06-08 10:23:03 -0400 | [diff] [blame] | 913 | FAIL ("Buffer resize failed"); |
| 914 | goto retry; |
| 915 | } |
| 916 | if (unlikely (hr == USP_E_SCRIPT_NOT_IN_FONT)) |
Behdad Esfahbod | e9c0f15 | 2012-07-20 17:05:46 -0400 | [diff] [blame] | 917 | { |
| 918 | if (items[i].a.eScript == SCRIPT_UNDEFINED) |
| 919 | FAIL ("ScriptShapeOpenType() failed: Font doesn't support script"); |
| 920 | items[i].a.eScript = SCRIPT_UNDEFINED; |
| 921 | goto retry_shape; |
| 922 | } |
Behdad Esfahbod | 0dd86f9 | 2012-06-08 10:23:03 -0400 | [diff] [blame] | 923 | if (unlikely (FAILED (hr))) |
Behdad Esfahbod | e9c0f15 | 2012-07-20 17:05:46 -0400 | [diff] [blame] | 924 | { |
Behdad Esfahbod | 0dd86f9 | 2012-06-08 10:23:03 -0400 | [diff] [blame] | 925 | FAIL ("ScriptShapeOpenType() failed: 0x%08xL", hr); |
Behdad Esfahbod | e9c0f15 | 2012-07-20 17:05:46 -0400 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | for (unsigned int j = chars_offset; j < chars_offset + item_chars_len; j++) |
| 929 | log_clusters[j] += glyphs_offset; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 930 | |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 931 | hr = funcs->ScriptPlaceOpenType (font_data->hdc, |
| 932 | &font_data->script_cache, |
| 933 | &items[i].a, |
| 934 | script_tags[i], |
| 935 | language_tag, |
Behdad Esfahbod | 38d5c58 | 2013-08-06 14:45:36 -0400 | [diff] [blame] | 936 | range_char_counts.array, |
| 937 | range_properties.array, |
| 938 | range_properties.len, |
Behdad Esfahbod | 68c372e | 2013-11-13 14:44:01 -0500 | [diff] [blame] | 939 | pchars + chars_offset, |
Behdad Esfahbod | 2a17f95 | 2013-05-28 13:10:51 -0400 | [diff] [blame] | 940 | log_clusters + chars_offset, |
| 941 | char_props + chars_offset, |
| 942 | item_chars_len, |
| 943 | glyphs + glyphs_offset, |
| 944 | glyph_props + glyphs_offset, |
| 945 | glyphs_len, |
| 946 | /* out */ |
| 947 | advances + glyphs_offset, |
| 948 | offsets + glyphs_offset, |
| 949 | NULL); |
Behdad Esfahbod | 0dd86f9 | 2012-06-08 10:23:03 -0400 | [diff] [blame] | 950 | if (unlikely (FAILED (hr))) |
| 951 | FAIL ("ScriptPlaceOpenType() failed: 0x%08xL", hr); |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 952 | |
Behdad Esfahbod | 1d05fdd | 2013-08-20 13:22:21 -0400 | [diff] [blame] | 953 | if (DEBUG_ENABLED (UNISCRIBE)) |
| 954 | fprintf (stderr, "Item %d RTL %d LayoutRTL %d LogicalOrder %d ScriptTag %c%c%c%c\n", |
| 955 | i, |
| 956 | items[i].a.fRTL, |
| 957 | items[i].a.fLayoutRTL, |
| 958 | items[i].a.fLogicalOrder, |
| 959 | HB_UNTAG (hb_uint32_swap (script_tags[i]))); |
| 960 | |
Behdad Esfahbod | 0dd86f9 | 2012-06-08 10:23:03 -0400 | [diff] [blame] | 961 | glyphs_offset += glyphs_len; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 962 | } |
| 963 | glyphs_len = glyphs_offset; |
| 964 | |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 965 | /* Ok, we've got everything we need, now compose output buffer, |
| 966 | * very, *very*, carefully! */ |
| 967 | |
| 968 | /* Calculate visual-clusters. That's what we ship. */ |
Behdad Esfahbod | 5c29934 | 2011-09-19 14:53:26 -0400 | [diff] [blame] | 969 | for (unsigned int i = 0; i < glyphs_len; i++) |
| 970 | vis_clusters[i] = -1; |
Behdad Esfahbod | 577326b | 2011-08-07 01:04:40 -0400 | [diff] [blame] | 971 | for (unsigned int i = 0; i < buffer->len; i++) { |
| 972 | uint32_t *p = &vis_clusters[log_clusters[buffer->info[i].utf16_index()]]; |
| 973 | *p = MIN (*p, buffer->info[i].cluster); |
| 974 | } |
Behdad Esfahbod | 3409fb1 | 2013-08-21 17:22:21 -0400 | [diff] [blame] | 975 | for (unsigned int i = 1; i < glyphs_len; i++) |
| 976 | if (vis_clusters[i] == -1) |
| 977 | vis_clusters[i] = vis_clusters[i - 1]; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 978 | |
| 979 | #undef utf16_index |
| 980 | |
Behdad Esfahbod | 15c633d | 2014-08-11 13:42:42 -0400 | [diff] [blame] | 981 | if (unlikely (!buffer->ensure (glyphs_len))) |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 982 | FAIL ("Buffer in error"); |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 983 | |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 984 | #undef FAIL |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 985 | |
| 986 | /* Set glyph infos */ |
Behdad Esfahbod | d753ac7 | 2011-08-09 14:03:12 +0200 | [diff] [blame] | 987 | buffer->len = 0; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 988 | for (unsigned int i = 0; i < glyphs_len; i++) |
| 989 | { |
Behdad Esfahbod | d753ac7 | 2011-08-09 14:03:12 +0200 | [diff] [blame] | 990 | hb_glyph_info_t *info = &buffer->info[buffer->len++]; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 991 | |
| 992 | info->codepoint = glyphs[i]; |
| 993 | info->cluster = vis_clusters[i]; |
| 994 | |
| 995 | /* The rest is crap. Let's store position info there for now. */ |
| 996 | info->mask = advances[i]; |
| 997 | info->var1.u32 = offsets[i].du; |
| 998 | info->var2.u32 = offsets[i].dv; |
| 999 | } |
| 1000 | |
| 1001 | /* Set glyph positions */ |
| 1002 | buffer->clear_positions (); |
| 1003 | for (unsigned int i = 0; i < glyphs_len; i++) |
| 1004 | { |
| 1005 | hb_glyph_info_t *info = &buffer->info[i]; |
| 1006 | hb_glyph_position_t *pos = &buffer->pos[i]; |
| 1007 | |
| 1008 | /* TODO vertical */ |
| 1009 | pos->x_advance = info->mask; |
Behdad Esfahbod | 3409fb1 | 2013-08-21 17:22:21 -0400 | [diff] [blame] | 1010 | pos->x_offset = backward ? -info->var1.u32 : info->var1.u32; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 1011 | pos->y_offset = info->var2.u32; |
| 1012 | } |
| 1013 | |
Behdad Esfahbod | 3409fb1 | 2013-08-21 17:22:21 -0400 | [diff] [blame] | 1014 | if (backward) |
| 1015 | hb_buffer_reverse (buffer); |
| 1016 | |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 1017 | /* Wow, done! */ |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 1018 | return true; |
Behdad Esfahbod | 0fbb2dc | 2011-08-03 19:55:04 -0400 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | |