2012-09-06 04:19:28 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 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.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
2022-06-03 10:54:33 +02:00
|
|
|
#ifndef HB_OT_SHAPER_ARABIC_FALLBACK_HH
|
|
|
|
#define HB_OT_SHAPER_ARABIC_FALLBACK_HH
|
2012-09-06 04:19:28 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb.hh"
|
2012-09-06 04:19:28 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-ot-shape.hh"
|
2012-09-06 04:19:28 +02:00
|
|
|
#include "hb-ot-layout-gsub-table.hh"
|
|
|
|
|
|
|
|
|
2014-08-01 22:14:33 +02:00
|
|
|
/* Features ordered the same as the entries in shaping_table rows,
|
2022-06-18 21:25:46 +02:00
|
|
|
* followed by rlig. Don't change.
|
|
|
|
*
|
|
|
|
* We currently support one subtable per lookup, and one lookup
|
|
|
|
* per feature. But we allow duplicate features, so we use that!
|
|
|
|
*/
|
2012-09-06 04:19:28 +02:00
|
|
|
static const hb_tag_t arabic_fallback_features[] =
|
|
|
|
{
|
|
|
|
HB_TAG('i','n','i','t'),
|
|
|
|
HB_TAG('m','e','d','i'),
|
|
|
|
HB_TAG('f','i','n','a'),
|
|
|
|
HB_TAG('i','s','o','l'),
|
2022-06-18 22:47:10 +02:00
|
|
|
HB_TAG('r','l','i','g'),
|
|
|
|
HB_TAG('r','l','i','g'),
|
|
|
|
HB_TAG('r','l','i','g'),
|
2012-09-06 04:19:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static OT::SubstLookup *
|
2012-12-06 00:46:04 +01:00
|
|
|
arabic_fallback_synthesize_lookup_single (const hb_ot_shape_plan_t *plan HB_UNUSED,
|
2012-09-06 04:19:28 +02:00
|
|
|
hb_font_t *font,
|
|
|
|
unsigned int feature_index)
|
|
|
|
{
|
2021-09-19 22:30:12 +02:00
|
|
|
OT::HBGlyphID16 glyphs[SHAPING_TABLE_LAST - SHAPING_TABLE_FIRST + 1];
|
|
|
|
OT::HBGlyphID16 substitutes[SHAPING_TABLE_LAST - SHAPING_TABLE_FIRST + 1];
|
2012-09-06 04:19:28 +02:00
|
|
|
unsigned int num_glyphs = 0;
|
|
|
|
|
|
|
|
/* Populate arrays */
|
|
|
|
for (hb_codepoint_t u = SHAPING_TABLE_FIRST; u < SHAPING_TABLE_LAST + 1; u++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t s = shaping_table[u - SHAPING_TABLE_FIRST][feature_index];
|
|
|
|
hb_codepoint_t u_glyph, s_glyph;
|
|
|
|
|
2012-09-06 07:16:39 +02:00
|
|
|
if (!s ||
|
2012-09-06 04:19:28 +02:00
|
|
|
!hb_font_get_glyph (font, u, 0, &u_glyph) ||
|
|
|
|
!hb_font_get_glyph (font, s, 0, &s_glyph) ||
|
|
|
|
u_glyph == s_glyph ||
|
2014-07-11 20:54:42 +02:00
|
|
|
u_glyph > 0xFFFFu || s_glyph > 0xFFFFu)
|
2012-09-06 04:19:28 +02:00
|
|
|
continue;
|
|
|
|
|
2019-03-30 04:17:46 +01:00
|
|
|
glyphs[num_glyphs] = u_glyph;
|
|
|
|
substitutes[num_glyphs] = s_glyph;
|
2012-09-06 04:19:28 +02:00
|
|
|
|
|
|
|
num_glyphs++;
|
|
|
|
}
|
|
|
|
|
2014-07-30 08:15:44 +02:00
|
|
|
if (!num_glyphs)
|
2017-10-15 12:11:08 +02:00
|
|
|
return nullptr;
|
2014-07-30 08:15:44 +02:00
|
|
|
|
2015-09-01 16:07:52 +02:00
|
|
|
/* Bubble-sort or something equally good!
|
2012-09-06 04:19:28 +02:00
|
|
|
* May not be good-enough for presidential candidate interviews, but good-enough for us... */
|
2018-12-31 02:24:21 +01:00
|
|
|
hb_stable_sort (&glyphs[0], num_glyphs,
|
2021-09-19 22:30:12 +02:00
|
|
|
(int(*)(const OT::HBUINT16*, const OT::HBUINT16 *)) OT::HBGlyphID16::cmp,
|
2018-12-31 02:24:21 +01:00
|
|
|
&substitutes[0]);
|
2012-09-06 04:19:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Each glyph takes four bytes max, and there's some overhead. */
|
|
|
|
char buf[(SHAPING_TABLE_LAST - SHAPING_TABLE_FIRST + 1) * 4 + 128];
|
2018-08-02 08:59:09 +02:00
|
|
|
hb_serialize_context_t c (buf, sizeof (buf));
|
2012-09-06 04:19:28 +02:00
|
|
|
OT::SubstLookup *lookup = c.start_serialize<OT::SubstLookup> ();
|
|
|
|
bool ret = lookup->serialize_single (&c,
|
|
|
|
OT::LookupFlag::IgnoreMarks,
|
2019-01-08 00:33:04 +01:00
|
|
|
hb_sorted_array (glyphs, num_glyphs),
|
2018-12-18 22:49:08 +01:00
|
|
|
hb_array (substitutes, num_glyphs));
|
2012-09-06 04:19:28 +02:00
|
|
|
c.end_serialize ();
|
|
|
|
|
2020-08-13 20:52:14 +02:00
|
|
|
return ret && !c.in_error () ? c.copy<OT::SubstLookup> () : nullptr;
|
2012-09-06 04:19:28 +02:00
|
|
|
}
|
|
|
|
|
2022-06-18 21:25:46 +02:00
|
|
|
template <typename T>
|
2012-09-06 04:19:28 +02:00
|
|
|
static OT::SubstLookup *
|
2012-12-06 00:46:04 +01:00
|
|
|
arabic_fallback_synthesize_lookup_ligature (const hb_ot_shape_plan_t *plan HB_UNUSED,
|
2022-06-18 21:25:46 +02:00
|
|
|
hb_font_t *font,
|
|
|
|
const T &ligature_table,
|
|
|
|
unsigned lookup_flags)
|
2012-09-06 04:19:28 +02:00
|
|
|
{
|
2021-09-19 22:30:12 +02:00
|
|
|
OT::HBGlyphID16 first_glyphs[ARRAY_LENGTH_CONST (ligature_table)];
|
2012-09-06 04:19:28 +02:00
|
|
|
unsigned int first_glyphs_indirection[ARRAY_LENGTH_CONST (ligature_table)];
|
|
|
|
unsigned int ligature_per_first_glyph_count_list[ARRAY_LENGTH_CONST (first_glyphs)];
|
|
|
|
unsigned int num_first_glyphs = 0;
|
|
|
|
|
2022-06-18 21:47:00 +02:00
|
|
|
/* We know that all our ligatures have the same number of components. */
|
2021-09-19 22:30:12 +02:00
|
|
|
OT::HBGlyphID16 ligature_list[ARRAY_LENGTH_CONST (first_glyphs) * ARRAY_LENGTH_CONST(ligature_table[0].ligatures)];
|
2012-09-06 07:12:50 +02:00
|
|
|
unsigned int component_count_list[ARRAY_LENGTH_CONST (ligature_list)];
|
2022-06-18 21:47:00 +02:00
|
|
|
OT::HBGlyphID16 component_list[ARRAY_LENGTH_CONST (ligature_list) *
|
|
|
|
ARRAY_LENGTH_CONST (ligature_table[0].ligatures[0].components)];
|
2012-09-06 04:19:28 +02:00
|
|
|
unsigned int num_ligatures = 0;
|
2022-06-18 22:07:48 +02:00
|
|
|
unsigned int num_components = 0;
|
2012-09-06 04:19:28 +02:00
|
|
|
|
|
|
|
/* Populate arrays */
|
|
|
|
|
|
|
|
/* Sort out the first-glyphs */
|
|
|
|
for (unsigned int first_glyph_idx = 0; first_glyph_idx < ARRAY_LENGTH (first_glyphs); first_glyph_idx++)
|
|
|
|
{
|
|
|
|
hb_codepoint_t first_u = ligature_table[first_glyph_idx].first;
|
|
|
|
hb_codepoint_t first_glyph;
|
|
|
|
if (!hb_font_get_glyph (font, first_u, 0, &first_glyph))
|
|
|
|
continue;
|
2019-03-30 04:17:46 +01:00
|
|
|
first_glyphs[num_first_glyphs] = first_glyph;
|
2012-09-06 04:19:28 +02:00
|
|
|
ligature_per_first_glyph_count_list[num_first_glyphs] = 0;
|
|
|
|
first_glyphs_indirection[num_first_glyphs] = first_glyph_idx;
|
|
|
|
num_first_glyphs++;
|
|
|
|
}
|
2018-12-31 02:24:21 +01:00
|
|
|
hb_stable_sort (&first_glyphs[0], num_first_glyphs,
|
2021-09-19 22:30:12 +02:00
|
|
|
(int(*)(const OT::HBUINT16*, const OT::HBUINT16 *)) OT::HBGlyphID16::cmp,
|
2018-12-31 02:24:21 +01:00
|
|
|
&first_glyphs_indirection[0]);
|
2012-09-06 04:19:28 +02:00
|
|
|
|
|
|
|
/* Now that the first-glyphs are sorted, walk again, populate ligatures. */
|
|
|
|
for (unsigned int i = 0; i < num_first_glyphs; i++)
|
|
|
|
{
|
|
|
|
unsigned int first_glyph_idx = first_glyphs_indirection[i];
|
|
|
|
|
2022-06-18 21:47:00 +02:00
|
|
|
for (unsigned int ligature_idx = 0; ligature_idx < ARRAY_LENGTH (ligature_table[0].ligatures); ligature_idx++)
|
2012-09-06 04:19:28 +02:00
|
|
|
{
|
2022-06-18 21:47:00 +02:00
|
|
|
hb_codepoint_t ligature_u = ligature_table[first_glyph_idx].ligatures[ligature_idx].ligature;
|
2022-06-18 22:04:56 +02:00
|
|
|
hb_codepoint_t ligature_glyph;
|
|
|
|
if (!hb_font_get_glyph (font, ligature_u, 0, &ligature_glyph))
|
|
|
|
continue;
|
|
|
|
|
2022-06-18 22:07:48 +02:00
|
|
|
const auto &components = ligature_table[first_glyph_idx].ligatures[ligature_idx].components;
|
|
|
|
unsigned component_count = ARRAY_LENGTH_CONST (components);
|
|
|
|
|
2023-01-18 18:44:13 +01:00
|
|
|
bool matched = true;
|
|
|
|
for (unsigned j = 0; j < component_count; j++)
|
2022-06-18 22:12:30 +02:00
|
|
|
{
|
2023-01-18 18:44:13 +01:00
|
|
|
hb_codepoint_t component_u = ligature_table[first_glyph_idx].ligatures[ligature_idx].components[j];
|
2022-06-18 22:12:30 +02:00
|
|
|
hb_codepoint_t component_glyph;
|
|
|
|
if (!component_u ||
|
2023-01-18 18:44:13 +01:00
|
|
|
!hb_font_get_nominal_glyph (font, component_u, &component_glyph))
|
|
|
|
{
|
|
|
|
matched = false;
|
|
|
|
break;
|
|
|
|
}
|
2022-06-18 22:12:30 +02:00
|
|
|
|
|
|
|
component_list[num_components++] = component_glyph;
|
|
|
|
}
|
2023-01-18 18:44:13 +01:00
|
|
|
if (!matched)
|
|
|
|
continue;
|
2012-09-06 04:19:28 +02:00
|
|
|
|
2022-06-18 22:07:48 +02:00
|
|
|
component_count_list[num_ligatures] = 1 + component_count;
|
2019-03-30 04:17:46 +01:00
|
|
|
ligature_list[num_ligatures] = ligature_glyph;
|
2022-06-18 22:04:56 +02:00
|
|
|
|
|
|
|
ligature_per_first_glyph_count_list[i]++;
|
|
|
|
|
2012-09-06 04:19:28 +02:00
|
|
|
num_ligatures++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-30 08:15:44 +02:00
|
|
|
if (!num_ligatures)
|
2017-10-15 12:11:08 +02:00
|
|
|
return nullptr;
|
2014-07-30 08:15:44 +02:00
|
|
|
|
2012-09-06 04:19:28 +02:00
|
|
|
|
2012-09-06 07:12:50 +02:00
|
|
|
/* 16 bytes per ligature ought to be enough... */
|
|
|
|
char buf[ARRAY_LENGTH_CONST (ligature_list) * 16 + 128];
|
2018-08-02 08:59:09 +02:00
|
|
|
hb_serialize_context_t c (buf, sizeof (buf));
|
2012-09-06 04:19:28 +02:00
|
|
|
OT::SubstLookup *lookup = c.start_serialize<OT::SubstLookup> ();
|
|
|
|
bool ret = lookup->serialize_ligature (&c,
|
2022-06-18 21:25:46 +02:00
|
|
|
lookup_flags,
|
2019-01-08 00:33:04 +01:00
|
|
|
hb_sorted_array (first_glyphs, num_first_glyphs),
|
2018-12-18 22:49:08 +01:00
|
|
|
hb_array (ligature_per_first_glyph_count_list, num_first_glyphs),
|
|
|
|
hb_array (ligature_list, num_ligatures),
|
|
|
|
hb_array (component_count_list, num_ligatures),
|
2022-06-18 22:34:46 +02:00
|
|
|
hb_array (component_list, num_components));
|
2012-09-06 04:19:28 +02:00
|
|
|
c.end_serialize ();
|
|
|
|
|
2020-08-13 20:52:14 +02:00
|
|
|
return ret && !c.in_error () ? c.copy<OT::SubstLookup> () : nullptr;
|
2012-09-06 04:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static OT::SubstLookup *
|
|
|
|
arabic_fallback_synthesize_lookup (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
unsigned int feature_index)
|
|
|
|
{
|
|
|
|
if (feature_index < 4)
|
|
|
|
return arabic_fallback_synthesize_lookup_single (plan, font, feature_index);
|
|
|
|
else
|
2022-06-18 21:25:46 +02:00
|
|
|
{
|
|
|
|
switch (feature_index) {
|
2022-06-18 22:34:46 +02:00
|
|
|
case 4: return arabic_fallback_synthesize_lookup_ligature (plan, font, ligature_3_table, OT::LookupFlag::IgnoreMarks);
|
|
|
|
case 5: return arabic_fallback_synthesize_lookup_ligature (plan, font, ligature_table, OT::LookupFlag::IgnoreMarks);
|
|
|
|
case 6: return arabic_fallback_synthesize_lookup_ligature (plan, font, ligature_mark_table, 0);
|
2022-06-18 21:25:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
assert (false);
|
2022-06-19 18:36:24 +02:00
|
|
|
return nullptr;
|
2012-09-06 04:19:28 +02:00
|
|
|
}
|
|
|
|
|
2022-06-18 21:25:46 +02:00
|
|
|
#define ARABIC_FALLBACK_MAX_LOOKUPS ARRAY_LENGTH_CONST (arabic_fallback_features)
|
2014-08-01 22:14:33 +02:00
|
|
|
|
2012-09-06 04:19:28 +02:00
|
|
|
struct arabic_fallback_plan_t
|
|
|
|
{
|
2014-07-30 08:15:44 +02:00
|
|
|
unsigned int num_lookups;
|
|
|
|
bool free_lookups;
|
|
|
|
|
2014-08-01 22:14:33 +02:00
|
|
|
hb_mask_t mask_array[ARABIC_FALLBACK_MAX_LOOKUPS];
|
|
|
|
OT::SubstLookup *lookup_array[ARABIC_FALLBACK_MAX_LOOKUPS];
|
2023-01-31 22:59:39 +01:00
|
|
|
OT::hb_ot_layout_lookup_accelerator_t *accel_array[ARABIC_FALLBACK_MAX_LOOKUPS];
|
2012-09-06 04:19:28 +02:00
|
|
|
};
|
|
|
|
|
2018-11-13 03:05:39 +01:00
|
|
|
#if defined(_WIN32) && !defined(HB_NO_WIN1256)
|
2014-07-30 08:15:44 +02:00
|
|
|
#define HB_WITH_WIN1256
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HB_WITH_WIN1256
|
2022-06-03 10:56:41 +02:00
|
|
|
#include "hb-ot-shaper-arabic-win1256.hh"
|
2014-07-30 08:15:44 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-06 15:17:48 +02:00
|
|
|
struct ManifestLookup
|
|
|
|
{
|
2018-11-11 02:11:10 +01:00
|
|
|
public:
|
2014-07-31 17:04:00 +02:00
|
|
|
OT::Tag tag;
|
2021-03-31 20:49:14 +02:00
|
|
|
OT::Offset16To<OT::SubstLookup> lookupOffset;
|
2018-11-11 02:11:10 +01:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (6);
|
2014-07-30 08:15:44 +02:00
|
|
|
};
|
2021-04-01 00:04:43 +02:00
|
|
|
typedef OT::Array16Of<ManifestLookup> Manifest;
|
2014-07-30 08:15:44 +02:00
|
|
|
|
|
|
|
static bool
|
2018-10-27 06:01:11 +02:00
|
|
|
arabic_fallback_plan_init_win1256 (arabic_fallback_plan_t *fallback_plan HB_UNUSED,
|
|
|
|
const hb_ot_shape_plan_t *plan HB_UNUSED,
|
|
|
|
hb_font_t *font HB_UNUSED)
|
2014-07-30 08:15:44 +02:00
|
|
|
{
|
|
|
|
#ifdef HB_WITH_WIN1256
|
|
|
|
/* Does this font look like it's Windows-1256-encoded? */
|
|
|
|
hb_codepoint_t g;
|
|
|
|
if (!(hb_font_get_glyph (font, 0x0627u, 0, &g) && g == 199 /* ALEF */ &&
|
|
|
|
hb_font_get_glyph (font, 0x0644u, 0, &g) && g == 225 /* LAM */ &&
|
|
|
|
hb_font_get_glyph (font, 0x0649u, 0, &g) && g == 236 /* ALEF MAKSURA */ &&
|
|
|
|
hb_font_get_glyph (font, 0x064Au, 0, &g) && g == 237 /* YEH */ &&
|
|
|
|
hb_font_get_glyph (font, 0x0652u, 0, &g) && g == 250 /* SUKUN */))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const Manifest &manifest = reinterpret_cast<const Manifest&> (arabic_win1256_gsub_lookups.manifest);
|
2022-06-18 22:47:10 +02:00
|
|
|
static_assert (sizeof (arabic_win1256_gsub_lookups.manifestData) <=
|
2019-10-01 10:36:22 +02:00
|
|
|
ARABIC_FALLBACK_MAX_LOOKUPS * sizeof (ManifestLookup), "");
|
2014-07-30 08:15:44 +02:00
|
|
|
|
|
|
|
unsigned j = 0;
|
|
|
|
unsigned int count = manifest.len;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
2014-07-31 17:04:00 +02:00
|
|
|
fallback_plan->mask_array[j] = plan->map.get_1_mask (manifest[i].tag);
|
2014-07-30 08:15:44 +02:00
|
|
|
if (fallback_plan->mask_array[j])
|
|
|
|
{
|
|
|
|
fallback_plan->lookup_array[j] = const_cast<OT::SubstLookup*> (&(&manifest+manifest[i].lookupOffset));
|
|
|
|
if (fallback_plan->lookup_array[j])
|
|
|
|
{
|
2023-01-31 22:59:39 +01:00
|
|
|
fallback_plan->accel_array[j] = OT::hb_ot_layout_lookup_accelerator_t::create (*fallback_plan->lookup_array[j]);
|
2014-07-30 08:15:44 +02:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback_plan->num_lookups = j;
|
|
|
|
fallback_plan->free_lookups = false;
|
|
|
|
|
|
|
|
return j > 0;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
arabic_fallback_plan_init_unicode (arabic_fallback_plan_t *fallback_plan,
|
|
|
|
const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font)
|
|
|
|
{
|
2022-06-18 21:25:46 +02:00
|
|
|
static_assert ((ARRAY_LENGTH_CONST (arabic_fallback_features) <= ARABIC_FALLBACK_MAX_LOOKUPS), "");
|
2014-07-30 08:15:44 +02:00
|
|
|
unsigned int j = 0;
|
2014-08-01 22:14:33 +02:00
|
|
|
for (unsigned int i = 0; i < ARRAY_LENGTH(arabic_fallback_features) ; i++)
|
2014-07-30 08:15:44 +02:00
|
|
|
{
|
|
|
|
fallback_plan->mask_array[j] = plan->map.get_1_mask (arabic_fallback_features[i]);
|
|
|
|
if (fallback_plan->mask_array[j])
|
|
|
|
{
|
|
|
|
fallback_plan->lookup_array[j] = arabic_fallback_synthesize_lookup (plan, font, i);
|
|
|
|
if (fallback_plan->lookup_array[j])
|
|
|
|
{
|
2023-01-31 22:59:39 +01:00
|
|
|
fallback_plan->accel_array[j] = OT::hb_ot_layout_lookup_accelerator_t::create (*fallback_plan->lookup_array[j]);
|
2014-07-30 08:15:44 +02:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback_plan->num_lookups = j;
|
|
|
|
fallback_plan->free_lookups = true;
|
|
|
|
|
|
|
|
return j > 0;
|
|
|
|
}
|
|
|
|
|
2012-09-06 04:19:28 +02:00
|
|
|
static arabic_fallback_plan_t *
|
|
|
|
arabic_fallback_plan_create (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font)
|
|
|
|
{
|
2021-07-08 18:58:50 +02:00
|
|
|
arabic_fallback_plan_t *fallback_plan = (arabic_fallback_plan_t *) hb_calloc (1, sizeof (arabic_fallback_plan_t));
|
2012-09-06 04:19:28 +02:00
|
|
|
if (unlikely (!fallback_plan))
|
2020-04-20 11:42:45 +02:00
|
|
|
return const_cast<arabic_fallback_plan_t *> (&Null (arabic_fallback_plan_t));
|
2012-09-06 04:19:28 +02:00
|
|
|
|
2014-07-30 08:15:44 +02:00
|
|
|
fallback_plan->num_lookups = 0;
|
|
|
|
fallback_plan->free_lookups = false;
|
|
|
|
|
|
|
|
/* Try synthesizing GSUB table using Unicode Arabic Presentation Forms,
|
|
|
|
* in case the font has cmap entries for the presentation-forms characters. */
|
|
|
|
if (arabic_fallback_plan_init_unicode (fallback_plan, plan, font))
|
|
|
|
return fallback_plan;
|
2012-09-06 04:19:28 +02:00
|
|
|
|
2014-07-30 08:15:44 +02:00
|
|
|
/* See if this looks like a Windows-1256-encoded font. If it does, use a
|
|
|
|
* hand-coded GSUB table. */
|
|
|
|
if (arabic_fallback_plan_init_win1256 (fallback_plan, plan, font))
|
|
|
|
return fallback_plan;
|
|
|
|
|
2018-08-06 15:30:12 +02:00
|
|
|
assert (fallback_plan->num_lookups == 0);
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_free (fallback_plan);
|
2020-04-20 11:42:45 +02:00
|
|
|
return const_cast<arabic_fallback_plan_t *> (&Null (arabic_fallback_plan_t));
|
2012-09-06 04:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arabic_fallback_plan_destroy (arabic_fallback_plan_t *fallback_plan)
|
|
|
|
{
|
2018-08-06 15:30:12 +02:00
|
|
|
if (!fallback_plan || fallback_plan->num_lookups == 0)
|
2012-09-06 04:19:28 +02:00
|
|
|
return;
|
|
|
|
|
2014-07-30 08:15:44 +02:00
|
|
|
for (unsigned int i = 0; i < fallback_plan->num_lookups; i++)
|
2012-09-06 04:19:28 +02:00
|
|
|
if (fallback_plan->lookup_array[i])
|
2013-05-03 00:06:51 +02:00
|
|
|
{
|
2023-01-31 22:59:39 +01:00
|
|
|
hb_free (fallback_plan->accel_array[i]);
|
2014-07-30 08:15:44 +02:00
|
|
|
if (fallback_plan->free_lookups)
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_free (fallback_plan->lookup_array[i]);
|
2013-05-03 00:06:51 +02:00
|
|
|
}
|
2012-09-06 04:19:28 +02:00
|
|
|
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_free (fallback_plan);
|
2012-09-06 04:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arabic_fallback_plan_shape (arabic_fallback_plan_t *fallback_plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer)
|
|
|
|
{
|
2018-01-18 01:46:51 +01:00
|
|
|
OT::hb_ot_apply_context_t c (0, font, buffer);
|
2014-07-30 08:15:44 +02:00
|
|
|
for (unsigned int i = 0; i < fallback_plan->num_lookups; i++)
|
2012-09-06 04:19:28 +02:00
|
|
|
if (fallback_plan->lookup_array[i]) {
|
2013-05-03 00:52:24 +02:00
|
|
|
c.set_lookup_mask (fallback_plan->mask_array[i]);
|
2023-01-31 22:59:39 +01:00
|
|
|
if (fallback_plan->accel_array[i])
|
|
|
|
hb_ot_layout_substitute_lookup (&c,
|
|
|
|
*fallback_plan->lookup_array[i],
|
|
|
|
*fallback_plan->accel_array[i]);
|
2012-09-06 04:19:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-03 10:54:33 +02:00
|
|
|
#endif /* HB_OT_SHAPER_ARABIC_FALLBACK_HH */
|