| Index: third_party/harfbuzz-ng/src/hb-uniscribe.cc
|
| diff --git a/third_party/harfbuzz-ng/src/hb-uniscribe.cc b/third_party/harfbuzz-ng/src/hb-uniscribe.cc
|
| index 9f84a3cc4cdf439474df53d489642f61a7f20671..18b88b2234f9f9a1a2a6bdaef0f204d970f5943e 100644
|
| --- a/third_party/harfbuzz-ng/src/hb-uniscribe.cc
|
| +++ b/third_party/harfbuzz-ng/src/hb-uniscribe.cc
|
| @@ -1,5 +1,5 @@
|
| /*
|
| - * Copyright © 2011 Google, Inc.
|
| + * Copyright © 2011,2012 Google, Inc.
|
| *
|
| * This is part of HarfBuzz, a text shaping library.
|
| *
|
| @@ -24,24 +24,20 @@
|
| * Google Author(s): Behdad Esfahbod
|
| */
|
|
|
| -#define _WIN32_WINNT 0x0500
|
| +#define _WIN32_WINNT 0x0600
|
| +#define WIN32_LEAN_AND_MEAN
|
|
|
| -#include "hb-private.hh"
|
| +#define HB_SHAPER uniscribe
|
| +#include "hb-shaper-impl-private.hh"
|
|
|
| #include <windows.h>
|
| #include <usp10.h>
|
|
|
| -typedef ULONG WIN_ULONG;
|
| -
|
| #include "hb-uniscribe.h"
|
|
|
| #include "hb-ot-name-table.hh"
|
| #include "hb-ot-tag.h"
|
|
|
| -#include "hb-font-private.hh"
|
| -#include "hb-buffer-private.hh"
|
| -
|
| -
|
|
|
| #ifndef HB_DEBUG_UNISCRIBE
|
| #define HB_DEBUG_UNISCRIBE (HB_DEBUG+0)
|
| @@ -58,17 +54,73 @@ DWORD GetFontData(
|
| );
|
| */
|
|
|
| +
|
| +HB_SHAPER_DATA_ENSURE_DECLARE(uniscribe, face)
|
| +HB_SHAPER_DATA_ENSURE_DECLARE(uniscribe, font)
|
| +
|
| +
|
| +/*
|
| + * shaper face data
|
| + */
|
| +
|
| +struct hb_uniscribe_shaper_face_data_t {
|
| + HANDLE fh;
|
| +};
|
| +
|
| +hb_uniscribe_shaper_face_data_t *
|
| +_hb_uniscribe_shaper_face_data_create (hb_face_t *face)
|
| +{
|
| + hb_uniscribe_shaper_face_data_t *data = (hb_uniscribe_shaper_face_data_t *) calloc (1, sizeof (hb_uniscribe_shaper_face_data_t));
|
| + if (unlikely (!data))
|
| + return NULL;
|
| +
|
| + hb_blob_t *blob = hb_face_reference_blob (face);
|
| + unsigned int blob_length;
|
| + const char *blob_data = hb_blob_get_data (blob, &blob_length);
|
| + if (unlikely (!blob_length))
|
| + DEBUG_MSG (UNISCRIBE, face, "Face has empty blob");
|
| +
|
| + DWORD num_fonts_installed;
|
| + data->fh = AddFontMemResourceEx ((void *) blob_data, blob_length, 0, &num_fonts_installed);
|
| + hb_blob_destroy (blob);
|
| + if (unlikely (!data->fh)) {
|
| + DEBUG_MSG (UNISCRIBE, face, "Face AddFontMemResourceEx() failed");
|
| + free (data);
|
| + return NULL;
|
| + }
|
| +
|
| + return data;
|
| +}
|
| +
|
| +void
|
| +_hb_uniscribe_shaper_face_data_destroy (hb_uniscribe_shaper_face_data_t *data)
|
| +{
|
| + RemoveFontMemResourceEx (data->fh);
|
| + free (data);
|
| +}
|
| +
|
| +
|
| +/*
|
| + * shaper font data
|
| + */
|
| +
|
| +struct hb_uniscribe_shaper_font_data_t {
|
| + HDC hdc;
|
| + LOGFONTW log_font;
|
| + HFONT hfont;
|
| + SCRIPT_CACHE script_cache;
|
| +};
|
| +
|
| static bool
|
| populate_log_font (LOGFONTW *lf,
|
| - HDC hdc,
|
| hb_font_t *font)
|
| {
|
| memset (lf, 0, sizeof (*lf));
|
| - int dpi = GetDeviceCaps (hdc, LOGPIXELSY);
|
| lf->lfHeight = -font->y_scale;
|
| + lf->lfCharSet = DEFAULT_CHARSET;
|
|
|
| - hb_blob_t *blob = Sanitizer<name>::sanitize (hb_face_reference_table (font->face, HB_TAG ('n','a','m','e')));
|
| - const name *name_table = Sanitizer<name>::lock_instance (blob);
|
| + hb_blob_t *blob = OT::Sanitizer<OT::name>::sanitize (hb_face_reference_table (font->face, HB_TAG ('n','a','m','e')));
|
| + const OT::name *name_table = OT::Sanitizer<OT::name>::lock_instance (blob);
|
| unsigned int len = name_table->get_name (3, 1, 0x409, 4,
|
| lf->lfFaceName,
|
| sizeof (lf->lfFaceName[0]) * LF_FACESIZE)
|
| @@ -91,71 +143,41 @@ populate_log_font (LOGFONTW *lf,
|
| return true;
|
| }
|
|
|
| -
|
| -static hb_user_data_key_t hb_uniscribe_data_key;
|
| -
|
| -
|
| -static struct hb_uniscribe_face_data_t {
|
| - HANDLE fh;
|
| -} _hb_uniscribe_face_data_nil = {0};
|
| -
|
| -static void
|
| -_hb_uniscribe_face_data_destroy (hb_uniscribe_face_data_t *data)
|
| +hb_uniscribe_shaper_font_data_t *
|
| +_hb_uniscribe_shaper_font_data_create (hb_font_t *font)
|
| {
|
| - if (data->fh)
|
| - RemoveFontMemResourceEx (data->fh);
|
| - free (data);
|
| -}
|
| + if (unlikely (!hb_uniscribe_shaper_face_data_ensure (font->face))) return NULL;
|
|
|
| -static hb_uniscribe_face_data_t *
|
| -_hb_uniscribe_face_get_data (hb_face_t *face)
|
| -{
|
| - hb_uniscribe_face_data_t *data = (hb_uniscribe_face_data_t *) hb_face_get_user_data (face, &hb_uniscribe_data_key);
|
| - if (likely (data)) return data;
|
| -
|
| - data = (hb_uniscribe_face_data_t *) calloc (1, sizeof (hb_uniscribe_face_data_t));
|
| + hb_uniscribe_shaper_font_data_t *data = (hb_uniscribe_shaper_font_data_t *) calloc (1, sizeof (hb_uniscribe_shaper_font_data_t));
|
| if (unlikely (!data))
|
| - return &_hb_uniscribe_face_data_nil;
|
| -
|
| + return NULL;
|
|
|
| - hb_blob_t *blob = hb_face_reference_blob (face);
|
| - unsigned int blob_length;
|
| - const char *blob_data = hb_blob_get_data (blob, &blob_length);
|
| - if (unlikely (!blob_length))
|
| - DEBUG_MSG (UNISCRIBE, face, "Face has empty blob");
|
| + data->hdc = GetDC (NULL);
|
|
|
| - DWORD num_fonts_installed;
|
| - data->fh = AddFontMemResourceEx ((void *) blob_data, blob_length, 0, &num_fonts_installed);
|
| - hb_blob_destroy (blob);
|
| - if (unlikely (!data->fh))
|
| - DEBUG_MSG (UNISCRIBE, face, "Face AddFontMemResourceEx() failed");
|
| + if (unlikely (!populate_log_font (&data->log_font, font))) {
|
| + DEBUG_MSG (UNISCRIBE, font, "Font populate_log_font() failed");
|
| + _hb_uniscribe_shaper_font_data_destroy (data);
|
| + return NULL;
|
| + }
|
|
|
| + data->hfont = CreateFontIndirectW (&data->log_font);
|
| + if (unlikely (!data->hfont)) {
|
| + DEBUG_MSG (UNISCRIBE, font, "Font CreateFontIndirectW() failed");
|
| + _hb_uniscribe_shaper_font_data_destroy (data);
|
| + return NULL;
|
| + }
|
|
|
| - if (unlikely (!hb_face_set_user_data (face, &hb_uniscribe_data_key, data,
|
| - (hb_destroy_func_t) _hb_uniscribe_face_data_destroy,
|
| - false)))
|
| - {
|
| - _hb_uniscribe_face_data_destroy (data);
|
| - data = (hb_uniscribe_face_data_t *) hb_face_get_user_data (face, &hb_uniscribe_data_key);
|
| - if (data)
|
| - return data;
|
| - else
|
| - return &_hb_uniscribe_face_data_nil;
|
| + if (!SelectObject (data->hdc, data->hfont)) {
|
| + DEBUG_MSG (UNISCRIBE, font, "Font SelectObject() failed");
|
| + _hb_uniscribe_shaper_font_data_destroy (data);
|
| + return NULL;
|
| }
|
|
|
| return data;
|
| }
|
|
|
| -
|
| -static struct hb_uniscribe_font_data_t {
|
| - HDC hdc;
|
| - LOGFONTW log_font;
|
| - HFONT hfont;
|
| - SCRIPT_CACHE script_cache;
|
| -} _hb_uniscribe_font_data_nil = {NULL, NULL, NULL};
|
| -
|
| -static void
|
| -_hb_uniscribe_font_data_destroy (hb_uniscribe_font_data_t *data)
|
| +void
|
| +_hb_uniscribe_shaper_font_data_destroy (hb_uniscribe_shaper_font_data_t *data)
|
| {
|
| if (data->hdc)
|
| ReleaseDC (NULL, data->hdc);
|
| @@ -166,69 +188,59 @@ _hb_uniscribe_font_data_destroy (hb_uniscribe_font_data_t *data)
|
| free (data);
|
| }
|
|
|
| -static hb_uniscribe_font_data_t *
|
| -_hb_uniscribe_font_get_data (hb_font_t *font)
|
| -{
|
| - hb_uniscribe_font_data_t *data = (hb_uniscribe_font_data_t *) hb_font_get_user_data (font, &hb_uniscribe_data_key);
|
| - if (likely (data)) return data;
|
|
|
| - data = (hb_uniscribe_font_data_t *) calloc (1, sizeof (hb_uniscribe_font_data_t));
|
| - if (unlikely (!data))
|
| - return &_hb_uniscribe_font_data_nil;
|
| +/*
|
| + * shaper shape_plan data
|
| + */
|
|
|
| - data->hdc = GetDC (NULL);
|
| +struct hb_uniscribe_shaper_shape_plan_data_t {};
|
|
|
| - if (unlikely (!populate_log_font (&data->log_font, data->hdc, font)))
|
| - DEBUG_MSG (UNISCRIBE, font, "Font populate_log_font() failed");
|
| - else {
|
| - data->hfont = CreateFontIndirectW (&data->log_font);
|
| - if (unlikely (!data->hfont))
|
| - DEBUG_MSG (UNISCRIBE, font, "Font CreateFontIndirectW() failed");
|
| - if (!SelectObject (data->hdc, data->hfont))
|
| - DEBUG_MSG (UNISCRIBE, font, "Font SelectObject() failed");
|
| - }
|
| -
|
| - if (unlikely (!hb_font_set_user_data (font, &hb_uniscribe_data_key, data,
|
| - (hb_destroy_func_t) _hb_uniscribe_font_data_destroy,
|
| - false)))
|
| - {
|
| - _hb_uniscribe_font_data_destroy (data);
|
| - data = (hb_uniscribe_font_data_t *) hb_font_get_user_data (font, &hb_uniscribe_data_key);
|
| - if (data)
|
| - return data;
|
| - else
|
| - return &_hb_uniscribe_font_data_nil;
|
| - }
|
| +hb_uniscribe_shaper_shape_plan_data_t *
|
| +_hb_uniscribe_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED,
|
| + const hb_feature_t *user_features HB_UNUSED,
|
| + unsigned int num_user_features HB_UNUSED)
|
| +{
|
| + return (hb_uniscribe_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
|
| +}
|
|
|
| - return data;
|
| +void
|
| +_hb_uniscribe_shaper_shape_plan_data_destroy (hb_uniscribe_shaper_shape_plan_data_t *data HB_UNUSED)
|
| +{
|
| }
|
|
|
| +
|
| +/*
|
| + * shaper
|
| + */
|
| +
|
| LOGFONTW *
|
| hb_uniscribe_font_get_logfontw (hb_font_t *font)
|
| {
|
| - hb_uniscribe_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
|
| - if (unlikely (!font_data))
|
| + if (unlikely (!hb_uniscribe_shaper_font_data_ensure (font))) return NULL;
|
| return NULL;
|
| + hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font);
|
| return &font_data->log_font;
|
| }
|
|
|
| HFONT
|
| hb_uniscribe_font_get_hfont (hb_font_t *font)
|
| {
|
| - hb_uniscribe_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
|
| - if (unlikely (!font_data))
|
| - return 0;
|
| + if (unlikely (!hb_uniscribe_shaper_font_data_ensure (font))) return NULL;
|
| + hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font);
|
| return font_data->hfont;
|
| }
|
|
|
|
|
| hb_bool_t
|
| -_hb_uniscribe_shape (hb_font_t *font,
|
| +_hb_uniscribe_shape (hb_shape_plan_t *shape_plan,
|
| + hb_font_t *font,
|
| hb_buffer_t *buffer,
|
| const hb_feature_t *features,
|
| unsigned int num_features)
|
| {
|
| - buffer->guess_properties ();
|
| + hb_face_t *face = font->face;
|
| + hb_uniscribe_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
|
| + hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font);
|
|
|
| #define FAIL(...) \
|
| HB_STMT_START { \
|
| @@ -236,17 +248,6 @@ _hb_uniscribe_shape (hb_font_t *font,
|
| return false; \
|
| } HB_STMT_END;
|
|
|
| - hb_uniscribe_face_data_t *face_data = _hb_uniscribe_face_get_data (font->face);
|
| - if (unlikely (!face_data->fh))
|
| - FAIL ("Couldn't get face data");
|
| -
|
| - hb_uniscribe_font_data_t *font_data = _hb_uniscribe_font_get_data (font);
|
| - if (unlikely (!font_data->hfont))
|
| - FAIL ("Couldn't get font font");
|
| -
|
| - if (unlikely (!buffer->len))
|
| - return true;
|
| -
|
| HRESULT hr;
|
|
|
| retry:
|
| @@ -258,8 +259,8 @@ retry:
|
|
|
| #define ALLOCATE_ARRAY(Type, name, len) \
|
| Type *name = (Type *) scratch; \
|
| - scratch += len * sizeof (name[0]); \
|
| - scratch_size -= len * sizeof (name[0]);
|
| + scratch += (len) * sizeof ((name)[0]); \
|
| + scratch_size -= (len) * sizeof ((name)[0]);
|
|
|
| #define utf16_index() var1.u32
|
|
|
| @@ -295,13 +296,14 @@ retry:
|
| ALLOCATE_ARRAY (GOFFSET, offsets, glyphs_size);
|
| ALLOCATE_ARRAY (uint32_t, vis_clusters, glyphs_size);
|
|
|
| +#undef ALLOCATE_ARRAY
|
|
|
| -#define MAX_ITEMS 10
|
| +#define MAX_ITEMS 256
|
|
|
| SCRIPT_ITEM items[MAX_ITEMS + 1];
|
| SCRIPT_CONTROL bidi_control = {0};
|
| SCRIPT_STATE bidi_state = {0};
|
| - WIN_ULONG script_tags[MAX_ITEMS];
|
| + ULONG script_tags[MAX_ITEMS];
|
| int item_count;
|
|
|
| /* MinGW32 doesn't define fMergeNeutralItems, so we bruteforce */
|
| @@ -309,7 +311,7 @@ retry:
|
| *(uint32_t*)&bidi_control |= 1<<24;
|
|
|
| bidi_state.uBidiLevel = HB_DIRECTION_IS_FORWARD (buffer->props.direction) ? 0 : 1;
|
| -// bidi_state.fOverrideDirection = 1;
|
| + bidi_state.fOverrideDirection = 1;
|
|
|
| hr = ScriptItemizeOpenType (wchars,
|
| chars_len,
|
| @@ -331,74 +333,83 @@ retry:
|
| /* TODO setup ranges */
|
| }
|
|
|
| - OPENTYPE_TAG language_tag = hb_ot_tag_from_language (buffer->props.language);
|
| + OPENTYPE_TAG language_tag = hb_uint32_swap (hb_ot_tag_from_language (buffer->props.language));
|
|
|
| unsigned int glyphs_offset = 0;
|
| unsigned int glyphs_len;
|
| - for (unsigned int i = 0; i < item_count; i++)
|
| + bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
|
| + for (unsigned int j = 0; j < item_count; j++)
|
| {
|
| - unsigned int chars_offset = items[i].iCharPos;
|
| - unsigned int item_chars_len = items[i + 1].iCharPos - chars_offset;
|
| - OPENTYPE_TAG script_tag = script_tags[i]; /* XXX buffer->props.script */
|
| -
|
| - hr = ScriptShapeOpenType (font_data->hdc,
|
| - &font_data->script_cache,
|
| - &items[i].a,
|
| - script_tag,
|
| - language_tag,
|
| - range_char_counts,
|
| - range_properties,
|
| - range_count,
|
| - wchars + chars_offset,
|
| - item_chars_len,
|
| - glyphs_size - glyphs_offset,
|
| - /* out */
|
| - log_clusters + chars_offset,
|
| - char_props + chars_offset,
|
| - glyphs + glyphs_offset,
|
| - glyph_props + glyphs_offset,
|
| - (int *) &glyphs_len);
|
| -
|
| - for (unsigned int j = chars_offset; j < chars_offset + item_chars_len; j++)
|
| - log_clusters[j] += glyphs_offset;
|
| -
|
| - if (unlikely (items[i].a.fNoGlyphIndex))
|
| - FAIL ("ScriptShapeOpenType() set fNoGlyphIndex");
|
| - if (unlikely (hr == E_OUTOFMEMORY))
|
| - {
|
| - buffer->ensure (buffer->allocated * 2);
|
| - if (buffer->in_error)
|
| - FAIL ("Buffer resize failed");
|
| - goto retry;
|
| - }
|
| - if (unlikely (hr == USP_E_SCRIPT_NOT_IN_FONT))
|
| + unsigned int i = backward ? item_count - 1 - j : j;
|
| + unsigned int chars_offset = items[i].iCharPos;
|
| + unsigned int item_chars_len = items[i + 1].iCharPos - chars_offset;
|
| +
|
| + retry_shape:
|
| + hr = ScriptShapeOpenType (font_data->hdc,
|
| + &font_data->script_cache,
|
| + &items[i].a,
|
| + script_tags[i],
|
| + language_tag,
|
| + range_char_counts,
|
| + range_properties,
|
| + range_count,
|
| + wchars + chars_offset,
|
| + item_chars_len,
|
| + glyphs_size - glyphs_offset,
|
| + /* out */
|
| + log_clusters + chars_offset,
|
| + char_props + chars_offset,
|
| + glyphs + glyphs_offset,
|
| + glyph_props + glyphs_offset,
|
| + (int *) &glyphs_len);
|
| +
|
| + if (unlikely (items[i].a.fNoGlyphIndex))
|
| + FAIL ("ScriptShapeOpenType() set fNoGlyphIndex");
|
| + if (unlikely (hr == E_OUTOFMEMORY))
|
| + {
|
| + buffer->ensure (buffer->allocated * 2);
|
| + if (buffer->in_error)
|
| + FAIL ("Buffer resize failed");
|
| + goto retry;
|
| + }
|
| + if (unlikely (hr == USP_E_SCRIPT_NOT_IN_FONT))
|
| + {
|
| + if (items[i].a.eScript == SCRIPT_UNDEFINED)
|
| FAIL ("ScriptShapeOpenType() failed: Font doesn't support script");
|
| - if (unlikely (FAILED (hr)))
|
| - FAIL ("ScriptShapeOpenType() failed: 0x%08xL", hr);
|
| -
|
| - hr = ScriptPlaceOpenType (font_data->hdc,
|
| - &font_data->script_cache,
|
| - &items[i].a,
|
| - script_tag,
|
| - language_tag,
|
| - range_char_counts,
|
| - range_properties,
|
| - range_count,
|
| - wchars + chars_offset,
|
| - log_clusters + chars_offset,
|
| - char_props + chars_offset,
|
| - item_chars_len,
|
| - glyphs + glyphs_offset,
|
| - glyph_props + glyphs_offset,
|
| - glyphs_len,
|
| - /* out */
|
| - advances + glyphs_offset,
|
| - offsets + glyphs_offset,
|
| - NULL);
|
| - if (unlikely (FAILED (hr)))
|
| - FAIL ("ScriptPlaceOpenType() failed: 0x%08xL", hr);
|
| -
|
| - glyphs_offset += glyphs_len;
|
| + items[i].a.eScript = SCRIPT_UNDEFINED;
|
| + goto retry_shape;
|
| + }
|
| + if (unlikely (FAILED (hr)))
|
| + {
|
| + FAIL ("ScriptShapeOpenType() failed: 0x%08xL", hr);
|
| + }
|
| +
|
| + for (unsigned int j = chars_offset; j < chars_offset + item_chars_len; j++)
|
| + log_clusters[j] += glyphs_offset;
|
| +
|
| + hr = ScriptPlaceOpenType (font_data->hdc,
|
| + &font_data->script_cache,
|
| + &items[i].a,
|
| + script_tags[i],
|
| + language_tag,
|
| + range_char_counts,
|
| + range_properties,
|
| + range_count,
|
| + wchars + chars_offset,
|
| + log_clusters + chars_offset,
|
| + char_props + chars_offset,
|
| + item_chars_len,
|
| + glyphs + glyphs_offset,
|
| + glyph_props + glyphs_offset,
|
| + glyphs_len,
|
| + /* out */
|
| + advances + glyphs_offset,
|
| + offsets + glyphs_offset,
|
| + NULL);
|
| + if (unlikely (FAILED (hr)))
|
| + FAIL ("ScriptPlaceOpenType() failed: 0x%08xL", hr);
|
| +
|
| + glyphs_offset += glyphs_len;
|
| }
|
| glyphs_len = glyphs_offset;
|
|
|
| @@ -412,13 +423,13 @@ retry:
|
| uint32_t *p = &vis_clusters[log_clusters[buffer->info[i].utf16_index()]];
|
| *p = MIN (*p, buffer->info[i].cluster);
|
| }
|
| - if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) {
|
| + if (!backward) {
|
| for (unsigned int i = 1; i < glyphs_len; i++)
|
| - if (!glyph_props[i].sva.fClusterStart)
|
| + if (vis_clusters[i] == -1)
|
| vis_clusters[i] = vis_clusters[i - 1];
|
| } else {
|
| for (int i = glyphs_len - 2; i >= 0; i--)
|
| - if (!glyph_props[i].sva.fClusterStart)
|
| + if (vis_clusters[i] == -1)
|
| vis_clusters[i] = vis_clusters[i + 1];
|
| }
|
|
|
|
|