2015-07-20 15:24:55 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2015 Mozilla Foundation.
|
|
|
|
* Copyright © 2015 Google, Inc.
|
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Mozilla Author(s): Jonathan Kew
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
2019-06-26 22:21:03 +02:00
|
|
|
#include "hb.hh"
|
|
|
|
|
|
|
|
#ifndef HB_NO_OT_SHAPE
|
|
|
|
|
2021-01-29 04:27:59 +01:00
|
|
|
#include "hb-ot-shape-complex-use-machine.hh"
|
2021-01-29 19:34:59 +01:00
|
|
|
#include "hb-ot-shape-complex-use-table.hh"
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-ot-shape-complex-arabic.hh"
|
2020-08-12 01:24:46 +02:00
|
|
|
#include "hb-ot-shape-complex-arabic-joining-list.hh"
|
2018-10-12 22:54:54 +02:00
|
|
|
#include "hb-ot-shape-complex-vowel-constraints.hh"
|
2015-07-20 15:24:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Universal Shaping Engine.
|
2018-04-12 11:10:45 +02:00
|
|
|
* https://docs.microsoft.com/en-us/typography/script-development/use
|
2015-07-20 15:24:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const hb_tag_t
|
2019-07-03 00:09:26 +02:00
|
|
|
use_basic_features[] =
|
2015-07-20 15:24:55 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Basic features.
|
2021-08-03 18:11:27 +02:00
|
|
|
* These features are applied all at once, before reordering, constrained
|
|
|
|
* to the syllable.
|
2015-07-20 15:24:55 +02:00
|
|
|
*/
|
2015-07-21 11:24:32 +02:00
|
|
|
HB_TAG('r','k','r','f'),
|
2015-07-20 15:24:55 +02:00
|
|
|
HB_TAG('a','b','v','f'),
|
|
|
|
HB_TAG('b','l','w','f'),
|
2015-07-21 11:24:32 +02:00
|
|
|
HB_TAG('h','a','l','f'),
|
2015-07-20 15:24:55 +02:00
|
|
|
HB_TAG('p','s','t','f'),
|
2015-07-21 11:24:32 +02:00
|
|
|
HB_TAG('v','a','t','u'),
|
|
|
|
HB_TAG('c','j','c','t'),
|
2015-07-20 15:24:55 +02:00
|
|
|
};
|
|
|
|
static const hb_tag_t
|
2019-07-03 00:17:56 +02:00
|
|
|
use_topographical_features[] =
|
2015-07-22 12:16:01 +02:00
|
|
|
{
|
|
|
|
HB_TAG('i','s','o','l'),
|
|
|
|
HB_TAG('i','n','i','t'),
|
|
|
|
HB_TAG('m','e','d','i'),
|
|
|
|
HB_TAG('f','i','n','a'),
|
|
|
|
};
|
2019-07-03 00:19:39 +02:00
|
|
|
/* Same order as use_topographical_features. */
|
2015-07-22 14:27:06 +02:00
|
|
|
enum joining_form_t {
|
2021-01-29 03:53:20 +01:00
|
|
|
JOINING_FORM_ISOL,
|
|
|
|
JOINING_FORM_INIT,
|
|
|
|
JOINING_FORM_MEDI,
|
|
|
|
JOINING_FORM_FINA,
|
|
|
|
_JOINING_FORM_NONE
|
2015-07-22 14:27:06 +02:00
|
|
|
};
|
2015-07-22 12:16:01 +02:00
|
|
|
static const hb_tag_t
|
2019-07-03 00:09:26 +02:00
|
|
|
use_other_features[] =
|
2015-07-20 15:24:55 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Other features.
|
2018-10-27 00:40:12 +02:00
|
|
|
* These features are applied all at once, after reordering and
|
|
|
|
* clearing syllables.
|
2015-07-20 15:24:55 +02:00
|
|
|
*/
|
|
|
|
HB_TAG('a','b','v','s'),
|
|
|
|
HB_TAG('b','l','w','s'),
|
2015-07-21 11:24:32 +02:00
|
|
|
HB_TAG('h','a','l','n'),
|
|
|
|
HB_TAG('p','r','e','s'),
|
2015-07-20 15:24:55 +02:00
|
|
|
HB_TAG('p','s','t','s'),
|
2018-09-24 04:33:38 +02:00
|
|
|
};
|
2015-07-20 15:24:55 +02:00
|
|
|
|
|
|
|
static void
|
2019-07-02 23:42:45 +02:00
|
|
|
setup_syllables_use (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer);
|
|
|
|
static void
|
|
|
|
record_rphf_use (const hb_ot_shape_plan_t *plan,
|
2015-07-20 15:24:55 +02:00
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer);
|
|
|
|
static void
|
2019-07-02 23:42:45 +02:00
|
|
|
record_pref_use (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer);
|
2015-07-21 15:15:35 +02:00
|
|
|
static void
|
2019-07-02 23:42:45 +02:00
|
|
|
reorder_use (const hb_ot_shape_plan_t *plan,
|
2015-07-21 15:15:35 +02:00
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer);
|
2015-07-20 15:24:55 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
collect_features_use (hb_ot_shape_planner_t *plan)
|
|
|
|
{
|
|
|
|
hb_ot_map_builder_t *map = &plan->map;
|
|
|
|
|
|
|
|
/* Do this before any lookups have been applied. */
|
2019-07-02 23:42:45 +02:00
|
|
|
map->add_gsub_pause (setup_syllables_use);
|
2015-07-20 15:24:55 +02:00
|
|
|
|
2015-07-21 11:24:32 +02:00
|
|
|
/* "Default glyph pre-processing group" */
|
2022-03-28 20:38:56 +02:00
|
|
|
map->enable_feature (HB_TAG('l','o','c','l'), F_PER_SYLLABLE);
|
|
|
|
map->enable_feature (HB_TAG('c','c','m','p'), F_PER_SYLLABLE);
|
|
|
|
map->enable_feature (HB_TAG('n','u','k','t'), F_PER_SYLLABLE);
|
|
|
|
map->enable_feature (HB_TAG('a','k','h','n'), F_MANUAL_ZWJ | F_PER_SYLLABLE);
|
2015-07-20 15:24:55 +02:00
|
|
|
|
2015-07-21 11:24:32 +02:00
|
|
|
/* "Reordering group" */
|
2019-07-02 23:42:45 +02:00
|
|
|
map->add_gsub_pause (_hb_clear_substitution_flags);
|
2022-03-28 20:38:56 +02:00
|
|
|
map->add_feature (HB_TAG('r','p','h','f'), F_MANUAL_ZWJ | F_PER_SYLLABLE);
|
2019-07-02 23:42:45 +02:00
|
|
|
map->add_gsub_pause (record_rphf_use);
|
|
|
|
map->add_gsub_pause (_hb_clear_substitution_flags);
|
2022-03-28 20:38:56 +02:00
|
|
|
map->enable_feature (HB_TAG('p','r','e','f'), F_MANUAL_ZWJ | F_PER_SYLLABLE);
|
2019-07-02 23:42:45 +02:00
|
|
|
map->add_gsub_pause (record_pref_use);
|
2015-07-21 11:24:32 +02:00
|
|
|
|
|
|
|
/* "Orthographic unit shaping group" */
|
2019-07-03 00:09:26 +02:00
|
|
|
for (unsigned int i = 0; i < ARRAY_LENGTH (use_basic_features); i++)
|
2022-03-28 20:38:56 +02:00
|
|
|
map->enable_feature (use_basic_features[i], F_MANUAL_ZWJ | F_PER_SYLLABLE);
|
2015-07-21 11:24:32 +02:00
|
|
|
|
2019-07-02 23:42:45 +02:00
|
|
|
map->add_gsub_pause (reorder_use);
|
2015-07-21 11:24:32 +02:00
|
|
|
|
|
|
|
/* "Topographical features" */
|
2019-07-03 00:17:56 +02:00
|
|
|
for (unsigned int i = 0; i < ARRAY_LENGTH (use_topographical_features); i++)
|
|
|
|
map->add_feature (use_topographical_features[i]);
|
2017-10-15 12:11:08 +02:00
|
|
|
map->add_gsub_pause (nullptr);
|
2015-07-21 11:24:32 +02:00
|
|
|
|
2018-09-24 04:33:38 +02:00
|
|
|
/* "Standard typographic presentation" */
|
2019-07-03 00:09:26 +02:00
|
|
|
for (unsigned int i = 0; i < ARRAY_LENGTH (use_other_features); i++)
|
|
|
|
map->enable_feature (use_other_features[i], F_MANUAL_ZWJ);
|
2015-07-20 15:24:55 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 15:15:35 +02:00
|
|
|
struct use_shape_plan_t
|
|
|
|
{
|
|
|
|
hb_mask_t rphf_mask;
|
2015-07-22 12:16:01 +02:00
|
|
|
|
|
|
|
arabic_shape_plan_t *arabic_plan;
|
2015-07-21 15:15:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void *
|
|
|
|
data_create_use (const hb_ot_shape_plan_t *plan)
|
|
|
|
{
|
2021-07-08 18:58:50 +02:00
|
|
|
use_shape_plan_t *use_plan = (use_shape_plan_t *) hb_calloc (1, sizeof (use_shape_plan_t));
|
2015-07-21 15:15:35 +02:00
|
|
|
if (unlikely (!use_plan))
|
2017-10-15 12:11:08 +02:00
|
|
|
return nullptr;
|
2015-07-21 15:15:35 +02:00
|
|
|
|
|
|
|
use_plan->rphf_mask = plan->map.get_1_mask (HB_TAG('r','p','h','f'));
|
|
|
|
|
2015-07-22 12:16:01 +02:00
|
|
|
if (has_arabic_joining (plan->props.script))
|
|
|
|
{
|
|
|
|
use_plan->arabic_plan = (arabic_shape_plan_t *) data_create_arabic (plan);
|
|
|
|
if (unlikely (!use_plan->arabic_plan))
|
|
|
|
{
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_free (use_plan);
|
2017-10-15 12:11:08 +02:00
|
|
|
return nullptr;
|
2015-07-22 12:16:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 15:15:35 +02:00
|
|
|
return use_plan;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_destroy_use (void *data)
|
|
|
|
{
|
2015-07-22 12:16:01 +02:00
|
|
|
use_shape_plan_t *use_plan = (use_shape_plan_t *) data;
|
|
|
|
|
|
|
|
if (use_plan->arabic_plan)
|
|
|
|
data_destroy_arabic (use_plan->arabic_plan);
|
|
|
|
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_free (data);
|
2015-07-21 15:15:35 +02:00
|
|
|
}
|
2015-07-20 15:24:55 +02:00
|
|
|
|
|
|
|
static void
|
2015-07-22 12:16:01 +02:00
|
|
|
setup_masks_use (const hb_ot_shape_plan_t *plan,
|
2015-07-20 15:24:55 +02:00
|
|
|
hb_buffer_t *buffer,
|
|
|
|
hb_font_t *font HB_UNUSED)
|
|
|
|
{
|
2015-07-22 12:16:01 +02:00
|
|
|
const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
|
|
|
|
|
|
|
|
/* Do this before allocating use_category(). */
|
|
|
|
if (use_plan->arabic_plan)
|
|
|
|
{
|
|
|
|
setup_masks_arabic_plan (use_plan->arabic_plan, buffer, plan->props.script);
|
|
|
|
}
|
|
|
|
|
2015-07-20 15:24:55 +02:00
|
|
|
HB_BUFFER_ALLOCATE_VAR (buffer, use_category);
|
|
|
|
|
|
|
|
/* We cannot setup masks here. We save information about characters
|
|
|
|
* and setup masks later on in a pause-callback. */
|
|
|
|
|
|
|
|
unsigned int count = buffer->len;
|
|
|
|
hb_glyph_info_t *info = buffer->info;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
2022-03-06 18:26:37 +01:00
|
|
|
info[i].use_category() = hb_use_get_category (info[i]);
|
2015-07-20 15:24:55 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 15:15:35 +02:00
|
|
|
static void
|
2015-07-22 14:27:06 +02:00
|
|
|
setup_rphf_mask (const hb_ot_shape_plan_t *plan,
|
2015-07-20 15:24:55 +02:00
|
|
|
hb_buffer_t *buffer)
|
|
|
|
{
|
2015-07-21 15:15:35 +02:00
|
|
|
const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
|
2015-07-22 12:54:02 +02:00
|
|
|
|
|
|
|
hb_mask_t mask = use_plan->rphf_mask;
|
|
|
|
if (!mask) return;
|
2015-07-21 15:15:35 +02:00
|
|
|
|
|
|
|
hb_glyph_info_t *info = buffer->info;
|
2015-07-22 12:54:02 +02:00
|
|
|
|
|
|
|
foreach_syllable (buffer, start, end)
|
|
|
|
{
|
2021-01-29 04:36:51 +01:00
|
|
|
unsigned int limit = info[start].use_category() == USE(R) ? 1 : hb_min (3u, end - start);
|
2015-07-22 12:54:02 +02:00
|
|
|
for (unsigned int i = start; i < start + limit; i++)
|
|
|
|
info[i].mask |= mask;
|
|
|
|
}
|
2015-07-21 15:15:35 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 14:27:06 +02:00
|
|
|
static void
|
|
|
|
setup_topographical_masks (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_buffer_t *buffer)
|
|
|
|
{
|
2015-12-18 14:54:06 +01:00
|
|
|
const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
|
|
|
|
if (use_plan->arabic_plan)
|
|
|
|
return;
|
2015-07-22 14:27:06 +02:00
|
|
|
|
2021-01-29 03:53:20 +01:00
|
|
|
static_assert ((JOINING_FORM_INIT < 4 && JOINING_FORM_ISOL < 4 && JOINING_FORM_MEDI < 4 && JOINING_FORM_FINA < 4), "");
|
2015-07-22 14:27:06 +02:00
|
|
|
hb_mask_t masks[4], all_masks = 0;
|
|
|
|
for (unsigned int i = 0; i < 4; i++)
|
|
|
|
{
|
2019-07-03 00:17:56 +02:00
|
|
|
masks[i] = plan->map.get_1_mask (use_topographical_features[i]);
|
2015-07-22 14:27:06 +02:00
|
|
|
if (masks[i] == plan->map.get_global_mask ())
|
|
|
|
masks[i] = 0;
|
|
|
|
all_masks |= masks[i];
|
|
|
|
}
|
|
|
|
if (!all_masks)
|
|
|
|
return;
|
|
|
|
hb_mask_t other_masks = ~all_masks;
|
|
|
|
|
|
|
|
unsigned int last_start = 0;
|
2021-01-29 03:53:20 +01:00
|
|
|
joining_form_t last_form = _JOINING_FORM_NONE;
|
2015-07-22 14:27:06 +02:00
|
|
|
hb_glyph_info_t *info = buffer->info;
|
|
|
|
foreach_syllable (buffer, start, end)
|
|
|
|
{
|
2019-07-02 23:42:45 +02:00
|
|
|
use_syllable_type_t syllable_type = (use_syllable_type_t) (info[start].syllable() & 0x0F);
|
2015-07-22 14:27:06 +02:00
|
|
|
switch (syllable_type)
|
|
|
|
{
|
2020-08-15 00:30:20 +02:00
|
|
|
case use_hieroglyph_cluster:
|
2019-07-02 23:42:45 +02:00
|
|
|
case use_non_cluster:
|
2015-07-22 14:27:06 +02:00
|
|
|
/* These don't join. Nothing to do. */
|
2021-01-29 03:53:20 +01:00
|
|
|
last_form = _JOINING_FORM_NONE;
|
2015-07-22 14:27:06 +02:00
|
|
|
break;
|
|
|
|
|
2019-07-02 23:42:45 +02:00
|
|
|
case use_virama_terminated_cluster:
|
|
|
|
case use_sakot_terminated_cluster:
|
|
|
|
case use_standard_cluster:
|
|
|
|
case use_number_joiner_terminated_cluster:
|
|
|
|
case use_numeral_cluster:
|
2022-03-05 01:18:40 +01:00
|
|
|
case use_symbol_cluster:
|
2019-07-02 23:42:45 +02:00
|
|
|
case use_broken_cluster:
|
2015-07-22 14:27:06 +02:00
|
|
|
|
2021-01-29 03:53:20 +01:00
|
|
|
bool join = last_form == JOINING_FORM_FINA || last_form == JOINING_FORM_ISOL;
|
2015-07-22 14:27:06 +02:00
|
|
|
|
|
|
|
if (join)
|
|
|
|
{
|
|
|
|
/* Fixup previous syllable's form. */
|
2021-01-29 03:53:20 +01:00
|
|
|
last_form = last_form == JOINING_FORM_FINA ? JOINING_FORM_MEDI : JOINING_FORM_INIT;
|
2015-07-22 14:27:06 +02:00
|
|
|
for (unsigned int i = last_start; i < start; i++)
|
|
|
|
info[i].mask = (info[i].mask & other_masks) | masks[last_form];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Form for this syllable. */
|
2021-01-29 03:53:20 +01:00
|
|
|
last_form = join ? JOINING_FORM_FINA : JOINING_FORM_ISOL;
|
2015-07-22 14:27:06 +02:00
|
|
|
for (unsigned int i = start; i < end; i++)
|
|
|
|
info[i].mask = (info[i].mask & other_masks) | masks[last_form];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_start = start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-07-02 23:42:45 +02:00
|
|
|
setup_syllables_use (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font HB_UNUSED,
|
|
|
|
hb_buffer_t *buffer)
|
2015-07-22 14:27:06 +02:00
|
|
|
{
|
2019-07-02 23:42:45 +02:00
|
|
|
find_syllables_use (buffer);
|
2017-08-11 03:45:33 +02:00
|
|
|
foreach_syllable (buffer, start, end)
|
|
|
|
buffer->unsafe_to_break (start, end);
|
2015-07-22 14:27:06 +02:00
|
|
|
setup_rphf_mask (plan, buffer);
|
|
|
|
setup_topographical_masks (plan, buffer);
|
|
|
|
}
|
|
|
|
|
2015-07-21 15:15:35 +02:00
|
|
|
static void
|
2019-07-02 23:42:45 +02:00
|
|
|
record_rphf_use (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font HB_UNUSED,
|
|
|
|
hb_buffer_t *buffer)
|
2015-07-21 15:15:35 +02:00
|
|
|
{
|
|
|
|
const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
|
|
|
|
|
2015-07-22 12:54:02 +02:00
|
|
|
hb_mask_t mask = use_plan->rphf_mask;
|
2015-07-21 15:15:35 +02:00
|
|
|
if (!mask) return;
|
|
|
|
hb_glyph_info_t *info = buffer->info;
|
|
|
|
|
2015-07-22 12:54:02 +02:00
|
|
|
foreach_syllable (buffer, start, end)
|
|
|
|
{
|
2021-01-29 04:36:51 +01:00
|
|
|
/* Mark a substituted repha as USE(R). */
|
2015-07-22 12:54:02 +02:00
|
|
|
for (unsigned int i = start; i < end && (info[i].mask & mask); i++)
|
|
|
|
if (_hb_glyph_info_substituted (&info[i]))
|
|
|
|
{
|
2021-01-29 04:36:51 +01:00
|
|
|
info[i].use_category() = USE(R);
|
2015-07-22 12:54:02 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-21 15:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-07-02 23:42:45 +02:00
|
|
|
record_pref_use (const hb_ot_shape_plan_t *plan HB_UNUSED,
|
|
|
|
hb_font_t *font HB_UNUSED,
|
|
|
|
hb_buffer_t *buffer)
|
2015-07-21 15:15:35 +02:00
|
|
|
{
|
|
|
|
hb_glyph_info_t *info = buffer->info;
|
2015-07-22 12:54:02 +02:00
|
|
|
|
|
|
|
foreach_syllable (buffer, start, end)
|
|
|
|
{
|
|
|
|
/* Mark a substituted pref as VPre, as they behave the same way. */
|
|
|
|
for (unsigned int i = start; i < end; i++)
|
|
|
|
if (_hb_glyph_info_substituted (&info[i]))
|
|
|
|
{
|
2021-01-29 04:36:51 +01:00
|
|
|
info[i].use_category() = USE(VPre);
|
2015-07-22 12:54:02 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-21 15:15:35 +02:00
|
|
|
}
|
2015-07-20 15:24:55 +02:00
|
|
|
|
2015-12-17 12:59:15 +01:00
|
|
|
static inline bool
|
2019-07-03 00:23:00 +02:00
|
|
|
is_halant_use (const hb_glyph_info_t &info)
|
2015-12-17 12:59:15 +01:00
|
|
|
{
|
2022-03-13 20:01:11 +01:00
|
|
|
return (info.use_category() == USE(H) || info.use_category() == USE(IS)) &&
|
2018-10-20 21:02:26 +02:00
|
|
|
!_hb_glyph_info_ligated (&info);
|
2015-12-17 12:59:15 +01:00
|
|
|
}
|
|
|
|
|
2015-07-20 15:24:55 +02:00
|
|
|
static void
|
2019-07-02 23:42:45 +02:00
|
|
|
reorder_syllable_use (hb_buffer_t *buffer, unsigned int start, unsigned int end)
|
2015-07-20 15:24:55 +02:00
|
|
|
{
|
2019-07-02 23:42:45 +02:00
|
|
|
use_syllable_type_t syllable_type = (use_syllable_type_t) (buffer->info[start].syllable() & 0x0F);
|
2015-07-21 17:07:10 +02:00
|
|
|
/* Only a few syllable types need reordering. */
|
2017-10-19 20:39:52 +02:00
|
|
|
if (unlikely (!(FLAG_UNSAFE (syllable_type) &
|
2019-07-02 23:42:45 +02:00
|
|
|
(FLAG (use_virama_terminated_cluster) |
|
|
|
|
FLAG (use_sakot_terminated_cluster) |
|
|
|
|
FLAG (use_standard_cluster) |
|
2022-03-05 01:18:40 +01:00
|
|
|
FLAG (use_symbol_cluster) |
|
2019-07-02 23:42:45 +02:00
|
|
|
FLAG (use_broken_cluster) |
|
2015-07-21 18:14:54 +02:00
|
|
|
0))))
|
2015-07-21 17:07:10 +02:00
|
|
|
return;
|
2015-07-20 15:24:55 +02:00
|
|
|
|
|
|
|
hb_glyph_info_t *info = buffer->info;
|
|
|
|
|
2021-01-29 04:36:51 +01:00
|
|
|
#define POST_BASE_FLAGS64 (FLAG64 (USE(FAbv)) | \
|
|
|
|
FLAG64 (USE(FBlw)) | \
|
|
|
|
FLAG64 (USE(FPst)) | \
|
|
|
|
FLAG64 (USE(MAbv)) | \
|
|
|
|
FLAG64 (USE(MBlw)) | \
|
|
|
|
FLAG64 (USE(MPst)) | \
|
|
|
|
FLAG64 (USE(MPre)) | \
|
|
|
|
FLAG64 (USE(VAbv)) | \
|
|
|
|
FLAG64 (USE(VBlw)) | \
|
|
|
|
FLAG64 (USE(VPst)) | \
|
|
|
|
FLAG64 (USE(VPre)) | \
|
|
|
|
FLAG64 (USE(VMAbv)) | \
|
|
|
|
FLAG64 (USE(VMBlw)) | \
|
|
|
|
FLAG64 (USE(VMPst)) | \
|
|
|
|
FLAG64 (USE(VMPre)))
|
2015-07-20 15:24:55 +02:00
|
|
|
|
2015-07-21 17:07:10 +02:00
|
|
|
/* Move things forward. */
|
2021-01-29 04:36:51 +01:00
|
|
|
if (info[start].use_category() == USE(R) && end - start > 1)
|
2015-07-21 17:07:10 +02:00
|
|
|
{
|
2018-10-20 21:02:26 +02:00
|
|
|
/* Got a repha. Reorder it towards the end, but before the first post-base
|
|
|
|
* glyph. */
|
2015-07-21 17:07:10 +02:00
|
|
|
for (unsigned int i = start + 1; i < end; i++)
|
2018-10-20 21:02:26 +02:00
|
|
|
{
|
2018-11-23 04:47:51 +01:00
|
|
|
bool is_post_base_glyph = (FLAG64_UNSAFE (info[i].use_category()) & POST_BASE_FLAGS64) ||
|
2019-07-03 00:23:00 +02:00
|
|
|
is_halant_use (info[i]);
|
2018-10-20 21:02:26 +02:00
|
|
|
if (is_post_base_glyph || i == end - 1)
|
2015-07-21 17:07:10 +02:00
|
|
|
{
|
2018-10-20 21:02:26 +02:00
|
|
|
/* If we hit a post-base glyph, move before it; otherwise move to the
|
|
|
|
* end. Shift things in between backward. */
|
2015-07-21 17:07:10 +02:00
|
|
|
|
2018-10-20 21:02:26 +02:00
|
|
|
if (is_post_base_glyph)
|
2015-07-21 17:07:10 +02:00
|
|
|
i--;
|
|
|
|
|
2015-09-01 17:24:34 +02:00
|
|
|
buffer->merge_clusters (start, i + 1);
|
2015-07-21 17:07:10 +02:00
|
|
|
hb_glyph_info_t t = info[start];
|
|
|
|
memmove (&info[start], &info[start + 1], (i - start) * sizeof (info[0]));
|
|
|
|
info[i] = t;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-10-20 21:02:26 +02:00
|
|
|
}
|
2015-07-20 15:24:55 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 17:55:26 +02:00
|
|
|
/* Move things back. */
|
2018-10-20 21:02:26 +02:00
|
|
|
unsigned int j = start;
|
2015-07-21 17:55:26 +02:00
|
|
|
for (unsigned int i = start; i < end; i++)
|
|
|
|
{
|
|
|
|
uint32_t flag = FLAG_UNSAFE (info[i].use_category());
|
2019-07-03 00:23:00 +02:00
|
|
|
if (is_halant_use (info[i]))
|
2015-07-21 17:55:26 +02:00
|
|
|
{
|
2018-10-20 21:02:26 +02:00
|
|
|
/* If we hit a halant, move after it; otherwise move to the beginning, and
|
|
|
|
* shift things in between forward. */
|
|
|
|
j = i + 1;
|
2015-07-21 17:55:26 +02:00
|
|
|
}
|
2021-01-29 04:36:51 +01:00
|
|
|
else if (((flag) & (FLAG (USE(VPre)) | FLAG (USE(VMPre)))) &&
|
2015-07-21 19:24:21 +02:00
|
|
|
/* Only move the first component of a MultipleSubst. */
|
|
|
|
0 == _hb_glyph_info_get_lig_comp (&info[i]) &&
|
|
|
|
j < i)
|
2015-07-21 17:55:26 +02:00
|
|
|
{
|
2015-09-01 17:24:34 +02:00
|
|
|
buffer->merge_clusters (j, i + 1);
|
2015-07-21 17:55:26 +02:00
|
|
|
hb_glyph_info_t t = info[i];
|
|
|
|
memmove (&info[j + 1], &info[j], (i - j) * sizeof (info[0]));
|
|
|
|
info[j] = t;
|
|
|
|
}
|
|
|
|
}
|
2015-07-20 15:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-07-02 23:42:45 +02:00
|
|
|
reorder_use (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer)
|
2015-07-20 15:24:55 +02:00
|
|
|
{
|
2021-01-16 03:13:47 +01:00
|
|
|
if (buffer->message (font, "start reordering USE"))
|
|
|
|
{
|
|
|
|
hb_syllabic_insert_dotted_circles (font, buffer,
|
|
|
|
use_broken_cluster,
|
2021-01-29 04:36:51 +01:00
|
|
|
USE(B),
|
|
|
|
USE(R));
|
2015-07-20 15:24:55 +02:00
|
|
|
|
2021-01-16 03:13:47 +01:00
|
|
|
foreach_syllable (buffer, start, end)
|
|
|
|
reorder_syllable_use (buffer, start, end);
|
2020-09-17 15:25:30 +02:00
|
|
|
|
2021-01-16 03:13:47 +01:00
|
|
|
(void) buffer->message (font, "end reordering USE");
|
2020-09-17 15:25:30 +02:00
|
|
|
}
|
2015-07-20 15:24:55 +02:00
|
|
|
|
2018-10-27 00:40:12 +02:00
|
|
|
HB_BUFFER_DEALLOCATE_VAR (buffer, use_category);
|
|
|
|
}
|
|
|
|
|
2018-10-23 11:51:42 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
preprocess_text_use (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_buffer_t *buffer,
|
|
|
|
hb_font_t *font)
|
|
|
|
{
|
|
|
|
_hb_preprocess_text_vowel_constraints (plan, buffer, font);
|
|
|
|
}
|
|
|
|
|
2015-07-21 19:09:40 +02:00
|
|
|
static bool
|
|
|
|
compose_use (const hb_ot_shape_normalize_context_t *c,
|
|
|
|
hb_codepoint_t a,
|
|
|
|
hb_codepoint_t b,
|
|
|
|
hb_codepoint_t *ab)
|
|
|
|
{
|
|
|
|
/* Avoid recomposing split matras. */
|
|
|
|
if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a)))
|
|
|
|
return false;
|
|
|
|
|
2015-11-21 22:57:26 +01:00
|
|
|
return (bool)c->unicode->compose (a, b, ab);
|
2015-07-21 19:09:40 +02:00
|
|
|
}
|
|
|
|
|
2015-07-20 15:24:55 +02:00
|
|
|
|
|
|
|
const hb_ot_complex_shaper_t _hb_ot_complex_shaper_use =
|
|
|
|
{
|
|
|
|
collect_features_use,
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr, /* override_features */
|
2015-07-21 15:15:35 +02:00
|
|
|
data_create_use,
|
|
|
|
data_destroy_use,
|
2018-10-23 11:51:42 +02:00
|
|
|
preprocess_text_use,
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr, /* postprocess_glyphs */
|
2015-07-20 15:24:55 +02:00
|
|
|
HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
|
2018-04-14 00:45:37 +02:00
|
|
|
nullptr, /* decompose */
|
2015-07-21 19:09:40 +02:00
|
|
|
compose_use,
|
2015-07-20 15:24:55 +02:00
|
|
|
setup_masks_use,
|
2018-10-02 14:17:42 +02:00
|
|
|
HB_TAG_NONE, /* gpos_tag */
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr, /* reorder_marks */
|
2016-02-16 11:16:33 +01:00
|
|
|
HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY,
|
2015-07-20 15:24:55 +02:00
|
|
|
false, /* fallback_position */
|
|
|
|
};
|
2019-06-26 22:21:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|