| Index: third_party/harfbuzz-ng/src/hb-ot-shape.cc
|
| diff --git a/third_party/harfbuzz-ng/src/hb-ot-shape.cc b/third_party/harfbuzz-ng/src/hb-ot-shape.cc
|
| index 19cf680c6886e2a06abc7eadfac55a29bedcc59f..9e44c5db27ad6f27959d37dbe84b6ac0cc811608 100644
|
| --- a/third_party/harfbuzz-ng/src/hb-ot-shape.cc
|
| +++ b/third_party/harfbuzz-ng/src/hb-ot-shape.cc
|
| @@ -1,6 +1,6 @@
|
| /*
|
| * Copyright © 2009,2010 Red Hat, Inc.
|
| - * Copyright © 2010,2011 Google, Inc.
|
| + * Copyright © 2010,2011,2012 Google, Inc.
|
| *
|
| * This is part of HarfBuzz, a text shaping library.
|
| *
|
| @@ -26,15 +26,21 @@
|
| * Google Author(s): Behdad Esfahbod
|
| */
|
|
|
| +#define HB_SHAPER ot
|
| +#define hb_ot_shaper_face_data_t hb_ot_layout_t
|
| +#define hb_ot_shaper_shape_plan_data_t hb_ot_shape_plan_t
|
| +#include "hb-shaper-impl-private.hh"
|
| +
|
| #include "hb-ot-shape-private.hh"
|
| +#include "hb-ot-shape-complex-private.hh"
|
| +#include "hb-ot-shape-fallback-private.hh"
|
| #include "hb-ot-shape-normalize-private.hh"
|
|
|
| -#include "hb-font-private.hh"
|
| +#include "hb-ot-layout-private.hh"
|
| #include "hb-set-private.hh"
|
|
|
|
|
| -
|
| -hb_tag_t common_features[] = {
|
| +static hb_tag_t common_features[] = {
|
| HB_TAG('c','c','m','p'),
|
| HB_TAG('l','i','g','a'),
|
| HB_TAG('l','o','c','l'),
|
| @@ -44,11 +50,12 @@ hb_tag_t common_features[] = {
|
| };
|
|
|
|
|
| -hb_tag_t horizontal_features[] = {
|
| +static hb_tag_t horizontal_features[] = {
|
| HB_TAG('c','a','l','t'),
|
| HB_TAG('c','l','i','g'),
|
| HB_TAG('c','u','r','s'),
|
| HB_TAG('k','e','r','n'),
|
| + HB_TAG('r','c','l','t'),
|
| };
|
|
|
| /* Note:
|
| @@ -56,7 +63,7 @@ hb_tag_t horizontal_features[] = {
|
| * According to the spec, valt and vpal are also mutually exclusive.
|
| * But we apply them all for now.
|
| */
|
| -hb_tag_t vertical_features[] = {
|
| +static hb_tag_t vertical_features[] = {
|
| HB_TAG('v','a','l','t'),
|
| HB_TAG('v','e','r','t'),
|
| HB_TAG('v','k','r','n'),
|
| @@ -66,40 +73,22 @@ hb_tag_t vertical_features[] = {
|
|
|
|
|
|
|
| -struct hb_ot_shape_planner_t
|
| -{
|
| - hb_ot_map_builder_t map;
|
| - hb_ot_complex_shaper_t shaper;
|
| -
|
| - hb_ot_shape_planner_t (void) : map () {}
|
| - ~hb_ot_shape_planner_t (void) { map.finish (); }
|
| -
|
| - inline void compile (hb_face_t *face,
|
| - const hb_segment_properties_t *props,
|
| - struct hb_ot_shape_plan_t &plan)
|
| - {
|
| - plan.shaper = shaper;
|
| - map.compile (face, props, plan.map);
|
| - }
|
| -
|
| - private:
|
| - NO_COPY (hb_ot_shape_planner_t);
|
| -};
|
| -
|
| static void
|
| hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
|
| const hb_segment_properties_t *props,
|
| const hb_feature_t *user_features,
|
| unsigned int num_user_features)
|
| {
|
| + hb_ot_map_builder_t *map = &planner->map;
|
| +
|
| switch (props->direction) {
|
| case HB_DIRECTION_LTR:
|
| - planner->map.add_bool_feature (HB_TAG ('l','t','r','a'));
|
| - planner->map.add_bool_feature (HB_TAG ('l','t','r','m'));
|
| + map->add_bool_feature (HB_TAG ('l','t','r','a'));
|
| + map->add_bool_feature (HB_TAG ('l','t','r','m'));
|
| break;
|
| case HB_DIRECTION_RTL:
|
| - planner->map.add_bool_feature (HB_TAG ('r','t','l','a'));
|
| - planner->map.add_bool_feature (HB_TAG ('r','t','l','m'), false);
|
| + map->add_bool_feature (HB_TAG ('r','t','l','a'));
|
| + map->add_bool_feature (HB_TAG ('r','t','l','m'), false);
|
| break;
|
| case HB_DIRECTION_TTB:
|
| case HB_DIRECTION_BTT:
|
| @@ -111,10 +100,11 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
|
| #define ADD_FEATURES(array) \
|
| HB_STMT_START { \
|
| for (unsigned int i = 0; i < ARRAY_LENGTH (array); i++) \
|
| - planner->map.add_bool_feature (array[i]); \
|
| + map->add_bool_feature (array[i]); \
|
| } HB_STMT_END
|
|
|
| - hb_ot_shape_complex_collect_features (planner->shaper, &planner->map, props);
|
| + if (planner->shaper->collect_features)
|
| + planner->shaper->collect_features (planner);
|
|
|
| ADD_FEATURES (common_features);
|
|
|
| @@ -123,18 +113,101 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
|
| else
|
| ADD_FEATURES (vertical_features);
|
|
|
| + if (planner->shaper->override_features)
|
| + planner->shaper->override_features (planner);
|
| +
|
| #undef ADD_FEATURES
|
|
|
| for (unsigned int i = 0; i < num_user_features; i++) {
|
| const hb_feature_t *feature = &user_features[i];
|
| - planner->map.add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1));
|
| + map->add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1));
|
| + }
|
| +}
|
| +
|
| +
|
| +/*
|
| + * shaper face data
|
| + */
|
| +
|
| +hb_ot_shaper_face_data_t *
|
| +_hb_ot_shaper_face_data_create (hb_face_t *face)
|
| +{
|
| + return _hb_ot_layout_create (face);
|
| +}
|
| +
|
| +void
|
| +_hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data)
|
| +{
|
| + _hb_ot_layout_destroy (data);
|
| +}
|
| +
|
| +
|
| +/*
|
| + * shaper font data
|
| + */
|
| +
|
| +struct hb_ot_shaper_font_data_t {};
|
| +
|
| +hb_ot_shaper_font_data_t *
|
| +_hb_ot_shaper_font_data_create (hb_font_t *font)
|
| +{
|
| + return (hb_ot_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
|
| +}
|
| +
|
| +void
|
| +_hb_ot_shaper_font_data_destroy (hb_ot_shaper_font_data_t *data)
|
| +{
|
| +}
|
| +
|
| +
|
| +/*
|
| + * shaper shape_plan data
|
| + */
|
| +
|
| +hb_ot_shaper_shape_plan_data_t *
|
| +_hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan,
|
| + const hb_feature_t *user_features,
|
| + unsigned int num_user_features)
|
| +{
|
| + hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t));
|
| + if (unlikely (!plan))
|
| + return NULL;
|
| +
|
| + hb_ot_shape_planner_t planner (shape_plan);
|
| +
|
| + planner.shaper = hb_ot_shape_complex_categorize (&shape_plan->props);
|
| +
|
| + hb_ot_shape_collect_features (&planner, &shape_plan->props, user_features, num_user_features);
|
| +
|
| + planner.compile (*plan);
|
| +
|
| + if (plan->shaper->data_create) {
|
| + plan->data = plan->shaper->data_create (plan);
|
| + if (unlikely (!plan->data))
|
| + return NULL;
|
| }
|
| +
|
| + return plan;
|
| +}
|
| +
|
| +void
|
| +_hb_ot_shaper_shape_plan_data_destroy (hb_ot_shaper_shape_plan_data_t *plan)
|
| +{
|
| + if (plan->shaper->data_destroy)
|
| + plan->shaper->data_destroy (const_cast<void *> (plan->data));
|
| +
|
| + plan->finish ();
|
| +
|
| + free (plan);
|
| }
|
|
|
|
|
| +/*
|
| + * shaper
|
| + */
|
| +
|
| struct hb_ot_shape_context_t
|
| {
|
| - /* Input to hb_ot_shape_execute() */
|
| hb_ot_shape_plan_t *plan;
|
| hb_font_t *font;
|
| hb_face_t *face;
|
| @@ -144,31 +217,13 @@ struct hb_ot_shape_context_t
|
|
|
| /* Transient stuff */
|
| hb_direction_t target_direction;
|
| - hb_bool_t applied_position_complex;
|
| };
|
|
|
| -static void
|
| -hb_ot_shape_setup_masks (hb_ot_shape_context_t *c)
|
| -{
|
| - hb_mask_t global_mask = c->plan->map.get_global_mask ();
|
| - c->buffer->reset_masks (global_mask);
|
| -
|
| - hb_ot_shape_complex_setup_masks (c->plan->shaper, &c->plan->map, c->buffer, c->font);
|
| -
|
| - for (unsigned int i = 0; i < c->num_user_features; i++)
|
| - {
|
| - const hb_feature_t *feature = &c->user_features[i];
|
| - if (!(feature->start == 0 && feature->end == (unsigned int)-1)) {
|
| - unsigned int shift;
|
| - hb_mask_t mask = c->plan->map.get_mask (feature->tag, &shift);
|
| - c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end);
|
| - }
|
| - }
|
| -}
|
|
|
|
|
| /* Main shaper */
|
|
|
| +
|
| /* Prepare */
|
|
|
| static void
|
| @@ -180,15 +235,43 @@ hb_set_unicode_props (hb_buffer_t *buffer)
|
| }
|
|
|
| static void
|
| +hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font)
|
| +{
|
| + /* TODO One day, when we keep _before_ text for the buffer, take
|
| + * that into consideration. For now, insert dotted-circle if the
|
| + * very first character is a non-spacing mark. */
|
| + if (_hb_glyph_info_get_general_category (&buffer->info[0]) !=
|
| + HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
|
| + return;
|
| +
|
| + hb_codepoint_t dottedcircle_glyph;
|
| + if (!font->get_glyph (0x25CC, 0, &dottedcircle_glyph))
|
| + return;
|
| +
|
| + hb_glyph_info_t dottedcircle;
|
| + dottedcircle.codepoint = 0x25CC;
|
| + _hb_glyph_info_set_unicode_props (&dottedcircle, buffer->unicode);
|
| +
|
| + buffer->clear_output ();
|
| +
|
| + buffer->idx = 0;
|
| + hb_glyph_info_t info = dottedcircle;
|
| + info.cluster = buffer->cur().cluster;
|
| + info.mask = buffer->cur().mask;
|
| + buffer->output_info (info);
|
| + while (buffer->idx < buffer->len)
|
| + buffer->next_glyph ();
|
| +
|
| + buffer->swap_buffers ();
|
| +}
|
| +
|
| +static void
|
| hb_form_clusters (hb_buffer_t *buffer)
|
| {
|
| unsigned int count = buffer->len;
|
| for (unsigned int i = 1; i < count; i++)
|
| - if (FLAG (_hb_glyph_info_get_general_category (&buffer->info[i])) &
|
| - (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) |
|
| - FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) |
|
| - FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))
|
| - buffer->info[i].cluster = buffer->info[i - 1].cluster; /* XXX do the min() here */
|
| + if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[i])))
|
| + buffer->merge_clusters (i - 1, i + 1);
|
| }
|
|
|
| static void
|
| @@ -211,100 +294,138 @@ hb_ensure_native_direction (hb_buffer_t *buffer)
|
|
|
| /* Substitute */
|
|
|
| -static void
|
| -hb_mirror_chars (hb_ot_shape_context_t *c)
|
| +static inline void
|
| +hb_ot_mirror_chars (hb_ot_shape_context_t *c)
|
| {
|
| - hb_unicode_funcs_t *unicode = c->buffer->unicode;
|
| -
|
| if (HB_DIRECTION_IS_FORWARD (c->target_direction))
|
| return;
|
|
|
| + hb_unicode_funcs_t *unicode = c->buffer->unicode;
|
| hb_mask_t rtlm_mask = c->plan->map.get_1_mask (HB_TAG ('r','t','l','m'));
|
|
|
| unsigned int count = c->buffer->len;
|
| for (unsigned int i = 0; i < count; i++) {
|
| - hb_codepoint_t codepoint = hb_unicode_mirroring (unicode, c->buffer->info[i].codepoint);
|
| + hb_codepoint_t codepoint = unicode->mirroring (c->buffer->info[i].codepoint);
|
| if (likely (codepoint == c->buffer->info[i].codepoint))
|
| - c->buffer->info[i].mask |= rtlm_mask; /* XXX this should be moved to before setting user-feature masks */
|
| + c->buffer->info[i].mask |= rtlm_mask;
|
| else
|
| c->buffer->info[i].codepoint = codepoint;
|
| }
|
| }
|
|
|
| -static void
|
| -hb_map_glyphs (hb_font_t *font,
|
| - hb_buffer_t *buffer)
|
| +static inline void
|
| +hb_ot_shape_setup_masks (hb_ot_shape_context_t *c)
|
| {
|
| - hb_codepoint_t glyph;
|
| + hb_ot_map_t *map = &c->plan->map;
|
|
|
| - if (unlikely (!buffer->len))
|
| - return;
|
| + hb_mask_t global_mask = map->get_global_mask ();
|
| + c->buffer->reset_masks (global_mask);
|
|
|
| - buffer->clear_output ();
|
| + if (c->plan->shaper->setup_masks)
|
| + c->plan->shaper->setup_masks (c->plan, c->buffer, c->font);
|
|
|
| - unsigned int count = buffer->len - 1;
|
| - for (buffer->idx = 0; buffer->idx < count;) {
|
| - if (unlikely (_hb_unicode_is_variation_selector (buffer->cur(+1).codepoint))) {
|
| - hb_font_get_glyph (font, buffer->cur().codepoint, buffer->cur(+1).codepoint, &glyph);
|
| - buffer->replace_glyphs (2, 1, &glyph);
|
| - } else {
|
| - hb_font_get_glyph (font, buffer->cur().codepoint, 0, &glyph);
|
| - buffer->replace_glyph (glyph);
|
| + for (unsigned int i = 0; i < c->num_user_features; i++)
|
| + {
|
| + const hb_feature_t *feature = &c->user_features[i];
|
| + if (!(feature->start == 0 && feature->end == (unsigned int)-1)) {
|
| + unsigned int shift;
|
| + hb_mask_t mask = map->get_mask (feature->tag, &shift);
|
| + c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end);
|
| }
|
| }
|
| - if (likely (buffer->idx < buffer->len)) {
|
| - hb_font_get_glyph (font, buffer->cur().codepoint, 0, &glyph);
|
| - buffer->replace_glyph (glyph);
|
| - }
|
| - buffer->swap_buffers ();
|
| }
|
|
|
| -static void
|
| -hb_substitute_default (hb_ot_shape_context_t *c)
|
| +static inline void
|
| +hb_ot_map_glyphs_fast (hb_buffer_t *buffer)
|
| {
|
| - hb_ot_layout_substitute_start (c->buffer);
|
| + /* Normalization process sets up glyph_index(), we just copy it. */
|
| + unsigned int count = buffer->len;
|
| + for (unsigned int i = 0; i < count; i++)
|
| + buffer->info[i].codepoint = buffer->info[i].glyph_index();
|
| +}
|
|
|
| - hb_mirror_chars (c);
|
| +static inline void
|
| +hb_synthesize_glyph_classes (hb_ot_shape_context_t *c)
|
| +{
|
| + unsigned int count = c->buffer->len;
|
| + for (unsigned int i = 0; i < count; i++)
|
| + c->buffer->info[i].glyph_props() = _hb_glyph_info_get_general_category (&c->buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK ?
|
| + HB_OT_LAYOUT_GLYPH_CLASS_MARK :
|
| + HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH;
|
| +}
|
|
|
| - hb_map_glyphs (c->font, c->buffer);
|
| +static inline void
|
| +hb_ot_substitute_default (hb_ot_shape_context_t *c)
|
| +{
|
| + if (c->plan->shaper->preprocess_text)
|
| + c->plan->shaper->preprocess_text (c->plan, c->buffer, c->font);
|
| +
|
| + hb_ot_mirror_chars (c);
|
| +
|
| + HB_BUFFER_ALLOCATE_VAR (c->buffer, glyph_index);
|
| +
|
| + _hb_ot_shape_normalize (c->font, c->buffer,
|
| + c->plan->shaper->normalization_preference ?
|
| + c->plan->shaper->normalization_preference (c->plan) :
|
| + HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT);
|
| +
|
| + hb_ot_shape_setup_masks (c);
|
| +
|
| + /* This is unfortunate to go here, but necessary... */
|
| + if (!hb_ot_layout_has_positioning (c->face))
|
| + _hb_ot_shape_fallback_position_recategorize_marks (c->plan, c->font, c->buffer);
|
| +
|
| + hb_ot_map_glyphs_fast (c->buffer);
|
| +
|
| + HB_BUFFER_DEALLOCATE_VAR (c->buffer, glyph_index);
|
| }
|
|
|
| -static void
|
| +static inline void
|
| hb_ot_substitute_complex (hb_ot_shape_context_t *c)
|
| {
|
| - if (hb_ot_layout_has_substitution (c->face)) {
|
| - c->plan->map.substitute (c->face, c->buffer);
|
| - }
|
| + hb_ot_layout_substitute_start (c->font, c->buffer);
|
| +
|
| + if (!hb_ot_layout_has_glyph_classes (c->face))
|
| + hb_synthesize_glyph_classes (c);
|
|
|
| - hb_ot_layout_substitute_finish (c->buffer);
|
| + c->plan->substitute (c->font, c->buffer);
|
| +
|
| + hb_ot_layout_substitute_finish (c->font, c->buffer);
|
|
|
| return;
|
| }
|
|
|
| +static inline void
|
| +hb_ot_substitute (hb_ot_shape_context_t *c)
|
| +{
|
| + hb_ot_substitute_default (c);
|
| + hb_ot_substitute_complex (c);
|
| +}
|
|
|
| /* Position */
|
|
|
| -static void
|
| -hb_position_default (hb_ot_shape_context_t *c)
|
| +static inline void
|
| +hb_ot_position_default (hb_ot_shape_context_t *c)
|
| {
|
| - hb_ot_layout_position_start (c->buffer);
|
| + hb_ot_layout_position_start (c->font, c->buffer);
|
|
|
| unsigned int count = c->buffer->len;
|
| for (unsigned int i = 0; i < count; i++) {
|
| - hb_font_get_glyph_advance_for_direction (c->font, c->buffer->info[i].codepoint,
|
| - c->buffer->props.direction,
|
| - &c->buffer->pos[i].x_advance,
|
| - &c->buffer->pos[i].y_advance);
|
| - hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
|
| - c->buffer->props.direction,
|
| - &c->buffer->pos[i].x_offset,
|
| - &c->buffer->pos[i].y_offset);
|
| + c->font->get_glyph_advance_for_direction (c->buffer->info[i].codepoint,
|
| + c->buffer->props.direction,
|
| + &c->buffer->pos[i].x_advance,
|
| + &c->buffer->pos[i].y_advance);
|
| + c->font->subtract_glyph_origin_for_direction (c->buffer->info[i].codepoint,
|
| + c->buffer->props.direction,
|
| + &c->buffer->pos[i].x_offset,
|
| + &c->buffer->pos[i].y_offset);
|
| }
|
| }
|
|
|
| -static void
|
| +static inline bool
|
| hb_ot_position_complex (hb_ot_shape_context_t *c)
|
| {
|
| + bool ret = false;
|
|
|
| if (hb_ot_layout_has_positioning (c->face))
|
| {
|
| @@ -312,46 +433,45 @@ hb_ot_position_complex (hb_ot_shape_context_t *c)
|
|
|
| unsigned int count = c->buffer->len;
|
| for (unsigned int i = 0; i < count; i++) {
|
| - hb_font_add_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
|
| - HB_DIRECTION_LTR,
|
| - &c->buffer->pos[i].x_offset,
|
| - &c->buffer->pos[i].y_offset);
|
| + c->font->add_glyph_origin_for_direction (c->buffer->info[i].codepoint,
|
| + HB_DIRECTION_LTR,
|
| + &c->buffer->pos[i].x_offset,
|
| + &c->buffer->pos[i].y_offset);
|
| }
|
|
|
| - c->plan->map.position (c->font, c->buffer);
|
| + c->plan->position (c->font, c->buffer);
|
|
|
| for (unsigned int i = 0; i < count; i++) {
|
| - hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
|
| - HB_DIRECTION_LTR,
|
| - &c->buffer->pos[i].x_offset,
|
| - &c->buffer->pos[i].y_offset);
|
| + c->font->subtract_glyph_origin_for_direction (c->buffer->info[i].codepoint,
|
| + HB_DIRECTION_LTR,
|
| + &c->buffer->pos[i].x_offset,
|
| + &c->buffer->pos[i].y_offset);
|
| }
|
|
|
| - c->applied_position_complex = true;
|
| + ret = true;
|
| }
|
|
|
| - hb_ot_layout_position_finish (c->buffer);
|
| + hb_ot_layout_position_finish (c->font, c->buffer, c->plan->shaper->zero_width_attached_marks);
|
|
|
| - return;
|
| + return ret;
|
| }
|
|
|
| -static void
|
| -hb_position_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED)
|
| +static inline void
|
| +hb_ot_position_complex_fallback (hb_ot_shape_context_t *c)
|
| {
|
| - /* TODO Mark pos */
|
| + _hb_ot_shape_fallback_position (c->plan, c->font, c->buffer);
|
| }
|
|
|
| -static void
|
| -hb_truetype_kern (hb_ot_shape_context_t *c)
|
| +static inline void
|
| +hb_ot_truetype_kern (hb_ot_shape_context_t *c)
|
| {
|
| /* TODO Check for kern=0 */
|
| unsigned int count = c->buffer->len;
|
| for (unsigned int i = 1; i < count; i++) {
|
| hb_position_t x_kern, y_kern, kern1, kern2;
|
| - hb_font_get_glyph_kerning_for_direction (c->font,
|
| - c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint,
|
| - c->buffer->props.direction,
|
| - &x_kern, &y_kern);
|
| + c->font->get_glyph_kerning_for_direction (c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint,
|
| + c->buffer->props.direction,
|
| + &x_kern, &y_kern);
|
|
|
| kern1 = x_kern >> 1;
|
| kern2 = x_kern - kern1;
|
| @@ -367,23 +487,47 @@ hb_truetype_kern (hb_ot_shape_context_t *c)
|
| }
|
| }
|
|
|
| -static void
|
| +static inline void
|
| hb_position_complex_fallback_visual (hb_ot_shape_context_t *c)
|
| {
|
| - hb_truetype_kern (c);
|
| + hb_ot_truetype_kern (c);
|
| }
|
|
|
| +static inline void
|
| +hb_ot_position (hb_ot_shape_context_t *c)
|
| +{
|
| + hb_ot_position_default (c);
|
| +
|
| + hb_bool_t fallback = !hb_ot_position_complex (c);
|
| +
|
| + if (fallback)
|
| + hb_ot_position_complex_fallback (c);
|
| +
|
| + if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction))
|
| + hb_buffer_reverse (c->buffer);
|
| +
|
| + if (fallback)
|
| + hb_position_complex_fallback_visual (c);
|
| +}
|
| +
|
| +
|
| +/* Post-process */
|
| +
|
| static void
|
| -hb_hide_zerowidth (hb_ot_shape_context_t *c)
|
| +hb_ot_hide_zerowidth (hb_ot_shape_context_t *c)
|
| {
|
| - /* TODO Save the space character in the font? */
|
| - hb_codepoint_t space;
|
| - if (!hb_font_get_glyph (c->font, ' ', 0, &space))
|
| - return; /* No point! */
|
| + hb_codepoint_t space = 0;
|
|
|
| unsigned int count = c->buffer->len;
|
| for (unsigned int i = 0; i < count; i++)
|
| - if (unlikely (_hb_glyph_info_is_zero_width (&c->buffer->info[i]))) {
|
| + if (unlikely (!is_a_ligature (c->buffer->info[i]) &&
|
| + _hb_glyph_info_is_zero_width (&c->buffer->info[i])))
|
| + {
|
| + if (!space) {
|
| + /* We assume that the space glyph is not gid0. */
|
| + if (unlikely (!c->font->get_glyph (' ', 0, &space)) || !space)
|
| + return; /* No point! */
|
| + }
|
| c->buffer->info[i].codepoint = space;
|
| c->buffer->pos[i].x_advance = 0;
|
| c->buffer->pos[i].y_advance = 0;
|
| @@ -391,10 +535,10 @@ hb_hide_zerowidth (hb_ot_shape_context_t *c)
|
| }
|
|
|
|
|
| -/* Do it! */
|
| +/* Pull it all together! */
|
|
|
| static void
|
| -hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
|
| +hb_ot_shape_internal (hb_ot_shape_context_t *c)
|
| {
|
| c->buffer->deallocate_var_all ();
|
|
|
| @@ -404,41 +548,18 @@ hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
|
| HB_BUFFER_ALLOCATE_VAR (c->buffer, unicode_props0);
|
| HB_BUFFER_ALLOCATE_VAR (c->buffer, unicode_props1);
|
|
|
| - hb_set_unicode_props (c->buffer);
|
| + c->buffer->clear_output ();
|
|
|
| + hb_set_unicode_props (c->buffer);
|
| + hb_insert_dotted_circle (c->buffer, c->font);
|
| hb_form_clusters (c->buffer);
|
|
|
| hb_ensure_native_direction (c->buffer);
|
|
|
| - _hb_ot_shape_normalize (c->font, c->buffer, hb_ot_shape_complex_normalization_preference (c->plan->shaper));
|
| -
|
| - hb_ot_shape_setup_masks (c);
|
| -
|
| - /* SUBSTITUTE */
|
| - {
|
| - hb_substitute_default (c);
|
| -
|
| - hb_ot_substitute_complex (c);
|
| - }
|
| -
|
| - /* POSITION */
|
| - {
|
| - hb_position_default (c);
|
| -
|
| - hb_ot_position_complex (c);
|
| -
|
| - hb_bool_t position_fallback = !c->applied_position_complex;
|
| - if (position_fallback)
|
| - hb_position_complex_fallback (c);
|
| -
|
| - if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction))
|
| - hb_buffer_reverse (c->buffer);
|
| -
|
| - if (position_fallback)
|
| - hb_position_complex_fallback_visual (c);
|
| - }
|
| + hb_ot_substitute (c);
|
| + hb_ot_position (c);
|
|
|
| - hb_hide_zerowidth (c);
|
| + hb_ot_hide_zerowidth (c);
|
|
|
| HB_BUFFER_DEALLOCATE_VAR (c->buffer, unicode_props1);
|
| HB_BUFFER_DEALLOCATE_VAR (c->buffer, unicode_props0);
|
| @@ -448,52 +569,31 @@ hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
|
| c->buffer->deallocate_var_all ();
|
| }
|
|
|
| -static void
|
| -hb_ot_shape_plan_internal (hb_ot_shape_plan_t *plan,
|
| - hb_face_t *face,
|
| - const hb_segment_properties_t *props,
|
| - const hb_feature_t *user_features,
|
| - unsigned int num_user_features)
|
| -{
|
| - hb_ot_shape_planner_t planner;
|
| -
|
| - assert (HB_DIRECTION_IS_VALID (props->direction));
|
| -
|
| - planner.shaper = hb_ot_shape_complex_categorize (props);
|
| -
|
| - hb_ot_shape_collect_features (&planner, props, user_features, num_user_features);
|
| -
|
| - planner.compile (face, props, *plan);
|
| -}
|
| -
|
| -static void
|
| -hb_ot_shape_execute (hb_ot_shape_plan_t *plan,
|
| - hb_font_t *font,
|
| - hb_buffer_t *buffer,
|
| - const hb_feature_t *user_features,
|
| - unsigned int num_user_features)
|
| -{
|
| - hb_ot_shape_context_t c = {plan, font, font->face, buffer, user_features, num_user_features};
|
| - hb_ot_shape_execute_internal (&c);
|
| -}
|
|
|
| hb_bool_t
|
| -_hb_ot_shape (hb_font_t *font,
|
| +_hb_ot_shape (hb_shape_plan_t *shape_plan,
|
| + hb_font_t *font,
|
| hb_buffer_t *buffer,
|
| const hb_feature_t *features,
|
| unsigned int num_features)
|
| {
|
| - hb_ot_shape_plan_t plan;
|
| -
|
| - buffer->guess_properties ();
|
| -
|
| - hb_ot_shape_plan_internal (&plan, font->face, &buffer->props, features, num_features);
|
| - hb_ot_shape_execute (&plan, font, buffer, features, num_features);
|
| + hb_ot_shape_context_t c = {HB_SHAPER_DATA_GET (shape_plan), font, font->face, buffer, features, num_features};
|
| + hb_ot_shape_internal (&c);
|
|
|
| return true;
|
| }
|
|
|
|
|
| +
|
| +static inline void
|
| +hb_ot_map_glyphs_dumb (hb_font_t *font,
|
| + hb_buffer_t *buffer)
|
| +{
|
| + unsigned int count = buffer->len;
|
| + for (unsigned int i = 0; i < count; i++)
|
| + font->get_glyph (buffer->cur().codepoint, 0, &buffer->cur().codepoint);
|
| +}
|
| +
|
| void
|
| hb_ot_shape_glyphs_closure (hb_font_t *font,
|
| hb_buffer_t *buffer,
|
| @@ -505,17 +605,18 @@ hb_ot_shape_glyphs_closure (hb_font_t *font,
|
|
|
| buffer->guess_properties ();
|
|
|
| - hb_ot_shape_plan_internal (&plan, font->face, &buffer->props, features, num_features);
|
| + /* TODO cache / ensure correct backend, etc. */
|
| + hb_shape_plan_t *shape_plan = hb_shape_plan_create (font->face, &buffer->props, features, num_features, NULL);
|
|
|
| /* TODO: normalization? have shapers do closure()? */
|
| /* TODO: Deal with mirrored chars? */
|
| - hb_map_glyphs (font, buffer);
|
| + hb_ot_map_glyphs_dumb (font, buffer);
|
|
|
| /* Seed it. It's user's responsibility to have cleard glyphs
|
| * if that's what they desire. */
|
| unsigned int count = buffer->len;
|
| for (unsigned int i = 0; i < count; i++)
|
| - hb_set_add (glyphs, buffer->info[i].codepoint);
|
| + glyphs->add (buffer->info[i].codepoint);
|
|
|
| /* And find transitive closure. */
|
| hb_set_t copy;
|
| @@ -523,6 +624,8 @@ hb_ot_shape_glyphs_closure (hb_font_t *font,
|
|
|
| do {
|
| copy.set (glyphs);
|
| - plan.map.substitute_closure (font->face, glyphs);
|
| + HB_SHAPER_DATA_GET (shape_plan)->substitute_closure (font->face, glyphs);
|
| } while (!copy.equal (glyphs));
|
| +
|
| + hb_shape_plan_destroy (shape_plan);
|
| }
|
|
|