mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-29 09:34:05 +01:00
Merge branch 'main' into varc-subsetting
Resolve the VARC record-decoding conflict by preserving the shared decoder while threading main's rendering budget through axis and variation work. Tests: meson test -C build (277 passed, 1 skipped) Assisted-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
commit
50046742d7
131 files changed
+51417
-1757
No files matched your search
@@ -19,6 +19,7 @@ jobs:
|
||||
- name: Configure CMake
|
||||
run: |
|
||||
cmake -S . -B build \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DCMAKE_TOOLCHAIN_FILE=${DEVKITPRO}/cmake/3DS.cmake
|
||||
- name: Build
|
||||
run: make CXX_FLAGS="-w -DHB_NO_MT"
|
||||
|
||||
@@ -59,6 +59,6 @@ jobs:
|
||||
|
||||
# Upload the results to GitHub's code scanning dashboard.
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7
|
||||
uses: github/codeql-action/upload-sarif@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
+14
-3
@@ -175,7 +175,17 @@ set (HB_VERSION_MINOR ${CMAKE_MATCH_3})
|
||||
set (HB_VERSION_MICRO ${CMAKE_MATCH_4})
|
||||
|
||||
## Define sources and headers of the project
|
||||
set (project_sources ${PROJECT_SOURCE_DIR}/src/harfbuzz.cc) # use amalgam source
|
||||
# Keep sources in separate archive members so duplicate internal sources in
|
||||
# dependent static libraries do not result in multiple definitions.
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
|
||||
${PROJECT_SOURCE_DIR}/src/harfbuzz.cc)
|
||||
file(STRINGS ${PROJECT_SOURCE_DIR}/src/harfbuzz.cc project_source_includes
|
||||
REGEX "^#include \".*\\.cc\"$")
|
||||
foreach (project_source_include IN LISTS project_source_includes)
|
||||
string(REGEX REPLACE "^#include \"(.*\\.cc)\"$" "\\1"
|
||||
project_source ${project_source_include})
|
||||
list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/${project_source})
|
||||
endforeach ()
|
||||
set (subset_project_sources
|
||||
${PROJECT_SOURCE_DIR}/src/OT/Var/VARC/VARC.cc
|
||||
${PROJECT_SOURCE_DIR}/src/OT/Var/VARC/VARC-subset.hh
|
||||
@@ -210,6 +220,7 @@ set (subset_project_sources
|
||||
${PROJECT_SOURCE_DIR}/src/hb-subset.cc
|
||||
${PROJECT_SOURCE_DIR}/src/hb-subset.hh
|
||||
${PROJECT_SOURCE_DIR}/src/hb-repacker.hh
|
||||
${PROJECT_SOURCE_DIR}/src/hb-result.hh
|
||||
${PROJECT_SOURCE_DIR}/src/graph/graph.hh
|
||||
${PROJECT_SOURCE_DIR}/src/graph/gsubgpos-graph.hh
|
||||
${PROJECT_SOURCE_DIR}/src/graph/gsubgpos-context.hh
|
||||
@@ -639,7 +650,7 @@ if (HB_BUILD_SUBSET)
|
||||
if (MINGW)
|
||||
target_compile_options(harfbuzz-subset PRIVATE "-Wa,-mbig-obj")
|
||||
endif()
|
||||
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
if (BUILD_FRAMEWORK)
|
||||
set_target_properties(harfbuzz harfbuzz-subset PROPERTIES
|
||||
@@ -1256,7 +1267,7 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
COMPONENT runtime OPTIONAL
|
||||
)
|
||||
make_pkgconfig_pc_file("harfbuzz-gobject")
|
||||
|
||||
@@ -1,12 +1,62 @@
|
||||
Overview of changes leading to 14.4.0
|
||||
Wednesday, August 26, 2026
|
||||
=====================================
|
||||
- Glyph positions and extents now saturate instead of overflowing.
|
||||
- Arabic Windows-1256 fallback shaping is now enabled on all platforms.
|
||||
- Fix cluster values and a dropped glyph advance in the Graphite shaper.
|
||||
- Fix `avar` axis value mapping in fonts that repeat the boundary entries.
|
||||
- Fix `avar` version 2 partial instancing.
|
||||
- Fix `COLR` sweep gradient truncation and unbounded memory use.
|
||||
- Faster subsetting, especially for large `GSUB`/`GPOS` and `CFF` tables.
|
||||
- Faster extraction of the experimental glyph dependency graph.
|
||||
- Various shaping speedups.
|
||||
- Various fixes for crashes and hangs with malformed fonts.
|
||||
- Various fixes to the experimental raster, vector, and GPU libraries.
|
||||
- Various improvements to the HarfRust integration shaper.
|
||||
- The DirectWrite backend no longer uses the C++ runtime.
|
||||
- Various build, portability, and fuzzing fixes.
|
||||
|
||||
- New API:
|
||||
+hb_set_intersects()
|
||||
|
||||
|
||||
Overview of changes leading to 14.3.1
|
||||
Thursday, August 13, 2026
|
||||
=====================================
|
||||
- Various fuzzing and build fixes.
|
||||
- Add public draw and paint work-budget APIs. Rendering backends can expose a
|
||||
persistent policy and a live counter so nested outline traversal consumes the
|
||||
same finite budget as emitted output.
|
||||
- Various subsetting fixes.
|
||||
- Fix AAT insertion at the end of the text.
|
||||
- Fix various rendering bugs in the experimental GPU library.
|
||||
- WASM shaper code can now read the user features.
|
||||
|
||||
- New API:
|
||||
* Common:
|
||||
+HB_BUDGET_DEFAULT
|
||||
+HB_BUDGET_UNLIMITED
|
||||
* Draw:
|
||||
+hb_draw_set_budget_func_t
|
||||
+hb_draw_get_budget_func_t
|
||||
+hb_draw_get_budget_remaining_func_t
|
||||
+hb_draw_funcs_set_set_budget_func()
|
||||
+hb_draw_funcs_set_get_budget_func()
|
||||
+hb_draw_funcs_set_get_budget_remaining_func()
|
||||
+hb_draw_set_budget()
|
||||
+hb_draw_get_budget()
|
||||
+hb_draw_get_budget_remaining()
|
||||
* Paint:
|
||||
+hb_paint_set_budget_func_t
|
||||
+hb_paint_get_budget_func_t
|
||||
+hb_paint_get_budget_remaining_func_t
|
||||
+hb_paint_funcs_set_set_budget_func()
|
||||
+hb_paint_funcs_set_get_budget_func()
|
||||
+hb_paint_funcs_set_get_budget_remaining_func()
|
||||
+hb_paint_set_budget()
|
||||
+hb_paint_get_budget()
|
||||
+hb_paint_get_budget_remaining()
|
||||
|
||||
|
||||
Overview of changes leading to 14.3.0
|
||||
Friday, July 31, 2026
|
||||
|
||||
@@ -137,6 +137,7 @@
|
||||
<index id="api-index-full"><title>API Index</title><xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include></index>
|
||||
<index id="deprecated-api-index"><title>Index of deprecated API</title><xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include></index>
|
||||
|
||||
<index id="api-index-14-4-0"><title>Index of new symbols in 14.4.0</title><xi:include href="xml/api-index-14.4.0.xml"><xi:fallback /></xi:include></index>
|
||||
<index id="api-index-14-3-0"><title>Index of new symbols in 14.3.0</title><xi:include href="xml/api-index-14.3.0.xml"><xi:fallback /></xi:include></index>
|
||||
<index id="api-index-14-2-0"><title>Index of new symbols in 14.2.0</title><xi:include href="xml/api-index-14.2.0.xml"><xi:fallback /></xi:include></index>
|
||||
<index id="api-index-14-1-0"><title>Index of new symbols in 14.1.0</title><xi:include href="xml/api-index-14.1.0.xml"><xi:fallback /></xi:include></index>
|
||||
|
||||
@@ -126,6 +126,8 @@ hb_buffer_diff_flags_t
|
||||
|
||||
<SECTION>
|
||||
<FILE>hb-common</FILE>
|
||||
HB_BUDGET_DEFAULT
|
||||
HB_BUDGET_UNLIMITED
|
||||
HB_TAG
|
||||
HB_UNTAG
|
||||
hb_tag_from_string
|
||||
@@ -235,6 +237,15 @@ hb_draw_cubic_to_func_t
|
||||
hb_draw_funcs_set_cubic_to_func
|
||||
hb_draw_close_path_func_t
|
||||
hb_draw_funcs_set_close_path_func
|
||||
hb_draw_set_budget_func_t
|
||||
hb_draw_funcs_set_set_budget_func
|
||||
hb_draw_get_budget_func_t
|
||||
hb_draw_funcs_set_get_budget_func
|
||||
hb_draw_get_budget_remaining_func_t
|
||||
hb_draw_funcs_set_get_budget_remaining_func
|
||||
hb_draw_set_budget
|
||||
hb_draw_get_budget
|
||||
hb_draw_get_budget_remaining
|
||||
hb_draw_move_to
|
||||
hb_draw_line_to
|
||||
hb_draw_quadratic_to
|
||||
@@ -261,6 +272,16 @@ hb_paint_funcs_get_user_data
|
||||
hb_paint_funcs_make_immutable
|
||||
hb_paint_funcs_is_immutable
|
||||
|
||||
hb_paint_set_budget_func_t
|
||||
hb_paint_funcs_set_set_budget_func
|
||||
hb_paint_get_budget_func_t
|
||||
hb_paint_funcs_set_get_budget_func
|
||||
hb_paint_get_budget_remaining_func_t
|
||||
hb_paint_funcs_set_get_budget_remaining_func
|
||||
hb_paint_set_budget
|
||||
hb_paint_get_budget
|
||||
hb_paint_get_budget_remaining
|
||||
|
||||
hb_paint_push_transform_func_t
|
||||
hb_paint_funcs_set_push_transform_func
|
||||
hb_paint_pop_transform_func_t
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
project('harfbuzz', ['c', 'cpp'],
|
||||
meson_version: '>= 0.60.0',
|
||||
version: '14.3.1',
|
||||
version: '14.4.0',
|
||||
default_options: [
|
||||
'cpp_eh=none', # Just to support msvc, we are passing -fno-exceptions also anyway
|
||||
# 'cpp_rtti=false', # Do NOT enable, wraps inherit it and ICU needs RTTI
|
||||
|
||||
@@ -118,6 +118,28 @@ BENCHMARK(BM_SetIteration)
|
||||
{{1 << 10, 1 << 16}, // Set Size
|
||||
{2, 512}}); // Density
|
||||
|
||||
/* Range iteration of sets of varying sizes. */
|
||||
static void BM_SetNextRange(benchmark::State& state) {
|
||||
unsigned set_size = state.range(0);
|
||||
unsigned max_value = state.range(0) * state.range(1);
|
||||
|
||||
hb_set_t* original = hb_set_create ();
|
||||
RandomSet(set_size, max_value, original);
|
||||
assert(hb_set_get_population(original) == set_size);
|
||||
|
||||
hb_codepoint_t first = HB_SET_VALUE_INVALID;
|
||||
hb_codepoint_t last = HB_SET_VALUE_INVALID;
|
||||
for (auto _ : state) {
|
||||
hb_set_next_range (original, &first, &last);
|
||||
}
|
||||
|
||||
hb_set_destroy(original);
|
||||
}
|
||||
BENCHMARK(BM_SetNextRange)
|
||||
->Ranges(
|
||||
{{1 << 10, 1 << 16}, // Set Size
|
||||
{2, 512}}); // Density
|
||||
|
||||
/* Set copy. */
|
||||
static void BM_SetCopy(benchmark::State& state) {
|
||||
unsigned set_size = state.range(0);
|
||||
|
||||
+69
-38
@@ -43,7 +43,9 @@ struct test_input_t
|
||||
|
||||
static test_input_t *tests = default_tests;
|
||||
static unsigned num_tests = sizeof (default_tests) / sizeof (default_tests[0]);
|
||||
const char *variation = nullptr;
|
||||
static const char *variations_string = nullptr;
|
||||
static hb_variation_t *variations = nullptr;
|
||||
static unsigned num_variations = 0;
|
||||
const char *direction = nullptr;
|
||||
|
||||
static bool shape (hb_buffer_t *buf,
|
||||
@@ -83,12 +85,8 @@ static void BM_Shape (benchmark::State &state,
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
if (variation)
|
||||
{
|
||||
hb_variation_t var;
|
||||
hb_variation_from_string (variation, -1, &var);
|
||||
hb_font_set_variations (font, &var, 1);
|
||||
}
|
||||
if (variations)
|
||||
hb_font_set_variations (font, variations, num_variations);
|
||||
|
||||
hb_blob_t *text_blob = hb_blob_create_from_file_or_fail (input.text_path);
|
||||
assert (text_blob);
|
||||
@@ -137,21 +135,48 @@ static void test_shaper (const char *shaper,
|
||||
->Unit(benchmark::kMillisecond);
|
||||
}
|
||||
|
||||
static const char *font_file = nullptr;
|
||||
static const char *text_file = nullptr;
|
||||
static bool
|
||||
parse_variations ()
|
||||
{
|
||||
if (!variations_string || !*variations_string)
|
||||
return true;
|
||||
|
||||
const char *p = variations_string;
|
||||
while (p)
|
||||
{
|
||||
num_variations++;
|
||||
p = strchr (p, ',');
|
||||
if (p) p++;
|
||||
}
|
||||
|
||||
variations = (hb_variation_t *) calloc (num_variations, sizeof (*variations));
|
||||
if (!variations)
|
||||
return false;
|
||||
|
||||
p = variations_string;
|
||||
num_variations = 0;
|
||||
while (p)
|
||||
{
|
||||
const char *end = strchr (p, ',');
|
||||
if (hb_variation_from_string (p, end ? end - p : -1,
|
||||
&variations[num_variations]))
|
||||
num_variations++;
|
||||
p = end ? end + 1 : nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static GOptionEntry entries[] =
|
||||
{
|
||||
{"font-file", 0, 0, G_OPTION_ARG_STRING, &font_file, "Font file-path to benchmark", "FONTFILE"},
|
||||
{"text-file", 0, 0, G_OPTION_ARG_STRING, &text_file, "Text file-path to benchmark", "TEXTFILE"},
|
||||
{"variations", 0, 0, G_OPTION_ARG_STRING, &variation, "Variations to apply during shaping", "VARIATIONS"},
|
||||
{"variations", 0, 0, G_OPTION_ARG_STRING, &variations_string, "Comma-separated font variations to apply during shaping", "VARIATIONS"},
|
||||
{"direction", 0, 0, G_OPTION_ARG_STRING, &direction, "Direction to apply during shaping", "DIRECTION"},
|
||||
{nullptr}
|
||||
};
|
||||
|
||||
static void print_usage (const char *prgname)
|
||||
{
|
||||
g_print ("Usage: %s [OPTIONS] [FONTFILE]\n", prgname);
|
||||
g_print ("Usage: %s [OPTIONS] [FONTFILE TEXTFILE]...\n", prgname);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@@ -191,39 +216,41 @@ int main(int argc, char** argv)
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (!font_file && argc)
|
||||
if (argc % 2)
|
||||
{
|
||||
font_file = *argv;
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
if (!text_file && argc)
|
||||
{
|
||||
text_file = *argv;
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
|
||||
if (argc)
|
||||
{
|
||||
g_printerr ("Unexpected arguments: ");
|
||||
for (int i = 0; i < argc; i++)
|
||||
g_printerr ("%s ", argv[i]);
|
||||
g_printerr ("\n\n");
|
||||
g_printerr ("Font and text files must be provided in pairs.\n\n");
|
||||
print_usage (prgname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
test_input_t static_test = {};
|
||||
if (font_file && text_file)
|
||||
unsigned custom_num_tests = argc / 2;
|
||||
if (custom_num_tests)
|
||||
{
|
||||
if (font_file && text_file)
|
||||
tests = (test_input_t *) calloc (custom_num_tests, sizeof (*tests));
|
||||
if (!tests)
|
||||
{
|
||||
static_test.font_path = font_file;
|
||||
static_test.text_path = text_file;
|
||||
tests = &static_test;
|
||||
num_tests = 1;
|
||||
g_printerr ("Failed to allocate test inputs.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned i = 0;
|
||||
while (argc)
|
||||
{
|
||||
tests[i].font_path = argv[0];
|
||||
tests[i].text_path = argv[1];
|
||||
i++;
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
num_tests = custom_num_tests;
|
||||
}
|
||||
|
||||
if (!parse_variations ())
|
||||
{
|
||||
g_printerr ("Failed to allocate font variations.\n");
|
||||
if (tests != default_tests)
|
||||
free (tests);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < num_tests; i++)
|
||||
@@ -236,4 +263,8 @@ int main(int argc, char** argv)
|
||||
|
||||
benchmark::RunSpecifiedBenchmarks();
|
||||
benchmark::Shutdown();
|
||||
|
||||
free (variations);
|
||||
if (tests != default_tests)
|
||||
free (tests);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
ja-runs.txt
|
||||
===========
|
||||
|
||||
Derived from the copyright-expired Japanese novel "Wagahai wa Neko de
|
||||
Aru" (吾輩は猫である) by Natsume Soseki (夏目漱石), first published in
|
||||
1905 and 1906. The source text was prepared and distributed by Aozora
|
||||
Bunko, which permits free reproduction, redistribution, sharing, and
|
||||
adaptation of its copyright-expired files:
|
||||
|
||||
https://www.aozora.gr.jp/guide/kijyunn.html
|
||||
|
||||
Work and source-file information:
|
||||
|
||||
https://www.aozora.gr.jp/cards/000148/card789.html
|
||||
https://www.aozora.gr.jp/cards/000148/files/789_ruby_5639.zip
|
||||
|
||||
Downloaded source ZIP SHA-256:
|
||||
|
||||
6545750b89ee2c57f215a65079eeab56ee7c997373b7b86e5b00ae74fe69208f
|
||||
|
||||
Source edition: "Natsume Soseki Zenshu 1", Chikuma Bunko, Chikuma
|
||||
Shobo, first printing dated September 29, 1987. Text entered by
|
||||
柴田卓治. Proofread by 渡部峰子, おのしげひこ, 田尻幹二,
|
||||
高橋真也, しず, and 瀬戸さえ子.
|
||||
|
||||
For this performance corpus, the Shift-JIS source was converted to
|
||||
UTF-8; its header, footer, ruby readings, and Aozora annotations were
|
||||
removed; and a 100,000-character sample of Han, Hiragana, Katakana, or
|
||||
Inherited characters was retained from the beginning of the work. Each
|
||||
line is one Unicode-script run. Common and other scripts are omitted
|
||||
and act as run boundaries.
|
||||
+45245
File diff suppressed because it is too large.
Load diff
@@ -138,6 +138,9 @@ struct CursivePosFormat1
|
||||
void collect_glyphs (hb_collect_glyphs_context_t *c) const
|
||||
{ if (unlikely (!(this+coverage).collect_coverage (c->input))) return; }
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{ (this+coverage).collect_coverage (digest); }
|
||||
|
||||
const Coverage &get_coverage () const { return this+coverage; }
|
||||
|
||||
bool apply (hb_ot_apply_context_t *c) const
|
||||
|
||||
@@ -88,6 +88,9 @@ struct MarkBasePosFormat1_2
|
||||
if (unlikely (!(this+baseCoverage).collect_coverage (c->input))) return;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{ (this+baseCoverage).collect_coverage (digest); }
|
||||
|
||||
const Coverage &get_coverage () const { return this+markCoverage; }
|
||||
|
||||
static inline bool accept (hb_buffer_t *buffer, unsigned idx)
|
||||
|
||||
@@ -90,6 +90,9 @@ struct MarkLigPosFormat1_2
|
||||
if (unlikely (!(this+ligatureCoverage).collect_coverage (c->input))) return;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{ (this+ligatureCoverage).collect_coverage (digest); }
|
||||
|
||||
const Coverage &get_coverage () const { return this+markCoverage; }
|
||||
|
||||
static inline bool accept (hb_buffer_t *buffer, unsigned idx)
|
||||
|
||||
@@ -90,6 +90,9 @@ struct MarkMarkPosFormat1_2
|
||||
if (unlikely (!(this+mark2Coverage).collect_coverage (c->input))) return;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{ (this+mark2Coverage).collect_coverage (digest); }
|
||||
|
||||
const Coverage &get_coverage () const { return this+mark1Coverage; }
|
||||
|
||||
bool apply (hb_ot_apply_context_t *c) const
|
||||
|
||||
@@ -101,18 +101,35 @@ struct PairPosFormat1_3
|
||||
(this+pairSet[i]).collect_glyphs (c, valueFormat);
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{
|
||||
unsigned count = pairSet.len;
|
||||
for (unsigned i = 0; i < count; i++)
|
||||
(this+pairSet[i]).collect_second_glyphs (digest, valueFormat);
|
||||
}
|
||||
|
||||
const Coverage &get_coverage () const { return this+coverage; }
|
||||
|
||||
struct external_cache_t
|
||||
{
|
||||
hb_ot_layout_mapping_cache_t coverage;
|
||||
hb_set_digest_t pair_sets[HB_VAR_ARRAY];
|
||||
};
|
||||
void *external_cache_create () const
|
||||
{
|
||||
external_cache_t *cache = (external_cache_t *) hb_malloc (sizeof (external_cache_t));
|
||||
unsigned count = pairSet.len;
|
||||
unsigned size = sizeof (external_cache_t) -
|
||||
HB_VAR_ARRAY * sizeof (hb_set_digest_t) +
|
||||
count * sizeof (hb_set_digest_t);
|
||||
external_cache_t *cache = (external_cache_t *) hb_malloc (size);
|
||||
if (likely (cache))
|
||||
{
|
||||
cache->coverage.clear ();
|
||||
for (unsigned i = 0; i < count; i++)
|
||||
{
|
||||
cache->pair_sets[i].init ();
|
||||
(this+pairSet[i]).collect_second_glyphs (&cache->pair_sets[i], valueFormat);
|
||||
}
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
@@ -140,6 +157,16 @@ struct PairPosFormat1_3
|
||||
return_trace (false);
|
||||
}
|
||||
|
||||
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
|
||||
if (cache &&
|
||||
index < pairSet.len &&
|
||||
!cache->pair_sets[index].may_have (buffer->info[skippy_iter.idx].codepoint))
|
||||
{
|
||||
buffer->unsafe_to_concat (buffer->idx, skippy_iter.idx + 1);
|
||||
return_trace (false);
|
||||
}
|
||||
#endif
|
||||
|
||||
return_trace ((this+pairSet[index]).apply (c, valueFormat, skippy_iter.idx));
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,15 @@ struct PairSet : ValueBase
|
||||
c->input->add_array (&record->secondGlyph, len, record_size);
|
||||
}
|
||||
|
||||
template <typename set_t>
|
||||
void collect_second_glyphs (set_t *glyphs,
|
||||
const ValueFormat *valueFormats) const
|
||||
{
|
||||
unsigned record_size = get_size (valueFormats);
|
||||
const PairValueRecord *record = &firstPairValueRecord;
|
||||
glyphs->add_array (&record->secondGlyph, len, record_size);
|
||||
}
|
||||
|
||||
void collect_variation_indices (hb_collect_variation_indices_context_t *c,
|
||||
const ValueFormat *valueFormats) const
|
||||
{
|
||||
@@ -143,6 +152,9 @@ struct PairSet : ValueBase
|
||||
|
||||
if (applied_first || applied_second)
|
||||
buffer->unsafe_to_break (buffer->idx, pos + 1);
|
||||
else
|
||||
/* Even a zero-valued pair record is a concat hazard. */
|
||||
buffer->unsafe_to_concat (buffer->idx, pos + 1);
|
||||
|
||||
if (len2)
|
||||
{
|
||||
|
||||
@@ -136,7 +136,10 @@ struct LigatureSet
|
||||
goto slow;
|
||||
|
||||
if (seconds && !seconds->may_have (second))
|
||||
{
|
||||
c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to);
|
||||
return_trace (false);
|
||||
}
|
||||
bool unsafe_to_concat = false;
|
||||
for (unsigned int i = 0; i < num_ligs; i++)
|
||||
{
|
||||
|
||||
@@ -79,6 +79,14 @@ struct LigatureSubstFormat1_2
|
||||
;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{
|
||||
+ hb_iter (ligatureSet)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([digest] (const LigatureSet<Types> &_) { _.collect_seconds (*digest); })
|
||||
;
|
||||
}
|
||||
|
||||
const Coverage &get_coverage () const { return this+coverage; }
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c) const
|
||||
|
||||
+40
-13
@@ -33,7 +33,8 @@ VarComponent::decompile_record (const VARC &varc,
|
||||
hb_ubytes_t total_record,
|
||||
hb_vector_t<unsigned> *axis_indices,
|
||||
hb_vector_t<float> *axis_values,
|
||||
record_t *decoded)
|
||||
record_t *decoded,
|
||||
int64_t *budget)
|
||||
{
|
||||
const unsigned char *start = total_record.arrayZ;
|
||||
const unsigned char *record = start;
|
||||
@@ -94,6 +95,9 @@ VarComponent::decompile_record (const VARC &varc,
|
||||
}
|
||||
else
|
||||
axis_count = hb_len ((&varc+varc.axisIndicesList)[decoded->axis_indices_index]);
|
||||
if (unlikely (budget && axis_count &&
|
||||
!hb_budget_spend (*budget, HB_BUDGET_1, axis_count)))
|
||||
return false;
|
||||
if (axis_values)
|
||||
{
|
||||
if (unlikely (!axis_values->resize (axis_count))) return false;
|
||||
@@ -201,6 +205,7 @@ struct hb_transforming_pen_context_t
|
||||
hb_draw_funcs_t *dfuncs;
|
||||
void *data;
|
||||
hb_draw_state_t *st;
|
||||
int64_t *budget_remaining;
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -276,6 +281,12 @@ hb_transforming_pen_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
c->dfuncs->close_path (c->data, *c->st);
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_transforming_pen_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_transforming_pen_context_t *) draw_data)->budget_remaining;
|
||||
}
|
||||
|
||||
static inline void free_static_transforming_pen_funcs ();
|
||||
|
||||
static struct hb_transforming_pen_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t<hb_transforming_pen_funcs_lazy_loader_t>
|
||||
@@ -289,6 +300,7 @@ static struct hb_transforming_pen_funcs_lazy_loader_t : hb_draw_funcs_lazy_loade
|
||||
hb_draw_funcs_set_quadratic_to_func (funcs, hb_transforming_pen_quadratic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, hb_transforming_pen_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, hb_transforming_pen_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_transforming_pen_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
|
||||
@@ -318,6 +330,9 @@ VarComponent::get_path_at (const hb_varc_context_t &c,
|
||||
hb_ubytes_t total_record,
|
||||
hb_scalar_cache_t *cache) const
|
||||
{
|
||||
if (unlikely (!hb_budget_spend (c.budget, HB_BUDGET_4)))
|
||||
return hb_ubytes_t ();
|
||||
|
||||
const unsigned char *end = total_record.arrayZ + total_record.length;
|
||||
auto &VARC = *c.font->face->table.VARC->table;
|
||||
auto &varStore = &VARC+VARC.varStore;
|
||||
@@ -326,7 +341,8 @@ VarComponent::get_path_at (const hb_varc_context_t &c,
|
||||
auto &axisValues = c.scratch.axisValues;
|
||||
record_t component;
|
||||
if (unlikely (!decompile_record (VARC, total_record,
|
||||
&axisIndices, &axisValues, &component)))
|
||||
&axisIndices, &axisValues, &component,
|
||||
&c.budget)))
|
||||
return hb_ubytes_t ();
|
||||
|
||||
uint32_t flags = component.flags;
|
||||
@@ -347,8 +363,13 @@ VarComponent::get_path_at (const hb_varc_context_t &c,
|
||||
// Apply variations if any
|
||||
if ((flags & (unsigned) flags_t::AXIS_VALUES_HAVE_VARIATION) &&
|
||||
show && coords && !axisValues.in_error ())
|
||||
{
|
||||
if (unlikely (!hb_budget_spend (c.budget, axisValues.length,
|
||||
coords.length)))
|
||||
return hb_ubytes_t ();
|
||||
varStore.get_delta (component.axis_values_var_idx, coords,
|
||||
axisValues.as_array (), cache);
|
||||
}
|
||||
|
||||
auto component_coords = coords;
|
||||
/* Copying coords is expensive; so we have put an arbitrary
|
||||
@@ -363,6 +384,10 @@ VarComponent::get_path_at (const hb_varc_context_t &c,
|
||||
if (show)
|
||||
{
|
||||
// Only use coord_setter if there's actually any axis overrides.
|
||||
if (unlikely (axisIndices &&
|
||||
!hb_budget_spend (c.budget, HB_BUDGET_1,
|
||||
component_coords.length)))
|
||||
return hb_ubytes_t ();
|
||||
coord_setter_t coord_setter (axisIndices ? component_coords : hb_array<int> ());
|
||||
for (unsigned i = 0; i < axisIndices.length; i++)
|
||||
coord_setter[axisIndices[i]] = roundf (axisValues[i]);
|
||||
@@ -379,6 +404,9 @@ VarComponent::get_path_at (const hb_varc_context_t &c,
|
||||
transformValues[numTransformValues++] = transform.name;
|
||||
VARC_PROCESS_TRANSFORM_COMPONENTS;
|
||||
#undef PROCESS_TRANSFORM_COMPONENT
|
||||
if (unlikely (!hb_budget_spend (c.budget, numTransformValues,
|
||||
coords.length)))
|
||||
return hb_ubytes_t ();
|
||||
varStore.get_delta (transformVarIdx, coords, hb_array (transformValues, numTransformValues), cache);
|
||||
numTransformValues = 0;
|
||||
#define PROCESS_TRANSFORM_COMPONENT(shift, type, flag, name) \
|
||||
@@ -436,8 +464,7 @@ VARC::get_path_at (const hb_varc_context_t &c,
|
||||
{
|
||||
/* Out of budget: draw nothing, but signal success so remaining
|
||||
* leaves are skipped instead of falling back per-glyph. */
|
||||
if (unlikely (c.budget_left <= 0)) return true;
|
||||
c.budget_left--;
|
||||
if (unlikely (!hb_budget_spend (c.budget, HB_BUDGET_1))) return true;
|
||||
|
||||
hb_transform_t<> leaf_transform = transform;
|
||||
leaf_transform.x0 *= c.font->x_multf;
|
||||
@@ -448,27 +475,27 @@ VARC::get_path_at (const hb_varc_context_t &c,
|
||||
hb_transforming_pen_context_t context {leaf_transform,
|
||||
c.draw_session->funcs,
|
||||
c.draw_session->draw_data,
|
||||
&c.draw_session->st};
|
||||
&c.draw_session->st,
|
||||
&c.budget};
|
||||
hb_draw_session_t transformer_session {transformer_funcs, &context};
|
||||
hb_draw_session_t &shape_draw_session = leaf_transform.is_identity () ? *c.draw_session : transformer_session;
|
||||
|
||||
if (c.font->face->table.glyf->get_path_at (c.font, glyph, shape_draw_session, coords, c.scratch.glyf_scratch, nullptr, &c.budget_left)) return true;
|
||||
if (c.font->face->table.glyf->get_path_at (c.font, glyph, shape_draw_session, coords, c.scratch.glyf_scratch, nullptr, &shape_draw_session.get_budget ())) return true;
|
||||
#ifndef HB_NO_CFF
|
||||
if (c.font->face->table.cff2->get_path_at (c.font, glyph, shape_draw_session, coords, &c.budget_left)) return true;
|
||||
if (c.font->face->table.cff1->get_path (c.font, glyph, shape_draw_session, &c.budget_left)) return true; // Doesn't have variations
|
||||
if (c.font->face->table.cff2->get_path_at (c.font, glyph, shape_draw_session, coords, &shape_draw_session.get_budget ())) return true;
|
||||
if (c.font->face->table.cff1->get_path (c.font, glyph, shape_draw_session, &shape_draw_session.get_budget ())) return true; // Doesn't have variations
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
else if (c.extents)
|
||||
{
|
||||
if (unlikely (c.budget_left <= 0)) return true;
|
||||
c.budget_left--;
|
||||
if (unlikely (!hb_budget_spend (c.budget, HB_BUDGET_1))) return true;
|
||||
|
||||
hb_glyph_extents_t glyph_extents;
|
||||
if (!c.font->face->table.glyf->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget_left))
|
||||
if (!c.font->face->table.glyf->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget))
|
||||
#ifndef HB_NO_CFF
|
||||
if (!c.font->face->table.cff2->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget_left))
|
||||
if (!c.font->face->table.cff1->get_extents (c.font, glyph, &glyph_extents, &c.budget_left)) // Doesn't have variations
|
||||
if (!c.font->face->table.cff2->get_extents_at (c.font, glyph, &glyph_extents, coords, &c.budget))
|
||||
if (!c.font->face->table.cff1->get_extents (c.font, glyph, &glyph_extents, &c.budget)) // Doesn't have variations
|
||||
#endif
|
||||
return false;
|
||||
|
||||
|
||||
@@ -38,10 +38,9 @@ struct hb_varc_context_t
|
||||
mutable hb_decycler_t decycler;
|
||||
mutable signed edges_left;
|
||||
mutable signed depth_left;
|
||||
/* Work budget shared by all leaf glyphs loaded from glyf/CFF/CFF2,
|
||||
* so their per-glyph work limits cannot multiply with our own
|
||||
* composite-graph limits. */
|
||||
mutable int64_t budget_left;
|
||||
/* Renderer-owned live budget, shared by VARC record processing and
|
||||
* every leaf loaded from glyf/CFF/CFF2. */
|
||||
int64_t &budget;
|
||||
hb_varc_scratch_t &scratch;
|
||||
};
|
||||
|
||||
@@ -103,7 +102,8 @@ struct VarComponent
|
||||
hb_ubytes_t record,
|
||||
hb_vector_t<unsigned> *axis_indices,
|
||||
hb_vector_t<float> *axis_values,
|
||||
record_t *decoded /* OUT */);
|
||||
record_t *decoded /* OUT */,
|
||||
int64_t *budget = nullptr);
|
||||
};
|
||||
|
||||
struct VarCompositeGlyph
|
||||
@@ -154,13 +154,14 @@ struct VARC
|
||||
hb_draw_session_t &draw_session,
|
||||
hb_varc_scratch_t &scratch) const
|
||||
{
|
||||
int64_t &budget = draw_session.get_budget ();
|
||||
hb_varc_context_t c {font,
|
||||
&draw_session,
|
||||
nullptr,
|
||||
hb_decycler_t {},
|
||||
HB_MAX_GRAPH_EDGE_COUNT,
|
||||
HB_MAX_NESTING_LEVEL,
|
||||
HB_VARC_MAX_WORK,
|
||||
budget,
|
||||
scratch};
|
||||
|
||||
return get_path_at (c, gid,
|
||||
@@ -173,13 +174,14 @@ struct VARC
|
||||
hb_extents_t<> *extents,
|
||||
hb_varc_scratch_t &scratch) const
|
||||
{
|
||||
int64_t budget = HB_BUDGET_GLYPH;
|
||||
hb_varc_context_t c {font,
|
||||
nullptr,
|
||||
extents,
|
||||
hb_decycler_t {},
|
||||
HB_MAX_GRAPH_EDGE_COUNT,
|
||||
HB_MAX_NESTING_LEVEL,
|
||||
HB_VARC_MAX_WORK,
|
||||
budget,
|
||||
scratch};
|
||||
|
||||
return get_path_at (c, gid,
|
||||
|
||||
+12
-4
@@ -314,7 +314,8 @@ struct Glyph
|
||||
hb_array_t<const int> coords = hb_array_t<const int> (),
|
||||
hb_scalar_cache_t *gvar_cache = nullptr,
|
||||
unsigned int depth = 0,
|
||||
unsigned *edge_count = nullptr) const
|
||||
unsigned *edge_count = nullptr,
|
||||
int64_t *budget = nullptr) const
|
||||
{
|
||||
if (unlikely (depth > HB_MAX_NESTING_LEVEL)) return false;
|
||||
unsigned stack_edge_count = 0;
|
||||
@@ -322,6 +323,10 @@ struct Glyph
|
||||
if (unlikely (*edge_count > HB_MAX_GRAPH_EDGE_COUNT)) return false;
|
||||
(*edge_count)++;
|
||||
|
||||
int64_t stack_budget = HB_BUDGET_GLYPH;
|
||||
if (!budget) budget = &stack_budget;
|
||||
if (unlikely (!hb_budget_spend (*budget, HB_BUDGET_16))) return false;
|
||||
|
||||
if (head_maxp_info)
|
||||
{
|
||||
head_maxp_info->maxComponentDepth = hb_max (head_maxp_info->maxComponentDepth, depth);
|
||||
@@ -390,7 +395,8 @@ struct Glyph
|
||||
points.as_array ().sub_array (old_length),
|
||||
scratch,
|
||||
gvar_cache,
|
||||
phantom_only && type == SIMPLE))
|
||||
phantom_only && type == SIMPLE,
|
||||
budget))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -400,7 +406,8 @@ struct Glyph
|
||||
points.as_array ().sub_array (old_length),
|
||||
scratch,
|
||||
gvar_cache,
|
||||
phantom_only && type == SIMPLE))
|
||||
phantom_only && type == SIMPLE,
|
||||
budget))
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
@@ -452,7 +459,8 @@ struct Glyph
|
||||
coords,
|
||||
gvar_cache,
|
||||
depth + 1,
|
||||
edge_count)))
|
||||
edge_count,
|
||||
budget)))
|
||||
{
|
||||
points.resize (old_length);
|
||||
return false;
|
||||
|
||||
+19
-8
@@ -238,15 +238,22 @@ struct glyf_accelerator_t
|
||||
bool get_points (hb_font_t *font, hb_codepoint_t gid, T consumer,
|
||||
hb_array_t<const int> coords,
|
||||
hb_glyf_scratch_t &scratch,
|
||||
hb_scalar_cache_t *gvar_cache = nullptr) const
|
||||
hb_scalar_cache_t *gvar_cache = nullptr,
|
||||
int64_t *budget = nullptr) const
|
||||
{
|
||||
if (gid >= num_glyphs) return false;
|
||||
|
||||
int64_t stack_budget = HB_BUDGET_GLYPH;
|
||||
if (!budget) budget = &stack_budget;
|
||||
|
||||
auto &all_points = scratch.all_points;
|
||||
all_points.clear ();
|
||||
|
||||
bool phantom_only = !consumer.is_consuming_contour_points ();
|
||||
if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, scratch, nullptr, nullptr, nullptr, true, true, phantom_only, coords, gvar_cache)))
|
||||
if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, scratch, nullptr, nullptr, nullptr, true, true, phantom_only, coords, gvar_cache, 0, nullptr, budget)))
|
||||
return false;
|
||||
|
||||
if (unlikely (!hb_budget_spend (*budget, HB_BUDGET_1, all_points.length)))
|
||||
return false;
|
||||
|
||||
unsigned count = all_points.length;
|
||||
@@ -470,8 +477,9 @@ struct glyf_accelerator_t
|
||||
gid,
|
||||
points_aggregator_t (font, extents, nullptr, true),
|
||||
coords,
|
||||
*scratch);
|
||||
if (budget) *budget -= scratch->all_points.length;
|
||||
*scratch,
|
||||
nullptr,
|
||||
budget);
|
||||
release_scratch (scratch);
|
||||
return ret;
|
||||
}
|
||||
@@ -508,7 +516,9 @@ struct glyf_accelerator_t
|
||||
}
|
||||
|
||||
bool
|
||||
get_path (hb_font_t *font, hb_codepoint_t gid, hb_draw_session_t &draw_session, hb_scalar_cache_t *gvar_cache = nullptr) const
|
||||
get_path (hb_font_t *font, hb_codepoint_t gid, hb_draw_session_t &draw_session,
|
||||
hb_scalar_cache_t *gvar_cache = nullptr,
|
||||
int64_t *budget = nullptr) const
|
||||
{
|
||||
if (!has_data ()) return false;
|
||||
|
||||
@@ -519,7 +529,8 @@ struct glyf_accelerator_t
|
||||
hb_array (font->coords,
|
||||
font->has_nonzero_coords ? font->num_coords : 0),
|
||||
*scratch,
|
||||
gvar_cache);
|
||||
gvar_cache,
|
||||
budget);
|
||||
|
||||
release_scratch (scratch);
|
||||
|
||||
@@ -537,8 +548,8 @@ struct glyf_accelerator_t
|
||||
bool ret = get_points (font, gid, glyf_impl::path_builder_t (font, draw_session),
|
||||
coords,
|
||||
scratch,
|
||||
gvar_cache);
|
||||
if (budget) *budget -= scratch.all_points.length;
|
||||
gvar_cache,
|
||||
budget);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -408,7 +408,7 @@ def map_to_use(data):
|
||||
if U in [0x11302, 0x11303, 0x114C1]: UIPC = Top
|
||||
|
||||
assert (UIPC in [Not_Applicable, Visual_Order_Left] or
|
||||
U in {0x0F7F, 0x11A3A} or
|
||||
U == 0x0F7F or
|
||||
USE in use_positions), "%s %s %s %s %s %s %s" % (hex(U), UIPC, USE, UISC, UDI, UGC, AJT)
|
||||
|
||||
pos_mapping = use_positions.get(USE, None)
|
||||
|
||||
+88
-60
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "graph.hh"
|
||||
#include "../hb-ot-layout-common.hh"
|
||||
#include "graph-result.hh"
|
||||
|
||||
#ifndef GRAPH_CLASSDEF_GRAPH_HH
|
||||
#define GRAPH_CLASSDEF_GRAPH_HH
|
||||
@@ -34,88 +35,99 @@ namespace graph {
|
||||
|
||||
struct ClassDefFormat1 : public OT::ClassDefFormat1_3<SmallTypes>
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
size_t vertex_len = vertex.table_size();
|
||||
constexpr unsigned min_size = OT::ClassDefFormat1_3<SmallTypes>::min_size;
|
||||
if (vertex_len < min_size) return false;
|
||||
if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
return vertex_len >= min_size + classValue.get_size () - classValue.len.get_size ();
|
||||
if (unlikely (vertex_len < min_size + classValue.get_size () - classValue.len.get_size ()))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
};
|
||||
|
||||
struct ClassDefFormat2 : public OT::ClassDefFormat2_4<SmallTypes>
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
size_t vertex_len = vertex.table_size();
|
||||
constexpr unsigned min_size = OT::ClassDefFormat2_4<SmallTypes>::min_size;
|
||||
if (vertex_len < min_size) return false;
|
||||
if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
return vertex_len >= min_size + rangeRecord.get_size () - rangeRecord.len.get_size ();
|
||||
if (unlikely (vertex_len < min_size + rangeRecord.get_size () - rangeRecord.len.get_size ()))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
};
|
||||
|
||||
struct ClassDef : public OT::ClassDef
|
||||
{
|
||||
template<typename It>
|
||||
static bool add_class_def (gsubgpos_graph_context_t& c,
|
||||
unsigned parent_id,
|
||||
unsigned link_position,
|
||||
It glyph_and_class,
|
||||
unsigned max_size)
|
||||
static graph_result_t<void> add_class_def (gsubgpos_graph_context_t& c,
|
||||
unsigned parent_id,
|
||||
unsigned link_position,
|
||||
It glyph_and_class,
|
||||
unsigned max_size)
|
||||
{
|
||||
unsigned class_def_prime_id = c.graph.new_node (nullptr, nullptr);
|
||||
TRY_ASSIGN (unsigned class_def_prime_id, c.graph.new_node (nullptr, nullptr));
|
||||
auto& class_def_prime_vertex = c.graph.vertices_[class_def_prime_id];
|
||||
if (!make_class_def (c, glyph_and_class, class_def_prime_id, max_size))
|
||||
return false;
|
||||
TRY (make_class_def (c, glyph_and_class, class_def_prime_id, max_size));
|
||||
|
||||
auto* class_def_link = c.graph.vertices_[parent_id].obj.real_links.push ();
|
||||
class_def_link->width = SmallTypes::size;
|
||||
class_def_link->objidx = class_def_prime_id;
|
||||
class_def_link->position = link_position;
|
||||
class_def_prime_vertex.add_parent (parent_id, false);
|
||||
TRY(c.graph.vertices_[parent_id].add_real_link (SmallTypes::size, class_def_prime_id, link_position));
|
||||
TRY(class_def_prime_vertex.add_parent (parent_id, false));
|
||||
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
template<typename It>
|
||||
static bool make_class_def (gsubgpos_graph_context_t& c,
|
||||
It glyph_and_class,
|
||||
unsigned dest_obj,
|
||||
unsigned max_size)
|
||||
static graph_result_t<void> make_class_def (gsubgpos_graph_context_t& c,
|
||||
It glyph_and_class,
|
||||
unsigned dest_obj,
|
||||
unsigned max_size)
|
||||
{
|
||||
char* buffer = (char*) hb_calloc (1, max_size);
|
||||
if (unlikely (!buffer))
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
|
||||
hb_serialize_context_t serializer (buffer, max_size);
|
||||
OT::ClassDef_serialize (&serializer, glyph_and_class);
|
||||
serializer.end_serialize ();
|
||||
if (serializer.in_error ())
|
||||
if (unlikely (serializer.in_error ()))
|
||||
{
|
||||
hb_free (buffer);
|
||||
return false;
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
}
|
||||
|
||||
hb_bytes_t class_def_copy = serializer.copy_bytes ();
|
||||
if (!class_def_copy.arrayZ) return false;
|
||||
// Give ownership to the context, it will cleanup the buffer.
|
||||
if (!c.add_buffer ((char *) class_def_copy.arrayZ))
|
||||
if (unlikely (!class_def_copy.arrayZ))
|
||||
{
|
||||
hb_free ((char *) class_def_copy.arrayZ);
|
||||
return false;
|
||||
hb_free (buffer);
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
}
|
||||
|
||||
auto& obj = c.graph.vertices_[dest_obj].obj;
|
||||
obj.head = (char *) class_def_copy.arrayZ;
|
||||
obj.tail = obj.head + class_def_copy.length;
|
||||
// Give ownership to the context, it will cleanup the buffer.
|
||||
auto res = c.add_buffer ((char *) class_def_copy.arrayZ);
|
||||
if (unlikely (!res.is_ok ()))
|
||||
{
|
||||
hb_free (buffer);
|
||||
hb_free ((char *) class_def_copy.arrayZ);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
auto& v = c.graph.vertices_[dest_obj];
|
||||
char* head = (char *) class_def_copy.arrayZ;
|
||||
v.set_buffer (head, head + class_def_copy.length);
|
||||
|
||||
hb_free (buffer);
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
if (vertex_len < OT::ClassDef::min_size) return false;
|
||||
size_t vertex_len = vertex.table_size();
|
||||
if (unlikely (vertex_len < OT::ClassDef::min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
switch (u.format.v)
|
||||
{
|
||||
@@ -126,7 +138,7 @@ struct ClassDef : public OT::ClassDef
|
||||
case 3:
|
||||
case 4:
|
||||
#endif
|
||||
default: return false;
|
||||
default: return Err(SANITIZE_FAILURE);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -142,33 +154,33 @@ struct class_def_size_estimator_t
|
||||
constexpr static unsigned bytes_per_glyph = 2;
|
||||
|
||||
template<typename It>
|
||||
class_def_size_estimator_t (It glyph_and_class)
|
||||
: num_ranges_per_class (), glyphs_per_class ()
|
||||
static graph_result_t<class_def_size_estimator_t> create (It glyph_and_class)
|
||||
{
|
||||
reset();
|
||||
class_def_size_estimator_t estimator;
|
||||
estimator.reset();
|
||||
for (auto p : + glyph_and_class)
|
||||
{
|
||||
unsigned gid = p.first;
|
||||
unsigned klass = p.second;
|
||||
|
||||
hb_set_t* glyphs;
|
||||
if (glyphs_per_class.has (klass, &glyphs) && glyphs) {
|
||||
if (estimator.glyphs_per_class.has (klass, &glyphs) && glyphs) {
|
||||
glyphs->add (gid);
|
||||
continue;
|
||||
}
|
||||
|
||||
hb_set_t new_glyphs;
|
||||
new_glyphs.add (gid);
|
||||
glyphs_per_class.set (klass, std::move (new_glyphs));
|
||||
estimator.glyphs_per_class.set (klass, std::move (new_glyphs));
|
||||
}
|
||||
|
||||
if (in_error ()) return;
|
||||
TRY(estimator.to_result ());
|
||||
|
||||
for (unsigned klass : glyphs_per_class.keys ())
|
||||
for (unsigned klass : estimator.glyphs_per_class.keys ())
|
||||
{
|
||||
if (!klass) continue; // class 0 doesn't get encoded.
|
||||
|
||||
const hb_set_t& glyphs = glyphs_per_class.get (klass);
|
||||
const hb_set_t& glyphs = estimator.glyphs_per_class.get (klass);
|
||||
hb_codepoint_t start = HB_SET_VALUE_INVALID;
|
||||
hb_codepoint_t end = HB_SET_VALUE_INVALID;
|
||||
|
||||
@@ -176,23 +188,25 @@ struct class_def_size_estimator_t
|
||||
while (glyphs.next_range (&start, &end))
|
||||
count++;
|
||||
|
||||
num_ranges_per_class.set (klass, count);
|
||||
estimator.num_ranges_per_class.set (klass, count);
|
||||
}
|
||||
|
||||
TRY(estimator.to_result ());
|
||||
return estimator;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
class_def_1_size = class_def_format1_base_size;
|
||||
class_def_2_size = class_def_format2_base_size;
|
||||
coverage_size_val = coverage_base_size;
|
||||
included_glyphs.clear();
|
||||
included_classes.clear();
|
||||
}
|
||||
|
||||
// Compute the size of coverage for all glyphs added via 'add_class_def_size'.
|
||||
// Size of coverage for all glyphs added via 'add_class_def_size'.
|
||||
unsigned coverage_size () const
|
||||
{
|
||||
unsigned format1_size = coverage_base_size + bytes_per_glyph * included_glyphs.get_population();
|
||||
unsigned format2_size = coverage_base_size + bytes_per_range * num_glyph_ranges();
|
||||
return hb_min(format1_size, format2_size);
|
||||
return coverage_size_val;
|
||||
}
|
||||
|
||||
// Compute the new size of the ClassDef table if all glyphs associated with 'klass' were added.
|
||||
@@ -201,7 +215,10 @@ struct class_def_size_estimator_t
|
||||
if (!included_classes.has(klass)) {
|
||||
hb_set_t* glyphs = nullptr;
|
||||
if (glyphs_per_class.has(klass, &glyphs)) {
|
||||
unsigned num_glyphs = included_glyphs.get_population();
|
||||
included_glyphs.union_(*glyphs);
|
||||
if (num_glyphs != included_glyphs.get_population())
|
||||
coverage_size_val = compute_coverage_size ();
|
||||
}
|
||||
|
||||
class_def_1_size = class_def_format1_base_size;
|
||||
@@ -230,25 +247,36 @@ struct class_def_size_estimator_t
|
||||
return count;
|
||||
}
|
||||
|
||||
bool in_error ()
|
||||
private:
|
||||
graph_result_t<void> to_result() const
|
||||
{
|
||||
if (num_ranges_per_class.in_error ()) return true;
|
||||
if (glyphs_per_class.in_error ()) return true;
|
||||
TRY (graph_result_t<void>::from (num_ranges_per_class, ALLOCATION_FAILURE));
|
||||
TRY (graph_result_t<void>::from (glyphs_per_class, ALLOCATION_FAILURE));
|
||||
|
||||
for (const hb_set_t& s : glyphs_per_class.values ())
|
||||
{
|
||||
if (s.in_error ()) return true;
|
||||
TRY (graph_result_t<void>::from (s, ALLOCATION_FAILURE));
|
||||
}
|
||||
return false;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
class_def_size_estimator_t ()
|
||||
: num_ranges_per_class (), glyphs_per_class () {}
|
||||
|
||||
unsigned compute_coverage_size () const
|
||||
{
|
||||
unsigned format1_size = coverage_base_size + bytes_per_glyph * included_glyphs.get_population();
|
||||
unsigned format2_size = coverage_base_size + bytes_per_range * num_glyph_ranges();
|
||||
return hb_min(format1_size, format2_size);
|
||||
}
|
||||
|
||||
private:
|
||||
hb_hashmap_t<unsigned, unsigned> num_ranges_per_class;
|
||||
hb_hashmap_t<unsigned, hb_set_t> glyphs_per_class;
|
||||
hb_set_t included_classes;
|
||||
hb_set_t included_glyphs;
|
||||
unsigned class_def_1_size;
|
||||
unsigned class_def_2_size;
|
||||
unsigned coverage_size_val;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+67
-56
@@ -32,42 +32,47 @@
|
||||
|
||||
namespace graph {
|
||||
|
||||
static bool sanitize (
|
||||
static graph_result_t<void> sanitize (
|
||||
const OT::Layout::Common::CoverageFormat1_3<OT::Layout::SmallTypes>* thiz,
|
||||
const graph_t::vertex_t& vertex
|
||||
) {
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
size_t vertex_len = vertex.table_size();
|
||||
constexpr unsigned min_size = OT::Layout::Common::CoverageFormat1_3<OT::Layout::SmallTypes>::min_size;
|
||||
if (vertex_len < min_size) return false;
|
||||
if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
return vertex_len >= min_size + thiz->glyphArray.get_size () - thiz->glyphArray.len.get_size ();
|
||||
if (unlikely (vertex_len < min_size + thiz->glyphArray.get_size () - thiz->glyphArray.len.get_size ()))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
static bool sanitize (
|
||||
static graph_result_t<void> sanitize (
|
||||
const OT::Layout::Common::CoverageFormat2_4<OT::Layout::SmallTypes>* thiz,
|
||||
const graph_t::vertex_t& vertex
|
||||
) {
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
size_t vertex_len = vertex.table_size();
|
||||
constexpr unsigned min_size = OT::Layout::Common::CoverageFormat2_4<OT::Layout::SmallTypes>::min_size;
|
||||
if (vertex_len < min_size) return false;
|
||||
if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
return vertex_len >= min_size + thiz->rangeRecord.get_size () - thiz->rangeRecord.len.get_size ();
|
||||
if (unlikely (vertex_len < min_size + thiz->rangeRecord.get_size () - thiz->rangeRecord.len.get_size ()))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
struct Coverage : public OT::Layout::Common::Coverage
|
||||
{
|
||||
static Coverage* clone_coverage (gsubgpos_graph_context_t& c,
|
||||
unsigned coverage_id,
|
||||
unsigned new_parent_id,
|
||||
unsigned link_position,
|
||||
unsigned start, unsigned end)
|
||||
static graph_result_t<void> clone_coverage (gsubgpos_graph_context_t& c,
|
||||
unsigned coverage_id,
|
||||
unsigned new_parent_id,
|
||||
unsigned link_position,
|
||||
unsigned start, unsigned end)
|
||||
|
||||
{
|
||||
unsigned coverage_size = c.graph.vertices_[coverage_id].table_size ();
|
||||
auto& coverage_v = c.graph.vertices_[coverage_id];
|
||||
Coverage* coverage_table = (Coverage*) coverage_v.obj.head;
|
||||
if (!coverage_table || !coverage_table->sanitize (coverage_v))
|
||||
return nullptr;
|
||||
const Coverage* coverage_table = (const Coverage*) coverage_v.obj().head;
|
||||
if (unlikely (!coverage_table))
|
||||
return Err(INVALID_ARGUMENT);
|
||||
TRY (coverage_table->sanitize (coverage_v));
|
||||
|
||||
auto new_coverage =
|
||||
+ hb_zip (coverage_table->iter (), hb_range ())
|
||||
@@ -81,35 +86,32 @@ struct Coverage : public OT::Layout::Common::Coverage
|
||||
}
|
||||
|
||||
template<typename It>
|
||||
static Coverage* add_coverage (gsubgpos_graph_context_t& c,
|
||||
unsigned parent_id,
|
||||
unsigned link_position,
|
||||
It glyphs,
|
||||
unsigned max_size)
|
||||
static graph_result_t<void> add_coverage (gsubgpos_graph_context_t& c,
|
||||
unsigned parent_id,
|
||||
unsigned link_position,
|
||||
It glyphs,
|
||||
unsigned max_size)
|
||||
{
|
||||
unsigned coverage_prime_id = c.graph.new_node (nullptr, nullptr);
|
||||
TRY_ASSIGN (unsigned coverage_prime_id, c.graph.new_node (nullptr, nullptr));
|
||||
auto& coverage_prime_vertex = c.graph.vertices_[coverage_prime_id];
|
||||
if (!make_coverage (c, glyphs, coverage_prime_id, max_size))
|
||||
return nullptr;
|
||||
TRY (make_coverage (c, glyphs, coverage_prime_id, max_size));
|
||||
|
||||
auto* coverage_link = c.graph.vertices_[parent_id].obj.real_links.push ();
|
||||
coverage_link->width = SmallTypes::size;
|
||||
coverage_link->objidx = coverage_prime_id;
|
||||
coverage_link->position = link_position;
|
||||
coverage_prime_vertex.add_parent (parent_id, false);
|
||||
TRY(c.graph.vertices_[parent_id].add_real_link (SmallTypes::size, coverage_prime_id, link_position));
|
||||
TRY(coverage_prime_vertex.add_parent (parent_id, false));
|
||||
|
||||
return (Coverage*) coverage_prime_vertex.obj.head;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
// Filter an existing coverage table to glyphs at indices [start, end) and replace it with the filtered version.
|
||||
static bool filter_coverage (gsubgpos_graph_context_t& c,
|
||||
unsigned existing_coverage,
|
||||
unsigned start, unsigned end) {
|
||||
static graph_result_t<void> filter_coverage (gsubgpos_graph_context_t& c,
|
||||
unsigned existing_coverage,
|
||||
unsigned start, unsigned end) {
|
||||
unsigned coverage_size = c.graph.vertices_[existing_coverage].table_size ();
|
||||
auto& coverage_v = c.graph.vertices_[existing_coverage];
|
||||
Coverage* coverage_table = (Coverage*) coverage_v.obj.head;
|
||||
if (!coverage_table || !coverage_table->sanitize (coverage_v))
|
||||
return false;
|
||||
const Coverage* coverage_table = (const Coverage*) coverage_v.obj().head;
|
||||
if (unlikely (!coverage_table))
|
||||
return Err(INVALID_ARGUMENT);
|
||||
TRY (coverage_table->sanitize (coverage_v));
|
||||
|
||||
auto new_coverage =
|
||||
+ hb_zip (coverage_table->iter (), hb_range ())
|
||||
@@ -124,42 +126,51 @@ struct Coverage : public OT::Layout::Common::Coverage
|
||||
|
||||
// Replace the coverage table at dest obj with one covering 'glyphs'.
|
||||
template<typename It>
|
||||
static bool make_coverage (gsubgpos_graph_context_t& c,
|
||||
It glyphs,
|
||||
unsigned dest_obj,
|
||||
unsigned max_size)
|
||||
static graph_result_t<void> make_coverage (gsubgpos_graph_context_t& c,
|
||||
It glyphs,
|
||||
unsigned dest_obj,
|
||||
unsigned max_size)
|
||||
{
|
||||
char* buffer = (char*) hb_calloc (1, max_size);
|
||||
if (unlikely (!buffer))
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
|
||||
hb_serialize_context_t serializer (buffer, max_size);
|
||||
OT::Layout::Common::Coverage_serialize (&serializer, glyphs);
|
||||
serializer.end_serialize ();
|
||||
if (serializer.in_error ())
|
||||
if (unlikely (serializer.in_error ()))
|
||||
{
|
||||
hb_free (buffer);
|
||||
return false;
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
}
|
||||
|
||||
hb_bytes_t coverage_copy = serializer.copy_bytes ();
|
||||
if (!coverage_copy.arrayZ) return false;
|
||||
// Give ownership to the context, it will cleanup the buffer.
|
||||
if (!c.add_buffer ((char *) coverage_copy.arrayZ))
|
||||
{
|
||||
hb_free ((char *) coverage_copy.arrayZ);
|
||||
return false;
|
||||
if (unlikely (!coverage_copy.arrayZ)) {
|
||||
hb_free (buffer);
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
}
|
||||
|
||||
auto& obj = c.graph.vertices_[dest_obj].obj;
|
||||
obj.head = (char *) coverage_copy.arrayZ;
|
||||
obj.tail = obj.head + coverage_copy.length;
|
||||
// Give ownership to the context, it will cleanup the buffer.
|
||||
auto res = c.add_buffer ((char *) coverage_copy.arrayZ);
|
||||
if (unlikely (!res.is_ok ()))
|
||||
{
|
||||
hb_free (buffer);
|
||||
hb_free ((char *) coverage_copy.arrayZ);
|
||||
return res;
|
||||
}
|
||||
|
||||
auto& v = c.graph.vertices_[dest_obj];
|
||||
char* head = (char *) coverage_copy.arrayZ;
|
||||
v.set_buffer (head, head + coverage_copy.length);
|
||||
|
||||
hb_free (buffer);
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
if (vertex_len < OT::Layout::Common::Coverage::min_size) return false;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
if (unlikely (vertex_len < OT::Layout::Common::Coverage::min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
switch (u.format.v)
|
||||
{
|
||||
@@ -170,7 +181,7 @@ struct Coverage : public OT::Layout::Common::Coverage
|
||||
case 3:
|
||||
case 4:
|
||||
#endif
|
||||
default: return false;
|
||||
default: return Err(SANITIZE_FAILURE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright © 2026 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): Garret Rieger
|
||||
*/
|
||||
|
||||
#ifndef GRAPH_GRAPH_RESULT_HH
|
||||
#define GRAPH_GRAPH_RESULT_HH
|
||||
|
||||
#include "../hb-result.hh"
|
||||
|
||||
namespace graph {
|
||||
|
||||
enum graph_error_t {
|
||||
ALLOCATION_FAILURE,
|
||||
LIMIT_EXCEEDED,
|
||||
INVALID_ARGUMENT,
|
||||
CYCLE_DETECTED,
|
||||
SANITIZE_FAILURE,
|
||||
OUT_OF_BOUNDS,
|
||||
ORPHANED_NODES,
|
||||
OVERFLOW_RESOLUTION_FAILED,
|
||||
UNKNOWN,
|
||||
};
|
||||
|
||||
static inline const char* to_string(graph_error_t e) {
|
||||
switch (e) {
|
||||
case ALLOCATION_FAILURE: return "Memory Allocation Failed";
|
||||
case LIMIT_EXCEEDED: return "Limit Exceeded";
|
||||
case INVALID_ARGUMENT: return "Invalid Argument";
|
||||
case CYCLE_DETECTED: return "Cycle in Graph";
|
||||
case SANITIZE_FAILURE: return "Failed Sanitization";
|
||||
case OUT_OF_BOUNDS: return "Out of Bounds";
|
||||
case ORPHANED_NODES: return "Graph is not fully connected";
|
||||
case OVERFLOW_RESOLUTION_FAILED: return "Overflows are not able to be resolved";
|
||||
case UNKNOWN:
|
||||
default:
|
||||
return "Unknown Error";
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
using graph_result_t = hb_result_t<T, graph_error_t>;
|
||||
|
||||
} // namespace graph
|
||||
|
||||
#endif /* GRAPH_GRAPH_RESULT_HH */
|
||||
+564
-395
File diff suppressed because it is too large.
Load diff
@@ -28,34 +28,41 @@
|
||||
|
||||
namespace graph {
|
||||
|
||||
graph_result_t<gsubgpos_graph_context_t> gsubgpos_graph_context_t::create (hb_tag_t table_tag_,
|
||||
graph_t& graph_)
|
||||
{
|
||||
gsubgpos_graph_context_t context (table_tag_, graph_);
|
||||
|
||||
if (unlikely (table_tag_ != HB_OT_TAG_GPOS
|
||||
&& table_tag_ != HB_OT_TAG_GSUB))
|
||||
return Err(INVALID_ARGUMENT);
|
||||
|
||||
TRY_ASSIGN (const GSTAR* gstar, graph::GSTAR::graph_to_gstar (context.graph));
|
||||
TRY(gstar->find_lookups (context.graph, context.lookups));
|
||||
TRY_ASSIGN (context.lookup_list_index, gstar->get_lookup_list_index (context.graph));
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
gsubgpos_graph_context_t::gsubgpos_graph_context_t (hb_tag_t table_tag_,
|
||||
graph_t& graph_)
|
||||
: table_tag (table_tag_),
|
||||
graph (graph_),
|
||||
lookup_list_index (0),
|
||||
lookups ()
|
||||
{
|
||||
if (table_tag_ != HB_OT_TAG_GPOS
|
||||
&& table_tag_ != HB_OT_TAG_GSUB)
|
||||
return;
|
||||
{}
|
||||
|
||||
GSTAR* gstar = graph::GSTAR::graph_to_gstar (graph_);
|
||||
if (gstar) {
|
||||
gstar->find_lookups (graph, lookups);
|
||||
lookup_list_index = gstar->get_lookup_list_index (graph_);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned gsubgpos_graph_context_t::create_node (unsigned size)
|
||||
graph_result_t<unsigned> gsubgpos_graph_context_t::create_node (unsigned size)
|
||||
{
|
||||
char* buffer = (char*) hb_calloc (1, size);
|
||||
if (!buffer)
|
||||
return -1;
|
||||
if (unlikely (!buffer))
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
|
||||
if (!add_buffer (buffer)) {
|
||||
auto res = add_buffer (buffer);
|
||||
if (unlikely (!res.is_ok ())) {
|
||||
// Allocation did not get stored for freeing later.
|
||||
hb_free (buffer);
|
||||
return -1;
|
||||
return Err(res.error ());
|
||||
}
|
||||
|
||||
return graph.new_node (buffer, buffer + size);
|
||||
|
||||
@@ -36,6 +36,9 @@ struct Lookup;
|
||||
|
||||
struct gsubgpos_graph_context_t
|
||||
{
|
||||
HB_INTERNAL static graph_result_t<gsubgpos_graph_context_t> create (hb_tag_t table_tag_,
|
||||
graph_t& graph_);
|
||||
|
||||
hb_tag_t table_tag;
|
||||
graph_t& graph;
|
||||
unsigned lookup_list_index;
|
||||
@@ -43,17 +46,18 @@ struct gsubgpos_graph_context_t
|
||||
hb_hashmap_t<unsigned, unsigned> subtable_to_extension;
|
||||
hb_hashmap_t<unsigned, hb_vector_t<unsigned>> split_subtables;
|
||||
|
||||
HB_INTERNAL gsubgpos_graph_context_t (hb_tag_t table_tag_,
|
||||
graph_t& graph_);
|
||||
|
||||
HB_INTERNAL unsigned create_node (unsigned size);
|
||||
HB_INTERNAL graph_result_t<unsigned> create_node (unsigned size);
|
||||
|
||||
bool add_buffer (char* buffer)
|
||||
graph_result_t<void> add_buffer (char* buffer)
|
||||
{
|
||||
return graph.add_buffer (buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
HB_INTERNAL gsubgpos_graph_context_t (hb_tag_t table_tag_,
|
||||
graph_t& graph_);
|
||||
|
||||
HB_INTERNAL unsigned num_non_ext_subtables ();
|
||||
};
|
||||
|
||||
|
||||
+127
-108
@@ -50,10 +50,12 @@ struct ExtensionFormat1 : public OT::ExtensionFormat1<T>
|
||||
this->extensionOffset = 0;
|
||||
}
|
||||
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
return vertex_len >= OT::ExtensionFormat1<T>::static_size;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
if (unlikely (vertex_len < OT::ExtensionFormat1<T>::static_size))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
unsigned get_lookup_type () const
|
||||
@@ -61,7 +63,7 @@ struct ExtensionFormat1 : public OT::ExtensionFormat1<T>
|
||||
return this->extensionLookupType;
|
||||
}
|
||||
|
||||
unsigned get_subtable_index (graph_t& graph, unsigned this_index) const
|
||||
graph_result_t<unsigned> get_subtable_index (graph_t& graph, unsigned this_index) const
|
||||
{
|
||||
return graph.index_for_offset (this_index, &this->extensionOffset);
|
||||
}
|
||||
@@ -74,12 +76,13 @@ struct Lookup : public OT::Lookup
|
||||
return subTable.len;
|
||||
}
|
||||
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
if (vertex_len < OT::Lookup::min_size) return false;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
if (unlikely (vertex_len < OT::Lookup::min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
return vertex_len >= this->get_size ();
|
||||
if (unlikely (vertex_len < this->get_size ())) return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
bool is_extension (hb_tag_t table_tag) const
|
||||
@@ -93,15 +96,15 @@ struct Lookup : public OT::Lookup
|
||||
return flag & 0x0010u;
|
||||
}
|
||||
|
||||
bool make_extension (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<void> make_extension (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
unsigned type = lookupType;
|
||||
unsigned ext_type = extension_type (c.table_tag);
|
||||
if (!ext_type || is_extension (c.table_tag))
|
||||
{
|
||||
// NOOP
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
@@ -111,42 +114,45 @@ struct Lookup : public OT::Lookup
|
||||
|
||||
for (unsigned i = 0; i < subTable.len; i++)
|
||||
{
|
||||
unsigned subtable_index = c.graph.index_for_offset (this_index, &subTable[i]);
|
||||
if (!make_subtable_extension (c,
|
||||
TRY_ASSIGN (unsigned subtable_index, c.graph.index_for_offset (this_index, &subTable[i]));
|
||||
TRY (make_subtable_extension (c,
|
||||
this_index,
|
||||
subtable_index))
|
||||
return false;
|
||||
subtable_index));
|
||||
}
|
||||
|
||||
lookupType = ext_type;
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
bool split_subtables_if_needed (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<void> split_subtables_if_needed (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
unsigned type = lookupType;
|
||||
bool is_ext = is_extension (c.table_tag);
|
||||
|
||||
if (c.table_tag != HB_OT_TAG_GPOS && c.table_tag != HB_OT_TAG_GSUB)
|
||||
return true;
|
||||
return Ok();
|
||||
|
||||
if (!is_ext && !is_supported_gpos_type(type, c) && !is_supported_gsub_type(type, c))
|
||||
return true;
|
||||
return Ok();
|
||||
|
||||
hb_vector_t<hb_pair_t<unsigned, hb_vector_t<unsigned>>> all_new_subtables;
|
||||
for (unsigned i = 0; i < subTable.len; i++)
|
||||
{
|
||||
unsigned subtable_index = c.graph.index_for_offset (this_index, &subTable[i]);
|
||||
// This assumes we are working with something like a GSUB/GPOS table, if
|
||||
// sanitization fails we ignore and skip splitting for the particular sub table.
|
||||
auto idx_res = c.graph.index_for_offset (this_index, &subTable[i]);
|
||||
if (!idx_res.is_ok ()) continue;
|
||||
unsigned subtable_index = *idx_res;
|
||||
if (is_ext) {
|
||||
unsigned ext_subtable_index = subtable_index;
|
||||
ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>* extension =
|
||||
(ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>*)
|
||||
c.graph.object (ext_subtable_index).head;
|
||||
if (!extension || !extension->sanitize (c.graph.vertices_[ext_subtable_index]))
|
||||
if (!extension || !extension->sanitize (c.graph.vertices_[ext_subtable_index]).is_ok ())
|
||||
continue;
|
||||
|
||||
subtable_index = extension->get_subtable_index (c.graph, ext_subtable_index);
|
||||
TRY_ASSIGN (subtable_index, extension->get_subtable_index (c.graph, ext_subtable_index));
|
||||
type = extension->get_lookup_type ();
|
||||
if (!is_supported_gpos_type(type, c) && !is_supported_gsub_type(type, c))
|
||||
continue;
|
||||
@@ -158,6 +164,7 @@ struct Lookup : public OT::Lookup
|
||||
if (split_result->length == 0)
|
||||
continue;
|
||||
all_new_subtables.push (hb_pair(i, *split_result));
|
||||
TRY (graph_result_t<void>::from (all_new_subtables, ALLOCATION_FAILURE));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -167,9 +174,15 @@ struct Lookup : public OT::Lookup
|
||||
switch (type)
|
||||
{
|
||||
case 2:
|
||||
new_sub_tables = split_subtable<PairPos> (c, subtable_index); break;
|
||||
{
|
||||
TRY_ASSIGN (new_sub_tables, split_subtable<PairPos> (c, subtable_index));
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
new_sub_tables = split_subtable<MarkBasePos> (c, subtable_index); break;
|
||||
{
|
||||
TRY_ASSIGN (new_sub_tables, split_subtable<MarkBasePos> (c, subtable_index));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -177,42 +190,46 @@ struct Lookup : public OT::Lookup
|
||||
switch (type)
|
||||
{
|
||||
case 4:
|
||||
new_sub_tables = split_subtable<graph::LigatureSubst> (c, subtable_index); break;
|
||||
{
|
||||
TRY_ASSIGN (new_sub_tables, split_subtable<graph::LigatureSubst> (c, subtable_index));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (new_sub_tables.in_error ()) return false;
|
||||
|
||||
c.split_subtables.set (subtable_index, new_sub_tables);
|
||||
if (new_sub_tables)
|
||||
TRY (graph_result_t<void>::from (c.split_subtables, ALLOCATION_FAILURE));
|
||||
if (new_sub_tables) {
|
||||
all_new_subtables.push (hb_pair (i, std::move (new_sub_tables)));
|
||||
TRY (graph_result_t<void>::from (all_new_subtables, ALLOCATION_FAILURE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (all_new_subtables) {
|
||||
return add_sub_tables (c, this_index, type, all_new_subtables);
|
||||
TRY (add_sub_tables (c, this_index, type, all_new_subtables));
|
||||
}
|
||||
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
hb_vector_t<unsigned> split_subtable (gsubgpos_graph_context_t& c,
|
||||
unsigned objidx)
|
||||
graph_result_t<hb_vector_t<unsigned>> split_subtable (gsubgpos_graph_context_t& c,
|
||||
unsigned objidx)
|
||||
{
|
||||
T* sub_table = (T*) c.graph.object (objidx).head;
|
||||
if (!sub_table || !sub_table->sanitize (c.graph.vertices_[objidx]))
|
||||
return hb_vector_t<unsigned> ();
|
||||
if (!sub_table || !sub_table->sanitize (c.graph.vertices_[objidx]).is_ok ())
|
||||
return Ok(hb_vector_t<unsigned> ());
|
||||
|
||||
return sub_table->split_subtables (c, objidx);
|
||||
}
|
||||
|
||||
bool add_sub_tables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned type,
|
||||
const hb_vector_t<hb_pair_t<unsigned, hb_vector_t<unsigned>>>& subtable_ids)
|
||||
graph_result_t<void> add_sub_tables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned type,
|
||||
const hb_vector_t<hb_pair_t<unsigned, hb_vector_t<unsigned>>>& subtable_ids)
|
||||
{
|
||||
bool is_ext = is_extension (c.table_tag);
|
||||
auto* v = &c.graph.vertices_[this_index];
|
||||
@@ -225,19 +242,19 @@ struct Lookup : public OT::Lookup
|
||||
size_t new_size = v->table_size ()
|
||||
+ new_subtable_count * OT::Offset16::static_size;
|
||||
char* buffer = (char*) hb_calloc (1, new_size);
|
||||
if (!buffer) return false;
|
||||
if (!c.add_buffer (buffer))
|
||||
if (unlikely (!buffer)) return Err(ALLOCATION_FAILURE);
|
||||
auto res = c.add_buffer (buffer);
|
||||
if (unlikely (!res.is_ok ()))
|
||||
{
|
||||
hb_free (buffer);
|
||||
return false;
|
||||
return res;
|
||||
}
|
||||
hb_memcpy (buffer, v->obj.head, v->table_size());
|
||||
hb_memcpy (buffer, v->obj ().head, v->table_size());
|
||||
|
||||
if (use_mark_filtering_set ())
|
||||
hb_memcpy (buffer + new_size - 2, v->obj.tail - 2, 2);
|
||||
hb_memcpy (buffer + new_size - 2, v->obj ().tail - 2, 2);
|
||||
|
||||
v->obj.head = buffer;
|
||||
v->obj.tail = buffer + new_size;
|
||||
v->set_buffer (buffer, buffer + new_size);
|
||||
|
||||
Lookup* new_lookup = (Lookup*) buffer;
|
||||
|
||||
@@ -252,29 +269,27 @@ struct Lookup : public OT::Lookup
|
||||
{
|
||||
if (is_ext)
|
||||
{
|
||||
unsigned ext_id = create_extension_subtable (c, subtable_id, type);
|
||||
c.graph.vertices_[subtable_id].add_parent (ext_id, false);
|
||||
TRY_ASSIGN (unsigned ext_id, create_extension_subtable (c, subtable_id, type));
|
||||
TRY(c.graph.vertices_[subtable_id].add_parent (ext_id, false));
|
||||
subtable_id = ext_id;
|
||||
// the reference to v may have changed on adding a node, so reassign it.
|
||||
v = &c.graph.vertices_[this_index];
|
||||
}
|
||||
|
||||
auto* link = v->obj.real_links.push ();
|
||||
link->width = 2;
|
||||
link->objidx = subtable_id;
|
||||
link->position = (char*) &new_lookup->subTable[offset_index++] -
|
||||
(char*) new_lookup;
|
||||
c.graph.vertices_[subtable_id].add_parent (this_index, false);
|
||||
TRY(v->add_real_link(2, subtable_id,
|
||||
(char*) &new_lookup->subTable[offset_index++] - (char*) new_lookup));
|
||||
TRY(c.graph.vertices_[subtable_id].add_parent (this_index, false));
|
||||
}
|
||||
}
|
||||
|
||||
// Repacker sort order depends on link order, which we've messed up so resort it.
|
||||
v->obj.real_links.qsort ();
|
||||
v->sort_real_links ();
|
||||
|
||||
// The head location of the lookup has changed, invalidating the lookups map entry
|
||||
// in the context. Update the map.
|
||||
c.lookups.set (this_index, new_lookup);
|
||||
return true;
|
||||
TRY (graph_result_t<void>::from (c.lookups, ALLOCATION_FAILURE));
|
||||
return Ok();
|
||||
}
|
||||
|
||||
void fix_existing_subtable_links (gsubgpos_graph_context_t& c,
|
||||
@@ -290,58 +305,50 @@ struct Lookup : public OT::Lookup
|
||||
unsigned insert_offset = Lookup::min_size + insert_index * OT::Offset16::static_size;
|
||||
shift += p.second.length;
|
||||
|
||||
for (auto& l : v.obj.all_links_writer ())
|
||||
for (auto& l : v.all_links_writer ())
|
||||
{
|
||||
if (l.position > insert_offset) l.position += pos_offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned create_extension_subtable (gsubgpos_graph_context_t& c,
|
||||
unsigned subtable_index,
|
||||
unsigned type)
|
||||
graph_result_t<unsigned> create_extension_subtable (gsubgpos_graph_context_t& c,
|
||||
unsigned subtable_index,
|
||||
unsigned type)
|
||||
{
|
||||
unsigned extension_size = OT::ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>::static_size;
|
||||
|
||||
unsigned ext_index = c.create_node (extension_size);
|
||||
if (ext_index == (unsigned) -1)
|
||||
return -1;
|
||||
TRY_ASSIGN (unsigned ext_index, c.create_node (extension_size));
|
||||
|
||||
auto& ext_vertex = c.graph.vertices_[ext_index];
|
||||
ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>* extension =
|
||||
(ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>*) ext_vertex.obj.head;
|
||||
ext_vertex.as<ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>*> ();
|
||||
extension->reset (type);
|
||||
|
||||
// Make extension point at the subtable.
|
||||
auto* l = ext_vertex.obj.real_links.push ();
|
||||
TRY(ext_vertex.add_real_link (4, subtable_index, 4));
|
||||
|
||||
l->width = 4;
|
||||
l->objidx = subtable_index;
|
||||
l->position = 4;
|
||||
|
||||
return ext_index;
|
||||
return Ok(ext_index);
|
||||
}
|
||||
|
||||
bool make_subtable_extension (gsubgpos_graph_context_t& c,
|
||||
unsigned lookup_index,
|
||||
unsigned subtable_index)
|
||||
graph_result_t<void> make_subtable_extension (gsubgpos_graph_context_t& c,
|
||||
unsigned lookup_index,
|
||||
unsigned subtable_index)
|
||||
{
|
||||
unsigned type = lookupType;
|
||||
unsigned ext_index = -1;
|
||||
unsigned ext_index = HB_GRAPH_INVALID;
|
||||
unsigned* existing_ext_index = nullptr;
|
||||
if (c.subtable_to_extension.has(subtable_index, &existing_ext_index)) {
|
||||
ext_index = *existing_ext_index;
|
||||
} else {
|
||||
ext_index = create_extension_subtable(c, subtable_index, type);
|
||||
TRY_ASSIGN (ext_index, create_extension_subtable(c, subtable_index, type));
|
||||
c.subtable_to_extension.set(subtable_index, ext_index);
|
||||
TRY (graph_result_t<void>::from (c.subtable_to_extension, ALLOCATION_FAILURE));
|
||||
}
|
||||
|
||||
if (ext_index == (unsigned) -1)
|
||||
return false;
|
||||
|
||||
auto& subtable_vertex = c.graph.vertices_[subtable_index];
|
||||
auto& lookup_vertex = c.graph.vertices_[lookup_index];
|
||||
for (auto& l : lookup_vertex.obj.real_links.writer ())
|
||||
for (auto& l : lookup_vertex.real_links_writer ())
|
||||
{
|
||||
if (l.objidx == subtable_index) {
|
||||
// Change lookup to point at the extension.
|
||||
@@ -353,11 +360,11 @@ struct Lookup : public OT::Lookup
|
||||
|
||||
// Make extension point at the subtable.
|
||||
auto& ext_vertex = c.graph.vertices_[ext_index];
|
||||
ext_vertex.add_parent (lookup_index, false);
|
||||
TRY(ext_vertex.add_parent (lookup_index, false));
|
||||
if (!existing_ext_index)
|
||||
subtable_vertex.remap_parent (lookup_index, ext_index);
|
||||
TRY(subtable_vertex.remap_parent (lookup_index, ext_index));
|
||||
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -388,24 +395,25 @@ struct Lookup : public OT::Lookup
|
||||
template <typename T>
|
||||
struct LookupList : public OT::LookupList<T>
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
if (vertex_len < OT::LookupList<T>::min_size) return false;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
if (unlikely (vertex_len < OT::LookupList<T>::min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
return vertex_len >= OT::LookupList<T>::item_size * this->len;
|
||||
if (unlikely (vertex_len < OT::LookupList<T>::item_size * this->len)) return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
};
|
||||
|
||||
struct GSTAR : public OT::GSUBGPOS
|
||||
{
|
||||
static GSTAR* graph_to_gstar (graph_t& graph)
|
||||
static graph_result_t<const GSTAR*> graph_to_gstar (graph_t& graph)
|
||||
{
|
||||
const auto& r = graph.root ();
|
||||
|
||||
GSTAR* gstar = (GSTAR*) r.obj.head;
|
||||
if (!gstar || !gstar->sanitize (r))
|
||||
return nullptr;
|
||||
const GSTAR* gstar = (GSTAR*) r.obj ().head;
|
||||
if (unlikely (!gstar)) return Err(INVALID_ARGUMENT);
|
||||
TRY (gstar->sanitize (r));
|
||||
hb_barrier ();
|
||||
|
||||
return gstar;
|
||||
@@ -422,48 +430,59 @@ struct GSTAR : public OT::GSUBGPOS
|
||||
}
|
||||
}
|
||||
|
||||
bool sanitize (const graph_t::vertex_t& vertex)
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t len = vertex.obj.tail - vertex.obj.head;
|
||||
if (len < OT::GSUBGPOS::min_size) return false;
|
||||
size_t len = vertex.table_size ();
|
||||
if (unlikely (len < OT::GSUBGPOS::min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
return len >= get_size ();
|
||||
switch (u.version.major) {
|
||||
case 1: break;
|
||||
#ifndef HB_NO_BEYOND_64K
|
||||
case 2: break;
|
||||
#endif
|
||||
default: return Err(SANITIZE_FAILURE);
|
||||
}
|
||||
if (unlikely (len < get_size ())) return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
void find_lookups (graph_t& graph,
|
||||
hb_hashmap_t<unsigned, Lookup*>& lookups /* OUT */)
|
||||
graph_result_t<void> find_lookups (graph_t& graph,
|
||||
hb_hashmap_t<unsigned, Lookup*>& lookups /* OUT */) const
|
||||
{
|
||||
switch (u.version.major) {
|
||||
case 1: find_lookups<SmallTypes> (graph, lookups); break;
|
||||
case 1: TRY(find_lookups<SmallTypes> (graph, lookups)); break;
|
||||
#ifndef HB_NO_BEYOND_64K
|
||||
case 2: find_lookups<MediumTypes> (graph, lookups); break;
|
||||
case 2: TRY(find_lookups<MediumTypes> (graph, lookups)); break;
|
||||
#endif
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
unsigned get_lookup_list_index (graph_t& graph)
|
||||
graph_result_t<unsigned> get_lookup_list_index (graph_t& graph) const
|
||||
{
|
||||
return graph.index_for_offset (graph.root_idx (),
|
||||
get_lookup_list_field_offset());
|
||||
const void* offset = get_lookup_list_field_offset ();
|
||||
if (unlikely (!offset)) return Err(INVALID_ARGUMENT);
|
||||
return graph.index_for_offset (graph.root_idx (), offset);
|
||||
}
|
||||
|
||||
template<typename Types>
|
||||
void find_lookups (graph_t& graph,
|
||||
hb_hashmap_t<unsigned, Lookup*>& lookups /* OUT */)
|
||||
graph_result_t<void> find_lookups (graph_t& graph,
|
||||
hb_hashmap_t<unsigned, Lookup*>& lookups /* OUT */) const
|
||||
{
|
||||
unsigned lookup_list_idx = get_lookup_list_index (graph);
|
||||
TRY_ASSIGN (unsigned lookup_list_idx, get_lookup_list_index (graph));
|
||||
const LookupList<Types>* lookupList =
|
||||
(const LookupList<Types>*) graph.object (lookup_list_idx).head;
|
||||
if (!lookupList || !lookupList->sanitize (graph.vertices_[lookup_list_idx]))
|
||||
return;
|
||||
if (unlikely (!lookupList)) return Err(INVALID_ARGUMENT);
|
||||
TRY(lookupList->sanitize (graph.vertices_[lookup_list_idx]));
|
||||
|
||||
for (unsigned i = 0; i < lookupList->len; i++)
|
||||
{
|
||||
unsigned lookup_idx = graph.index_for_offset (lookup_list_idx, &(lookupList->arrayZ[i]));
|
||||
TRY_ASSIGN (unsigned lookup_idx, graph.index_for_offset (lookup_list_idx, &(lookupList->arrayZ[i])));
|
||||
Lookup* lookup = (Lookup*) graph.object (lookup_idx).head;
|
||||
if (!lookup || !lookup->sanitize (graph.vertices_[lookup_idx])) continue;
|
||||
if (!lookup || !lookup->sanitize (graph.vertices_[lookup_idx]).is_ok ()) continue;
|
||||
lookups.set (lookup_idx, lookup);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+103
-122
@@ -40,85 +40,84 @@ namespace graph {
|
||||
|
||||
struct LigatureSet : public OT::Layout::GSUB_impl::LigatureSet<SmallTypes>
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
if (vertex_len < OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size) return false;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
if (unlikely (vertex_len < OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
|
||||
size_t total_len = ligature.get_size() + OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size - ligature.len.get_size();
|
||||
if (vertex_len < total_len) {
|
||||
return false;
|
||||
if (unlikely (vertex_len < total_len)) {
|
||||
return Err(SANITIZE_FAILURE);
|
||||
}
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
};
|
||||
|
||||
struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
unsigned min_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>::min_size;
|
||||
if (vertex_len < min_size) return false;
|
||||
if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
|
||||
return vertex_len >=
|
||||
min_size + ligatureSet.get_size() - ligatureSet.len.get_size();
|
||||
if (unlikely (vertex_len < min_size + ligatureSet.get_size() - ligatureSet.len.get_size()))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
hb_vector_t<unsigned> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<hb_vector_t<unsigned>> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
auto split_points = compute_split_points(c, this_index);
|
||||
TRY_ASSIGN (auto split_points, compute_split_points(c, this_index));
|
||||
if (!split_points)
|
||||
return hb_vector_t<unsigned> ();
|
||||
return Ok(hb_vector_t<unsigned> ());
|
||||
|
||||
TRY_ASSIGN (unsigned total_ligas, total_number_ligas(c, this_index));
|
||||
TRY_ASSIGN (hb_vector_t<unsigned> counts, liga_counts(c, this_index));
|
||||
split_context_t split_context {
|
||||
c,
|
||||
this,
|
||||
this_index,
|
||||
total_number_ligas(c, this_index),
|
||||
liga_counts(c, this_index),
|
||||
total_ligas,
|
||||
std::move (counts),
|
||||
};
|
||||
return actuate_subtable_split<split_context_t> (split_context, split_points);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned total_number_ligas(gsubgpos_graph_context_t& c, unsigned this_index) const {
|
||||
graph_result_t<unsigned> total_number_ligas(gsubgpos_graph_context_t& c, unsigned this_index) const {
|
||||
unsigned total = 0;
|
||||
for (unsigned i = 0; i < ligatureSet.len; i++)
|
||||
{
|
||||
auto liga_set = c.graph.as_table<LigatureSet>(this_index, &ligatureSet[i]);
|
||||
if (!liga_set.table) {
|
||||
return 0;
|
||||
}
|
||||
TRY_ASSIGN (auto liga_set, c.graph.as_table<LigatureSet>(this_index, &ligatureSet[i]));
|
||||
total += liga_set.table->ligature.len;
|
||||
}
|
||||
return total;
|
||||
return Ok(total);
|
||||
}
|
||||
|
||||
hb_vector_t<unsigned> liga_counts(gsubgpos_graph_context_t& c, unsigned this_index) const {
|
||||
graph_result_t<hb_vector_t<unsigned>> liga_counts(gsubgpos_graph_context_t& c, unsigned this_index) const {
|
||||
hb_vector_t<unsigned> result;
|
||||
for (unsigned i = 0; i < ligatureSet.len; i++)
|
||||
{
|
||||
auto liga_set = c.graph.as_table<LigatureSet>(this_index, &ligatureSet[i]);
|
||||
TRY_ASSIGN (auto liga_set, c.graph.as_table<LigatureSet>(this_index, &ligatureSet[i]));
|
||||
result.push(!liga_set.table ? 0 : liga_set.table->ligature.len);
|
||||
}
|
||||
return result;
|
||||
return graph_result_t<hb_vector_t<unsigned>>::from(std::move(result), ALLOCATION_FAILURE);
|
||||
}
|
||||
|
||||
template <graph_t::vertex_mutability_t mutability>
|
||||
hb_vector_t<unsigned> ligature_index_to_object_id(const graph_t::vertex_and_table_t<LigatureSet, mutability>& liga_set) const {
|
||||
graph_result_t<hb_vector_t<unsigned>> ligature_index_to_object_id(const graph_t::vertex_and_table_t<LigatureSet, mutability>& liga_set) const {
|
||||
hb_vector_t<unsigned> map;
|
||||
map.resize_exact(liga_set.table->ligature.len);
|
||||
if (map.in_error()) return map;
|
||||
if (!map.resize_exact(liga_set.table->ligature.len)) return Err(ALLOCATION_FAILURE);
|
||||
|
||||
for (unsigned i = 0; i < map.length; i++) {
|
||||
map[i] = (unsigned) -1;
|
||||
map[i] = HB_GRAPH_INVALID;
|
||||
}
|
||||
|
||||
for (const auto& l : liga_set.vertex->obj.real_links) {
|
||||
for (const auto& l : liga_set.vertex->obj ().real_links) {
|
||||
if (l.position < 2) continue;
|
||||
unsigned array_index = (l.position - 2) / 2;
|
||||
map[array_index] = l.objidx;
|
||||
@@ -126,8 +125,8 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
return map;
|
||||
}
|
||||
|
||||
hb_vector_t<unsigned> compute_split_points(gsubgpos_graph_context_t& c,
|
||||
unsigned this_index) const
|
||||
graph_result_t<hb_vector_t<unsigned>> compute_split_points(gsubgpos_graph_context_t& c,
|
||||
unsigned this_index) const
|
||||
{
|
||||
// For ligature subst coverage is always packed last, and as a result is where an overflow
|
||||
// will happen if there is one, so we can check the estimate length of the
|
||||
@@ -143,21 +142,17 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
accumulated += OT::HBUINT16::static_size; // for ligature set offset
|
||||
accumulated += OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size; // for ligature set table
|
||||
|
||||
auto liga_set = c.graph.as_table<LigatureSet>(this_index, &ligatureSet[i]);
|
||||
if (!liga_set.table) {
|
||||
return hb_vector_t<unsigned> {};
|
||||
}
|
||||
TRY_ASSIGN (auto liga_set, c.graph.as_table<LigatureSet>(this_index, &ligatureSet[i]));
|
||||
|
||||
// Finding the object id associated with an array index is O(n)
|
||||
// so to avoid O(n^2), precompute the mapping by scanning through
|
||||
// all links
|
||||
auto index_to_id = ligature_index_to_object_id(liga_set);
|
||||
if (index_to_id.in_error()) return hb_vector_t<unsigned>();
|
||||
TRY_ASSIGN (auto index_to_id, ligature_index_to_object_id (liga_set));
|
||||
|
||||
for (unsigned j = 0; j < liga_set.table->ligature.len; j++)
|
||||
{
|
||||
const unsigned liga_id = index_to_id[j];
|
||||
if (liga_id == (unsigned) -1) continue; // no outgoing link, ignore
|
||||
if (liga_id == HB_GRAPH_INVALID) continue; // no outgoing link, ignore
|
||||
const unsigned liga_size = c.graph.vertices_[liga_id].table_size ();
|
||||
|
||||
accumulated += OT::HBUINT16::static_size; // for ligature offset
|
||||
@@ -194,45 +189,44 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
return original_count_;
|
||||
}
|
||||
|
||||
unsigned clone_range (unsigned start, unsigned end)
|
||||
graph_result_t<unsigned> clone_range (unsigned start, unsigned end)
|
||||
{
|
||||
return thiz->clone_range (c, this_index, liga_counts, start, end);
|
||||
}
|
||||
|
||||
bool shrink (unsigned count)
|
||||
graph_result_t<void> shrink (unsigned count)
|
||||
{
|
||||
return thiz->shrink (c, this_index, original_count(), liga_counts, count);
|
||||
}
|
||||
};
|
||||
|
||||
hb_pair_t<unsigned, LigatureSet*> new_liga_set(gsubgpos_graph_context_t& c, unsigned count) const {
|
||||
graph_result_t<hb_pair_t<unsigned, LigatureSet*>> new_liga_set(gsubgpos_graph_context_t& c, unsigned count) const {
|
||||
unsigned prime_size = OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size
|
||||
+ count * SmallTypes::size;
|
||||
|
||||
unsigned prime_id = c.create_node (prime_size);
|
||||
if (prime_id == (unsigned) -1) return hb_pair(-1, nullptr);
|
||||
TRY_ASSIGN (unsigned prime_id, c.create_node (prime_size));
|
||||
|
||||
LigatureSet* prime = (LigatureSet*) c.graph.object (prime_id).head;
|
||||
prime->ligature.len = count;
|
||||
return hb_pair(prime_id, prime);
|
||||
return Ok(hb_pair(prime_id, prime));
|
||||
}
|
||||
|
||||
void clear_virtual_links (gsubgpos_graph_context_t& c, unsigned node_index) const
|
||||
{
|
||||
auto& obj = c.graph.vertices_[node_index].obj;
|
||||
for (const auto& l : obj.virtual_links)
|
||||
auto& v = c.graph.vertices_[node_index];
|
||||
for (const auto& l : v.obj ().virtual_links)
|
||||
{
|
||||
auto& child = c.graph.vertices_[l.objidx];
|
||||
child.remove_parent(node_index);
|
||||
}
|
||||
obj.virtual_links.clear();
|
||||
v.clear_virtual_links ();
|
||||
}
|
||||
|
||||
void add_virtual_link(gsubgpos_graph_context_t& c, unsigned from, unsigned to) const {
|
||||
auto& from_obj = c.graph.vertices_[from].obj;
|
||||
c.graph.vertices_[to].add_parent(from, true);
|
||||
auto& link = *from_obj.virtual_links.push ();
|
||||
link.objidx = to;
|
||||
graph_result_t<void> add_virtual_link(gsubgpos_graph_context_t& c, unsigned from, unsigned to) const {
|
||||
if (unlikely (from >= c.graph.vertices_.length || to >= c.graph.vertices_.length)) return Err(OUT_OF_BOUNDS);
|
||||
TRY(c.graph.vertices_[to].add_parent (from, true));
|
||||
TRY(c.graph.vertices_[from].add_virtual_link (to));
|
||||
return Ok();
|
||||
}
|
||||
|
||||
hb_pair_t<unsigned, unsigned> current_liga_set_bounds (gsubgpos_graph_context_t& c,
|
||||
@@ -241,7 +235,7 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
{
|
||||
// Finds the actual liga indices present in the liga set currently. Takes
|
||||
// into account those that have been removed by processing.
|
||||
unsigned min_index = (unsigned) -1;
|
||||
unsigned min_index = HB_GRAPH_INVALID;
|
||||
unsigned max_index = 0;
|
||||
for (const auto& l : liga_set.real_links) {
|
||||
if (l.position < 2) continue;
|
||||
@@ -253,28 +247,29 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
return hb_pair(min_index, max_index + 1);
|
||||
}
|
||||
|
||||
void compact_liga_set (gsubgpos_graph_context_t& c, LigatureSet* table, hb_serialize_context_t::object_t& obj) const
|
||||
void compact_liga_set (gsubgpos_graph_context_t& c, LigatureSet* table, graph_t::vertex_t* v) const
|
||||
{
|
||||
const auto& obj = v->obj ();
|
||||
if (table->ligature.len <= obj.real_links.length) return;
|
||||
|
||||
// compact the remaining linked liga offsets into a continous array and shrink the node as needed.
|
||||
unsigned to_remove = table->ligature.len - obj.real_links.length;
|
||||
unsigned new_position = SmallTypes::size;
|
||||
obj.real_links.qsort(); // for this to work we need to process links in order of position.
|
||||
for (auto& l : obj.real_links)
|
||||
v->sort_real_links (); // for this to work we need to process links in order of position.
|
||||
for (auto& l : v->real_links_writer ())
|
||||
{
|
||||
l.position = new_position;
|
||||
new_position += SmallTypes::size;
|
||||
}
|
||||
|
||||
table->ligature.len = obj.real_links.length;
|
||||
obj.tail -= to_remove * SmallTypes::size;
|
||||
v->shrink_buffer (to_remove * SmallTypes::size);
|
||||
}
|
||||
|
||||
unsigned clone_range (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
hb_vector_t<unsigned> liga_counts,
|
||||
unsigned start, unsigned end) const
|
||||
graph_result_t<unsigned> clone_range (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
hb_vector_t<unsigned> liga_counts,
|
||||
unsigned start, unsigned end) const
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
" Cloning LigatureSubstFormat1 (%u) range [%u, %u).", this_index, start, end);
|
||||
@@ -285,8 +280,7 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
unsigned prime_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>::min_size
|
||||
+ ligatureSet.get_size() - ligatureSet.len.get_size();
|
||||
|
||||
unsigned liga_subst_prime_id = c.create_node (prime_size);
|
||||
if (liga_subst_prime_id == (unsigned) -1) return -1;
|
||||
TRY_ASSIGN (unsigned liga_subst_prime_id, c.create_node (prime_size));
|
||||
|
||||
LigatureSubstFormat1* liga_subst_prime = (LigatureSubstFormat1*) c.graph.object (liga_subst_prime_id).head;
|
||||
liga_subst_prime->format = this->format;
|
||||
@@ -294,20 +288,18 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
|
||||
// Create a place holder coverage prime id since we need to add virtual links to it while
|
||||
// generating liga and liga sets. Afterwards it will be updated to have the correct coverage.
|
||||
unsigned coverage_id = c.graph.index_for_offset (this_index, &coverage);
|
||||
unsigned coverage_prime_id = c.graph.duplicate(coverage_id);
|
||||
TRY_ASSIGN (unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage));
|
||||
TRY_ASSIGN (unsigned coverage_prime_id, c.graph.duplicate(coverage_id));
|
||||
auto& coverage_prime_vertex = c.graph.vertices_[coverage_prime_id];
|
||||
auto* coverage_prime_link = c.graph.vertices_[liga_subst_prime_id].obj.real_links.push ();
|
||||
coverage_prime_link->width = SmallTypes::size;
|
||||
coverage_prime_link->objidx = coverage_prime_id;
|
||||
coverage_prime_link->position = 2;
|
||||
coverage_prime_vertex.add_parent (liga_subst_prime_id, false);
|
||||
|
||||
TRY(c.graph.vertices_[liga_subst_prime_id].add_real_link (SmallTypes::size, coverage_prime_id, 2));
|
||||
TRY(coverage_prime_vertex.add_parent (liga_subst_prime_id, false));
|
||||
|
||||
// Locate all liga sets with ligas between start and end.
|
||||
// Clone or move them as needed.
|
||||
unsigned count = 0;
|
||||
unsigned liga_set_count = 0;
|
||||
unsigned liga_set_start = -1;
|
||||
unsigned liga_set_start = HB_GRAPH_INVALID;
|
||||
unsigned liga_set_end = 0; // inclusive
|
||||
for (unsigned i = 0; i < liga_counts.length; i++)
|
||||
{
|
||||
@@ -322,14 +314,11 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
continue;
|
||||
}
|
||||
|
||||
auto liga_set = c.graph.as_mutable_table<LigatureSet>(this_index, &ligatureSet[i]);
|
||||
if (!liga_set.table) {
|
||||
return -1;
|
||||
}
|
||||
TRY_ASSIGN (auto liga_set, c.graph.as_mutable_table<LigatureSet>(this_index, &ligatureSet[i]));
|
||||
|
||||
unsigned liga_set_index = liga_set.index;
|
||||
// Bounds may need to be adjusted if some ligas have been previously removed.
|
||||
hb_pair_t<unsigned, unsigned> liga_bounds = current_liga_set_bounds(c, liga_set_index, liga_set.vertex->obj);
|
||||
hb_pair_t<unsigned, unsigned> liga_bounds = current_liga_set_bounds(c, liga_set_index, liga_set.vertex->obj ());
|
||||
current_start = hb_max(count + liga_bounds.first, current_start);
|
||||
current_end = hb_min(count + liga_bounds.second, current_end);
|
||||
|
||||
@@ -339,11 +328,11 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
// We can move the entire ligaset to the new liga subset object.
|
||||
liga_set_end = i;
|
||||
if (i < liga_set_start) liga_set_start = i;
|
||||
liga_set_prime_id = c.graph.move_child<> (this_index,
|
||||
TRY_ASSIGN (liga_set_prime_id, c.graph.move_child<> (this_index,
|
||||
&ligatureSet[i],
|
||||
liga_subst_prime_id,
|
||||
&liga_subst_prime->ligatureSet[liga_set_count++]);
|
||||
compact_liga_set(c, liga_set.table, liga_set.vertex->obj);
|
||||
&liga_subst_prime->ligatureSet[liga_set_count++]));
|
||||
compact_liga_set (c, liga_set.table, liga_set.vertex);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -352,66 +341,61 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
unsigned start_index = hb_max(start, current_start) - count;
|
||||
unsigned end_index = hb_min(end, current_end) - count;
|
||||
unsigned liga_count = end_index - start_index;
|
||||
auto result = new_liga_set(c, liga_count);
|
||||
TRY_ASSIGN (auto result, new_liga_set(c, liga_count));
|
||||
liga_set_prime_id = result.first;
|
||||
if (liga_set_prime_id == (unsigned) -1) return -1;
|
||||
|
||||
c.graph.move_children<OT::Offset16>(
|
||||
TRY (c.graph.move_children<OT::Offset16>(
|
||||
liga_set_index,
|
||||
2 + start_index * 2,
|
||||
2 + end_index * 2,
|
||||
liga_set_prime_id,
|
||||
2);
|
||||
2));
|
||||
|
||||
liga_set_end = i;
|
||||
if (i < liga_set_start) liga_set_start = i;
|
||||
c.graph.add_link(&liga_subst_prime->ligatureSet[liga_set_count++], liga_subst_prime_id, liga_set_prime_id);
|
||||
TRY (c.graph.add_link(&liga_subst_prime->ligatureSet[liga_set_count++], liga_subst_prime_id, liga_set_prime_id));
|
||||
}
|
||||
|
||||
// The new liga and all children set needs to have a virtual link to the new coverage table:
|
||||
auto& liga_set_prime = c.graph.vertices_[liga_set_prime_id].obj;
|
||||
const auto& liga_set_prime = c.graph.vertices_[liga_set_prime_id].obj ();
|
||||
clear_virtual_links(c, liga_set_prime_id);
|
||||
add_virtual_link(c, liga_set_prime_id, coverage_prime_id);
|
||||
TRY(add_virtual_link(c, liga_set_prime_id, coverage_prime_id));
|
||||
for (const auto& l : liga_set_prime.real_links) {
|
||||
clear_virtual_links(c, l.objidx);
|
||||
add_virtual_link(c, l.objidx, coverage_prime_id);
|
||||
TRY(add_virtual_link(c, l.objidx, coverage_prime_id));
|
||||
}
|
||||
|
||||
count += num_ligas;
|
||||
}
|
||||
|
||||
c.graph.vertices_[liga_subst_prime_id].obj.tail -= (liga_subst_prime->ligatureSet.len - liga_set_count) * SmallTypes::size;
|
||||
c.graph.vertices_[liga_subst_prime_id].shrink_buffer ((liga_subst_prime->ligatureSet.len - liga_set_count) * SmallTypes::size);
|
||||
liga_subst_prime->ligatureSet.len = liga_set_count;
|
||||
|
||||
if (!Coverage::filter_coverage (c,
|
||||
TRY (Coverage::filter_coverage (c,
|
||||
coverage_prime_id,
|
||||
liga_set_start, liga_set_end + 1))
|
||||
return -1;
|
||||
liga_set_start, liga_set_end + 1));
|
||||
|
||||
return liga_subst_prime_id;
|
||||
return Ok(liga_subst_prime_id);
|
||||
}
|
||||
|
||||
bool shrink (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned old_count,
|
||||
hb_vector_t<unsigned> liga_counts,
|
||||
unsigned count)
|
||||
graph_result_t<void> shrink (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned old_count,
|
||||
hb_vector_t<unsigned> liga_counts,
|
||||
unsigned count)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
" Shrinking LigatureSubstFormat1 (%u) to [0, %u).",
|
||||
this_index,
|
||||
count);
|
||||
if (count >= old_count)
|
||||
return true;
|
||||
return Ok();
|
||||
|
||||
hb_set_t retained_indices;
|
||||
unsigned new_liga_set_count = 0;
|
||||
for (unsigned i = 0; i < liga_counts.length; i++)
|
||||
{
|
||||
auto liga_set = c.graph.as_mutable_table<LigatureSet>(this_index, &ligatureSet[i]);
|
||||
if (!liga_set.table) {
|
||||
return false;
|
||||
}
|
||||
TRY_ASSIGN (auto liga_set, c.graph.as_mutable_table<LigatureSet>(this_index, &ligatureSet[i]));
|
||||
|
||||
// We need the virtual links to coverage removed from all descendants on this liga subst.
|
||||
// If any are left when we try to mutate the coverage table later it will be unnessecarily
|
||||
@@ -419,12 +403,11 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
clear_virtual_links(c, liga_set.index);
|
||||
retained_indices.add(liga_set.index);
|
||||
|
||||
auto index_to_id = ligature_index_to_object_id(liga_set);
|
||||
if (index_to_id.in_error()) return false;
|
||||
TRY_ASSIGN (auto index_to_id, ligature_index_to_object_id (liga_set));
|
||||
|
||||
for (unsigned i = 0; i < liga_set.table->ligature.len; i++) {
|
||||
unsigned liga_index = index_to_id[i];
|
||||
if (liga_index != (unsigned) -1) {
|
||||
if (liga_index != HB_GRAPH_INVALID) {
|
||||
clear_virtual_links(c, liga_index);
|
||||
retained_indices.add(liga_index);
|
||||
}
|
||||
@@ -435,7 +418,7 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
// drop the trailing liga's from this set and all subsequent liga sets
|
||||
unsigned num_ligas_to_remove = num_ligas - count;
|
||||
new_liga_set_count = i + 1;
|
||||
c.graph.vertices_[liga_set.index].obj.tail -= num_ligas_to_remove * SmallTypes::size;
|
||||
c.graph.vertices_[liga_set.index].shrink_buffer (num_ligas_to_remove * SmallTypes::size);
|
||||
liga_set.table->ligature.len = count;
|
||||
break;
|
||||
} else {
|
||||
@@ -445,25 +428,23 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
|
||||
// Adjust liga set array
|
||||
auto& this_vertex = c.graph.vertices_[this_index];
|
||||
this_vertex.obj.tail -= (ligatureSet.len - new_liga_set_count) * SmallTypes::size;
|
||||
this_vertex.shrink_buffer ((ligatureSet.len - new_liga_set_count) * SmallTypes::size);
|
||||
ligatureSet.len = new_liga_set_count;
|
||||
|
||||
// Coverage matches the number of liga sets so rebuild as needed
|
||||
unsigned coverage_idx = c.graph.index_for_offset (this_index, &this->coverage);
|
||||
if (coverage_idx == (unsigned) -1) return false;
|
||||
TRY_ASSIGN (unsigned coverage_idx, c.graph.index_for_offset (this_index, &this->coverage));
|
||||
|
||||
auto& coverage_v = c.graph.vertices_[coverage_idx];
|
||||
unsigned coverage_size = coverage_v.table_size ();
|
||||
Coverage* coverage_table = (Coverage*) coverage_v.obj.head;
|
||||
const Coverage* coverage_table = (const Coverage*) coverage_v.obj ().head;
|
||||
|
||||
if (coverage_v.is_shared ())
|
||||
{
|
||||
coverage_idx = c.graph.remap_child (this_index, coverage_idx);
|
||||
if (coverage_idx == (unsigned) -1) return false;
|
||||
TRY_ASSIGN (coverage_idx, c.graph.remap_child (this_index, coverage_idx));
|
||||
}
|
||||
|
||||
for (unsigned i : retained_indices.iter())
|
||||
add_virtual_link(c, i, coverage_idx);
|
||||
TRY(add_virtual_link(c, i, coverage_idx));
|
||||
|
||||
auto new_coverage =
|
||||
+ hb_zip (coverage_table->iter (), hb_range ())
|
||||
@@ -480,8 +461,8 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1
|
||||
struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst
|
||||
{
|
||||
|
||||
hb_vector_t<unsigned> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<hb_vector_t<unsigned>> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
switch (u.format.v) {
|
||||
case 1:
|
||||
@@ -492,14 +473,14 @@ struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst
|
||||
// Don't split 24bit Ligature Subs
|
||||
#endif
|
||||
default:
|
||||
return hb_vector_t<unsigned> ();
|
||||
return Ok(hb_vector_t<unsigned> ());
|
||||
}
|
||||
}
|
||||
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
if (vertex_len < u.format.v.get_size ()) return false;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
if (unlikely (vertex_len < u.format.v.get_size ())) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
|
||||
switch (u.format.v) {
|
||||
@@ -511,7 +492,7 @@ struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst
|
||||
#endif
|
||||
default:
|
||||
// We don't handle format 2 here.
|
||||
return false;
|
||||
return Err(SANITIZE_FAILURE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+166
-149
@@ -36,62 +36,67 @@ namespace graph {
|
||||
|
||||
struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex, unsigned class_count) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex, unsigned class_count) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
if (vertex_len < AnchorMatrix::min_size) return false;
|
||||
size_t vertex_len = vertex.table_size();
|
||||
if (unlikely (vertex_len < AnchorMatrix::min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
|
||||
return vertex_len >= AnchorMatrix::min_size +
|
||||
OT::Offset16::static_size * class_count * this->rows;
|
||||
if (unlikely (vertex_len < AnchorMatrix::min_size +
|
||||
OT::Offset16::static_size * class_count * this->rows))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
bool shrink (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned old_class_count,
|
||||
unsigned new_class_count)
|
||||
graph_result_t<void> shrink (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned old_class_count,
|
||||
unsigned new_class_count)
|
||||
{
|
||||
if (new_class_count >= old_class_count) return false;
|
||||
auto& o = c.graph.vertices_[this_index].obj;
|
||||
if (unlikely (new_class_count >= old_class_count)) return Err(INVALID_ARGUMENT);
|
||||
auto& v = c.graph.vertices_[this_index];
|
||||
const auto& o = v.obj ();
|
||||
unsigned base_count = rows;
|
||||
o.tail = o.head +
|
||||
AnchorMatrix::min_size +
|
||||
OT::Offset16::static_size * base_count * new_class_count;
|
||||
v.set_buffer (o.head,
|
||||
o.head +
|
||||
AnchorMatrix::min_size +
|
||||
OT::Offset16::static_size * base_count * new_class_count);
|
||||
|
||||
// Reposition links into the new indexing scheme.
|
||||
for (auto& link : o.real_links.writer ())
|
||||
for (auto& link : v.real_links_writer ())
|
||||
{
|
||||
unsigned index = (link.position - 2) / 2;
|
||||
unsigned base = index / old_class_count;
|
||||
unsigned klass = index % old_class_count;
|
||||
if (klass >= new_class_count)
|
||||
if (unlikely (klass >= new_class_count))
|
||||
// should have already been removed
|
||||
return false;
|
||||
return Err(INVALID_ARGUMENT);
|
||||
|
||||
unsigned new_index = base * new_class_count + klass;
|
||||
|
||||
link.position = (char*) &(this->matrixZ[new_index]) - (char*) this;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
unsigned clone (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned start,
|
||||
unsigned end,
|
||||
unsigned class_count)
|
||||
graph_result_t<unsigned> clone (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned start,
|
||||
unsigned end,
|
||||
unsigned class_count)
|
||||
{
|
||||
unsigned base_count = rows;
|
||||
unsigned new_class_count = end - start;
|
||||
unsigned size = AnchorMatrix::min_size +
|
||||
OT::Offset16::static_size * new_class_count * rows;
|
||||
unsigned prime_id = c.create_node (size);
|
||||
if (prime_id == (unsigned) -1) return -1;
|
||||
TRY_ASSIGN (unsigned prime_id, c.create_node (size));
|
||||
AnchorMatrix* prime = (AnchorMatrix*) c.graph.object (prime_id).head;
|
||||
prime->rows = base_count;
|
||||
|
||||
auto& o = c.graph.vertices_[this_index].obj;
|
||||
auto& v = c.graph.vertices_[this_index];
|
||||
const auto& o = v.obj ();
|
||||
|
||||
int num_links = o.real_links.length;
|
||||
for (int i = 0; i < num_links; i++)
|
||||
{
|
||||
@@ -106,43 +111,48 @@ struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix
|
||||
|
||||
|
||||
unsigned child_idx = link.objidx;
|
||||
c.graph.add_link (&(prime->matrixZ[new_index]),
|
||||
prime_id,
|
||||
child_idx);
|
||||
TRY (c.graph.add_link (&(prime->matrixZ[new_index]),
|
||||
prime_id,
|
||||
child_idx));
|
||||
|
||||
auto& child = c.graph.vertices_[child_idx];
|
||||
child.remove_parent (this_index);
|
||||
|
||||
o.real_links.remove_unordered (i);
|
||||
v.remove_real_link_unordered (i);
|
||||
num_links--;
|
||||
i--;
|
||||
}
|
||||
|
||||
return prime_id;
|
||||
// Restore correct ordering after the above removes, which mess up link ordering.
|
||||
v.sort_real_links ();
|
||||
|
||||
return Ok(prime_id);
|
||||
}
|
||||
};
|
||||
|
||||
struct MarkArray : public OT::Layout::GPOS_impl::MarkArray
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
size_t vertex_len = vertex.table_size();
|
||||
unsigned min_size = MarkArray::min_size;
|
||||
if (vertex_len < min_size) return false;
|
||||
if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
|
||||
return vertex_len >= get_size ();
|
||||
if (unlikely (vertex_len < get_size ())) return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
bool shrink (gsubgpos_graph_context_t& c,
|
||||
const hb_hashmap_t<unsigned, unsigned>& mark_array_links,
|
||||
unsigned this_index,
|
||||
unsigned new_class_count)
|
||||
graph_result_t<void> shrink (gsubgpos_graph_context_t& c,
|
||||
const hb_hashmap_t<unsigned, unsigned>& mark_array_links,
|
||||
unsigned this_index,
|
||||
unsigned new_class_count)
|
||||
{
|
||||
auto& o = c.graph.vertices_[this_index].obj;
|
||||
auto& v = c.graph.vertices_[this_index];
|
||||
const auto& o = v.obj ();
|
||||
for (const auto& link : o.real_links)
|
||||
c.graph.vertices_[link.objidx].remove_parent (this_index);
|
||||
o.real_links.reset ();
|
||||
v.clear_real_links ();
|
||||
|
||||
unsigned new_index = 0;
|
||||
for (const auto& record : this->iter ())
|
||||
@@ -159,27 +169,27 @@ struct MarkArray : public OT::Layout::GPOS_impl::MarkArray
|
||||
continue;
|
||||
}
|
||||
|
||||
c.graph.add_link (&(*this)[new_index].markAnchor, this_index, *objidx);
|
||||
TRY (c.graph.add_link (&(*this)[new_index].markAnchor, this_index, *objidx));
|
||||
new_index++;
|
||||
}
|
||||
|
||||
this->len = new_index;
|
||||
o.tail = o.head + MarkArray::min_size +
|
||||
OT::Layout::GPOS_impl::MarkRecord::static_size * new_index;
|
||||
return true;
|
||||
v.set_buffer (o.head, o.head + MarkArray::min_size +
|
||||
OT::Layout::GPOS_impl::MarkRecord::static_size * new_index);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
unsigned clone (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
const hb_hashmap_t<unsigned, unsigned>& pos_to_index,
|
||||
hb_set_t& marks,
|
||||
unsigned start_class)
|
||||
graph_result_t<unsigned> clone (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
const hb_hashmap_t<unsigned, unsigned>& pos_to_index,
|
||||
hb_set_t& marks,
|
||||
unsigned start_class)
|
||||
{
|
||||
unsigned size = MarkArray::min_size +
|
||||
OT::Layout::GPOS_impl::MarkRecord::static_size *
|
||||
marks.get_population ();
|
||||
unsigned prime_id = c.create_node (size);
|
||||
if (prime_id == (unsigned) -1) return -1;
|
||||
TRY_ASSIGN (unsigned prime_id, c.create_node (size));
|
||||
MarkArray* prime = (MarkArray*) c.graph.object (prime_id).head;
|
||||
prime->len = marks.get_population ();
|
||||
|
||||
@@ -191,45 +201,50 @@ struct MarkArray : public OT::Layout::GPOS_impl::MarkArray
|
||||
unsigned offset_pos = (char*) &((*this)[mark].markAnchor) - (char*) this;
|
||||
unsigned* anchor_index;
|
||||
if (pos_to_index.has (offset_pos, &anchor_index))
|
||||
c.graph.move_child (this_index,
|
||||
&((*this)[mark].markAnchor),
|
||||
prime_id,
|
||||
&((*prime)[i].markAnchor));
|
||||
TRY (c.graph.move_child (this_index,
|
||||
&((*this)[mark].markAnchor),
|
||||
prime_id,
|
||||
&((*prime)[i].markAnchor)));
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return prime_id;
|
||||
// Restore correct ordering of the vertex links which are disturbed by move_child.
|
||||
c.graph.vertices_[this_index].sort_real_links ();
|
||||
|
||||
return Ok(prime_id);
|
||||
}
|
||||
};
|
||||
|
||||
struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<SmallTypes>
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
return vertex_len >= MarkBasePosFormat1::static_size;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
if (unlikely (vertex_len < MarkBasePosFormat1::static_size))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
hb_vector_t<unsigned> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<hb_vector_t<unsigned>> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
hb_set_t visited;
|
||||
|
||||
const unsigned base_coverage_id = c.graph.index_for_offset (this_index, &baseCoverage);
|
||||
TRY_ASSIGN (const unsigned base_coverage_id, c.graph.index_for_offset (this_index, &baseCoverage));
|
||||
|
||||
const unsigned base_size =
|
||||
OT::Layout::GPOS_impl::MarkBasePosFormat1_2<SmallTypes>::min_size +
|
||||
MarkArray::min_size +
|
||||
AnchorMatrix::min_size +
|
||||
c.graph.vertices_[base_coverage_id].table_size ();
|
||||
|
||||
hb_vector_t<class_info_t> class_to_info = get_class_info (c, this_index);
|
||||
TRY_ASSIGN (hb_vector_t<class_info_t> class_to_info, get_class_info (c, this_index));
|
||||
|
||||
unsigned class_count = classCount;
|
||||
auto base_array = c.graph.as_table<AnchorMatrix> (this_index,
|
||||
&baseArray,
|
||||
class_count);
|
||||
if (!base_array) return hb_vector_t<unsigned> ();
|
||||
TRY_ASSIGN (auto base_array, c.graph.as_table<AnchorMatrix> (this_index,
|
||||
&baseArray,
|
||||
class_count));
|
||||
unsigned base_count = base_array.table->rows;
|
||||
|
||||
unsigned partial_coverage_size = 4;
|
||||
@@ -245,7 +260,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
|
||||
OT::Offset16::static_size * base_count;
|
||||
|
||||
for (unsigned objidx : info.child_indices)
|
||||
accumulated_delta += c.graph.find_subgraph_size (objidx, visited);
|
||||
accumulated_delta += c.graph.find_subgraph_size (objidx, visited).value_or (0);
|
||||
|
||||
accumulated += accumulated_delta;
|
||||
unsigned total = accumulated + partial_coverage_size;
|
||||
@@ -253,6 +268,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
|
||||
if (total >= (1 << 16))
|
||||
{
|
||||
split_points.push (klass);
|
||||
TRY (graph_result_t<void>::from (split_points, ALLOCATION_FAILURE));
|
||||
accumulated = base_size + accumulated_delta;
|
||||
partial_coverage_size = 4 + OT::HBUINT16::static_size * info.marks.get_population ();
|
||||
visited.clear (); // node sharing isn't allowed between splits.
|
||||
@@ -260,13 +276,15 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
|
||||
}
|
||||
|
||||
|
||||
const unsigned mark_array_id = c.graph.index_for_offset (this_index, &markArray);
|
||||
TRY_ASSIGN (const unsigned mark_array_id, c.graph.index_for_offset (this_index, &markArray));
|
||||
TRY_ASSIGN (auto mark_array_links, c.graph.vertices_[mark_array_id].position_to_index_map ());
|
||||
|
||||
split_context_t split_context {
|
||||
c,
|
||||
this,
|
||||
this_index,
|
||||
std::move (class_to_info),
|
||||
c.graph.vertices_[mark_array_id].position_to_index_map (),
|
||||
std::move (mark_array_links),
|
||||
};
|
||||
|
||||
return actuate_subtable_split<split_context_t> (split_context, split_points);
|
||||
@@ -303,30 +321,30 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
|
||||
return thiz->classCount;
|
||||
}
|
||||
|
||||
unsigned clone_range (unsigned start, unsigned end)
|
||||
graph_result_t<unsigned> clone_range (unsigned start, unsigned end)
|
||||
{
|
||||
return thiz->clone_range (*this, this->this_index, start, end);
|
||||
}
|
||||
|
||||
bool shrink (unsigned count)
|
||||
graph_result_t<void> shrink (unsigned count)
|
||||
{
|
||||
return thiz->shrink (*this, this->this_index, count);
|
||||
}
|
||||
};
|
||||
|
||||
hb_vector_t<class_info_t> get_class_info (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<hb_vector_t<class_info_t>> get_class_info (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
hb_vector_t<class_info_t> class_to_info;
|
||||
|
||||
unsigned class_count = classCount;
|
||||
if (!class_count) return class_to_info;
|
||||
|
||||
if (!class_to_info.resize (class_count))
|
||||
return hb_vector_t<class_info_t>();
|
||||
if (unlikely (!class_to_info.resize (class_count)))
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
|
||||
TRY_ASSIGN (auto mark_array, c.graph.as_table<MarkArray> (this_index, &markArray));
|
||||
|
||||
auto mark_array = c.graph.as_table<MarkArray> (this_index, &markArray);
|
||||
if (!mark_array) return hb_vector_t<class_info_t> ();
|
||||
unsigned mark_count = mark_array.table->len;
|
||||
for (unsigned mark = 0; mark < mark_count; mark++)
|
||||
{
|
||||
@@ -335,7 +353,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
|
||||
class_to_info[klass].marks.add (mark);
|
||||
}
|
||||
|
||||
for (const auto& link : mark_array.vertex->obj.real_links)
|
||||
for (const auto& link : mark_array.vertex->obj ().real_links)
|
||||
{
|
||||
unsigned mark = (link.position - 2) /
|
||||
OT::Layout::GPOS_impl::MarkRecord::static_size;
|
||||
@@ -344,11 +362,12 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
|
||||
class_to_info[klass].child_indices.push (link.objidx);
|
||||
}
|
||||
|
||||
unsigned base_array_id =
|
||||
c.graph.index_for_offset (this_index, &baseArray);
|
||||
TRY_ASSIGN (unsigned base_array_id,
|
||||
c.graph.index_for_offset (this_index, &baseArray));
|
||||
|
||||
auto& base_array_v = c.graph.vertices_[base_array_id];
|
||||
|
||||
for (const auto& link : base_array_v.obj.real_links)
|
||||
for (const auto& link : base_array_v.obj ().real_links)
|
||||
{
|
||||
unsigned index = (link.position - 2) / OT::Offset16::static_size;
|
||||
unsigned klass = index % class_count;
|
||||
@@ -358,9 +377,9 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
|
||||
return class_to_info;
|
||||
}
|
||||
|
||||
bool shrink (split_context_t& sc,
|
||||
unsigned this_index,
|
||||
unsigned count)
|
||||
graph_result_t<void> shrink (split_context_t& sc,
|
||||
unsigned this_index,
|
||||
unsigned count)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
" Shrinking MarkBasePosFormat1 (%u) to [0, %u).",
|
||||
@@ -369,49 +388,48 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
|
||||
|
||||
unsigned old_count = classCount;
|
||||
if (count >= old_count)
|
||||
return true;
|
||||
return Ok();
|
||||
|
||||
classCount = count;
|
||||
|
||||
auto mark_coverage = sc.c.graph.as_mutable_table<Coverage> (this_index,
|
||||
&markCoverage);
|
||||
if (!mark_coverage) return false;
|
||||
TRY_ASSIGN (auto mark_coverage, sc.c.graph.as_mutable_table<Coverage> (this_index,
|
||||
&markCoverage));
|
||||
|
||||
hb_set_t marks = sc.marks_for (0, count);
|
||||
auto new_coverage =
|
||||
+ hb_enumerate (mark_coverage.table->iter ())
|
||||
| hb_filter (marks, hb_first)
|
||||
| hb_map_retains_sorting (hb_second)
|
||||
;
|
||||
if (!Coverage::make_coverage (sc.c, + new_coverage,
|
||||
TRY (Coverage::make_coverage (sc.c, + new_coverage,
|
||||
mark_coverage.index,
|
||||
4 + 2 * marks.get_population ()))
|
||||
return false;
|
||||
4 + 2 * marks.get_population ()));
|
||||
|
||||
|
||||
auto base_array = sc.c.graph.as_mutable_table<AnchorMatrix> (this_index,
|
||||
&baseArray,
|
||||
old_count);
|
||||
if (!base_array || !base_array.table->shrink (sc.c,
|
||||
base_array.index,
|
||||
old_count,
|
||||
count))
|
||||
return false;
|
||||
TRY_ASSIGN (auto base_array, sc.c.graph.as_mutable_table<AnchorMatrix> (this_index,
|
||||
&baseArray,
|
||||
old_count));
|
||||
|
||||
auto mark_array = sc.c.graph.as_mutable_table<MarkArray> (this_index,
|
||||
&markArray);
|
||||
if (!mark_array || !mark_array.table->shrink (sc.c,
|
||||
sc.mark_array_links,
|
||||
mark_array.index,
|
||||
count))
|
||||
return false;
|
||||
TRY (base_array.table->shrink (sc.c,
|
||||
base_array.index,
|
||||
old_count,
|
||||
count));
|
||||
|
||||
return true;
|
||||
TRY_ASSIGN (auto mark_array, sc.c.graph.as_mutable_table<MarkArray> (this_index,
|
||||
&markArray));
|
||||
|
||||
TRY (mark_array.table->shrink (sc.c,
|
||||
sc.mark_array_links,
|
||||
mark_array.index,
|
||||
count));
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
// Create a new MarkBasePos that has all of the data for classes from [start, end).
|
||||
unsigned clone_range (split_context_t& sc,
|
||||
unsigned this_index,
|
||||
unsigned start, unsigned end) const
|
||||
graph_result_t<unsigned> clone_range (split_context_t& sc,
|
||||
unsigned this_index,
|
||||
unsigned start, unsigned end) const
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
" Cloning MarkBasePosFormat1 (%u) range [%u, %u).", this_index, start, end);
|
||||
@@ -419,64 +437,63 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
|
||||
graph_t& graph = sc.c.graph;
|
||||
unsigned prime_size = OT::Layout::GPOS_impl::MarkBasePosFormat1_2<SmallTypes>::static_size;
|
||||
|
||||
unsigned prime_id = sc.c.create_node (prime_size);
|
||||
if (prime_id == (unsigned) -1) return -1;
|
||||
TRY_ASSIGN (unsigned prime_id, sc.c.create_node (prime_size));
|
||||
|
||||
MarkBasePosFormat1* prime = (MarkBasePosFormat1*) graph.object (prime_id).head;
|
||||
prime->format = this->format;
|
||||
unsigned new_class_count = end - start;
|
||||
prime->classCount = new_class_count;
|
||||
|
||||
unsigned base_coverage_id =
|
||||
graph.index_for_offset (sc.this_index, &baseCoverage);
|
||||
graph.add_link (&(prime->baseCoverage), prime_id, base_coverage_id);
|
||||
TRY_ASSIGN (unsigned base_coverage_id,
|
||||
graph.index_for_offset (sc.this_index, &baseCoverage));
|
||||
|
||||
TRY (graph.add_link (&(prime->baseCoverage), prime_id, base_coverage_id));
|
||||
|
||||
TRY_ASSIGN (auto mark_coverage, sc.c.graph.as_table<Coverage> (this_index,
|
||||
&markCoverage));
|
||||
|
||||
auto mark_coverage = sc.c.graph.as_table<Coverage> (this_index,
|
||||
&markCoverage);
|
||||
if (!mark_coverage) return false;
|
||||
hb_set_t marks = sc.marks_for (start, end);
|
||||
auto new_coverage =
|
||||
+ hb_enumerate (mark_coverage.table->iter ())
|
||||
| hb_filter (marks, hb_first)
|
||||
| hb_map_retains_sorting (hb_second)
|
||||
;
|
||||
if (!Coverage::add_coverage (sc.c,
|
||||
TRY (Coverage::add_coverage (sc.c,
|
||||
prime_id,
|
||||
2,
|
||||
+ new_coverage,
|
||||
marks.get_population () * 2 + 4))
|
||||
return -1;
|
||||
marks.get_population () * 2 + 4));
|
||||
|
||||
auto mark_array =
|
||||
graph.as_mutable_table <MarkArray> (sc.this_index, &markArray);
|
||||
if (!mark_array) return -1;
|
||||
unsigned new_mark_array =
|
||||
mark_array.table->clone (sc.c,
|
||||
mark_array.index,
|
||||
sc.mark_array_links,
|
||||
marks,
|
||||
start);
|
||||
graph.add_link (&(prime->markArray), prime_id, new_mark_array);
|
||||
TRY_ASSIGN (auto mark_array,
|
||||
graph.as_mutable_table <MarkArray> (sc.this_index, &markArray));
|
||||
|
||||
TRY_ASSIGN (unsigned new_mark_array,
|
||||
mark_array.table->clone (sc.c,
|
||||
mark_array.index,
|
||||
sc.mark_array_links,
|
||||
marks,
|
||||
start));
|
||||
TRY (graph.add_link (&(prime->markArray), prime_id, new_mark_array));
|
||||
|
||||
unsigned class_count = classCount;
|
||||
auto base_array =
|
||||
graph.as_mutable_table<AnchorMatrix> (sc.this_index, &baseArray, class_count);
|
||||
if (!base_array) return -1;
|
||||
unsigned new_base_array =
|
||||
base_array.table->clone (sc.c,
|
||||
base_array.index,
|
||||
start, end, this->classCount);
|
||||
graph.add_link (&(prime->baseArray), prime_id, new_base_array);
|
||||
TRY_ASSIGN (auto base_array,
|
||||
graph.as_mutable_table<AnchorMatrix> (sc.this_index, &baseArray, class_count));
|
||||
|
||||
return prime_id;
|
||||
TRY_ASSIGN (unsigned new_base_array,
|
||||
base_array.table->clone (sc.c,
|
||||
base_array.index,
|
||||
start, end, this->classCount));
|
||||
TRY (graph.add_link (&(prime->baseArray), prime_id, new_base_array));
|
||||
|
||||
return Ok(prime_id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct MarkBasePos : public OT::Layout::GPOS_impl::MarkBasePos
|
||||
{
|
||||
hb_vector_t<unsigned> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<hb_vector_t<unsigned>> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
switch (u.format.v) {
|
||||
case 1:
|
||||
@@ -487,14 +504,14 @@ struct MarkBasePos : public OT::Layout::GPOS_impl::MarkBasePos
|
||||
// Don't split 24bit MarkBasePos's.
|
||||
#endif
|
||||
default:
|
||||
return hb_vector_t<unsigned> ();
|
||||
return Ok(hb_vector_t<unsigned> ());
|
||||
}
|
||||
}
|
||||
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
if (vertex_len < u.format.v.get_size ()) return false;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
if (unlikely (vertex_len < u.format.v.get_size ())) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
|
||||
switch (u.format.v) {
|
||||
@@ -506,7 +523,7 @@ struct MarkBasePos : public OT::Layout::GPOS_impl::MarkBasePos
|
||||
#endif
|
||||
default:
|
||||
// We don't handle format 3 and 4 here.
|
||||
return false;
|
||||
return Err(SANITIZE_FAILURE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+144
-141
@@ -37,23 +37,24 @@ namespace graph {
|
||||
|
||||
struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3<SmallTypes>
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
unsigned min_size = OT::Layout::GPOS_impl::PairPosFormat1_3<SmallTypes>::min_size;
|
||||
if (vertex_len < min_size) return false;
|
||||
if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
|
||||
return vertex_len >=
|
||||
min_size + pairSet.get_size () - pairSet.len.get_size();
|
||||
if (unlikely (vertex_len < min_size + pairSet.get_size () - pairSet.len.get_size()))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
hb_vector_t<unsigned> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<hb_vector_t<unsigned>> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
hb_set_t visited;
|
||||
|
||||
const unsigned coverage_id = c.graph.index_for_offset (this_index, &coverage);
|
||||
TRY_ASSIGN (const unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage));
|
||||
const unsigned coverage_size = c.graph.vertices_[coverage_id].table_size ();
|
||||
const unsigned base_size = OT::Layout::GPOS_impl::PairPosFormat1_3<SmallTypes>::min_size;
|
||||
|
||||
@@ -62,9 +63,9 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3<SmallType
|
||||
hb_vector_t<unsigned> split_points;
|
||||
for (unsigned i = 0; i < pairSet.len; i++)
|
||||
{
|
||||
unsigned pair_set_index = pair_set_graph_index (c, this_index, i);
|
||||
TRY_ASSIGN (unsigned pair_set_index, pair_set_graph_index (c, this_index, i));
|
||||
unsigned accumulated_delta =
|
||||
c.graph.find_subgraph_size (pair_set_index, visited) +
|
||||
c.graph.find_subgraph_size (pair_set_index, visited).value_or (0) +
|
||||
SmallTypes::size; // for PairSet offset.
|
||||
partial_coverage_size += OT::HBUINT16::static_size;
|
||||
|
||||
@@ -74,6 +75,7 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3<SmallType
|
||||
if (total >= (1 << 16))
|
||||
{
|
||||
split_points.push (i);
|
||||
TRY (graph_result_t<void>::from (split_points, ALLOCATION_FAILURE));
|
||||
accumulated = base_size + accumulated_delta;
|
||||
partial_coverage_size = 6;
|
||||
visited.clear (); // node sharing isn't allowed between splits.
|
||||
@@ -101,20 +103,20 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3<SmallType
|
||||
return thiz->pairSet.len;
|
||||
}
|
||||
|
||||
unsigned clone_range (unsigned start, unsigned end)
|
||||
graph_result_t<unsigned> clone_range (unsigned start, unsigned end)
|
||||
{
|
||||
return thiz->clone_range (this->c, this->this_index, start, end);
|
||||
}
|
||||
|
||||
bool shrink (unsigned count)
|
||||
graph_result_t<void> shrink (unsigned count)
|
||||
{
|
||||
return thiz->shrink (this->c, this->this_index, count);
|
||||
}
|
||||
};
|
||||
|
||||
bool shrink (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned count)
|
||||
graph_result_t<void> shrink (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned count)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
" Shrinking PairPosFormat1 (%u) to [0, %u).",
|
||||
@@ -122,13 +124,12 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3<SmallType
|
||||
count);
|
||||
unsigned old_count = pairSet.len;
|
||||
if (count >= old_count)
|
||||
return true;
|
||||
return Ok();
|
||||
|
||||
pairSet.len = count;
|
||||
c.graph.vertices_[this_index].obj.tail -= (old_count - count) * SmallTypes::size;
|
||||
c.graph.vertices_[this_index].shrink_buffer ((old_count - count) * SmallTypes::size);
|
||||
|
||||
auto coverage = c.graph.as_mutable_table<Coverage> (this_index, &this->coverage);
|
||||
if (!coverage) return false;
|
||||
TRY_ASSIGN (auto coverage, c.graph.as_mutable_table<Coverage> (this_index, &this->coverage));
|
||||
|
||||
unsigned coverage_size = coverage.vertex->table_size ();
|
||||
auto new_coverage =
|
||||
@@ -144,9 +145,9 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3<SmallType
|
||||
|
||||
// Create a new PairPos including PairSet's from start (inclusive) to end (exclusive).
|
||||
// Returns object id of the new object.
|
||||
unsigned clone_range (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned start, unsigned end) const
|
||||
graph_result_t<unsigned> clone_range (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
unsigned start, unsigned end) const
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
" Cloning PairPosFormat1 (%u) range [%u, %u).", this_index, start, end);
|
||||
@@ -155,8 +156,7 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3<SmallType
|
||||
unsigned prime_size = OT::Layout::GPOS_impl::PairPosFormat1_3<SmallTypes>::min_size
|
||||
+ num_pair_sets * SmallTypes::size;
|
||||
|
||||
unsigned pair_pos_prime_id = c.create_node (prime_size);
|
||||
if (pair_pos_prime_id == (unsigned) -1) return -1;
|
||||
TRY_ASSIGN (unsigned pair_pos_prime_id, c.create_node (prime_size));
|
||||
|
||||
PairPosFormat1* pair_pos_prime = (PairPosFormat1*) c.graph.object (pair_pos_prime_id).head;
|
||||
pair_pos_prime->format = this->format;
|
||||
@@ -166,26 +166,28 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3<SmallType
|
||||
|
||||
for (unsigned i = start; i < end; i++)
|
||||
{
|
||||
c.graph.move_child<> (this_index,
|
||||
&pairSet[i],
|
||||
pair_pos_prime_id,
|
||||
&pair_pos_prime->pairSet[i - start]);
|
||||
TRY (c.graph.move_child<> (this_index,
|
||||
&pairSet[i],
|
||||
pair_pos_prime_id,
|
||||
&pair_pos_prime->pairSet[i - start]));
|
||||
}
|
||||
|
||||
unsigned coverage_id = c.graph.index_for_offset (this_index, &coverage);
|
||||
if (!Coverage::clone_coverage (c,
|
||||
// Restore correct ordering of the vertex links which are disturbed by move_child.
|
||||
c.graph.vertices_[this_index].sort_real_links ();
|
||||
|
||||
TRY_ASSIGN (unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage));
|
||||
TRY (Coverage::clone_coverage (c,
|
||||
coverage_id,
|
||||
pair_pos_prime_id,
|
||||
2,
|
||||
start, end))
|
||||
return -1;
|
||||
start, end));
|
||||
|
||||
return pair_pos_prime_id;
|
||||
return Ok(pair_pos_prime_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned pair_set_graph_index (gsubgpos_graph_context_t& c, unsigned this_index, unsigned i) const
|
||||
graph_result_t<unsigned> pair_set_graph_index (gsubgpos_graph_context_t& c, unsigned this_index, unsigned i) const
|
||||
{
|
||||
return c.graph.index_for_offset (this_index, &pairSet[i]);
|
||||
}
|
||||
@@ -193,32 +195,33 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3<SmallType
|
||||
|
||||
struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallTypes>
|
||||
{
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.table_size ();
|
||||
unsigned min_size = OT::Layout::GPOS_impl::PairPosFormat2_4<SmallTypes>::min_size;
|
||||
if (vertex_len < min_size) return false;
|
||||
if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
|
||||
const unsigned class1_count = class1Count;
|
||||
return vertex_len >=
|
||||
min_size + class1_count * get_class1_record_size ();
|
||||
if (unlikely (vertex_len < min_size + class1_count * get_class1_record_size ()))
|
||||
return Err(SANITIZE_FAILURE);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
hb_vector_t<unsigned> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<hb_vector_t<unsigned>> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
const unsigned base_size = OT::Layout::GPOS_impl::PairPosFormat2_4<SmallTypes>::min_size;
|
||||
const unsigned class_def_2_size = size_of (c, this_index, &classDef2);
|
||||
const Coverage* coverage = get_coverage (c, this_index);
|
||||
const ClassDef* class_def_1 = get_class_def_1 (c, this_index);
|
||||
TRY_ASSIGN (const unsigned class_def_2_size, size_of (c, this_index, &classDef2));
|
||||
TRY_ASSIGN (const Coverage* coverage, get_coverage (c, this_index));
|
||||
TRY_ASSIGN (const ClassDef* class_def_1, get_class_def_1 (c, this_index));
|
||||
auto gid_and_class =
|
||||
+ coverage->iter ()
|
||||
| hb_map_retains_sorting ([&] (hb_codepoint_t gid) {
|
||||
return hb_codepoint_pair_t (gid, class_def_1->get_class (gid));
|
||||
})
|
||||
;
|
||||
class_def_size_estimator_t estimator (gid_and_class);
|
||||
TRY_ASSIGN (class_def_size_estimator_t estimator, class_def_size_estimator_t::create (gid_and_class));
|
||||
|
||||
const unsigned class1_count = class1Count;
|
||||
const unsigned class2_count = class2Count;
|
||||
@@ -236,7 +239,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
|
||||
hb_vector_t<unsigned> split_points;
|
||||
|
||||
hb_hashmap_t<unsigned, unsigned> device_tables = get_all_device_tables (c, this_index);
|
||||
TRY_ASSIGN (auto device_tables, get_all_device_tables (c, this_index));
|
||||
hb_vector_t<unsigned> format1_device_table_indices = valueFormat1.get_device_table_indices ();
|
||||
hb_vector_t<unsigned> format2_device_table_indices = valueFormat2.get_device_table_indices ();
|
||||
bool has_device_tables = bool(format1_device_table_indices) || bool(format2_device_table_indices);
|
||||
@@ -276,6 +279,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
if (total >= (1 << 16))
|
||||
{
|
||||
split_points.push (i);
|
||||
TRY (graph_result_t<void>::from (split_points, ALLOCATION_FAILURE));
|
||||
// split does not include i, so add the size for i when we reset the size counters.
|
||||
accumulated = base_size + accumulated_delta;
|
||||
|
||||
@@ -326,12 +330,12 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
return thiz->class1Count;
|
||||
}
|
||||
|
||||
unsigned clone_range (unsigned start, unsigned end)
|
||||
graph_result_t<unsigned> clone_range (unsigned start, unsigned end)
|
||||
{
|
||||
return thiz->clone_range (*this, start, end);
|
||||
}
|
||||
|
||||
bool shrink (unsigned count)
|
||||
graph_result_t<void> shrink (unsigned count)
|
||||
{
|
||||
return thiz->shrink (*this, count);
|
||||
}
|
||||
@@ -344,8 +348,8 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
class2_count * (valueFormat1.get_size () + valueFormat2.get_size ());
|
||||
}
|
||||
|
||||
unsigned clone_range (split_context_t& split_context,
|
||||
unsigned start, unsigned end) const
|
||||
graph_result_t<unsigned> clone_range (split_context_t& split_context,
|
||||
unsigned start, unsigned end) const
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
" Cloning PairPosFormat2 (%u) range [%u, %u).", split_context.this_index, start, end);
|
||||
@@ -356,8 +360,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
unsigned prime_size = OT::Layout::GPOS_impl::PairPosFormat2_4<SmallTypes>::min_size
|
||||
+ num_records * split_context.class1_record_size;
|
||||
|
||||
unsigned pair_pos_prime_id = split_context.c.create_node (prime_size);
|
||||
if (pair_pos_prime_id == (unsigned) -1) return -1;
|
||||
TRY_ASSIGN (unsigned pair_pos_prime_id, split_context.c.create_node (prime_size));
|
||||
|
||||
PairPosFormat2* pair_pos_prime =
|
||||
(PairPosFormat2*) graph.object (pair_pos_prime_id).head;
|
||||
@@ -366,24 +369,24 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
pair_pos_prime->valueFormat2 = this->valueFormat2;
|
||||
pair_pos_prime->class1Count = num_records;
|
||||
pair_pos_prime->class2Count = this->class2Count;
|
||||
clone_class1_records (split_context,
|
||||
pair_pos_prime_id,
|
||||
start,
|
||||
end);
|
||||
TRY (clone_class1_records (split_context,
|
||||
pair_pos_prime_id,
|
||||
start,
|
||||
end));
|
||||
|
||||
TRY_ASSIGN (unsigned coverage_id,
|
||||
graph.index_for_offset (split_context.this_index, &coverage));
|
||||
TRY_ASSIGN (unsigned class_def_1_id,
|
||||
graph.index_for_offset (split_context.this_index, &classDef1));
|
||||
|
||||
unsigned coverage_id =
|
||||
graph.index_for_offset (split_context.this_index, &coverage);
|
||||
unsigned class_def_1_id =
|
||||
graph.index_for_offset (split_context.this_index, &classDef1);
|
||||
auto& coverage_v = graph.vertices_[coverage_id];
|
||||
auto& class_def_1_v = graph.vertices_[class_def_1_id];
|
||||
Coverage* coverage_table = (Coverage*) coverage_v.obj.head;
|
||||
ClassDef* class_def_1_table = (ClassDef*) class_def_1_v.obj.head;
|
||||
if (!coverage_table
|
||||
|| !coverage_table->sanitize (coverage_v)
|
||||
|| !class_def_1_table
|
||||
|| !class_def_1_table->sanitize (class_def_1_v))
|
||||
return -1;
|
||||
const Coverage* coverage_table = (const Coverage*) coverage_v.obj().head;
|
||||
const ClassDef* class_def_1_table = (const ClassDef*) class_def_1_v.obj().head;
|
||||
if (unlikely (!coverage_table || !class_def_1_table))
|
||||
return Err(INVALID_ARGUMENT);
|
||||
TRY (coverage_table->sanitize (coverage_v));
|
||||
TRY (class_def_1_table->sanitize (class_def_1_v));
|
||||
|
||||
auto klass_map =
|
||||
+ coverage_table->iter ()
|
||||
@@ -399,36 +402,32 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
})
|
||||
;
|
||||
|
||||
if (!Coverage::add_coverage (split_context.c,
|
||||
TRY (Coverage::add_coverage (split_context.c,
|
||||
pair_pos_prime_id,
|
||||
2,
|
||||
+ klass_map | hb_map_retains_sorting (hb_first),
|
||||
split_context.max_coverage_size))
|
||||
return -1;
|
||||
split_context.max_coverage_size));
|
||||
|
||||
// classDef1
|
||||
if (!ClassDef::add_class_def (split_context.c,
|
||||
TRY (ClassDef::add_class_def (split_context.c,
|
||||
pair_pos_prime_id,
|
||||
8,
|
||||
+ klass_map,
|
||||
split_context.max_class_def_size))
|
||||
return -1;
|
||||
split_context.max_class_def_size));
|
||||
|
||||
// classDef2
|
||||
unsigned class_def_2_id =
|
||||
graph.index_for_offset (split_context.this_index, &classDef2);
|
||||
auto* class_def_link = graph.vertices_[pair_pos_prime_id].obj.real_links.push ();
|
||||
class_def_link->width = SmallTypes::size;
|
||||
class_def_link->objidx = class_def_2_id;
|
||||
class_def_link->position = 10;
|
||||
graph.vertices_[class_def_2_id].add_parent (pair_pos_prime_id, false);
|
||||
TRY_ASSIGN (unsigned class_def_2_id,
|
||||
graph.index_for_offset (split_context.this_index, &classDef2));
|
||||
|
||||
return pair_pos_prime_id;
|
||||
TRY(graph.vertices_[pair_pos_prime_id].add_real_link (SmallTypes::size, class_def_2_id, 10));
|
||||
TRY(graph.vertices_[class_def_2_id].add_parent (pair_pos_prime_id, false));
|
||||
|
||||
return Ok(pair_pos_prime_id);
|
||||
}
|
||||
|
||||
void clone_class1_records (split_context_t& split_context,
|
||||
unsigned pair_pos_prime_id,
|
||||
unsigned start, unsigned end) const
|
||||
graph_result_t<void> clone_class1_records (split_context_t& split_context,
|
||||
unsigned pair_pos_prime_id,
|
||||
unsigned start, unsigned end) const
|
||||
{
|
||||
PairPosFormat2* pair_pos_prime =
|
||||
(PairPosFormat2*) split_context.c.graph.object (pair_pos_prime_id).head;
|
||||
@@ -442,7 +441,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
if (!split_context.format1_device_table_indices
|
||||
&& !split_context.format2_device_table_indices)
|
||||
// No device tables to move over.
|
||||
return;
|
||||
return Ok();
|
||||
|
||||
unsigned class2_count = class2Count;
|
||||
for (unsigned i = start; i < end; i++)
|
||||
@@ -455,26 +454,27 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
unsigned new_value1_index = split_context.value_record_len * (class2_count * (i - start) + j);
|
||||
unsigned new_value2_index = new_value1_index + split_context.value1_record_len;
|
||||
|
||||
transfer_device_tables (split_context,
|
||||
pair_pos_prime_id,
|
||||
split_context.format1_device_table_indices,
|
||||
value1_index,
|
||||
new_value1_index);
|
||||
TRY (transfer_device_tables (split_context,
|
||||
pair_pos_prime_id,
|
||||
split_context.format1_device_table_indices,
|
||||
value1_index,
|
||||
new_value1_index));
|
||||
|
||||
transfer_device_tables (split_context,
|
||||
pair_pos_prime_id,
|
||||
split_context.format2_device_table_indices,
|
||||
value2_index,
|
||||
new_value2_index);
|
||||
TRY (transfer_device_tables (split_context,
|
||||
pair_pos_prime_id,
|
||||
split_context.format2_device_table_indices,
|
||||
value2_index,
|
||||
new_value2_index));
|
||||
}
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
void transfer_device_tables (split_context_t& split_context,
|
||||
unsigned pair_pos_prime_id,
|
||||
const hb_vector_t<unsigned>& device_table_indices,
|
||||
unsigned old_value_record_index,
|
||||
unsigned new_value_record_index) const
|
||||
graph_result_t<void> transfer_device_tables (split_context_t& split_context,
|
||||
unsigned pair_pos_prime_id,
|
||||
const hb_vector_t<unsigned>& device_table_indices,
|
||||
unsigned old_value_record_index,
|
||||
unsigned new_value_record_index) const
|
||||
{
|
||||
PairPosFormat2* pair_pos_prime =
|
||||
(PairPosFormat2*) split_context.c.graph.object (pair_pos_prime_id).head;
|
||||
@@ -485,16 +485,21 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
unsigned record_position = ((char*) record) - ((char*) this);
|
||||
if (!split_context.device_tables.has (record_position)) continue;
|
||||
|
||||
split_context.c.graph.move_child (
|
||||
TRY (split_context.c.graph.move_child (
|
||||
split_context.this_index,
|
||||
record,
|
||||
pair_pos_prime_id,
|
||||
(OT::Offset16*) &pair_pos_prime->values[new_value_record_index + i]);
|
||||
(OT::Offset16*) &pair_pos_prime->values[new_value_record_index + i]));
|
||||
}
|
||||
|
||||
// Restore correct ordering of the vertex links which are disturbed by move_child.
|
||||
split_context.c.graph.vertices_[split_context.this_index].sort_real_links ();
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
bool shrink (split_context_t& split_context,
|
||||
unsigned count)
|
||||
graph_result_t<void> shrink (split_context_t& split_context,
|
||||
unsigned count)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
" Shrinking PairPosFormat2 (%u) to [0, %u).",
|
||||
@@ -502,20 +507,18 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
count);
|
||||
unsigned old_count = class1Count;
|
||||
if (count >= old_count)
|
||||
return true;
|
||||
return Ok();
|
||||
|
||||
graph_t& graph = split_context.c.graph;
|
||||
class1Count = count;
|
||||
graph.vertices_[split_context.this_index].obj.tail -=
|
||||
(old_count - count) * split_context.class1_record_size;
|
||||
graph.vertices_[split_context.this_index].shrink_buffer(
|
||||
(old_count - count) * split_context.class1_record_size);
|
||||
|
||||
auto coverage =
|
||||
graph.as_mutable_table<Coverage> (split_context.this_index, &this->coverage);
|
||||
if (!coverage) return false;
|
||||
TRY_ASSIGN (auto coverage,
|
||||
graph.as_mutable_table<Coverage> (split_context.this_index, &this->coverage));
|
||||
|
||||
auto class_def_1 =
|
||||
graph.as_mutable_table<ClassDef> (split_context.this_index, &classDef1);
|
||||
if (!class_def_1) return false;
|
||||
TRY_ASSIGN (auto class_def_1,
|
||||
graph.as_mutable_table<ClassDef> (split_context.this_index, &classDef1));
|
||||
|
||||
auto klass_map =
|
||||
+ coverage.table->iter ()
|
||||
@@ -528,13 +531,12 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
;
|
||||
|
||||
auto new_coverage = + klass_map | hb_map_retains_sorting (hb_first);
|
||||
if (!Coverage::make_coverage (split_context.c,
|
||||
TRY (Coverage::make_coverage (split_context.c,
|
||||
+ new_coverage,
|
||||
coverage.index,
|
||||
// existing ranges my not be kept, worst case size is a format 1
|
||||
// coverage table.
|
||||
4 + new_coverage.len() * 2))
|
||||
return false;
|
||||
4 + new_coverage.len() * 2));
|
||||
|
||||
return ClassDef::make_class_def (split_context.c,
|
||||
+ klass_map,
|
||||
@@ -542,7 +544,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
class_def_1.vertex->table_size ());
|
||||
}
|
||||
|
||||
hb_hashmap_t<unsigned, unsigned>
|
||||
graph_result_t<hb_hashmap_t<unsigned, unsigned>>
|
||||
get_all_device_tables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index) const
|
||||
{
|
||||
@@ -550,27 +552,28 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
return v.position_to_index_map ();
|
||||
}
|
||||
|
||||
const Coverage* get_coverage (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index) const
|
||||
graph_result_t<const Coverage*> get_coverage (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index) const
|
||||
{
|
||||
unsigned coverage_id = c.graph.index_for_offset (this_index, &coverage);
|
||||
TRY_ASSIGN (unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage));
|
||||
auto& coverage_v = c.graph.vertices_[coverage_id];
|
||||
|
||||
Coverage* coverage_table = (Coverage*) coverage_v.obj.head;
|
||||
if (!coverage_table || !coverage_table->sanitize (coverage_v))
|
||||
return &Null(Coverage);
|
||||
const Coverage* coverage_table = (const Coverage*) coverage_v.obj().head;
|
||||
if (unlikely (!coverage_table)) return Err(INVALID_ARGUMENT);
|
||||
TRY(coverage_table->sanitize (coverage_v));
|
||||
|
||||
return coverage_table;
|
||||
}
|
||||
|
||||
const ClassDef* get_class_def_1 (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index) const
|
||||
graph_result_t<const ClassDef*> get_class_def_1 (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index) const
|
||||
{
|
||||
unsigned class_def_1_id = c.graph.index_for_offset (this_index, &classDef1);
|
||||
TRY_ASSIGN (unsigned class_def_1_id, c.graph.index_for_offset (this_index, &classDef1));
|
||||
auto& class_def_1_v = c.graph.vertices_[class_def_1_id];
|
||||
|
||||
ClassDef* class_def_1_table = (ClassDef*) class_def_1_v.obj.head;
|
||||
if (!class_def_1_table || !class_def_1_table->sanitize (class_def_1_v))
|
||||
return &Null(ClassDef);
|
||||
const ClassDef* class_def_1_table = (const ClassDef*) class_def_1_v.obj().head;
|
||||
if (unlikely (!class_def_1_table)) return Err(INVALID_ARGUMENT);
|
||||
TRY(class_def_1_table->sanitize (class_def_1_v));
|
||||
return class_def_1_table;
|
||||
}
|
||||
|
||||
@@ -587,24 +590,24 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4<SmallType
|
||||
unsigned record_position = ((char*) record) - ((char*) this);
|
||||
unsigned* obj_idx;
|
||||
if (!device_tables.has (record_position, &obj_idx)) continue;
|
||||
size += c.graph.find_subgraph_size (*obj_idx, visited);
|
||||
size += c.graph.find_subgraph_size (*obj_idx, visited).value_or (0);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
unsigned size_of (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
const void* offset) const
|
||||
graph_result_t<unsigned> size_of (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index,
|
||||
const void* offset) const
|
||||
{
|
||||
const unsigned id = c.graph.index_for_offset (this_index, offset);
|
||||
return c.graph.vertices_[id].table_size ();
|
||||
TRY_ASSIGN (const unsigned id, c.graph.index_for_offset (this_index, offset));
|
||||
return Ok(c.graph.vertices_[id].table_size ());
|
||||
}
|
||||
};
|
||||
|
||||
struct PairPos : public OT::Layout::GPOS_impl::PairPos
|
||||
{
|
||||
hb_vector_t<unsigned> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
graph_result_t<hb_vector_t<unsigned>> split_subtables (gsubgpos_graph_context_t& c,
|
||||
unsigned this_index)
|
||||
{
|
||||
switch (u.format.v) {
|
||||
case 1:
|
||||
@@ -619,14 +622,14 @@ struct PairPos : public OT::Layout::GPOS_impl::PairPos
|
||||
// Don't split 24bit PairPos's.
|
||||
#endif
|
||||
default:
|
||||
return hb_vector_t<unsigned> ();
|
||||
return Ok(hb_vector_t<unsigned> ());
|
||||
}
|
||||
}
|
||||
|
||||
bool sanitize (const graph_t::vertex_t& vertex) const
|
||||
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
|
||||
{
|
||||
size_t vertex_len = vertex.obj.tail - vertex.obj.head;
|
||||
if (vertex_len < u.format.v.get_size ()) return false;
|
||||
size_t vertex_len = vertex.table_size();
|
||||
if (unlikely (vertex_len < u.format.v.get_size ())) return Err(SANITIZE_FAILURE);
|
||||
hb_barrier ();
|
||||
|
||||
switch (u.format.v) {
|
||||
@@ -642,7 +645,7 @@ struct PairPos : public OT::Layout::GPOS_impl::PairPos
|
||||
#endif
|
||||
default:
|
||||
// We don't handle format 3 and 4 here.
|
||||
return false;
|
||||
return Err(SANITIZE_FAILURE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+43
-24
@@ -27,6 +27,8 @@
|
||||
#ifndef GRAPH_SERIALIZE_HH
|
||||
#define GRAPH_SERIALIZE_HH
|
||||
|
||||
#include "graph-result.hh"
|
||||
|
||||
namespace graph {
|
||||
|
||||
struct overflow_record_t
|
||||
@@ -104,38 +106,41 @@ bool is_valid_offset (int64_t offset,
|
||||
/*
|
||||
* Will any offsets overflow on graph when it's serialized?
|
||||
*/
|
||||
inline bool
|
||||
inline graph_result_t<bool>
|
||||
will_overflow (graph_t& graph,
|
||||
hb_vector_t<overflow_record_t>* overflows = nullptr)
|
||||
{
|
||||
if (overflows) overflows->clear ();
|
||||
graph.update_positions ();
|
||||
|
||||
hb_hashmap_t<overflow_record_t*, bool> record_set;
|
||||
hb_hashmap_t<overflow_record_t, bool> record_set;
|
||||
const auto& vertices = graph.vertices_;
|
||||
for (unsigned parent_idx : graph.ordering_)
|
||||
{
|
||||
// Don't need to check virtual links for overflow
|
||||
for (const auto& link : vertices.arrayZ[parent_idx].obj.real_links)
|
||||
for (const auto& link : vertices.arrayZ[parent_idx].obj ().real_links)
|
||||
{
|
||||
int64_t offset = compute_offset (graph, parent_idx, link);
|
||||
if (likely (is_valid_offset (offset, link)))
|
||||
continue;
|
||||
|
||||
if (!overflows) return true;
|
||||
if (!overflows) return Ok(true);
|
||||
|
||||
overflow_record_t r;
|
||||
r.parent = parent_idx;
|
||||
r.child = link.objidx;
|
||||
if (record_set.has(&r)) continue; // don't keep duplicate overflows.
|
||||
if (record_set.has(r)) continue; // don't keep duplicate overflows.
|
||||
|
||||
overflows->push (r);
|
||||
record_set.set(&r, true);
|
||||
record_set.set (r, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!overflows) return false;
|
||||
return overflows->length;
|
||||
TRY (graph_result_t<void>::from (record_set, ALLOCATION_FAILURE));
|
||||
if (overflows)
|
||||
TRY (graph_result_t<void>::from (*overflows, ALLOCATION_FAILURE));
|
||||
|
||||
return Ok((bool) (overflows && overflows->length));
|
||||
}
|
||||
|
||||
inline
|
||||
@@ -144,7 +149,13 @@ void print_overflows (graph_t& graph,
|
||||
{
|
||||
if (!DEBUG_ENABLED(SUBSET_REPACK)) return;
|
||||
|
||||
graph.update_parents ();
|
||||
auto r = graph.update_parents ();
|
||||
if (r.is_err()) {
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Unable to print overflows due to error updating parent links: %s",
|
||||
to_string(r.error()));
|
||||
return;
|
||||
}
|
||||
|
||||
int limit = 10;
|
||||
for (const auto& o : overflows)
|
||||
{
|
||||
@@ -157,11 +168,11 @@ void print_overflows (graph_t& graph,
|
||||
"%4u (%4u in, %4u out, space %2u)",
|
||||
o.parent,
|
||||
parent.incoming_edges (),
|
||||
parent.obj.real_links.length + parent.obj.virtual_links.length,
|
||||
parent.obj ().real_links.length + parent.obj ().virtual_links.length,
|
||||
graph.space_for (o.parent),
|
||||
o.child,
|
||||
child.incoming_edges (),
|
||||
child.obj.real_links.length + child.obj.virtual_links.length,
|
||||
child.obj ().real_links.length + child.obj ().virtual_links.length,
|
||||
graph.space_for (o.child));
|
||||
}
|
||||
if (overflows.length > 10) {
|
||||
@@ -231,16 +242,16 @@ void serialize_link (const hb_serialize_context_t::object_t::link_t& link,
|
||||
/*
|
||||
* serialize graph into the provided serialization buffer.
|
||||
*/
|
||||
inline hb_blob_t* serialize (const graph_t& graph)
|
||||
inline graph_result_t<hb_blob_t*> serialize (const graph_t& graph)
|
||||
{
|
||||
hb_vector_t<char> buffer;
|
||||
size_t size = graph.total_size_in_bytes ();
|
||||
|
||||
if (!size) return hb_blob_get_empty ();
|
||||
if (!size) return Ok(hb_blob_get_empty ());
|
||||
|
||||
if (!buffer.alloc (size)) {
|
||||
if (unlikely (!buffer.alloc (size))) {
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Unable to allocate output buffer.");
|
||||
return nullptr;
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
}
|
||||
hb_serialize_context_t c((void *) buffer, size);
|
||||
|
||||
@@ -252,25 +263,29 @@ inline hb_blob_t* serialize (const graph_t& graph)
|
||||
|
||||
// Maps from our obj id's to the id's used during this serialization.
|
||||
hb_vector_t<unsigned> id_map;
|
||||
id_map.resize(graph.ordering_.length);
|
||||
if (unlikely (!id_map.resize(graph.ordering_.length))) {
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Unable to allocate id_map buffer.");
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
}
|
||||
|
||||
for (int pos = graph.ordering_.length - 1; pos >= 0; pos--) {
|
||||
unsigned i = graph.ordering_[pos];
|
||||
c.push ();
|
||||
|
||||
auto& v = vertices[i];
|
||||
|
||||
size_t size = v.obj.tail - v.obj.head;
|
||||
size_t size = v.table_size ();
|
||||
|
||||
char* start = c.allocate_size <char> (size);
|
||||
if (!start) {
|
||||
if (unlikely (!start)) {
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Buffer out of space.");
|
||||
return nullptr;
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
}
|
||||
|
||||
hb_memcpy (start, v.obj.head, size);
|
||||
hb_memcpy (start, v.obj ().head, size);
|
||||
|
||||
// Only real links needs to be serialized.
|
||||
for (const auto& link : v.obj.real_links)
|
||||
for (const auto& link : v.obj ().real_links)
|
||||
serialize_link (link, start, size, id_map, &c);
|
||||
|
||||
// All duplications are already encoded in the graph, so don't
|
||||
@@ -279,13 +294,17 @@ inline hb_blob_t* serialize (const graph_t& graph)
|
||||
}
|
||||
c.end_serialize ();
|
||||
|
||||
if (c.in_error ()) {
|
||||
if (unlikely (c.in_error ())) {
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Error during serialization. Err flag: %d",
|
||||
c.errors);
|
||||
return nullptr;
|
||||
if (c.errors & HB_SERIALIZE_ERROR_OFFSET_OVERFLOW)
|
||||
return Err(OVERFLOW_RESOLUTION_FAILED);
|
||||
return Err(ALLOCATION_FAILURE);
|
||||
}
|
||||
|
||||
return c.copy_blob ();
|
||||
auto* blob = c.copy_blob ();
|
||||
if (unlikely (!blob)) return Err(ALLOCATION_FAILURE);
|
||||
return Ok(blob);
|
||||
}
|
||||
|
||||
} // namespace graph
|
||||
|
||||
@@ -27,16 +27,18 @@
|
||||
#ifndef GRAPH_SPLIT_HELPERS_HH
|
||||
#define GRAPH_SPLIT_HELPERS_HH
|
||||
|
||||
#include "graph-result.hh"
|
||||
|
||||
namespace graph {
|
||||
|
||||
template<typename Context>
|
||||
HB_INTERNAL
|
||||
hb_vector_t<unsigned> actuate_subtable_split (Context& split_context,
|
||||
const hb_vector_t<unsigned>& split_points)
|
||||
graph_result_t<hb_vector_t<unsigned>> actuate_subtable_split (Context& split_context,
|
||||
const hb_vector_t<unsigned>& split_points)
|
||||
{
|
||||
hb_vector_t<unsigned> new_objects;
|
||||
if (!split_points)
|
||||
return new_objects;
|
||||
return Ok(new_objects);
|
||||
|
||||
for (unsigned i = 0; i < split_points.length; i++)
|
||||
{
|
||||
@@ -44,24 +46,14 @@ hb_vector_t<unsigned> actuate_subtable_split (Context& split_context,
|
||||
unsigned end = (i < split_points.length - 1)
|
||||
? split_points[i + 1]
|
||||
: split_context.original_count ();
|
||||
unsigned id = split_context.clone_range (start, end);
|
||||
|
||||
if (id == (unsigned) -1)
|
||||
{
|
||||
new_objects.reset ();
|
||||
new_objects.ensure_error ();
|
||||
return new_objects;
|
||||
}
|
||||
TRY_ASSIGN (unsigned id, split_context.clone_range (start, end));
|
||||
new_objects.push (id);
|
||||
TRY (graph_result_t<void>::from (new_objects, ALLOCATION_FAILURE));
|
||||
}
|
||||
|
||||
if (!split_context.shrink (split_points[0]))
|
||||
{
|
||||
new_objects.reset ();
|
||||
new_objects.ensure_error ();
|
||||
}
|
||||
TRY (split_context.shrink (split_points[0]));
|
||||
|
||||
return new_objects;
|
||||
return Ok(new_objects);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ static HB_UNUSED bool check_add_class_def_size(graph::class_def_size_estimator_t
|
||||
|
||||
static HB_UNUSED bool check_add_class_def_size (const gid_and_class_list_t& list, unsigned klass)
|
||||
{
|
||||
graph::class_def_size_estimator_t estimator (list.iter ());
|
||||
graph::class_def_size_estimator_t estimator = *graph::class_def_size_estimator_t::create (list.iter ());
|
||||
|
||||
unsigned result = estimator.add_class_def_size (klass);
|
||||
auto filtered_it =
|
||||
@@ -228,7 +228,7 @@ static void test_running_class_and_coverage_size_estimates () {
|
||||
{12, 3},
|
||||
};
|
||||
|
||||
graph::class_def_size_estimator_t estimator1(consecutive_map.iter());
|
||||
graph::class_def_size_estimator_t estimator1 = *graph::class_def_size_estimator_t::create (consecutive_map.iter());
|
||||
hb_always_assert(check_add_class_def_size(estimator1, consecutive_map, 1, {1}));
|
||||
hb_always_assert(check_add_class_def_size(estimator1, consecutive_map, 2, {1, 2}));
|
||||
hb_always_assert(check_add_class_def_size(estimator1, consecutive_map, 2, {1, 2})); // check that adding the same class again works
|
||||
@@ -260,7 +260,7 @@ static void test_running_class_and_coverage_size_estimates () {
|
||||
{15, 3},
|
||||
};
|
||||
|
||||
graph::class_def_size_estimator_t estimator2(non_consecutive_map.iter());
|
||||
graph::class_def_size_estimator_t estimator2 = *graph::class_def_size_estimator_t::create (non_consecutive_map.iter());
|
||||
hb_always_assert(check_add_class_def_size(estimator2, non_consecutive_map, 1, {1}));
|
||||
hb_always_assert(check_add_class_def_size(estimator2, non_consecutive_map, 2, {1, 2}));
|
||||
hb_always_assert(check_add_class_def_size(estimator2, non_consecutive_map, 3, {1, 2, 3}));
|
||||
@@ -277,7 +277,7 @@ static void test_running_class_size_estimates_with_locally_consecutive_glyphs ()
|
||||
{7, 3},
|
||||
};
|
||||
|
||||
graph::class_def_size_estimator_t estimator(map.iter());
|
||||
graph::class_def_size_estimator_t estimator = *graph::class_def_size_estimator_t::create (map.iter());
|
||||
hb_always_assert(check_add_class_def_size(estimator, map, 1, {1}));
|
||||
hb_always_assert(check_add_class_def_size(estimator, map, 2, {1, 2}));
|
||||
hb_always_assert(check_add_class_def_size(estimator, map, 3, {1, 2, 3}));
|
||||
|
||||
+107
-9
@@ -31,7 +31,6 @@
|
||||
#include "hb.hh"
|
||||
#include "hb-bit-page.hh"
|
||||
|
||||
|
||||
struct hb_bit_set_t
|
||||
{
|
||||
hb_bit_set_t () = default;
|
||||
@@ -827,13 +826,62 @@ struct hb_bit_set_t
|
||||
return false;
|
||||
}
|
||||
|
||||
/* TODO Speed up. */
|
||||
*last = *first = i;
|
||||
while (next (&i) && i == *last + 1)
|
||||
(*last)++;
|
||||
|
||||
return true;
|
||||
const auto* page_map_array = page_map.arrayZ;
|
||||
const auto* pages_array = pages.arrayZ;
|
||||
unsigned int major = get_major (*last);
|
||||
unsigned int p_index = last_page_lookup;
|
||||
|
||||
if (unlikely (p_index >= page_map.length || page_map_array[p_index].major != major))
|
||||
{
|
||||
page_map.bfind (major, &p_index, HB_NOT_FOUND_STORE_CLOSEST);
|
||||
// The above next() call gaurantees the page we're looking for exists.
|
||||
assert(p_index < page_map.length && page_map_array[p_index].major == major);
|
||||
last_page_lookup = p_index;
|
||||
}
|
||||
|
||||
unsigned int rem = page_remainder (*last);
|
||||
unsigned int elt = rem / page_t::ELT_BITS;
|
||||
unsigned int bit = rem & page_t::ELT_MASK;
|
||||
|
||||
const page_t *page = &pages_array[page_map_array[p_index].index];
|
||||
unsigned int run = hb_ctz (~(page->v[elt] >> bit));
|
||||
*last += run - 1;
|
||||
if (run < page_t::ELT_BITS - bit)
|
||||
return true;
|
||||
|
||||
elt++;
|
||||
|
||||
while (true)
|
||||
{
|
||||
for (; elt < page_t::len (); elt++)
|
||||
{
|
||||
uint64_t w = page->v[elt];
|
||||
if (w == (uint64_t) -1)
|
||||
{
|
||||
*last += page_t::ELT_BITS;
|
||||
continue;
|
||||
}
|
||||
uint64_t inv = ~w;
|
||||
*last += hb_ctz (inv);
|
||||
return true;
|
||||
}
|
||||
|
||||
p_index++;
|
||||
|
||||
|
||||
if (p_index >= page_map.length || page_map_array[p_index].major != major + 1)
|
||||
return true;
|
||||
|
||||
const auto& entry = page_map_array[p_index];
|
||||
major = entry.major;
|
||||
last_page_lookup = p_index;
|
||||
page = &pages_array[entry.index];
|
||||
elt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool previous_range (hb_codepoint_t *first, hb_codepoint_t *last) const
|
||||
{
|
||||
hb_codepoint_t i;
|
||||
@@ -845,12 +893,62 @@ struct hb_bit_set_t
|
||||
return false;
|
||||
}
|
||||
|
||||
/* TODO Speed up. */
|
||||
*last = *first = i;
|
||||
while (previous (&i) && i == *first - 1)
|
||||
(*first)--;
|
||||
|
||||
return true;
|
||||
const auto* page_map_array = page_map.arrayZ;
|
||||
const auto* pages_array = pages.arrayZ;
|
||||
unsigned int major = get_major (*first);
|
||||
unsigned int p_index = last_page_lookup;
|
||||
|
||||
if (unlikely (p_index >= page_map.length || page_map_array[p_index].major != major))
|
||||
{
|
||||
page_map.bfind (major, &p_index, HB_NOT_FOUND_STORE_CLOSEST);
|
||||
// The above previous() call gaurantees the page we're looking for exists.
|
||||
assert(p_index < page_map.length && page_map_array[p_index].major == major);
|
||||
last_page_lookup = p_index;
|
||||
}
|
||||
|
||||
unsigned int rem = page_remainder (*first);
|
||||
int elt = rem / page_t::ELT_BITS;
|
||||
unsigned int bit = rem & page_t::ELT_MASK;
|
||||
|
||||
const page_t *page = &pages_array[page_map_array[p_index].index];
|
||||
uint64_t inv = ~(page->v[elt] << (63 - bit));
|
||||
unsigned int run = hb_bit_storage (inv) ? (page_t::ELT_BITS - hb_bit_storage (inv)) : page_t::ELT_BITS;
|
||||
*first -= run - 1;
|
||||
if (run < bit + 1)
|
||||
return true;
|
||||
|
||||
elt--;
|
||||
|
||||
while (true)
|
||||
{
|
||||
for (; elt >= 0; elt--)
|
||||
{
|
||||
uint64_t w = page->v[elt];
|
||||
if (w == (uint64_t) -1)
|
||||
{
|
||||
*first -= page_t::ELT_BITS;
|
||||
continue;
|
||||
}
|
||||
uint64_t inv = ~w;
|
||||
unsigned int zeros = hb_bit_storage (inv) ? (page_t::ELT_BITS - hb_bit_storage (inv)) : page_t::ELT_BITS;
|
||||
*first -= zeros;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (p_index == 0 || page_map_array[p_index - 1].major != major - 1)
|
||||
return true;
|
||||
|
||||
p_index--;
|
||||
const auto& entry = page_map_array[p_index];
|
||||
|
||||
major = entry.major;
|
||||
last_page_lookup = p_index;
|
||||
page = &pages_array[entry.index];
|
||||
elt = page_t::len () - 1;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int next_many (hb_codepoint_t codepoint,
|
||||
|
||||
@@ -385,11 +385,6 @@ struct hb_buffer_t
|
||||
}
|
||||
/* Advance idx without copying to output. */
|
||||
void skip_glyph () { idx++; }
|
||||
void reset_masks (hb_mask_t mask)
|
||||
{
|
||||
for (unsigned int j = 0; j < len; j++)
|
||||
info[j].mask = mask;
|
||||
}
|
||||
void add_masks (hb_mask_t mask)
|
||||
{
|
||||
for (unsigned int j = 0; j < len; j++)
|
||||
|
||||
+58
-2
@@ -31,12 +31,68 @@
|
||||
#include "hb-cairo.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
struct hb_cairo_budget_t
|
||||
{
|
||||
/* Cairo serializes glyph-cache population for a scaled font. Keeping the
|
||||
* owner there lets recursive color-glyph callbacks share one session. */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
unsigned int active = 0;
|
||||
|
||||
void enter ()
|
||||
{
|
||||
if (!active++)
|
||||
recharge ();
|
||||
}
|
||||
|
||||
void leave ()
|
||||
{
|
||||
assert (active);
|
||||
active--;
|
||||
}
|
||||
|
||||
void recharge ()
|
||||
{
|
||||
budget_remaining = budget == HB_BUDGET_DEFAULT ?
|
||||
HB_BUDGET_GLYPH : budget;
|
||||
}
|
||||
};
|
||||
|
||||
struct hb_cairo_context_t
|
||||
{
|
||||
hb_cairo_context_t (cairo_scaled_font_t *scaled_font_,
|
||||
cairo_t *cr_,
|
||||
hb_map_t *color_cache_,
|
||||
hb_cairo_budget_t *budget_) :
|
||||
scaled_font (scaled_font_), cr (cr_), color_cache (color_cache_),
|
||||
budget (budget_)
|
||||
{
|
||||
budget->enter ();
|
||||
}
|
||||
|
||||
~hb_cairo_context_t ()
|
||||
{
|
||||
budget->leave ();
|
||||
}
|
||||
|
||||
bool set_budget (int64_t value)
|
||||
{
|
||||
budget->budget = value;
|
||||
budget->recharge ();
|
||||
return true;
|
||||
}
|
||||
|
||||
int64_t get_budget () const { return budget->budget; }
|
||||
int64_t *get_budget_remaining () { return &budget->budget_remaining; }
|
||||
|
||||
bool spend (unsigned int cost, unsigned int mult = 1)
|
||||
{ return hb_budget_spend (budget->budget_remaining, cost, mult); }
|
||||
|
||||
cairo_scaled_font_t *scaled_font;
|
||||
cairo_t *cr;
|
||||
hb_map_t *color_cache;
|
||||
} hb_cairo_context_t;
|
||||
hb_cairo_budget_t *budget;
|
||||
};
|
||||
|
||||
static inline cairo_operator_t
|
||||
_hb_paint_composite_mode_to_cairo (hb_paint_composite_mode_t mode)
|
||||
|
||||
+114
-16
@@ -54,9 +54,11 @@ hb_cairo_move_to (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
cairo_t *cr = (cairo_t *) draw_data;
|
||||
hb_cairo_context_t *c = (hb_cairo_context_t *) draw_data;
|
||||
if (unlikely (!c->spend (HB_BUDGET_1)))
|
||||
return;
|
||||
|
||||
cairo_move_to (cr, (double) to_x, (double) to_y);
|
||||
cairo_move_to (c->cr, (double) to_x, (double) to_y);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -66,9 +68,11 @@ hb_cairo_line_to (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
cairo_t *cr = (cairo_t *) draw_data;
|
||||
hb_cairo_context_t *c = (hb_cairo_context_t *) draw_data;
|
||||
if (unlikely (!c->spend (HB_BUDGET_1)))
|
||||
return;
|
||||
|
||||
cairo_line_to (cr, (double) to_x, (double) to_y);
|
||||
cairo_line_to (c->cr, (double) to_x, (double) to_y);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -80,9 +84,11 @@ hb_cairo_cubic_to (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
cairo_t *cr = (cairo_t *) draw_data;
|
||||
hb_cairo_context_t *c = (hb_cairo_context_t *) draw_data;
|
||||
if (unlikely (!c->spend (HB_BUDGET_1)))
|
||||
return;
|
||||
|
||||
cairo_curve_to (cr,
|
||||
cairo_curve_to (c->cr,
|
||||
(double) control1_x, (double) control1_y,
|
||||
(double) control2_x, (double) control2_y,
|
||||
(double) to_x, (double) to_y);
|
||||
@@ -94,9 +100,36 @@ hb_cairo_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
hb_draw_state_t *st HB_UNUSED,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
cairo_t *cr = (cairo_t *) draw_data;
|
||||
hb_cairo_context_t *c = (hb_cairo_context_t *) draw_data;
|
||||
if (unlikely (!c->spend (HB_BUDGET_1)))
|
||||
return;
|
||||
|
||||
cairo_close_path (cr);
|
||||
cairo_close_path (c->cr);
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_cairo_draw_set_budget (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *draw_data,
|
||||
int64_t budget,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return ((hb_cairo_context_t *) draw_data)->set_budget (budget);
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_cairo_draw_get_budget (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *draw_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return ((hb_cairo_context_t *) draw_data)->get_budget ();
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_cairo_draw_get_budget_remaining (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *draw_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return ((hb_cairo_context_t *) draw_data)->get_budget_remaining ();
|
||||
}
|
||||
|
||||
static inline void free_static_cairo_draw_funcs ();
|
||||
@@ -111,6 +144,9 @@ static struct hb_cairo_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t<hb
|
||||
hb_draw_funcs_set_line_to_func (funcs, hb_cairo_line_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, hb_cairo_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, hb_cairo_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_set_budget_func (funcs, hb_cairo_draw_set_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_func (funcs, hb_cairo_draw_get_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_cairo_draw_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
|
||||
@@ -181,7 +217,7 @@ hb_cairo_fill_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
cairo_save (cr);
|
||||
|
||||
cairo_new_path (cr);
|
||||
hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), cr);
|
||||
hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), c);
|
||||
cairo_close_path (cr);
|
||||
_hb_cairo_set_source_color (c, use_foreground, color);
|
||||
cairo_fill (cr);
|
||||
@@ -199,6 +235,9 @@ hb_cairo_paint_color_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
hb_cairo_context_t *c = (hb_cairo_context_t *) paint_data;
|
||||
cairo_t *cr = c->cr;
|
||||
|
||||
if (unlikely (!c->spend (HB_BUDGET_1)))
|
||||
return true;
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
hb_position_t x_scale, y_scale;
|
||||
@@ -228,7 +267,7 @@ hb_cairo_push_clip_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
cairo_save (cr);
|
||||
cairo_new_path (cr);
|
||||
|
||||
hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), cr);
|
||||
hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), c);
|
||||
|
||||
cairo_close_path (cr);
|
||||
cairo_clip (cr);
|
||||
@@ -261,7 +300,7 @@ hb_cairo_push_clip_path_start (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
|
||||
cairo_save (cr);
|
||||
cairo_new_path (cr);
|
||||
*draw_data = cr;
|
||||
*draw_data = c;
|
||||
return hb_cairo_draw_get_funcs ();
|
||||
}
|
||||
|
||||
@@ -449,6 +488,31 @@ hb_cairo_paint_custom_palette_color (hb_paint_funcs_t *funcs,
|
||||
return false;
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_cairo_paint_set_budget (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
void *paint_data,
|
||||
int64_t budget,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return ((hb_cairo_context_t *) paint_data)->set_budget (budget);
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_cairo_paint_get_budget (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
void *paint_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return ((hb_cairo_context_t *) paint_data)->get_budget ();
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_cairo_paint_get_budget_remaining (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
void *paint_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return ((hb_cairo_context_t *) paint_data)->get_budget_remaining ();
|
||||
}
|
||||
|
||||
static inline void free_static_cairo_paint_funcs ();
|
||||
|
||||
static struct hb_cairo_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t<hb_cairo_paint_funcs_lazy_loader_t>
|
||||
@@ -474,6 +538,9 @@ static struct hb_cairo_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t<
|
||||
hb_paint_funcs_set_radial_gradient_func (funcs, hb_cairo_paint_radial_gradient, nullptr, nullptr);
|
||||
hb_paint_funcs_set_sweep_gradient_func (funcs, hb_cairo_paint_sweep_gradient, nullptr, nullptr);
|
||||
hb_paint_funcs_set_custom_palette_color_func (funcs, hb_cairo_paint_custom_palette_color, nullptr, nullptr);
|
||||
hb_paint_funcs_set_set_budget_func (funcs, hb_cairo_paint_set_budget, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_func (funcs, hb_cairo_paint_get_budget, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_cairo_paint_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_paint_funcs_make_immutable (funcs);
|
||||
|
||||
@@ -501,9 +568,17 @@ static const cairo_user_data_key_t hb_cairo_font_user_data_key = {0};
|
||||
static const cairo_user_data_key_t hb_cairo_font_init_func_user_data_key = {0};
|
||||
static const cairo_user_data_key_t hb_cairo_font_init_user_data_user_data_key = {0};
|
||||
static const cairo_user_data_key_t hb_cairo_scale_factor_user_data_key = {0};
|
||||
static const cairo_user_data_key_t hb_cairo_budget_user_data_key = {0};
|
||||
|
||||
static void hb_cairo_face_destroy (void *p) { hb_face_destroy ((hb_face_t *) p); }
|
||||
static void hb_cairo_font_destroy (void *p) { hb_font_destroy ((hb_font_t *) p); }
|
||||
static void
|
||||
hb_cairo_budget_destroy (void *p)
|
||||
{
|
||||
hb_cairo_budget_t *budget = (hb_cairo_budget_t *) p;
|
||||
budget->~hb_cairo_budget_t ();
|
||||
hb_free (budget);
|
||||
}
|
||||
|
||||
static cairo_status_t
|
||||
hb_cairo_init_scaled_font (cairo_scaled_font_t *scaled_font,
|
||||
@@ -571,6 +646,20 @@ hb_cairo_init_scaled_font (cairo_scaled_font_t *scaled_font,
|
||||
(void *) hb_font_reference (font),
|
||||
hb_cairo_font_destroy);
|
||||
|
||||
hb_cairo_budget_t *budget = (hb_cairo_budget_t *) hb_malloc (sizeof (hb_cairo_budget_t));
|
||||
if (unlikely (!budget))
|
||||
return CAIRO_STATUS_NO_MEMORY;
|
||||
new (budget) hb_cairo_budget_t ();
|
||||
cairo_status_t status = cairo_scaled_font_set_user_data (scaled_font,
|
||||
&hb_cairo_budget_user_data_key,
|
||||
budget,
|
||||
hb_cairo_budget_destroy);
|
||||
if (unlikely (status != CAIRO_STATUS_SUCCESS))
|
||||
{
|
||||
hb_cairo_budget_destroy (budget);
|
||||
return status;
|
||||
}
|
||||
|
||||
hb_position_t x_scale, y_scale;
|
||||
hb_font_get_scale (font, &x_scale, &y_scale);
|
||||
|
||||
@@ -636,6 +725,11 @@ hb_cairo_render_glyph (cairo_scaled_font_t *scaled_font,
|
||||
{
|
||||
hb_font_t *font = (hb_font_t *) cairo_scaled_font_get_user_data (scaled_font,
|
||||
&hb_cairo_font_user_data_key);
|
||||
hb_cairo_budget_t *budget = (hb_cairo_budget_t *) cairo_scaled_font_get_user_data (scaled_font,
|
||||
&hb_cairo_budget_user_data_key);
|
||||
if (unlikely (!budget))
|
||||
return CAIRO_STATUS_NO_MEMORY;
|
||||
hb_cairo_context_t c {scaled_font, cr, nullptr, budget};
|
||||
|
||||
hb_position_t x_scale, y_scale;
|
||||
hb_font_get_scale (font, &x_scale, &y_scale);
|
||||
@@ -643,7 +737,7 @@ hb_cairo_render_glyph (cairo_scaled_font_t *scaled_font,
|
||||
cairo_scale (cr,
|
||||
+1. / (x_scale ? x_scale : 1),
|
||||
-1. / (y_scale ? y_scale : 1));
|
||||
if (hb_font_draw_glyph_or_fail (font, glyph, hb_cairo_draw_get_funcs (), cr))
|
||||
if (hb_font_draw_glyph_or_fail (font, glyph, hb_cairo_draw_get_funcs (), &c))
|
||||
cairo_fill (cr);
|
||||
|
||||
// If draw fails, we still return SUCCESS, as we want empty drawing, not
|
||||
@@ -661,6 +755,10 @@ hb_cairo_render_color_glyph (cairo_scaled_font_t *scaled_font,
|
||||
{
|
||||
hb_font_t *font = (hb_font_t *) cairo_scaled_font_get_user_data (scaled_font,
|
||||
&hb_cairo_font_user_data_key);
|
||||
hb_cairo_budget_t *budget = (hb_cairo_budget_t *) cairo_scaled_font_get_user_data (scaled_font,
|
||||
&hb_cairo_budget_user_data_key);
|
||||
if (unlikely (!budget))
|
||||
return CAIRO_STATUS_NO_MEMORY;
|
||||
|
||||
unsigned int palette = 0;
|
||||
#ifdef CAIRO_COLOR_PALETTE_DEFAULT
|
||||
@@ -677,10 +775,10 @@ hb_cairo_render_color_glyph (cairo_scaled_font_t *scaled_font,
|
||||
+1. / (x_scale ? x_scale : 1),
|
||||
-1. / (y_scale ? y_scale : 1));
|
||||
|
||||
hb_cairo_context_t c;
|
||||
c.scaled_font = scaled_font;
|
||||
c.cr = cr;
|
||||
c.color_cache = (hb_map_t *) cairo_scaled_font_get_user_data (scaled_font, &color_cache_key);
|
||||
hb_cairo_context_t c {scaled_font,
|
||||
cr,
|
||||
(hb_map_t *) cairo_scaled_font_get_user_data (scaled_font, &color_cache_key),
|
||||
budget};
|
||||
|
||||
/* Synthesizing variant: mono glyphs render here too via the
|
||||
* fill_glyph foreground fallback inside hb_font_paint_glyph.
|
||||
|
||||
@@ -121,6 +121,7 @@ struct cs_interp_env_t : interp_env_t<ARG>
|
||||
hstem_count = 0;
|
||||
vstem_count = 0;
|
||||
hintmask_size = 0;
|
||||
budget = nullptr;
|
||||
pt.set_int (0, 0);
|
||||
globalSubrs.init (globalSubrs_);
|
||||
localSubrs.init (localSubrs_);
|
||||
@@ -186,6 +187,11 @@ struct cs_interp_env_t : interp_env_t<ARG>
|
||||
void set_endchar (bool endchar_flag_) { endchar_flag = endchar_flag_; }
|
||||
bool is_endchar () const { return endchar_flag; }
|
||||
|
||||
void set_budget (int64_t *budget_) { budget = budget_; }
|
||||
int64_t *get_budget () const { return budget; }
|
||||
bool spend_budget (unsigned int cost, unsigned int mult = 1)
|
||||
{ return !budget || hb_budget_spend (*budget, cost, mult); }
|
||||
|
||||
const number_t &get_x () const { return pt.x; }
|
||||
const number_t &get_y () const { return pt.y; }
|
||||
const point_t &get_pt () const { return pt; }
|
||||
@@ -201,6 +207,7 @@ struct cs_interp_env_t : interp_env_t<ARG>
|
||||
unsigned int hstem_count;
|
||||
unsigned int vstem_count;
|
||||
unsigned int hintmask_size;
|
||||
int64_t *budget;
|
||||
call_stack_t callStack;
|
||||
biased_subrs_t<SUBRS> globalSubrs;
|
||||
biased_subrs_t<SUBRS> localSubrs;
|
||||
@@ -880,22 +887,39 @@ struct cs_interpreter_t : interpreter_t<ENV>
|
||||
bool interpret (PARAM& param, int64_t *budget = nullptr)
|
||||
{
|
||||
SUPER::env.set_endchar (false);
|
||||
SUPER::env.set_budget (budget);
|
||||
|
||||
/* Cap the operator count by the caller's remaining budget so the single
|
||||
* max_ops counter enforces both the structural limit and the live work
|
||||
* budget, with no budget check in the hot loop. The consumed operators
|
||||
* are charged back after the loop, and since the cap never exceeds the
|
||||
* remaining budget the charstring cannot overshoot it. CFF2 blend
|
||||
* charges its proportional work separately, in place. */
|
||||
int64_t remaining = budget ? *budget : (int64_t) HB_CFF_MAX_OPS;
|
||||
unsigned max_ops = (unsigned) hb_clamp (remaining, (int64_t) 0, (int64_t) HB_CFF_MAX_OPS);
|
||||
unsigned start_ops = max_ops;
|
||||
|
||||
bool ret = true;
|
||||
unsigned max_ops = HB_CFF_MAX_OPS;
|
||||
for (;;) {
|
||||
OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param);
|
||||
if (unlikely (SUPER::env.in_error () || !--max_ops))
|
||||
{
|
||||
SUPER::env.set_error ();
|
||||
ret = false;
|
||||
break;
|
||||
if (likely (max_ops))
|
||||
for (;;) {
|
||||
OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param);
|
||||
if (unlikely (SUPER::env.in_error () || !--max_ops))
|
||||
{
|
||||
SUPER::env.set_error ();
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
if (SUPER::env.is_endchar ())
|
||||
break;
|
||||
}
|
||||
if (SUPER::env.is_endchar ())
|
||||
break;
|
||||
else
|
||||
{
|
||||
SUPER::env.set_error ();
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (budget) *budget -= (int64_t) (HB_CFF_MAX_OPS - max_ops);
|
||||
if (budget) *budget -= (int64_t) (start_ops - max_ops);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -305,6 +305,11 @@ struct cff2_cs_opset_t : cs_opset_t<ELEM, OPSET, cff2_cs_interp_env_t<ELEM>, PAR
|
||||
env.set_error ();
|
||||
return;
|
||||
}
|
||||
if (unlikely (!env.spend_budget (HB_BUDGET_1, total - n)))
|
||||
{
|
||||
env.set_error ();
|
||||
return;
|
||||
}
|
||||
unsigned int start = count - total;
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
{
|
||||
|
||||
+2
-8
@@ -433,14 +433,8 @@ hb_script_from_iso15924_tag (hb_tag_t tag)
|
||||
/* Be lenient, adjust case (one capital letter followed by three small letters) */
|
||||
tag = (tag & 0xDFDFDFDFu) | 0x00202020u;
|
||||
|
||||
switch (tag) {
|
||||
|
||||
/* These graduated from the 'Q' private-area codes, but
|
||||
* the old code is still aliased by Unicode, and the Qaai
|
||||
* one in use by ICU. */
|
||||
case HB_TAG('Q','a','a','i'): return HB_SCRIPT_INHERITED;
|
||||
case HB_TAG('Q','a','a','c'): return HB_SCRIPT_COPTIC;
|
||||
|
||||
switch (tag)
|
||||
{
|
||||
/* Script variants from https://unicode.org/iso15924/ */
|
||||
case HB_TAG('A','r','a','n'): return HB_SCRIPT_ARABIC;
|
||||
case HB_TAG('C','y','r','s'): return HB_SCRIPT_CYRILLIC;
|
||||
|
||||
@@ -94,6 +94,25 @@ HB_BEGIN_DECLS
|
||||
**/
|
||||
typedef int hb_bool_t;
|
||||
|
||||
/**
|
||||
* HB_BUDGET_DEFAULT:
|
||||
*
|
||||
* Use the implementation's finite default work budget.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
#define HB_BUDGET_DEFAULT ((int64_t) (-0x7FFFFFFFFFFFFFFF - 1))
|
||||
|
||||
/**
|
||||
* HB_BUDGET_UNLIMITED:
|
||||
*
|
||||
* Use an effectively unlimited work budget. Structural safety limits remain
|
||||
* active.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
#define HB_BUDGET_UNLIMITED ((int64_t) 0x7FFFFFFFFFFFFFFF)
|
||||
|
||||
/**
|
||||
* hb_codepoint_t:
|
||||
*
|
||||
|
||||
@@ -96,6 +96,19 @@ hb_draw_close_path_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UN
|
||||
hb_draw_state_t *st HB_UNUSED,
|
||||
void *user_data HB_UNUSED) {}
|
||||
|
||||
static hb_bool_t
|
||||
hb_draw_set_budget_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
|
||||
int64_t budget HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return false; }
|
||||
|
||||
static int64_t
|
||||
hb_draw_get_budget_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return HB_BUDGET_DEFAULT; }
|
||||
|
||||
static int64_t *
|
||||
hb_draw_get_budget_remaining_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return nullptr; }
|
||||
|
||||
|
||||
static bool
|
||||
_hb_draw_funcs_set_preamble (hb_draw_funcs_t *dfuncs,
|
||||
@@ -355,6 +368,67 @@ hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs)
|
||||
return hb_object_is_immutable (dfuncs);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_draw_set_budget:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: associated draw data
|
||||
* @budget: the new work-budget policy
|
||||
*
|
||||
* Sets the work-budget policy and recharges the live work budget. Negative
|
||||
* values other than #HB_BUDGET_DEFAULT are clamped to zero.
|
||||
*
|
||||
* Return value: `true` if the draw functions support work budgets
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
hb_bool_t
|
||||
hb_draw_set_budget (hb_draw_funcs_t *dfuncs, void *draw_data, int64_t budget)
|
||||
{
|
||||
return dfuncs->set_budget (draw_data, budget);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_draw_get_budget:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: associated draw data
|
||||
*
|
||||
* Fetches the configured work-budget policy.
|
||||
*
|
||||
* Return value: the configured policy, or #HB_BUDGET_DEFAULT if unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
int64_t
|
||||
hb_draw_get_budget (hb_draw_funcs_t *dfuncs, void *draw_data)
|
||||
{
|
||||
return dfuncs->get_budget (draw_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_draw_get_budget_remaining:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: associated draw data
|
||||
*
|
||||
* Fetches the live work budget. A negative value means the budget was
|
||||
* exhausted. Zero means the preceding work fit exactly, but no positive-cost
|
||||
* work can start.
|
||||
*
|
||||
* Return value: the live work budget; if it is not tracked, the concrete
|
||||
* configured policy or #HB_BUDGET_UNLIMITED
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
int64_t
|
||||
hb_draw_get_budget_remaining (hb_draw_funcs_t *dfuncs, void *draw_data)
|
||||
{
|
||||
int64_t *remaining = dfuncs->get_budget_remaining_ptr (draw_data);
|
||||
if (remaining)
|
||||
return *remaining;
|
||||
|
||||
int64_t budget = dfuncs->get_budget (draw_data);
|
||||
return budget == HB_BUDGET_DEFAULT ? HB_BUDGET_UNLIMITED : budget;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hb_draw_move_to:
|
||||
|
||||
+113
@@ -195,6 +195,61 @@ typedef void (*hb_draw_close_path_func_t) (hb_draw_funcs_t *dfuncs, void *draw_d
|
||||
hb_draw_state_t *st,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_draw_set_budget_func_t:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: The data accompanying the draw functions
|
||||
* @budget: the new work-budget policy
|
||||
* @user_data: User data pointer passed to hb_draw_funcs_set_set_budget_func()
|
||||
*
|
||||
* Sets the work-budget policy and recharges the live work budget. @budget is
|
||||
* #HB_BUDGET_DEFAULT, #HB_BUDGET_UNLIMITED, or a non-negative concrete value.
|
||||
*
|
||||
* Return value: `true` if the budget was set, `false` if unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef hb_bool_t (*hb_draw_set_budget_func_t) (hb_draw_funcs_t *dfuncs,
|
||||
void *draw_data,
|
||||
int64_t budget,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_draw_get_budget_func_t:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: The data accompanying the draw functions
|
||||
* @user_data: User data pointer passed to hb_draw_funcs_set_get_budget_func()
|
||||
*
|
||||
* Fetches the configured work-budget policy.
|
||||
*
|
||||
* Return value: the configured work-budget policy
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef int64_t (*hb_draw_get_budget_func_t) (hb_draw_funcs_t *dfuncs,
|
||||
void *draw_data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_draw_get_budget_remaining_func_t:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: The data accompanying the draw functions
|
||||
* @user_data: User data pointer passed to
|
||||
* hb_draw_funcs_set_get_budget_remaining_func()
|
||||
*
|
||||
* Fetches the address of the live work budget. The returned address must stay
|
||||
* valid while @draw_data is used with @dfuncs. The live value must be concrete;
|
||||
* it must not contain #HB_BUDGET_DEFAULT.
|
||||
*
|
||||
* Return value: (nullable) (transfer none): the live work budget, or `NULL` if
|
||||
* live budget accounting is unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef int64_t *(*hb_draw_get_budget_remaining_func_t) (hb_draw_funcs_t *dfuncs,
|
||||
void *draw_data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_draw_funcs_set_move_to_func:
|
||||
* @dfuncs: draw functions object
|
||||
@@ -275,6 +330,54 @@ hb_draw_funcs_set_close_path_func (hb_draw_funcs_t *dfuncs,
|
||||
hb_draw_close_path_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_draw_funcs_set_set_budget_func:
|
||||
* @dfuncs: draw functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): budget setter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the budget setter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_draw_funcs_set_set_budget_func (hb_draw_funcs_t *dfuncs,
|
||||
hb_draw_set_budget_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_draw_funcs_set_get_budget_func:
|
||||
* @dfuncs: draw functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): budget getter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the budget-policy getter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_draw_funcs_set_get_budget_func (hb_draw_funcs_t *dfuncs,
|
||||
hb_draw_get_budget_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_draw_funcs_set_get_budget_remaining_func:
|
||||
* @dfuncs: draw functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): live-budget getter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the live-budget getter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_draw_funcs_set_get_budget_remaining_func (hb_draw_funcs_t *dfuncs,
|
||||
hb_draw_get_budget_remaining_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
|
||||
HB_EXTERN hb_draw_funcs_t *
|
||||
hb_draw_funcs_create (void);
|
||||
@@ -306,6 +409,16 @@ hb_draw_funcs_make_immutable (hb_draw_funcs_t *dfuncs);
|
||||
HB_EXTERN hb_bool_t
|
||||
hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs);
|
||||
|
||||
HB_EXTERN hb_bool_t
|
||||
hb_draw_set_budget (hb_draw_funcs_t *dfuncs, void *draw_data,
|
||||
int64_t budget);
|
||||
|
||||
HB_EXTERN int64_t
|
||||
hb_draw_get_budget (hb_draw_funcs_t *dfuncs, void *draw_data);
|
||||
|
||||
HB_EXTERN int64_t
|
||||
hb_draw_get_budget_remaining (hb_draw_funcs_t *dfuncs, void *draw_data);
|
||||
|
||||
|
||||
HB_EXTERN void
|
||||
hb_draw_move_to (hb_draw_funcs_t *dfuncs, void *draw_data,
|
||||
|
||||
+27
-2
@@ -38,6 +38,9 @@
|
||||
HB_DRAW_FUNC_IMPLEMENT (quadratic_to) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (cubic_to) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (close_path) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (set_budget) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (get_budget) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (get_budget_remaining) \
|
||||
/* ^--- Add new callbacks here */
|
||||
|
||||
struct hb_draw_funcs_t
|
||||
@@ -92,6 +95,20 @@ struct hb_draw_funcs_t
|
||||
{ func.close_path (this, draw_data, &st,
|
||||
!user_data ? nullptr : user_data->close_path); }
|
||||
|
||||
bool set_budget (void *draw_data, int64_t budget)
|
||||
{
|
||||
if (budget < 0 && budget != HB_BUDGET_DEFAULT)
|
||||
budget = 0;
|
||||
return func.set_budget (this, draw_data, budget,
|
||||
!user_data ? nullptr : user_data->set_budget);
|
||||
}
|
||||
int64_t get_budget (void *draw_data)
|
||||
{ return func.get_budget (this, draw_data,
|
||||
!user_data ? nullptr : user_data->get_budget); }
|
||||
int64_t *get_budget_remaining_ptr (void *draw_data)
|
||||
{ return func.get_budget_remaining (this, draw_data,
|
||||
!user_data ? nullptr : user_data->get_budget_remaining); }
|
||||
|
||||
|
||||
void
|
||||
HB_ALWAYS_INLINE
|
||||
@@ -176,8 +193,12 @@ DECLARE_NULL_INSTANCE (hb_draw_funcs_t);
|
||||
struct hb_draw_session_t
|
||||
{
|
||||
hb_draw_session_t (hb_draw_funcs_t *funcs_, void *draw_data_)
|
||||
: funcs {funcs_}, draw_data {draw_data_}, st HB_DRAW_STATE_DEFAULT
|
||||
{}
|
||||
: funcs {funcs_}, draw_data {draw_data_}, st HB_DRAW_STATE_DEFAULT,
|
||||
local_budget {HB_BUDGET_GLYPH}, budget {funcs->get_budget_remaining_ptr (draw_data)}
|
||||
{
|
||||
if (!budget)
|
||||
budget = &local_budget;
|
||||
}
|
||||
|
||||
~hb_draw_session_t () { close_path (); }
|
||||
|
||||
@@ -219,10 +240,14 @@ struct hb_draw_session_t
|
||||
funcs->close_path (draw_data, st);
|
||||
}
|
||||
|
||||
int64_t &get_budget () { return *budget; }
|
||||
|
||||
public:
|
||||
hb_draw_funcs_t *funcs;
|
||||
void *draw_data;
|
||||
hb_draw_state_t st;
|
||||
int64_t local_budget;
|
||||
int64_t *budget;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -731,6 +731,31 @@ hb_draw_close_path_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
|
||||
adaptor->draw_funcs->emit_close_path (adaptor->draw_data, *st);
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_draw_set_budget_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
|
||||
int64_t budget,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
|
||||
return adaptor->draw_funcs->set_budget (adaptor->draw_data, budget);
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_draw_get_budget_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
|
||||
return adaptor->draw_funcs->get_budget (adaptor->draw_data);
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_draw_get_budget_remaining_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
|
||||
return adaptor->draw_funcs->get_budget_remaining_ptr (adaptor->draw_data);
|
||||
}
|
||||
|
||||
static const hb_draw_funcs_t _hb_draw_funcs_default = {
|
||||
HB_OBJECT_HEADER_STATIC,
|
||||
|
||||
|
||||
@@ -710,6 +710,7 @@ struct hb_font_t
|
||||
#ifndef HB_NO_OUTLINE
|
||||
|
||||
hb_outline_t outline;
|
||||
outline.budget_remaining = draw_funcs->get_budget_remaining_ptr (draw_data);
|
||||
if (!klass->get.f.draw_glyph_or_fail (this, user_data,
|
||||
glyph,
|
||||
hb_outline_recording_pen_get_funcs (), &outline,
|
||||
|
||||
+90
-13
@@ -88,12 +88,15 @@
|
||||
|
||||
using hb_ft_advance_cache_t = hb_cache_t<16, 24, 8, false>;
|
||||
|
||||
static void _hb_ft_face_destroy_static (void *data);
|
||||
|
||||
struct hb_ft_font_t
|
||||
{
|
||||
int load_flags;
|
||||
bool symbol; /* Whether selected cmap is symbol cmap. */
|
||||
bool unref; /* Whether to destroy ft_face when done. */
|
||||
bool transform; /* Whether to apply FT_Face's transform. */
|
||||
bool static_library; /* Whether ft_face uses static_ft_library. */
|
||||
|
||||
mutable hb_mutex_t lock; /* Protects members below. */
|
||||
FT_Face ft_face;
|
||||
@@ -102,7 +105,7 @@ struct hb_ft_font_t
|
||||
};
|
||||
|
||||
static hb_ft_font_t *
|
||||
_hb_ft_font_create (FT_Face ft_face, bool symbol, bool unref)
|
||||
_hb_ft_font_create (FT_Face ft_face, bool symbol, bool unref, bool static_library)
|
||||
{
|
||||
hb_ft_font_t *ft_font = (hb_ft_font_t *) hb_calloc (1, sizeof (hb_ft_font_t));
|
||||
if (unlikely (!ft_font)) return nullptr;
|
||||
@@ -111,6 +114,7 @@ _hb_ft_font_create (FT_Face ft_face, bool symbol, bool unref)
|
||||
ft_font->ft_face = ft_face;
|
||||
ft_font->symbol = symbol;
|
||||
ft_font->unref = unref;
|
||||
ft_font->static_library = static_library;
|
||||
|
||||
ft_font->load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING;
|
||||
|
||||
@@ -132,7 +136,12 @@ _hb_ft_font_destroy (void *data)
|
||||
hb_ft_font_t *ft_font = (hb_ft_font_t *) data;
|
||||
|
||||
if (ft_font->unref)
|
||||
_hb_ft_face_destroy (ft_font->ft_face);
|
||||
{
|
||||
if (ft_font->static_library)
|
||||
_hb_ft_face_destroy_static (ft_font->ft_face);
|
||||
else
|
||||
_hb_ft_face_destroy (ft_font->ft_face);
|
||||
}
|
||||
|
||||
ft_font->lock.fini ();
|
||||
|
||||
@@ -1097,11 +1106,12 @@ _hb_ft_get_font_funcs ()
|
||||
}
|
||||
|
||||
static void
|
||||
_hb_ft_font_set_funcs (hb_font_t *font, FT_Face ft_face, bool unref)
|
||||
_hb_ft_font_set_funcs (hb_font_t *font, FT_Face ft_face, bool unref,
|
||||
bool static_library = false)
|
||||
{
|
||||
bool symbol = ft_face->charmap && ft_face->charmap->encoding == FT_ENCODING_MS_SYMBOL;
|
||||
|
||||
hb_ft_font_t *ft_font = _hb_ft_font_create (ft_face, symbol, unref);
|
||||
hb_ft_font_t *ft_font = _hb_ft_font_create (ft_face, symbol, unref, static_library);
|
||||
if (unlikely (!ft_font)) return;
|
||||
|
||||
hb_font_set_funcs (font,
|
||||
@@ -1501,6 +1511,31 @@ static FT_MemoryRec_ m =
|
||||
};
|
||||
|
||||
static inline void free_static_ft_library ();
|
||||
static inline void free_static_ft_library_mutex ();
|
||||
|
||||
static struct hb_ft_library_mutex_lazy_loader_t : hb_lazy_loader_t<hb_mutex_t,
|
||||
hb_ft_library_mutex_lazy_loader_t>
|
||||
{
|
||||
static hb_mutex_t *create ()
|
||||
{
|
||||
hb_mutex_t *lock = (hb_mutex_t *) hb_calloc (1, sizeof (hb_mutex_t));
|
||||
if (unlikely (!lock))
|
||||
return nullptr;
|
||||
|
||||
lock = new (lock) hb_mutex_t;
|
||||
hb_atexit (free_static_ft_library_mutex);
|
||||
return lock;
|
||||
}
|
||||
static void destroy (hb_mutex_t *lock)
|
||||
{
|
||||
lock->~hb_mutex_t ();
|
||||
hb_free (lock);
|
||||
}
|
||||
static hb_mutex_t *get_null ()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
} static_ft_library_mutex;
|
||||
|
||||
static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer<FT_Library>,
|
||||
hb_ft_library_lazy_loader_t>
|
||||
@@ -1528,15 +1563,26 @@ static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer<F
|
||||
}
|
||||
} static_ft_library;
|
||||
|
||||
static inline
|
||||
void free_static_ft_library_mutex ()
|
||||
{
|
||||
static_ft_library_mutex.free_instance ();
|
||||
}
|
||||
|
||||
static inline
|
||||
void free_static_ft_library ()
|
||||
{
|
||||
hb_lock_t lock (static_ft_library_mutex.get_unconst ());
|
||||
static_ft_library.free_instance ();
|
||||
}
|
||||
|
||||
static FT_Library
|
||||
reference_ft_library ()
|
||||
{
|
||||
hb_mutex_t *mutex = static_ft_library_mutex.get_unconst ();
|
||||
if (unlikely (!mutex))
|
||||
return nullptr;
|
||||
hb_lock_t lock (mutex);
|
||||
FT_Library l = static_ft_library.get_unconst ();
|
||||
if (unlikely (FT_Reference_Library (l)))
|
||||
{
|
||||
@@ -1548,6 +1594,34 @@ reference_ft_library ()
|
||||
|
||||
static hb_user_data_key_t ft_library_key = {0};
|
||||
|
||||
static void
|
||||
_hb_ft_face_destroy_static (void *data)
|
||||
{
|
||||
hb_lock_t lock (static_ft_library_mutex.get_unconst ());
|
||||
FT_Done_Face ((FT_Face) data);
|
||||
}
|
||||
|
||||
static FT_Error
|
||||
new_ft_face (FT_Library ft_library,
|
||||
const char *file_name,
|
||||
unsigned int index,
|
||||
FT_Face *ft_face)
|
||||
{
|
||||
hb_lock_t lock (static_ft_library_mutex.get_unconst ());
|
||||
return FT_New_Face (ft_library, file_name, index, ft_face);
|
||||
}
|
||||
|
||||
static FT_Error
|
||||
new_ft_memory_face (FT_Library ft_library,
|
||||
const FT_Byte *blob_data,
|
||||
unsigned int blob_size,
|
||||
unsigned int index,
|
||||
FT_Face *ft_face)
|
||||
{
|
||||
hb_lock_t lock (static_ft_library_mutex.get_unconst ());
|
||||
return FT_New_Memory_Face (ft_library, blob_data, blob_size, index, ft_face);
|
||||
}
|
||||
|
||||
static void
|
||||
finalize_ft_library (void *arg)
|
||||
{
|
||||
@@ -1558,6 +1632,7 @@ finalize_ft_library (void *arg)
|
||||
static void
|
||||
destroy_ft_library (void *arg)
|
||||
{
|
||||
hb_lock_t lock (static_ft_library_mutex.get_unconst ());
|
||||
FT_Done_Library ((FT_Library) arg);
|
||||
}
|
||||
|
||||
@@ -1590,14 +1665,15 @@ hb_ft_face_create_from_file_or_fail (const char *file_name,
|
||||
}
|
||||
|
||||
FT_Face ft_face;
|
||||
if (unlikely (FT_New_Face (ft_library,
|
||||
if (unlikely (new_ft_face (ft_library,
|
||||
file_name,
|
||||
index,
|
||||
&ft_face)))
|
||||
return nullptr;
|
||||
|
||||
hb_face_t *face = hb_ft_face_create_referenced (ft_face);
|
||||
FT_Done_Face (ft_face);
|
||||
FT_Reference_Face (ft_face);
|
||||
hb_face_t *face = hb_ft_face_create (ft_face, _hb_ft_face_destroy_static);
|
||||
_hb_ft_face_destroy_static (ft_face);
|
||||
|
||||
ft_face->generic.data = ft_library;
|
||||
ft_face->generic.finalizer = finalize_ft_library;
|
||||
@@ -1649,15 +1725,16 @@ hb_ft_face_create_from_blob_or_fail (hb_blob_t *blob,
|
||||
const char *blob_data = hb_blob_get_data (blob, &blob_size);
|
||||
|
||||
FT_Face ft_face;
|
||||
if (unlikely (FT_New_Memory_Face (ft_library,
|
||||
if (unlikely (new_ft_memory_face (ft_library,
|
||||
(const FT_Byte *) blob_data,
|
||||
blob_size,
|
||||
index,
|
||||
&ft_face)))
|
||||
return nullptr;
|
||||
|
||||
hb_face_t *face = hb_ft_face_create_referenced (ft_face);
|
||||
FT_Done_Face (ft_face);
|
||||
FT_Reference_Face (ft_face);
|
||||
hb_face_t *face = hb_ft_face_create (ft_face, _hb_ft_face_destroy_static);
|
||||
_hb_ft_face_destroy_static (ft_face);
|
||||
|
||||
ft_face->generic.data = ft_library;
|
||||
ft_face->generic.finalizer = finalize_ft_library;
|
||||
@@ -1740,7 +1817,7 @@ hb_ft_font_set_funcs (hb_font_t *font)
|
||||
}
|
||||
|
||||
FT_Face ft_face = nullptr;
|
||||
if (unlikely (FT_New_Memory_Face (ft_library,
|
||||
if (unlikely (new_ft_memory_face (ft_library,
|
||||
(const FT_Byte *) blob_data,
|
||||
blob_length,
|
||||
hb_face_get_index (font->face),
|
||||
@@ -1762,11 +1839,11 @@ hb_ft_font_set_funcs (hb_font_t *font)
|
||||
if (unlikely (!hb_blob_set_user_data (blob, &ft_library_key, ft_library, destroy_ft_library, true)))
|
||||
{
|
||||
DEBUG_MSG (FT, font, "hb_blob_set_user_data() failed");
|
||||
FT_Done_Face (ft_face);
|
||||
_hb_ft_face_destroy_static (ft_face);
|
||||
return;
|
||||
}
|
||||
|
||||
_hb_ft_font_set_funcs (font, ft_face, true);
|
||||
_hb_ft_font_set_funcs (font, ft_face, true, true);
|
||||
hb_ft_font_set_load_flags (font, load_flags);
|
||||
|
||||
_hb_ft_hb_font_changed (font, ft_face);
|
||||
|
||||
@@ -51,6 +51,10 @@ acc_emit (hb_gpu_draw_t *g,
|
||||
double p2x, double p2y,
|
||||
double p3x, double p3y)
|
||||
{
|
||||
int64_t *budget = g->get_budget_remaining ();
|
||||
if (unlikely (!hb_budget_spend (*budget, HB_BUDGET_1)))
|
||||
return;
|
||||
|
||||
if (unlikely (g->num_curves >= HB_GPU_DRAW_MAX_CURVES))
|
||||
{
|
||||
g->success = false;
|
||||
@@ -235,6 +239,28 @@ hb_gpu_draw_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
g->acc_close_path ();
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_gpu_draw_set_budget (hb_draw_funcs_t *, void *draw_data,
|
||||
int64_t budget, void *)
|
||||
{
|
||||
auto *draw = (hb_gpu_draw_t *) draw_data;
|
||||
draw->budget = budget;
|
||||
draw->recharge_budget ();
|
||||
return true;
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_gpu_draw_get_budget (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_gpu_draw_t *) draw_data)->budget;
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_gpu_draw_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_gpu_draw_t *) draw_data)->get_budget_remaining ();
|
||||
}
|
||||
|
||||
static inline void free_static_gpu_draw_funcs ();
|
||||
|
||||
static struct hb_gpu_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t<hb_gpu_draw_funcs_lazy_loader_t>
|
||||
@@ -248,6 +274,9 @@ static struct hb_gpu_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t<hb_g
|
||||
hb_draw_funcs_set_quadratic_to_func (funcs, hb_gpu_draw_quadratic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, hb_gpu_draw_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, hb_gpu_draw_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_set_budget_func (funcs, hb_gpu_draw_set_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_func (funcs, hb_gpu_draw_get_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_gpu_draw_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
|
||||
@@ -1098,6 +1127,8 @@ hb_gpu_draw_clear (hb_gpu_draw_t *draw)
|
||||
draw->ext_min_y = HUGE_VAL;
|
||||
draw->ext_max_x = -HUGE_VAL;
|
||||
draw->ext_max_y = -HUGE_VAL;
|
||||
|
||||
draw->recharge_budget ();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1114,6 +1145,7 @@ hb_gpu_draw_reset (hb_gpu_draw_t *draw)
|
||||
{
|
||||
draw->x_scale = 0;
|
||||
draw->y_scale = 0;
|
||||
draw->budget = HB_BUDGET_DEFAULT;
|
||||
hb_gpu_draw_clear (draw);
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,22 @@ struct hb_gpu_draw_t
|
||||
int x_scale = 0;
|
||||
int y_scale = 0;
|
||||
|
||||
/* Work budget for outline traversal and generated curves. A paint
|
||||
* backend seeds this through the public draw-budget API before drawing
|
||||
* and reads the remainder back afterwards, so a whole paint session
|
||||
* shares one budget without reaching into this object. */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
|
||||
void recharge_budget ()
|
||||
{
|
||||
budget_remaining = budget == HB_BUDGET_DEFAULT ?
|
||||
HB_BUDGET_GLYPH : budget;
|
||||
}
|
||||
|
||||
int64_t *get_budget_remaining ()
|
||||
{ return &budget_remaining; }
|
||||
|
||||
/* Encode scratch (reused across calls) */
|
||||
hb_gpu_encode_scratch_t scratch;
|
||||
|
||||
|
||||
+51
-4
@@ -136,6 +136,10 @@ hb_gpu_paint_push_clip_path_start (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
}
|
||||
|
||||
hb_gpu_draw_clear (c->scratch_draw);
|
||||
/* Seed the scratch encoder's budget from the session's remainder; it is
|
||||
* read back in push_clip_path_end after the caller has drawn the path. */
|
||||
hb_draw_set_budget (hb_gpu_draw_get_funcs (c->scratch_draw), c->scratch_draw,
|
||||
c->budget_remaining);
|
||||
hb_gpu_draw_set_scale (c->scratch_draw, c->x_scale, c->y_scale);
|
||||
|
||||
c->pending_clip_path_transform = c->cur_transform;
|
||||
@@ -156,7 +160,9 @@ hb_gpu_paint_push_clip_path_end (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
return;
|
||||
c->pending_clip_path = false;
|
||||
|
||||
c->work_left -= 1 + (int64_t) c->scratch_draw->num_curves;
|
||||
/* Pull back the outline budget the caller's path draw consumed. */
|
||||
c->budget_remaining = hb_draw_get_budget_remaining (hb_gpu_draw_get_funcs (c->scratch_draw),
|
||||
c->scratch_draw);
|
||||
|
||||
hb_glyph_extents_t ext;
|
||||
hb_blob_t *blob = hb_gpu_draw_encode (c->scratch_draw, &ext);
|
||||
@@ -327,6 +333,7 @@ struct hb_gpu_paint_pen_t
|
||||
hb_draw_funcs_t *dfuncs;
|
||||
void *data;
|
||||
hb_draw_state_t down_st;
|
||||
int64_t *budget_remaining;
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -388,6 +395,12 @@ hb_gpu_paint_pen_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
c->dfuncs->close_path (c->data, c->down_st);
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_gpu_paint_pen_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_gpu_paint_pen_t *) draw_data)->budget_remaining;
|
||||
}
|
||||
|
||||
static inline void free_static_gpu_paint_pen_funcs ();
|
||||
|
||||
static struct hb_gpu_paint_pen_funcs_lazy_loader_t
|
||||
@@ -401,6 +414,7 @@ static struct hb_gpu_paint_pen_funcs_lazy_loader_t
|
||||
hb_draw_funcs_set_quadratic_to_func (funcs, hb_gpu_paint_pen_quadratic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, hb_gpu_paint_pen_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, hb_gpu_paint_pen_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_gpu_paint_pen_get_budget_remaining, nullptr, nullptr);
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
hb_atexit (free_static_gpu_paint_pen_funcs);
|
||||
return funcs;
|
||||
@@ -451,7 +465,7 @@ emit_clip_sub_blob (hb_gpu_paint_t *c,
|
||||
/* Out of budget: skip the glyph-outline extraction entirely, so
|
||||
* per-glyph outline limits cannot multiply with the caller's
|
||||
* paint-graph traversal limits. */
|
||||
if (unlikely (c->work_left <= 0))
|
||||
if (unlikely (c->budget_remaining < 0))
|
||||
{
|
||||
c->unsupported = true;
|
||||
return -1;
|
||||
@@ -467,6 +481,11 @@ emit_clip_sub_blob (hb_gpu_paint_t *c,
|
||||
}
|
||||
}
|
||||
hb_gpu_draw_clear (c->scratch_draw);
|
||||
/* Seed the scratch encoder's budget from the session's remainder and
|
||||
* read it back after the glyph is drawn, so the whole paint walk shares
|
||||
* one budget through the public draw-budget API. */
|
||||
hb_draw_set_budget (hb_gpu_draw_get_funcs (c->scratch_draw), c->scratch_draw,
|
||||
c->budget_remaining);
|
||||
|
||||
bool ok;
|
||||
if (clip.transform.is_identity ())
|
||||
@@ -490,6 +509,7 @@ emit_clip_sub_blob (hb_gpu_paint_t *c,
|
||||
pen.dfuncs = hb_gpu_draw_get_funcs (c->scratch_draw);
|
||||
pen.data = c->scratch_draw;
|
||||
pen.down_st = HB_DRAW_STATE_DEFAULT;
|
||||
pen.budget_remaining = &c->scratch_draw->budget_remaining;
|
||||
ok = hb_font_draw_glyph_or_fail (clip.font, clip.glyph,
|
||||
static_gpu_paint_pen_funcs.get_unconst (),
|
||||
&pen);
|
||||
@@ -497,7 +517,8 @@ emit_clip_sub_blob (hb_gpu_paint_t *c,
|
||||
* hb_font_draw_glyph_or_fail only closes via our pen's state. */
|
||||
pen.dfuncs->close_path (pen.data, pen.down_st);
|
||||
}
|
||||
c->work_left -= 1 + (int64_t) c->scratch_draw->num_curves;
|
||||
c->budget_remaining = hb_draw_get_budget_remaining (hb_gpu_draw_get_funcs (c->scratch_draw),
|
||||
c->scratch_draw);
|
||||
if (!ok)
|
||||
return -1; /* Clip glyph has no outline -- skip. */
|
||||
|
||||
@@ -1001,6 +1022,28 @@ hb_gpu_paint_image (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
return false;
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_gpu_paint_set_budget (hb_paint_funcs_t *, void *paint_data,
|
||||
int64_t budget, void *)
|
||||
{
|
||||
auto *paint = (hb_gpu_paint_t *) paint_data;
|
||||
paint->budget = budget;
|
||||
paint->recharge_budget ();
|
||||
return true;
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_gpu_paint_get_budget (hb_paint_funcs_t *, void *paint_data, void *)
|
||||
{
|
||||
return ((hb_gpu_paint_t *) paint_data)->budget;
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_gpu_paint_get_budget_remaining (hb_paint_funcs_t *, void *paint_data, void *)
|
||||
{
|
||||
return &((hb_gpu_paint_t *) paint_data)->budget_remaining;
|
||||
}
|
||||
|
||||
static inline void free_static_gpu_paint_funcs ();
|
||||
|
||||
static struct hb_gpu_paint_funcs_lazy_loader_t
|
||||
@@ -1025,6 +1068,9 @@ static struct hb_gpu_paint_funcs_lazy_loader_t
|
||||
hb_paint_funcs_set_custom_palette_color_func (funcs, hb_gpu_paint_custom_palette_color, nullptr, nullptr);
|
||||
/* PaintImage can't be represented by our slug+gradient encoder. */
|
||||
hb_paint_funcs_set_image_func (funcs, hb_gpu_paint_image, nullptr, nullptr);
|
||||
hb_paint_funcs_set_set_budget_func (funcs, hb_gpu_paint_set_budget, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_func (funcs, hb_gpu_paint_get_budget, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_gpu_paint_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_paint_funcs_make_immutable (funcs);
|
||||
|
||||
@@ -1563,7 +1609,7 @@ hb_gpu_paint_clear (hb_gpu_paint_t *paint)
|
||||
paint->clip_depth = 0;
|
||||
paint->pending_clip_path = false;
|
||||
paint->unsupported = false;
|
||||
paint->work_left = HB_GPU_PAINT_MAX_WORK;
|
||||
paint->recharge_budget ();
|
||||
paint->cur_transform = {1, 0, 0, 1, 0, 0};
|
||||
paint->transform_stack.reset ();
|
||||
paint->ext_min_x = 0x7fffffff;
|
||||
@@ -1587,6 +1633,7 @@ hb_gpu_paint_reset (hb_gpu_paint_t *paint)
|
||||
paint->x_scale = 0;
|
||||
paint->y_scale = 0;
|
||||
paint->palette = 0;
|
||||
paint->budget = HB_BUDGET_DEFAULT;
|
||||
hb_map_destroy (paint->custom_palette);
|
||||
paint->custom_palette = nullptr;
|
||||
hb_gpu_paint_clear (paint);
|
||||
|
||||
+14
-6
@@ -273,12 +273,20 @@ struct hb_gpu_paint_t
|
||||
* which matches HB_GPU_PAINT_GROUP_DEPTH in the fragment shader. */
|
||||
unsigned group_depth = 0;
|
||||
|
||||
/* Cumulative work budget for the current paint walk; reset by
|
||||
* hb_gpu_paint_clear(). Charged with the curves consumed by each
|
||||
* clip-glyph encode, so per-glyph outline limits cannot multiply
|
||||
* with the paint-graph traversal limits of the font tables
|
||||
* driving us (e.g. COLR). */
|
||||
int64_t work_left = HB_GPU_PAINT_MAX_WORK;
|
||||
/* Work budget for the current paint session; reset by
|
||||
* hb_gpu_paint_clear(). All the session's work is outline-derived
|
||||
* (outline traversal and the curves generated from it -- the GPU
|
||||
* backend never rasterizes), so a single counter suffices. It is the
|
||||
* public draw/paint budget: seeded into the scratch encoder through the
|
||||
* public draw-budget API before each glyph and read back afterwards. */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
|
||||
void recharge_budget ()
|
||||
{
|
||||
budget_remaining = budget == HB_BUDGET_DEFAULT ?
|
||||
HB_BUDGET_GLYPH : budget;
|
||||
}
|
||||
|
||||
/* Stack of pending clips. Each color/gradient op consumes the
|
||||
* current state of this stack: the layer is rendered where ALL
|
||||
|
||||
+41
-44
@@ -133,6 +133,16 @@
|
||||
#define HB_SVG_MAX_DOCUMENT_SIZE ((size_t) 16 << 20)
|
||||
#endif
|
||||
|
||||
/* Maximum size of one serialized vector document (SVG or PDF) produced by
|
||||
* the vector backends. Bounds output that is not outline-derived -- most
|
||||
* of a path, but especially sweep-gradient meshes and embedded bitmaps --
|
||||
* which the outline work budget cannot see. vector is one glyph per
|
||||
* context, so a flat cap suffices. Unsigned (not size_t like the SVG-table
|
||||
* limit above) to match hb_vector_buf_t's unsigned length arithmetic. */
|
||||
#ifndef HB_VECTOR_MAX_DOCUMENT_SIZE
|
||||
#define HB_VECTOR_MAX_DOCUMENT_SIZE ((unsigned) 16 << 20)
|
||||
#endif
|
||||
|
||||
#ifndef HB_RASTER_MAX_BUFFER_SIZE
|
||||
#define HB_RASTER_MAX_BUFFER_SIZE ((size_t) 1 << 30)
|
||||
#endif
|
||||
@@ -159,55 +169,42 @@
|
||||
* is skipped best-effort.
|
||||
*/
|
||||
|
||||
/* One VARC glyph (draw or extents), shared by all leaf glyphs loaded
|
||||
* from glyf/CFF/CFF2, in units of glyf points / CFF charstring ops. */
|
||||
#ifndef HB_VARC_MAX_WORK
|
||||
#define HB_VARC_MAX_WORK ((int64_t) 1 << 20)
|
||||
/* Fixed relative weights. Keep the value in the name so charge sites are
|
||||
* easy to audit; tune the common session cap, not these values. */
|
||||
#define HB_BUDGET_1 1u
|
||||
#define HB_BUDGET_2 2u
|
||||
#define HB_BUDGET_4 4u
|
||||
#define HB_BUDGET_8 8u
|
||||
#define HB_BUDGET_16 16u
|
||||
#define HB_BUDGET_32 32u
|
||||
#define HB_BUDGET_64 64u
|
||||
#define HB_BUDGET_128 128u
|
||||
#define HB_BUDGET_256 256u
|
||||
#define HB_BUDGET_512 512u
|
||||
#define HB_BUDGET_1024 1024u
|
||||
|
||||
/* The common finite default for one top-level glyph rendering session.
|
||||
* Nested outline and paint work shares the same live counter. */
|
||||
#ifndef HB_BUDGET_GLYPH
|
||||
#define HB_BUDGET_GLYPH ((int64_t) 1 << 26)
|
||||
#endif
|
||||
|
||||
/* One paint-extents session, in outline points consumed by
|
||||
* clip-glyph draws. */
|
||||
#ifndef HB_PAINT_EXTENTS_MAX_WORK
|
||||
#define HB_PAINT_EXTENTS_MAX_WORK ((int64_t) 1 << 20)
|
||||
#endif
|
||||
|
||||
/* One GPU paint walk, in curves consumed by clip encodes. */
|
||||
#ifndef HB_GPU_PAINT_MAX_WORK
|
||||
#define HB_GPU_PAINT_MAX_WORK ((int64_t) 1 << 20)
|
||||
#endif
|
||||
|
||||
/* One vector (SVG/PDF) draw session, in bytes of generated outline
|
||||
* path data. */
|
||||
#ifndef HB_VECTOR_MAX_DRAW_WORK
|
||||
#define HB_VECTOR_MAX_DRAW_WORK ((int64_t) 16 << 20)
|
||||
#endif
|
||||
|
||||
/* One vector (SVG/PDF) paint session, in bytes of generated outline
|
||||
* path and sweep-gradient patch data. */
|
||||
#ifndef HB_VECTOR_MAX_PAINT_WORK
|
||||
#define HB_VECTOR_MAX_PAINT_WORK ((int64_t) 16 << 20)
|
||||
#endif
|
||||
/* Precharge COST * MULT. Callers bound COST and MULT structurally, and live
|
||||
* budgets are concrete non-negative values when a session starts. */
|
||||
static HB_ALWAYS_INLINE bool
|
||||
hb_budget_spend (int64_t &budget, unsigned int cost, unsigned int mult = 1)
|
||||
{
|
||||
budget -= (int64_t) cost * mult;
|
||||
return budget >= 0;
|
||||
}
|
||||
|
||||
/* One raster paint session (everything painted between two
|
||||
* render/clear calls), in pixel-op units; pixel loops charge their
|
||||
* area, consumed outline segments are charged with a fixed weight.
|
||||
* The session budget is the larger of this flat value and
|
||||
* HB_RASTER_MAX_PAINT_WORK_PASSES full-surface passes, so very large
|
||||
* surfaces still get a few full-surface operations. */
|
||||
#ifndef HB_RASTER_MAX_PAINT_WORK
|
||||
#define HB_RASTER_MAX_PAINT_WORK ((int64_t) 1 << 26)
|
||||
#endif
|
||||
|
||||
#ifndef HB_RASTER_MAX_PAINT_WORK_PASSES
|
||||
#define HB_RASTER_MAX_PAINT_WORK_PASSES 4
|
||||
#endif
|
||||
|
||||
/* One raster draw session (everything drawn between two render/clear
|
||||
* calls) through the standalone hb-raster-draw API, in Bézier
|
||||
* subdivision steps. When driven by raster-paint, the paint session
|
||||
* budget above is charged instead. */
|
||||
#ifndef HB_RASTER_MAX_DRAW_WORK
|
||||
#define HB_RASTER_MAX_DRAW_WORK ((int64_t) 1 << 24)
|
||||
* area, consumed outline segments are charged with a fixed weight. Its
|
||||
* default is the larger of HB_BUDGET_GLYPH and this many full-surface
|
||||
* passes, so very large surfaces still get a few full-surface operations. */
|
||||
#ifndef HB_BUDGET_RASTER_PAINT_PASSES
|
||||
#define HB_BUDGET_RASTER_PAINT_PASSES 4
|
||||
#endif
|
||||
|
||||
/* One raster draw session, in accumulated non-horizontal edges. */
|
||||
|
||||
+10
-4
@@ -379,8 +379,8 @@ struct cff1_cs_opset_extents_t : cff1_cs_opset_t<cff1_cs_opset_extents_t, cff1_e
|
||||
|
||||
bounds_t base_bounds, accent_bounds;
|
||||
if (likely (!env.in_seac && base && accent
|
||||
&& _get_bounds (param.cff, base, base_bounds, true)
|
||||
&& _get_bounds (param.cff, accent, accent_bounds, true)))
|
||||
&& _get_bounds (param.cff, base, base_bounds, true, env.get_budget ())
|
||||
&& _get_bounds (param.cff, accent, accent_bounds, true, env.get_budget ())))
|
||||
{
|
||||
param.bounds.merge (base_bounds);
|
||||
accent_bounds.offset (delta);
|
||||
@@ -416,6 +416,9 @@ bool OT::cff1::accelerator_t::get_extents (hb_font_t *font, hb_codepoint_t glyph
|
||||
|
||||
bounds_t bounds;
|
||||
|
||||
int64_t stack_budget = HB_BUDGET_GLYPH;
|
||||
if (!budget) budget = &stack_budget;
|
||||
|
||||
if (!_get_bounds (this, glyph, bounds, false, budget))
|
||||
return false;
|
||||
|
||||
@@ -535,8 +538,8 @@ struct cff1_cs_opset_path_t : cff1_cs_opset_t<cff1_cs_opset_path_t, cff1_path_pa
|
||||
hb_codepoint_t accent = param.cff->std_code_to_glyph (env.argStack[n-1].to_int ());
|
||||
|
||||
if (unlikely (!(!env.in_seac && base && accent
|
||||
&& _get_path (param.cff, param.font, base, *param.draw_session, true)
|
||||
&& _get_path (param.cff, param.font, accent, *param.draw_session, true, &delta))))
|
||||
&& _get_path (param.cff, param.font, base, *param.draw_session, true, nullptr, env.get_budget ())
|
||||
&& _get_path (param.cff, param.font, accent, *param.draw_session, true, &delta, env.get_budget ()))))
|
||||
env.set_error ();
|
||||
}
|
||||
};
|
||||
@@ -568,6 +571,9 @@ bool OT::cff1::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, h
|
||||
return true;
|
||||
#endif
|
||||
|
||||
int64_t stack_budget = HB_BUDGET_GLYPH;
|
||||
if (!budget) budget = &stack_budget;
|
||||
|
||||
return _get_path (this, font, glyph, draw_session, false, nullptr, budget);
|
||||
}
|
||||
|
||||
|
||||
+14
-2
@@ -123,6 +123,9 @@ bool OT::cff2::accelerator_t::get_extents_at (hb_font_t *font,
|
||||
|
||||
if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false;
|
||||
|
||||
int64_t stack_budget = HB_BUDGET_GLYPH;
|
||||
if (!budget) budget = &stack_budget;
|
||||
|
||||
unsigned int fd = fdSelect->get_fd (glyph);
|
||||
const hb_ubytes_t str = (*charStrings)[glyph];
|
||||
cff2_cs_interp_env_t<number_t> env (str, *this, fd, coords.arrayZ, coords.length);
|
||||
@@ -207,13 +210,19 @@ struct cff2_path_procs_path_t : path_procs_t<cff2_path_procs_path_t, cff2_cs_int
|
||||
|
||||
struct cff2_cs_opset_path_t : cff2_cs_opset_t<cff2_cs_opset_path_t, cff2_path_param_t, number_t, cff2_path_procs_path_t> {};
|
||||
|
||||
bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const
|
||||
bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph,
|
||||
hb_draw_session_t &draw_session,
|
||||
int64_t *budget) const
|
||||
{
|
||||
int64_t stack_budget = HB_BUDGET_GLYPH;
|
||||
if (!budget) budget = &stack_budget;
|
||||
|
||||
return get_path_at (font,
|
||||
glyph,
|
||||
draw_session,
|
||||
hb_array (font->coords,
|
||||
font->has_nonzero_coords ? font->num_coords : 0));
|
||||
font->has_nonzero_coords ? font->num_coords : 0),
|
||||
budget);
|
||||
}
|
||||
|
||||
bool OT::cff2::accelerator_t::get_path_at (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, hb_array_t<const int> coords, int64_t *budget) const
|
||||
@@ -225,6 +234,9 @@ bool OT::cff2::accelerator_t::get_path_at (hb_font_t *font, hb_codepoint_t glyph
|
||||
|
||||
if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false;
|
||||
|
||||
int64_t stack_budget = HB_BUDGET_GLYPH;
|
||||
if (!budget) budget = &stack_budget;
|
||||
|
||||
unsigned int fd = fdSelect->get_fd (glyph);
|
||||
const hb_ubytes_t str = (*charStrings)[glyph];
|
||||
cff2_cs_interp_env_t<number_t> env (str, *this, fd, coords.arrayZ, coords.length);
|
||||
|
||||
@@ -539,7 +539,7 @@ struct cff2
|
||||
hb_glyph_extents_t *extents,
|
||||
hb_array_t<const int> coords,
|
||||
int64_t *budget = nullptr) const;
|
||||
HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const;
|
||||
HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, int64_t *budget = nullptr) const;
|
||||
HB_INTERNAL bool get_path_at (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, hb_array_t<const int> coords, int64_t *budget = nullptr) const;
|
||||
};
|
||||
|
||||
|
||||
+8
-4
@@ -782,7 +782,8 @@ hb_ot_get_glyph_v_origins (hb_font_t *font,
|
||||
{
|
||||
hb_glyph_extents_t extents = {0};
|
||||
if (likely (font->get_glyph_extents (*first_glyph, &extents)))
|
||||
origin = extents.y_bearing + ((font_advance - -extents.height) >> 1);
|
||||
origin = hb_clamp_to<hb_position_t> ((int64_t) extents.y_bearing +
|
||||
(((int64_t) font_advance + extents.height) >> 1));
|
||||
else
|
||||
origin = font_extents.ascender;
|
||||
|
||||
@@ -914,11 +915,14 @@ hb_ot_draw_glyph_or_fail (hb_font_t *font,
|
||||
if (font->face->table.VARC->get_path (font, glyph, draw_session)) return true;
|
||||
#endif
|
||||
// Keep the following in synch with VARC::get_path_at()
|
||||
if (font->face->table.glyf->get_path (font, glyph, draw_session, gvar_cache)) return true;
|
||||
if (font->face->table.glyf->get_path (font, glyph, draw_session, gvar_cache,
|
||||
&draw_session.get_budget ())) return true;
|
||||
|
||||
#ifndef HB_NO_CFF
|
||||
if (font->face->table.cff2->get_path (font, glyph, draw_session)) return true;
|
||||
if (font->face->table.cff1->get_path (font, glyph, draw_session)) return true;
|
||||
if (font->face->table.cff2->get_path (font, glyph, draw_session,
|
||||
&draw_session.get_budget ())) return true;
|
||||
if (font->face->table.cff1->get_path (font, glyph, draw_session,
|
||||
&draw_session.get_budget ())) return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
|
||||
@@ -790,10 +790,10 @@ struct BASE
|
||||
if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false);
|
||||
|
||||
out->version = version;
|
||||
if (has_var_store () && !subset_varstore (c, out))
|
||||
return_trace (false);
|
||||
bool ret = false;
|
||||
if (version.to_int () >= 0x00010001u) ret |= subset_varstore (c, out);
|
||||
|
||||
bool ret = out->hAxis.serialize_subset (c, hAxis, this);
|
||||
ret |= out->hAxis.serialize_subset (c, hAxis, this);
|
||||
ret |= out->vAxis.serialize_subset (c, vAxis, this);
|
||||
|
||||
return_trace (ret);
|
||||
|
||||
+334
-24
@@ -1129,7 +1129,6 @@ struct hb_ot_apply_context_t :
|
||||
recurse_func_t recurse_func = nullptr;
|
||||
const GDEF &gdef;
|
||||
const GDEF::accelerator_t &gdef_accel;
|
||||
const hb_ot_layout_lookup_accelerator_t *lookup_accel = nullptr;
|
||||
const ItemVariationStore &var_store;
|
||||
hb_scalar_cache_t *var_store_cache;
|
||||
|
||||
@@ -1378,6 +1377,16 @@ enum class hb_ot_subtable_cache_op_t
|
||||
struct hb_accelerate_subtables_context_t :
|
||||
hb_dispatch_context_t<hb_accelerate_subtables_context_t>
|
||||
{
|
||||
template <typename T>
|
||||
static inline auto collect_second_glyphs_ (const T &obj,
|
||||
hb_set_digest_t *digest,
|
||||
hb_priority<1>) HB_RETURN (void, obj.collect_second_glyphs (digest) )
|
||||
template <typename T>
|
||||
static inline void collect_second_glyphs_ (const T &obj HB_UNUSED,
|
||||
hb_set_digest_t *digest,
|
||||
hb_priority<0>)
|
||||
{ *digest = hb_set_digest_t::full (); }
|
||||
|
||||
template <typename T>
|
||||
static inline auto apply_ (const T *obj, hb_ot_apply_context_t *c, void *external_cache, hb_priority<1>) HB_RETURN (bool, obj->apply (c, external_cache) )
|
||||
template <typename T>
|
||||
@@ -1512,6 +1521,8 @@ struct hb_accelerate_subtables_context_t :
|
||||
template <typename T>
|
||||
return_t dispatch (const T &obj)
|
||||
{
|
||||
collect_second_glyphs_ (obj, &digest_second, hb_prioritize);
|
||||
|
||||
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
|
||||
void *external_cache = nullptr;
|
||||
if (i < 8)
|
||||
@@ -1555,6 +1566,7 @@ struct hb_accelerate_subtables_context_t :
|
||||
|
||||
hb_applicable_t *array;
|
||||
unsigned i = 0;
|
||||
hb_set_digest_t digest_second;
|
||||
|
||||
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
|
||||
unsigned subtable_cache_user_idx = (unsigned) -1;
|
||||
@@ -1567,6 +1579,19 @@ typedef bool (*intersects_func_t) (const hb_set_t *glyphs, unsigned value, const
|
||||
typedef void (*intersected_glyphs_func_t) (const hb_set_t *glyphs, const void *data, unsigned value, hb_set_t *intersected_glyphs, void *cache);
|
||||
typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, unsigned value, const void *data);
|
||||
typedef bool (*match_func_t) (hb_glyph_info_t &info, unsigned value, const void *data);
|
||||
typedef unsigned (*get_value_func_t) (hb_glyph_info_t &info, const void *data);
|
||||
|
||||
/* One word per RuleSet, summarizing the classes accepted at the first
|
||||
* input position after the current glyph. Collisions only cause extra work. */
|
||||
struct hb_ot_layout_ruleset_digest_t
|
||||
{
|
||||
void init () { mask = 0; }
|
||||
void set_full () { mask = (uint64_t) -1; }
|
||||
void add (unsigned value) { mask |= (uint64_t) 1 << (value & 63); }
|
||||
bool may_have (unsigned value) const { return mask & ((uint64_t) 1 << (value & 63)); }
|
||||
|
||||
uint64_t mask;
|
||||
};
|
||||
|
||||
struct ContextClosureFuncs
|
||||
{
|
||||
@@ -1770,6 +1795,26 @@ static inline bool match_class (hb_glyph_info_t &info, unsigned value, const voi
|
||||
const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
|
||||
return class_def.get_class (info.codepoint) == value;
|
||||
}
|
||||
static inline unsigned get_class_value (hb_glyph_info_t &info, const void *data)
|
||||
{
|
||||
const ClassDef &class_def = *reinterpret_cast<const ClassDef *> (data);
|
||||
return class_def.get_class (info.codepoint);
|
||||
}
|
||||
struct match_class_cache_data_t
|
||||
{
|
||||
const ClassDef *class_def;
|
||||
hb_ot_layout_mapping_cache_t *cache;
|
||||
};
|
||||
static inline bool match_class_cache (hb_glyph_info_t &info, unsigned value, const void *data)
|
||||
{
|
||||
const auto &cache_data = *reinterpret_cast<const match_class_cache_data_t *> (data);
|
||||
return cache_data.class_def->get_class (info.codepoint, cache_data.cache) == value;
|
||||
}
|
||||
static inline unsigned get_class_cache_value (hb_glyph_info_t &info, const void *data)
|
||||
{
|
||||
const auto &cache_data = *reinterpret_cast<const match_class_cache_data_t *> (data);
|
||||
return cache_data.class_def->get_class (info.codepoint, cache_data.cache);
|
||||
}
|
||||
static inline unsigned get_class_cached (const ClassDef &class_def, hb_glyph_info_t &info)
|
||||
{
|
||||
unsigned klass = info.syllable();
|
||||
@@ -1785,6 +1830,11 @@ static inline bool match_class_cached (hb_glyph_info_t &info, unsigned value, co
|
||||
const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
|
||||
return get_class_cached (class_def, info) == value;
|
||||
}
|
||||
static inline unsigned get_class_cached_value (hb_glyph_info_t &info, const void *data)
|
||||
{
|
||||
const ClassDef &class_def = *reinterpret_cast<const ClassDef *> (data);
|
||||
return get_class_cached (class_def, info);
|
||||
}
|
||||
static inline unsigned get_class_cached1 (const ClassDef &class_def, hb_glyph_info_t &info)
|
||||
{
|
||||
unsigned klass = info.syllable() & 0x0F;
|
||||
@@ -1815,6 +1865,11 @@ static inline bool match_class_cached2 (hb_glyph_info_t &info, unsigned value, c
|
||||
const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
|
||||
return get_class_cached2 (class_def, info) == value;
|
||||
}
|
||||
static inline unsigned get_class_cached2_value (hb_glyph_info_t &info, const void *data)
|
||||
{
|
||||
const ClassDef &class_def = *reinterpret_cast<const ClassDef *> (data);
|
||||
return get_class_cached2 (class_def, info);
|
||||
}
|
||||
static inline bool match_coverage (hb_glyph_info_t &info, unsigned value, const void *data)
|
||||
{
|
||||
Offset16To<Coverage> coverage;
|
||||
@@ -2804,6 +2859,7 @@ struct ContextApplyLookupContext
|
||||
{
|
||||
ContextApplyFuncs funcs;
|
||||
const void *match_data;
|
||||
get_value_func_t get_value;
|
||||
};
|
||||
|
||||
template <typename HBUINT>
|
||||
@@ -2892,7 +2948,7 @@ static inline void context_depend_lookup (hb_depend_context_t *c,
|
||||
}
|
||||
|
||||
/* Positions 1+ (Input array) */
|
||||
for (unsigned i = 0; i < inputCount - 1; i++)
|
||||
for (unsigned i = 0; i + 1 < inputCount; i++)
|
||||
{
|
||||
const hb_set_t *pos_glyphs = depend_position_glyphs (
|
||||
c, lookup_context.context_format, lookup_context.intersects_data,
|
||||
@@ -3065,6 +3121,24 @@ struct Rule
|
||||
lookup_context);
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest,
|
||||
const ClassDef *class_def = nullptr) const
|
||||
{
|
||||
if (inputCount <= 1)
|
||||
{
|
||||
*digest = hb_set_digest_t::full ();
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned second = inputZ.arrayZ[0];
|
||||
if (!class_def)
|
||||
digest->add (second);
|
||||
else if (!second)
|
||||
*digest = hb_set_digest_t::full ();
|
||||
else
|
||||
class_def->collect_class (digest, second);
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c,
|
||||
const ContextApplyLookupContext &lookup_context) const
|
||||
{
|
||||
@@ -3164,6 +3238,21 @@ struct RuleSet
|
||||
;
|
||||
}
|
||||
|
||||
void collect_first_input_classes (hb_ot_layout_ruleset_digest_t *digest) const
|
||||
{
|
||||
digest->init ();
|
||||
for (unsigned i = 0; i < rule.len; i++)
|
||||
{
|
||||
const Rule &r = this+rule.arrayZ[i];
|
||||
if (r.inputCount <= 1)
|
||||
{
|
||||
digest->set_full ();
|
||||
return;
|
||||
}
|
||||
digest->add (r.inputZ.arrayZ[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void depend (hb_depend_context_t *c, unsigned value, ContextDependLookupContext &lookup_context) const
|
||||
{
|
||||
+ hb_iter (rule)
|
||||
@@ -3204,6 +3293,15 @@ struct RuleSet
|
||||
;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest,
|
||||
const ClassDef *class_def = nullptr) const
|
||||
{
|
||||
+ hb_iter (rule)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([=] (const Rule &_) { _.collect_second_glyphs (digest, class_def); })
|
||||
;
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c,
|
||||
const ContextApplyLookupContext &lookup_context) const
|
||||
{
|
||||
@@ -3216,7 +3314,8 @@ struct RuleSet
|
||||
}
|
||||
|
||||
bool apply (hb_ot_apply_context_t *c,
|
||||
const ContextApplyLookupContext &lookup_context) const
|
||||
const ContextApplyLookupContext &lookup_context,
|
||||
const hb_ot_layout_ruleset_digest_t *digest = nullptr) const
|
||||
{
|
||||
TRACE_APPLY (this);
|
||||
|
||||
@@ -3252,7 +3351,7 @@ struct RuleSet
|
||||
skippy_iter.set_glyph_data ((HBUINT16 *) nullptr);
|
||||
unsigned unsafe_to = (unsigned) -1, unsafe_to1, unsafe_to2 = 0;
|
||||
hb_glyph_info_t *first = nullptr, *second = nullptr;
|
||||
bool matched = skippy_iter.next ();
|
||||
bool matched = skippy_iter.next (&unsafe_to1);
|
||||
if (likely (matched))
|
||||
{
|
||||
if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx]))
|
||||
@@ -3264,19 +3363,32 @@ struct RuleSet
|
||||
|
||||
first = &c->buffer->info[skippy_iter.idx];
|
||||
unsafe_to1 = skippy_iter.idx + 1;
|
||||
|
||||
if (digest && lookup_context.get_value &&
|
||||
!digest->may_have (lookup_context.get_value (*first, lookup_context.match_data)))
|
||||
{
|
||||
c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1);
|
||||
return_trace (false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Failed to match a next glyph. Only try applying rules that have
|
||||
* no further input. */
|
||||
return_trace (
|
||||
bool unsafe_to_concat = false;
|
||||
bool ret =
|
||||
+ hb_iter (rule)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_filter ([&] (const Rule &_) { return _.inputCount <= 1; })
|
||||
| hb_filter ([&] (const Rule &_)
|
||||
{
|
||||
if (_.inputCount <= 1) return true;
|
||||
unsafe_to_concat = true;
|
||||
return false;
|
||||
})
|
||||
| hb_map ([&] (const Rule &_) { return _.apply (c, lookup_context); })
|
||||
| hb_any
|
||||
)
|
||||
;
|
||||
if (unsafe_to_concat)
|
||||
c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1);
|
||||
return_trace (ret);
|
||||
}
|
||||
matched = skippy_iter.next ();
|
||||
if (likely (matched))
|
||||
@@ -3493,6 +3605,14 @@ struct ContextFormat1_4
|
||||
;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{
|
||||
+ hb_iter (ruleSet)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([digest] (const RuleSet &_) { _.collect_second_glyphs (digest); })
|
||||
;
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c) const
|
||||
{
|
||||
const RuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])];
|
||||
@@ -3719,6 +3839,15 @@ struct ContextFormat2_5
|
||||
;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{
|
||||
const ClassDef &class_def = this+classDef;
|
||||
+ hb_iter (ruleSet)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([=, &class_def] (const RuleSet &_) { _.collect_second_glyphs (digest, &class_def); })
|
||||
;
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c) const
|
||||
{
|
||||
const ClassDef &class_def = this+classDef;
|
||||
@@ -3745,13 +3874,20 @@ struct ContextFormat2_5
|
||||
struct external_cache_t
|
||||
{
|
||||
hb_ot_layout_binary_cache_t coverage;
|
||||
hb_ot_layout_ruleset_digest_t rule_sets[HB_VAR_ARRAY];
|
||||
};
|
||||
void *external_cache_create () const
|
||||
{
|
||||
external_cache_t *cache = (external_cache_t *) hb_malloc (sizeof (external_cache_t));
|
||||
unsigned count = ruleSet.len;
|
||||
unsigned size = sizeof (external_cache_t) -
|
||||
HB_VAR_ARRAY * sizeof (hb_ot_layout_ruleset_digest_t) +
|
||||
count * sizeof (hb_ot_layout_ruleset_digest_t);
|
||||
external_cache_t *cache = (external_cache_t *) hb_malloc (size);
|
||||
if (likely (cache))
|
||||
{
|
||||
cache->coverage.clear ();
|
||||
for (unsigned i = 0; i < count; i++)
|
||||
(this+ruleSet[i]).collect_first_input_classes (&cache->rule_sets[i]);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
@@ -3772,12 +3908,18 @@ struct ContextFormat2_5
|
||||
|
||||
struct ContextApplyLookupContext lookup_context = {
|
||||
{cached ? match_class_cached : match_class},
|
||||
&class_def
|
||||
&class_def,
|
||||
cached ? get_class_cached_value : get_class_value
|
||||
};
|
||||
|
||||
index = cached ? get_class_cached (class_def, c->buffer->cur()) : class_def.get_class (c->buffer->cur().codepoint);
|
||||
const RuleSet &rule_set = this+ruleSet[index];
|
||||
return_trace (rule_set.apply (c, lookup_context));
|
||||
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
|
||||
const hb_ot_layout_ruleset_digest_t *digest = cache && index < ruleSet.len ? &cache->rule_sets[index] : nullptr;
|
||||
#else
|
||||
const hb_ot_layout_ruleset_digest_t *digest = nullptr;
|
||||
#endif
|
||||
return_trace (rule_set.apply (c, lookup_context, digest));
|
||||
}
|
||||
|
||||
bool subset (hb_subset_context_t *c) const
|
||||
@@ -3956,6 +4098,14 @@ struct ContextFormat3
|
||||
lookup_context);
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{
|
||||
if (glyphCount <= 1)
|
||||
*digest = hb_set_digest_t::full ();
|
||||
else
|
||||
(this+coverageZ[1]).collect_coverage (digest);
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c) const
|
||||
{
|
||||
const LookupRecord *lookupRecord = &StructAfter<LookupRecord> (coverageZ.as_array (glyphCount));
|
||||
@@ -4097,6 +4247,7 @@ struct ChainContextApplyLookupContext
|
||||
{
|
||||
ChainContextApplyFuncs funcs;
|
||||
const void *match_data[3];
|
||||
get_value_func_t get_input_value;
|
||||
};
|
||||
|
||||
template <typename HBUINT>
|
||||
@@ -4300,7 +4451,7 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c,
|
||||
}
|
||||
|
||||
/* Positions 1+ (Input array) */
|
||||
for (unsigned i = 0; i < inputCount - 1; i++)
|
||||
for (unsigned i = 0; i + 1 < inputCount; i++)
|
||||
{
|
||||
const hb_set_t *pos_glyphs = depend_position_glyphs (
|
||||
c, lookup_context.context_format, lookup_context.intersects_data[1],
|
||||
@@ -4496,6 +4647,39 @@ struct ChainRule
|
||||
lookup_context);
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest,
|
||||
const ClassDef *input_class_def = nullptr,
|
||||
const ClassDef *lookahead_class_def = nullptr) const
|
||||
{
|
||||
const auto &input = StructAfter<decltype (inputX)> (backtrack);
|
||||
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
|
||||
|
||||
unsigned second;
|
||||
const ClassDef *class_def;
|
||||
if (input.lenP1 > 1)
|
||||
{
|
||||
second = input.arrayZ[0];
|
||||
class_def = input_class_def;
|
||||
}
|
||||
else if (lookahead.len)
|
||||
{
|
||||
second = lookahead.arrayZ[0];
|
||||
class_def = lookahead_class_def;
|
||||
}
|
||||
else
|
||||
{
|
||||
*digest = hb_set_digest_t::full ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!class_def)
|
||||
digest->add (second);
|
||||
else if (!second)
|
||||
*digest = hb_set_digest_t::full ();
|
||||
else
|
||||
class_def->collect_class (digest, second);
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c,
|
||||
const ChainContextApplyLookupContext &lookup_context) const
|
||||
{
|
||||
@@ -4647,6 +4831,22 @@ struct ChainRuleSet
|
||||
| hb_any
|
||||
;
|
||||
}
|
||||
|
||||
void collect_first_input_classes (hb_ot_layout_ruleset_digest_t *digest) const
|
||||
{
|
||||
digest->init ();
|
||||
for (unsigned i = 0; i < rule.len; i++)
|
||||
{
|
||||
const ChainRule &r = this+rule.arrayZ[i];
|
||||
const auto &input = StructAfter<decltype (r.inputX)> (r.backtrack);
|
||||
if (input.lenP1 <= 1)
|
||||
{
|
||||
digest->set_full ();
|
||||
return;
|
||||
}
|
||||
digest->add (input.arrayZ[0]);
|
||||
}
|
||||
}
|
||||
void depend (hb_depend_context_t *c, unsigned value, ChainContextDependLookupContext &lookup_context) const
|
||||
{
|
||||
+ hb_iter (rule)
|
||||
@@ -4685,6 +4885,17 @@ struct ChainRuleSet
|
||||
;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest,
|
||||
const ClassDef *input_class_def = nullptr,
|
||||
const ClassDef *lookahead_class_def = nullptr) const
|
||||
{
|
||||
+ hb_iter (rule)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([=] (const ChainRule &_)
|
||||
{ _.collect_second_glyphs (digest, input_class_def, lookahead_class_def); })
|
||||
;
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c,
|
||||
const ChainContextApplyLookupContext &lookup_context) const
|
||||
{
|
||||
@@ -4697,7 +4908,8 @@ struct ChainRuleSet
|
||||
}
|
||||
|
||||
bool apply (hb_ot_apply_context_t *c,
|
||||
const ChainContextApplyLookupContext &lookup_context) const
|
||||
const ChainContextApplyLookupContext &lookup_context,
|
||||
const hb_ot_layout_ruleset_digest_t *digest = nullptr) const
|
||||
{
|
||||
TRACE_APPLY (this);
|
||||
|
||||
@@ -4733,7 +4945,7 @@ struct ChainRuleSet
|
||||
skippy_iter.set_glyph_data ((HBUINT16 *) nullptr);
|
||||
unsigned unsafe_to = (unsigned) -1, unsafe_to1, unsafe_to2 = 0;
|
||||
hb_glyph_info_t *first = nullptr, *second = nullptr;
|
||||
bool matched = skippy_iter.next ();
|
||||
bool matched = skippy_iter.next (&unsafe_to1);
|
||||
if (likely (matched))
|
||||
{
|
||||
if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx]))
|
||||
@@ -4745,24 +4957,34 @@ struct ChainRuleSet
|
||||
|
||||
first = &c->buffer->info[skippy_iter.idx];
|
||||
unsafe_to1 = skippy_iter.idx + 1;
|
||||
|
||||
if (digest && lookup_context.get_input_value &&
|
||||
!digest->may_have (lookup_context.get_input_value (*first, lookup_context.match_data[1])))
|
||||
{
|
||||
c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1);
|
||||
return_trace (false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Failed to match a next glyph. Only try applying rules that have
|
||||
* no further input and lookahead. */
|
||||
return_trace (
|
||||
bool unsafe_to_concat = false;
|
||||
bool ret =
|
||||
+ hb_iter (rule)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_filter ([&] (const ChainRule &_)
|
||||
{
|
||||
const auto &input = StructAfter<decltype (_.inputX)> (_.backtrack);
|
||||
const auto &lookahead = StructAfter<decltype (_.lookaheadX)> (input);
|
||||
return input.lenP1 <= 1 && lookahead.len == 0;
|
||||
if (input.lenP1 <= 1 && lookahead.len == 0) return true;
|
||||
unsafe_to_concat = true;
|
||||
return false;
|
||||
})
|
||||
| hb_map ([&] (const ChainRule &_) { return _.apply (c, lookup_context); })
|
||||
| hb_any
|
||||
)
|
||||
;
|
||||
if (unsafe_to_concat)
|
||||
c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to1);
|
||||
return_trace (ret);
|
||||
}
|
||||
matched = skippy_iter.next ();
|
||||
if (likely (matched))
|
||||
@@ -4998,6 +5220,14 @@ struct ChainContextFormat1_4
|
||||
;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{
|
||||
+ hb_iter (ruleSet)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([digest] (const ChainRuleSet &_) { _.collect_second_glyphs (digest); })
|
||||
;
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c) const
|
||||
{
|
||||
const ChainRuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])];
|
||||
@@ -5243,6 +5473,17 @@ struct ChainContextFormat2_5
|
||||
;
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{
|
||||
const ClassDef &input_class_def = this+inputClassDef;
|
||||
const ClassDef &lookahead_class_def = this+lookaheadClassDef;
|
||||
+ hb_iter (ruleSet)
|
||||
| hb_map (hb_add (this))
|
||||
| hb_apply ([digest, &input_class_def, &lookahead_class_def] (const ChainRuleSet &_)
|
||||
{ _.collect_second_glyphs (digest, &input_class_def, &lookahead_class_def); })
|
||||
;
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c) const
|
||||
{
|
||||
const ClassDef &backtrack_class_def = this+backtrackClassDef;
|
||||
@@ -5274,13 +5515,24 @@ struct ChainContextFormat2_5
|
||||
struct external_cache_t
|
||||
{
|
||||
hb_ot_layout_binary_cache_t coverage;
|
||||
hb_ot_layout_mapping_cache_t input_class;
|
||||
hb_ot_layout_mapping_cache_t lookahead_class;
|
||||
hb_ot_layout_ruleset_digest_t rule_sets[HB_VAR_ARRAY];
|
||||
};
|
||||
void *external_cache_create () const
|
||||
{
|
||||
external_cache_t *cache = (external_cache_t *) hb_malloc (sizeof (external_cache_t));
|
||||
unsigned count = ruleSet.len;
|
||||
unsigned size = sizeof (external_cache_t) -
|
||||
HB_VAR_ARRAY * sizeof (hb_ot_layout_ruleset_digest_t) +
|
||||
count * sizeof (hb_ot_layout_ruleset_digest_t);
|
||||
external_cache_t *cache = (external_cache_t *) hb_malloc (size);
|
||||
if (likely (cache))
|
||||
{
|
||||
cache->coverage.clear ();
|
||||
cache->input_class.clear ();
|
||||
cache->lookahead_class.clear ();
|
||||
for (unsigned i = 0; i < count; i++)
|
||||
(this+ruleSet[i]).collect_first_input_classes (&cache->rule_sets[i]);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
@@ -5301,22 +5553,67 @@ struct ChainContextFormat2_5
|
||||
const ClassDef &input_class_def = this+inputClassDef;
|
||||
const ClassDef &lookahead_class_def = this+lookaheadClassDef;
|
||||
|
||||
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
|
||||
match_class_cache_data_t input_cache_data = {
|
||||
&input_class_def,
|
||||
cache ? &cache->input_class : nullptr
|
||||
};
|
||||
match_class_cache_data_t lookahead_cache_data = {
|
||||
&lookahead_class_def,
|
||||
cache ? &cache->lookahead_class : nullptr
|
||||
};
|
||||
const void *input_match_data = cached
|
||||
? static_cast<const void *> (&input_class_def)
|
||||
: static_cast<const void *> (&input_cache_data);
|
||||
const void *lookahead_match_data = cached
|
||||
? static_cast<const void *> (&lookahead_class_def)
|
||||
: static_cast<const void *> (&lookahead_cache_data);
|
||||
bool backtrack_uses_lookahead_cache =
|
||||
!cached && &backtrack_class_def == &lookahead_class_def;
|
||||
const void *backtrack_match_data = backtrack_uses_lookahead_cache
|
||||
? static_cast<const void *> (&lookahead_cache_data)
|
||||
: static_cast<const void *> (&backtrack_class_def);
|
||||
#endif
|
||||
|
||||
/* match_class_caches1 is slightly faster. Use it for lookahead,
|
||||
* which is typically longer. */
|
||||
struct ChainContextApplyLookupContext lookup_context = {
|
||||
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
|
||||
{{cached && &backtrack_class_def == &lookahead_class_def ? match_class_cached1 :
|
||||
backtrack_uses_lookahead_cache ? match_class_cache : match_class,
|
||||
cached ? match_class_cached2 : match_class_cache,
|
||||
cached ? match_class_cached1 : match_class_cache}},
|
||||
{backtrack_match_data,
|
||||
input_match_data,
|
||||
lookahead_match_data},
|
||||
cached ? get_class_cached2_value : get_class_cache_value
|
||||
#else
|
||||
{{cached && &backtrack_class_def == &lookahead_class_def ? match_class_cached1 : match_class,
|
||||
cached ? match_class_cached2 : match_class,
|
||||
cached ? match_class_cached1 : match_class}},
|
||||
{&backtrack_class_def,
|
||||
&input_class_def,
|
||||
&lookahead_class_def}
|
||||
&lookahead_class_def},
|
||||
cached ? get_class_cached2_value : get_class_value
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
|
||||
index = cached
|
||||
? get_class_cached2 (input_class_def, c->buffer->cur())
|
||||
: input_class_def.get_class (c->buffer->cur().codepoint, input_cache_data.cache);
|
||||
#else
|
||||
index = cached
|
||||
? get_class_cached2 (input_class_def, c->buffer->cur())
|
||||
: input_class_def.get_class (c->buffer->cur().codepoint);
|
||||
#endif
|
||||
const ChainRuleSet &rule_set = this+ruleSet[index];
|
||||
return_trace (rule_set.apply (c, lookup_context));
|
||||
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
|
||||
const hb_ot_layout_ruleset_digest_t *digest = cache && index < ruleSet.len ? &cache->rule_sets[index] : nullptr;
|
||||
#else
|
||||
const hb_ot_layout_ruleset_digest_t *digest = nullptr;
|
||||
#endif
|
||||
return_trace (rule_set.apply (c, lookup_context, digest));
|
||||
}
|
||||
|
||||
bool subset (hb_subset_context_t *c) const
|
||||
@@ -5543,6 +5840,18 @@ struct ChainContextFormat3
|
||||
lookup_context);
|
||||
}
|
||||
|
||||
void collect_second_glyphs (hb_set_digest_t *digest) const
|
||||
{
|
||||
const auto &input = StructAfter<decltype (inputX)> (backtrack);
|
||||
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
|
||||
if (input.len > 1)
|
||||
(this+input[1]).collect_coverage (digest);
|
||||
else if (lookahead.len)
|
||||
(this+lookahead[0]).collect_coverage (digest);
|
||||
else
|
||||
*digest = hb_set_digest_t::full ();
|
||||
}
|
||||
|
||||
bool would_apply (hb_would_apply_context_t *c) const
|
||||
{
|
||||
const auto &input = StructAfter<decltype (inputX)> (backtrack);
|
||||
@@ -5846,6 +6155,7 @@ struct hb_ot_layout_lookup_accelerator_t
|
||||
thiz->digest.init ();
|
||||
for (auto& subtable : hb_iter (thiz->subtables, count))
|
||||
thiz->digest.union_ (subtable.digest);
|
||||
thiz->digest_second = c_accelerate_subtables.digest_second;
|
||||
|
||||
thiz->count = count;
|
||||
|
||||
@@ -5876,7 +6186,6 @@ struct hb_ot_layout_lookup_accelerator_t
|
||||
#endif
|
||||
bool apply (hb_ot_apply_context_t *c, bool use_cache) const
|
||||
{
|
||||
c->lookup_accel = this;
|
||||
if (count == 1)
|
||||
{
|
||||
/* The accelerator digest is the union of the subtable digests, so
|
||||
@@ -5929,6 +6238,7 @@ struct hb_ot_layout_lookup_accelerator_t
|
||||
|
||||
|
||||
hb_set_digest_t digest;
|
||||
hb_set_digest_t digest_second;
|
||||
private:
|
||||
unsigned count = 0; /* Number of subtables in the array. */
|
||||
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
|
||||
|
||||
+15
-2
@@ -265,6 +265,7 @@ OT::GDEF::is_blocklisted (hb_blob_t *blob,
|
||||
return false;
|
||||
}
|
||||
|
||||
template <bool SetDigest>
|
||||
static void
|
||||
_hb_ot_layout_set_glyph_props (hb_font_t *font,
|
||||
hb_buffer_t *buffer)
|
||||
@@ -276,6 +277,8 @@ _hb_ot_layout_set_glyph_props (hb_font_t *font,
|
||||
hb_glyph_info_t *info = buffer->info;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
if (SetDigest)
|
||||
buffer->digest.add (info[i].codepoint);
|
||||
_hb_glyph_info_set_glyph_props (&info[i], gdef.get_glyph_props (info[i].codepoint));
|
||||
_hb_glyph_info_clear_lig_props (&info[i]);
|
||||
}
|
||||
@@ -1573,7 +1576,15 @@ void
|
||||
hb_ot_layout_substitute_start (hb_font_t *font,
|
||||
hb_buffer_t *buffer)
|
||||
{
|
||||
_hb_ot_layout_set_glyph_props (font, buffer);
|
||||
_hb_ot_layout_set_glyph_props<false> (font, buffer);
|
||||
}
|
||||
|
||||
void
|
||||
hb_ot_layout_substitute_start_with_digest (hb_font_t *font,
|
||||
hb_buffer_t *buffer)
|
||||
{
|
||||
buffer->digest = hb_set_digest_t ();
|
||||
_hb_ot_layout_set_glyph_props<true> (font, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2037,7 +2048,9 @@ inline void hb_ot_map_t::apply (const Proxy &proxy,
|
||||
!buffer->message (font, "start lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag))) continue;
|
||||
|
||||
/* Only try applying the lookup if there is any overlap. */
|
||||
if (accel->digest.may_intersect (buffer->digest))
|
||||
if (accel->digest.may_intersect (buffer->digest) &&
|
||||
((buffer->flags & HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT) ||
|
||||
accel->digest_second.may_intersect (buffer->digest)))
|
||||
{
|
||||
c.set_lookup_index (lookup_index);
|
||||
c.set_lookup_mask (lookup.mask, false);
|
||||
|
||||
@@ -102,6 +102,10 @@ HB_INTERNAL void
|
||||
hb_ot_layout_substitute_start (hb_font_t *font,
|
||||
hb_buffer_t *buffer);
|
||||
|
||||
HB_INTERNAL void
|
||||
hb_ot_layout_substitute_start_with_digest (hb_font_t *font,
|
||||
hb_buffer_t *buffer);
|
||||
|
||||
namespace OT {
|
||||
struct hb_ot_apply_context_t;
|
||||
struct hb_ot_layout_lookup_accelerator_t;
|
||||
|
||||
+15
-19
@@ -468,7 +468,8 @@ struct hb_ot_shape_context_t
|
||||
/* Prepare */
|
||||
|
||||
static void
|
||||
hb_set_unicode_props (hb_buffer_t *buffer)
|
||||
hb_set_unicode_props (hb_buffer_t *buffer,
|
||||
hb_mask_t global_mask)
|
||||
{
|
||||
/* Implement enough of Unicode Graphemes here that shaping
|
||||
* in reverse-direction wouldn't break graphemes. Namely,
|
||||
@@ -482,6 +483,7 @@ hb_set_unicode_props (hb_buffer_t *buffer)
|
||||
hb_glyph_info_t *info = buffer->info;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
info[i].mask = global_mask;
|
||||
_hb_glyph_info_set_unicode_props (&info[i], buffer);
|
||||
|
||||
if (info[i].codepoint < 0x80)
|
||||
@@ -519,6 +521,7 @@ hb_set_unicode_props (hb_buffer_t *buffer)
|
||||
_hb_unicode_is_emoji_Extended_Pictographic (info[i + 1].codepoint))
|
||||
{
|
||||
i++;
|
||||
info[i].mask = global_mask;
|
||||
_hb_glyph_info_set_unicode_props (&info[i], buffer);
|
||||
_hb_glyph_info_set_continuation (&info[i], buffer);
|
||||
}
|
||||
@@ -743,16 +746,6 @@ hb_ot_shape_setup_masks_fraction (const hb_ot_shape_context_t *c)
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
hb_ot_shape_initialize_masks (const hb_ot_shape_context_t *c)
|
||||
{
|
||||
hb_ot_map_t *map = &c->plan->map;
|
||||
hb_buffer_t *buffer = c->buffer;
|
||||
|
||||
hb_mask_t global_mask = map->get_global_mask ();
|
||||
buffer->reset_masks (global_mask);
|
||||
}
|
||||
|
||||
static inline void
|
||||
hb_ot_shape_setup_masks (const hb_ot_shape_context_t *c)
|
||||
{
|
||||
@@ -912,14 +905,14 @@ hb_ot_substitute_plan (const hb_ot_shape_context_t *c)
|
||||
{
|
||||
hb_buffer_t *buffer = c->buffer;
|
||||
|
||||
hb_ot_layout_substitute_start (c->font, buffer);
|
||||
|
||||
if (c->plan->fallback_glyph_classes)
|
||||
hb_synthesize_glyph_classes (c->buffer);
|
||||
|
||||
#ifndef HB_NO_AAT_SHAPE
|
||||
if (unlikely (c->plan->apply_morx))
|
||||
{
|
||||
hb_ot_layout_substitute_start (c->font, buffer);
|
||||
|
||||
if (c->plan->fallback_glyph_classes)
|
||||
hb_synthesize_glyph_classes (buffer);
|
||||
|
||||
hb_aat_layout_substitute (c->plan, c->font, c->buffer,
|
||||
c->user_features, c->num_user_features);
|
||||
/* The buffer digest is only used by the OT lookup-apply loop;
|
||||
@@ -930,7 +923,11 @@ hb_ot_substitute_plan (const hb_ot_shape_context_t *c)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
c->buffer->update_digest ();
|
||||
hb_ot_layout_substitute_start_with_digest (c->font, buffer);
|
||||
|
||||
if (c->plan->fallback_glyph_classes)
|
||||
hb_synthesize_glyph_classes (buffer);
|
||||
|
||||
c->plan->substitute (c->font, buffer);
|
||||
}
|
||||
}
|
||||
@@ -1178,8 +1175,7 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c)
|
||||
|
||||
_hb_buffer_allocate_unicode_vars (c->buffer);
|
||||
|
||||
hb_ot_shape_initialize_masks (c);
|
||||
hb_set_unicode_props (c->buffer);
|
||||
hb_set_unicode_props (c->buffer, c->plan->map.get_global_mask ());
|
||||
hb_insert_dotted_circle (c->buffer, c->font);
|
||||
|
||||
hb_form_clusters (c->buffer);
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
* # Updated for Unicode 15.0 by Andrew Glass 2022-09-16
|
||||
* # Updated for Unicode 15.1 by Andrew Glass 2023-09-14
|
||||
* # Updated for Unicode 16.0 by Andrew Glass 2024-09-11
|
||||
* # Updated for Unicode 17.0 by Andrew Glass 2025-09-15
|
||||
* # Updated for Unicode 18.0 by Andrew Glass 2026-09-04
|
||||
* # Override values For Indic_Positional_Category
|
||||
* # Not derivable
|
||||
* # Initial version based on Unicode 7.0 by Andrew Glass 2014-03-17
|
||||
@@ -40,6 +42,8 @@
|
||||
* # Updated for Unicode 15.0 by Andrew Glass 2022-09-16
|
||||
* # Updated for Unicode 15.1 by Andrew Glass 2023-09-14
|
||||
* # Updated for Unicode 16.0 by Andrew Glass 2024-09-11
|
||||
* # Updated for Unicode 17.0 by Andrew Glass 2025-09-15
|
||||
* # Updated for Unicode 18.0 by Andrew Glass 2026-09-04
|
||||
* UnicodeData.txt does not have a header.
|
||||
*/
|
||||
|
||||
|
||||
@@ -757,7 +757,8 @@ struct gvar_GVAR
|
||||
const hb_array_t<contour_point_t> points,
|
||||
hb_glyf_scratch_t &scratch,
|
||||
hb_scalar_cache_t *gvar_cache = nullptr,
|
||||
bool phantom_only = false) const
|
||||
bool phantom_only = false,
|
||||
int64_t *budget = nullptr) const
|
||||
{
|
||||
if (unlikely (glyph >= glyphCount)) return true;
|
||||
hb_scalar_cache_t *scalar_cache = gvar_cache ?
|
||||
@@ -806,6 +807,11 @@ struct gvar_GVAR
|
||||
|
||||
if (scalar == 0.f) continue;
|
||||
|
||||
if (budget &&
|
||||
unlikely (!hb_budget_spend (*budget, HB_BUDGET_1,
|
||||
phantom_only && count >= 4 ? 4 : count)))
|
||||
return false;
|
||||
|
||||
if (!private_points_checked)
|
||||
{
|
||||
auto scan = iterator;
|
||||
|
||||
@@ -298,6 +298,16 @@ hb_outline_recording_pen_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
c->contours.push (c->points.length);
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_outline_recording_pen_get_budget_remaining (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_outline_t *c = (hb_outline_t *) data;
|
||||
|
||||
return c->budget_remaining;
|
||||
}
|
||||
|
||||
static inline void free_static_outline_recording_pen_funcs ();
|
||||
|
||||
static struct hb_outline_recording_pen_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t<hb_outline_recording_pen_funcs_lazy_loader_t>
|
||||
@@ -311,6 +321,7 @@ static struct hb_outline_recording_pen_funcs_lazy_loader_t : hb_draw_funcs_lazy_
|
||||
hb_draw_funcs_set_quadratic_to_func (funcs, hb_outline_recording_pen_quadratic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, hb_outline_recording_pen_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, hb_outline_recording_pen_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_outline_recording_pen_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ struct hb_outline_t
|
||||
|
||||
hb_vector_t<hb_outline_point_t> points;
|
||||
hb_vector_t<unsigned> contours;
|
||||
int64_t *budget_remaining = nullptr;
|
||||
};
|
||||
|
||||
HB_INTERNAL hb_draw_funcs_t *
|
||||
|
||||
+52
-18
@@ -62,13 +62,17 @@ hb_paint_extents_pop_transform (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
c->pop_transform ();
|
||||
}
|
||||
|
||||
/* Like the hb_draw_extents_get_funcs() sink, but also counts the
|
||||
* consumed segments so they can be charged against the session work
|
||||
* budget. */
|
||||
struct hb_paint_extents_counting_sink_t
|
||||
/* Like the hb_draw_extents_get_funcs() sink, but tied to the paint
|
||||
* session's live work budget. */
|
||||
struct hb_paint_extents_sink_t
|
||||
{
|
||||
hb_extents_t<> extents;
|
||||
int64_t count = 0;
|
||||
int64_t *budget_remaining;
|
||||
|
||||
bool consume_segment ()
|
||||
{
|
||||
return hb_budget_spend (*budget_remaining, HB_BUDGET_1);
|
||||
}
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -77,8 +81,8 @@ hb_paint_extents_count_move_to (hb_draw_funcs_t *dfuncs HB_UNUSED, void *data,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_paint_extents_counting_sink_t *sink = (hb_paint_extents_counting_sink_t *) data;
|
||||
sink->count++;
|
||||
hb_paint_extents_sink_t *sink = (hb_paint_extents_sink_t *) data;
|
||||
if (unlikely (!sink->consume_segment ())) return;
|
||||
sink->extents.add_point (to_x, to_y);
|
||||
}
|
||||
|
||||
@@ -88,8 +92,8 @@ hb_paint_extents_count_line_to (hb_draw_funcs_t *dfuncs HB_UNUSED, void *data,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_paint_extents_counting_sink_t *sink = (hb_paint_extents_counting_sink_t *) data;
|
||||
sink->count++;
|
||||
hb_paint_extents_sink_t *sink = (hb_paint_extents_sink_t *) data;
|
||||
if (unlikely (!sink->consume_segment ())) return;
|
||||
sink->extents.add_point (to_x, to_y);
|
||||
}
|
||||
|
||||
@@ -100,8 +104,8 @@ hb_paint_extents_count_quadratic_to (hb_draw_funcs_t *dfuncs HB_UNUSED, void *da
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_paint_extents_counting_sink_t *sink = (hb_paint_extents_counting_sink_t *) data;
|
||||
sink->count++;
|
||||
hb_paint_extents_sink_t *sink = (hb_paint_extents_sink_t *) data;
|
||||
if (unlikely (!sink->consume_segment ())) return;
|
||||
sink->extents.add_point (control_x, control_y);
|
||||
sink->extents.add_point (to_x, to_y);
|
||||
}
|
||||
@@ -114,13 +118,19 @@ hb_paint_extents_count_cubic_to (hb_draw_funcs_t *dfuncs HB_UNUSED, void *data,
|
||||
float to_x, float to_y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_paint_extents_counting_sink_t *sink = (hb_paint_extents_counting_sink_t *) data;
|
||||
sink->count++;
|
||||
hb_paint_extents_sink_t *sink = (hb_paint_extents_sink_t *) data;
|
||||
if (unlikely (!sink->consume_segment ())) return;
|
||||
sink->extents.add_point (control1_x, control1_y);
|
||||
sink->extents.add_point (control2_x, control2_y);
|
||||
sink->extents.add_point (to_x, to_y);
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_paint_extents_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_paint_extents_sink_t *) draw_data)->budget_remaining;
|
||||
}
|
||||
|
||||
static inline void free_static_paint_extents_draw_funcs ();
|
||||
|
||||
static struct hb_paint_extents_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t<hb_paint_extents_draw_funcs_lazy_loader_t>
|
||||
@@ -133,6 +143,7 @@ static struct hb_paint_extents_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loa
|
||||
hb_draw_funcs_set_line_to_func (funcs, hb_paint_extents_count_line_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_quadratic_to_func (funcs, hb_paint_extents_count_quadratic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, hb_paint_extents_count_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_paint_extents_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
|
||||
@@ -157,14 +168,11 @@ hb_paint_extents_push_clip_glyph (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
{
|
||||
hb_paint_extents_context_t *c = (hb_paint_extents_context_t *) paint_data;
|
||||
|
||||
hb_paint_extents_counting_sink_t sink;
|
||||
hb_paint_extents_sink_t sink {{}, &c->budget_remaining};
|
||||
/* Skip the outline extraction when the session work budget is
|
||||
* spent; an empty clip clips everything out. */
|
||||
if (likely (c->work_left > 0))
|
||||
{
|
||||
if (likely (c->budget_remaining >= 0))
|
||||
hb_font_draw_glyph (font, glyph, static_paint_extents_draw_funcs.get_unconst (), &sink);
|
||||
c->work_left -= 1 + sink.count;
|
||||
}
|
||||
c->push_clip (sink.extents);
|
||||
}
|
||||
|
||||
@@ -291,6 +299,29 @@ hb_paint_extents_paint_sweep_gradient (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
c->paint ();
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_paint_extents_set_budget (hb_paint_funcs_t *, void *paint_data,
|
||||
int64_t budget, void *)
|
||||
{
|
||||
auto *context = (hb_paint_extents_context_t *) paint_data;
|
||||
context->budget = budget;
|
||||
context->budget_initialized = true;
|
||||
context->recharge_budget ();
|
||||
return true;
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_paint_extents_get_budget (hb_paint_funcs_t *, void *paint_data, void *)
|
||||
{
|
||||
return ((hb_paint_extents_context_t *) paint_data)->budget;
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_paint_extents_get_budget_remaining (hb_paint_funcs_t *, void *paint_data, void *)
|
||||
{
|
||||
return &((hb_paint_extents_context_t *) paint_data)->budget_remaining;
|
||||
}
|
||||
|
||||
static inline void free_static_paint_extents_funcs ();
|
||||
|
||||
static struct hb_paint_extents_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t<hb_paint_extents_funcs_lazy_loader_t>
|
||||
@@ -311,6 +342,9 @@ static struct hb_paint_extents_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_
|
||||
hb_paint_funcs_set_linear_gradient_func (funcs, hb_paint_extents_paint_linear_gradient, nullptr, nullptr);
|
||||
hb_paint_funcs_set_radial_gradient_func (funcs, hb_paint_extents_paint_radial_gradient, nullptr, nullptr);
|
||||
hb_paint_funcs_set_sweep_gradient_func (funcs, hb_paint_extents_paint_sweep_gradient, nullptr, nullptr);
|
||||
hb_paint_funcs_set_set_budget_func (funcs, hb_paint_extents_set_budget, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_func (funcs, hb_paint_extents_get_budget, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_paint_extents_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_paint_funcs_make_immutable (funcs);
|
||||
|
||||
|
||||
+20
-5
@@ -40,7 +40,15 @@ struct hb_paint_extents_context_t
|
||||
transforms.clear ();
|
||||
clips.clear ();
|
||||
groups.clear ();
|
||||
work_left = HB_PAINT_EXTENTS_MAX_WORK;
|
||||
/* COLR scratch storage is zero-allocated and reused without running
|
||||
* constructors. Distinguish that state from an explicitly requested
|
||||
* zero budget. */
|
||||
if (unlikely (!budget_initialized))
|
||||
{
|
||||
budget = HB_BUDGET_DEFAULT;
|
||||
budget_initialized = true;
|
||||
}
|
||||
recharge_budget ();
|
||||
|
||||
transforms.push (hb_transform_t<>{});
|
||||
clips.push (hb_bounds_t<>{hb_bounds_t<>::UNBOUNDED});
|
||||
@@ -133,10 +141,17 @@ struct hb_paint_extents_context_t
|
||||
}
|
||||
|
||||
/* Cumulative work budget for the current session; reset by clear().
|
||||
* Charged with the outline points consumed by each clip-glyph draw,
|
||||
* so per-glyph outline limits cannot multiply with the paint-graph
|
||||
* traversal limits of the font tables driving us (e.g. COLR). */
|
||||
int64_t work_left = HB_PAINT_EXTENTS_MAX_WORK;
|
||||
* Outline traversal and consumed segments charge the same live
|
||||
* counter. */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
bool budget_initialized = true;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
|
||||
void recharge_budget ()
|
||||
{
|
||||
budget_remaining = budget == HB_BUDGET_DEFAULT ?
|
||||
HB_BUDGET_GLYPH : budget;
|
||||
}
|
||||
|
||||
protected:
|
||||
hb_vector_t<hb_transform_t<>> transforms;
|
||||
|
||||
@@ -160,6 +160,19 @@ hb_paint_custom_palette_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
|
||||
hb_color_t *color,
|
||||
void *user_data) { return false; }
|
||||
|
||||
static hb_bool_t
|
||||
hb_paint_set_budget_nil (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data HB_UNUSED,
|
||||
int64_t budget HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return false; }
|
||||
|
||||
static int64_t
|
||||
hb_paint_get_budget_nil (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return HB_BUDGET_DEFAULT; }
|
||||
|
||||
static int64_t *
|
||||
hb_paint_get_budget_remaining_nil (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return nullptr; }
|
||||
|
||||
static bool
|
||||
_hb_paint_funcs_set_preamble (hb_paint_funcs_t *funcs,
|
||||
bool func_is_null,
|
||||
@@ -420,6 +433,67 @@ hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs)
|
||||
return hb_object_is_immutable (funcs);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_paint_set_budget:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: associated paint data
|
||||
* @budget: the new work-budget policy
|
||||
*
|
||||
* Sets the work-budget policy and recharges the live work budget. Negative
|
||||
* values other than #HB_BUDGET_DEFAULT are clamped to zero.
|
||||
*
|
||||
* Return value: `true` if the paint functions support work budgets
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
hb_bool_t
|
||||
hb_paint_set_budget (hb_paint_funcs_t *funcs, void *paint_data, int64_t budget)
|
||||
{
|
||||
return funcs->set_budget (paint_data, budget);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_paint_get_budget:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: associated paint data
|
||||
*
|
||||
* Fetches the configured work-budget policy.
|
||||
*
|
||||
* Return value: the configured policy, or #HB_BUDGET_DEFAULT if unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
int64_t
|
||||
hb_paint_get_budget (hb_paint_funcs_t *funcs, void *paint_data)
|
||||
{
|
||||
return funcs->get_budget (paint_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_paint_get_budget_remaining:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: associated paint data
|
||||
*
|
||||
* Fetches the live work budget. A negative value means the budget was
|
||||
* exhausted. Zero means the preceding work fit exactly, but no positive-cost
|
||||
* work can start.
|
||||
*
|
||||
* Return value: the live work budget; if it is not tracked, the concrete
|
||||
* configured policy or #HB_BUDGET_UNLIMITED
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
int64_t
|
||||
hb_paint_get_budget_remaining (hb_paint_funcs_t *funcs, void *paint_data)
|
||||
{
|
||||
int64_t *remaining = funcs->get_budget_remaining_ptr (paint_data);
|
||||
if (remaining)
|
||||
return *remaining;
|
||||
|
||||
int64_t budget = funcs->get_budget (paint_data);
|
||||
return budget == HB_BUDGET_DEFAULT ? HB_BUDGET_UNLIMITED : budget;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hb_color_line_get_color_stops:
|
||||
|
||||
+113
@@ -63,6 +63,109 @@ HB_BEGIN_DECLS
|
||||
**/
|
||||
typedef struct hb_paint_funcs_t hb_paint_funcs_t;
|
||||
|
||||
/**
|
||||
* hb_paint_set_budget_func_t:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: The data accompanying the paint functions
|
||||
* @budget: the new work-budget policy
|
||||
* @user_data: User data pointer passed to hb_paint_funcs_set_set_budget_func()
|
||||
*
|
||||
* Sets the work-budget policy and recharges the live work budget. @budget is
|
||||
* #HB_BUDGET_DEFAULT, #HB_BUDGET_UNLIMITED, or a non-negative concrete value.
|
||||
*
|
||||
* Return value: `true` if the budget was set, `false` if unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef hb_bool_t (*hb_paint_set_budget_func_t) (hb_paint_funcs_t *funcs,
|
||||
void *paint_data,
|
||||
int64_t budget,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_paint_get_budget_func_t:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: The data accompanying the paint functions
|
||||
* @user_data: User data pointer passed to hb_paint_funcs_set_get_budget_func()
|
||||
*
|
||||
* Fetches the configured work-budget policy.
|
||||
*
|
||||
* Return value: the configured work-budget policy
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef int64_t (*hb_paint_get_budget_func_t) (hb_paint_funcs_t *funcs,
|
||||
void *paint_data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_paint_get_budget_remaining_func_t:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: The data accompanying the paint functions
|
||||
* @user_data: User data pointer passed to
|
||||
* hb_paint_funcs_set_get_budget_remaining_func()
|
||||
*
|
||||
* Fetches the address of the live work budget. The returned address must stay
|
||||
* valid while @paint_data is used with @funcs. The live value must be concrete;
|
||||
* it must not contain #HB_BUDGET_DEFAULT.
|
||||
*
|
||||
* Return value: (nullable) (transfer none): the live work budget, or `NULL` if
|
||||
* live budget accounting is unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef int64_t *(*hb_paint_get_budget_remaining_func_t) (hb_paint_funcs_t *funcs,
|
||||
void *paint_data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_paint_funcs_set_set_budget_func:
|
||||
* @funcs: paint functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): budget setter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the budget setter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_paint_funcs_set_set_budget_func (hb_paint_funcs_t *funcs,
|
||||
hb_paint_set_budget_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_paint_funcs_set_get_budget_func:
|
||||
* @funcs: paint functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): budget getter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the budget-policy getter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_paint_funcs_set_get_budget_func (hb_paint_funcs_t *funcs,
|
||||
hb_paint_get_budget_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_paint_funcs_set_get_budget_remaining_func:
|
||||
* @funcs: paint functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): live-budget getter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the live-budget getter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_paint_funcs_set_get_budget_remaining_func (hb_paint_funcs_t *funcs,
|
||||
hb_paint_get_budget_remaining_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
HB_EXTERN hb_paint_funcs_t *
|
||||
hb_paint_funcs_create (void);
|
||||
|
||||
@@ -93,6 +196,16 @@ hb_paint_funcs_make_immutable (hb_paint_funcs_t *funcs);
|
||||
HB_EXTERN hb_bool_t
|
||||
hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs);
|
||||
|
||||
HB_EXTERN hb_bool_t
|
||||
hb_paint_set_budget (hb_paint_funcs_t *funcs, void *paint_data,
|
||||
int64_t budget);
|
||||
|
||||
HB_EXTERN int64_t
|
||||
hb_paint_get_budget (hb_paint_funcs_t *funcs, void *paint_data);
|
||||
|
||||
HB_EXTERN int64_t
|
||||
hb_paint_get_budget_remaining (hb_paint_funcs_t *funcs, void *paint_data);
|
||||
|
||||
/**
|
||||
* hb_paint_push_transform_func_t:
|
||||
* @funcs: paint functions object
|
||||
|
||||
@@ -49,6 +49,9 @@
|
||||
HB_PAINT_FUNC_IMPLEMENT (pop_group) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (custom_palette_color) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (fill_glyph) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (set_budget) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (get_budget) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (get_budget_remaining) \
|
||||
/* ^--- Add new callbacks here */
|
||||
|
||||
struct hb_paint_funcs_t
|
||||
@@ -183,6 +186,19 @@ struct hb_paint_funcs_t
|
||||
color_index,
|
||||
color,
|
||||
!user_data ? nullptr : user_data->custom_palette_color); }
|
||||
bool set_budget (void *paint_data, int64_t budget)
|
||||
{
|
||||
if (budget < 0 && budget != HB_BUDGET_DEFAULT)
|
||||
budget = 0;
|
||||
return func.set_budget (this, paint_data, budget,
|
||||
!user_data ? nullptr : user_data->set_budget);
|
||||
}
|
||||
int64_t get_budget (void *paint_data)
|
||||
{ return func.get_budget (this, paint_data,
|
||||
!user_data ? nullptr : user_data->get_budget); }
|
||||
int64_t *get_budget_remaining_ptr (void *paint_data)
|
||||
{ return func.get_budget_remaining (this, paint_data,
|
||||
!user_data ? nullptr : user_data->get_budget_remaining); }
|
||||
|
||||
|
||||
/* Internal specializations. */
|
||||
|
||||
+44
-26
@@ -83,11 +83,21 @@ struct hb_raster_draw_t
|
||||
float flatten_clip_x0 = 0.f, flatten_clip_y0 = 0.f;
|
||||
float flatten_clip_x1 = 0.f, flatten_clip_y1 = 0.f;
|
||||
|
||||
/* Curve-flattening work, charged one unit per Bézier subdivision.
|
||||
When external_work is set (by raster-paint), that session budget
|
||||
is charged instead of the standalone per-session one. */
|
||||
int64_t flatten_work_left = HB_RASTER_MAX_DRAW_WORK;
|
||||
int64_t *external_work = nullptr;
|
||||
/* Work budget for outline traversal and curve flattening. A paint
|
||||
backend seeds this through the public draw-budget API before drawing
|
||||
and reads the remainder back afterwards, so a whole paint session
|
||||
shares one budget without reaching into this object. */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
|
||||
void recharge_budget ()
|
||||
{
|
||||
budget_remaining = budget == HB_BUDGET_DEFAULT ?
|
||||
HB_BUDGET_GLYPH : budget;
|
||||
}
|
||||
|
||||
int64_t *get_budget_remaining ()
|
||||
{ return &budget_remaining; }
|
||||
|
||||
/* Accumulated geometry */
|
||||
int64_t edges_left = HB_RASTER_MAX_DRAW_EDGES;
|
||||
@@ -478,8 +488,7 @@ hb_raster_draw_clear (hb_raster_draw_t *draw)
|
||||
draw->has_extents = false;
|
||||
draw->has_clip_box = false;
|
||||
draw->flatten_clip_active = false;
|
||||
draw->flatten_work_left = HB_RASTER_MAX_DRAW_WORK;
|
||||
draw->external_work = nullptr;
|
||||
draw->recharge_budget ();
|
||||
draw->edges_left = HB_RASTER_MAX_DRAW_EDGES;
|
||||
draw->edges.clear ();
|
||||
draw->active_edges.clear ();
|
||||
@@ -501,6 +510,7 @@ hb_raster_draw_reset (hb_raster_draw_t *draw)
|
||||
draw->transform = {1, 0, 0, 1, 0, 0};
|
||||
draw->x_scale_factor = 1.f;
|
||||
draw->y_scale_factor = 1.f;
|
||||
draw->budget = HB_BUDGET_DEFAULT;
|
||||
hb_raster_draw_clear (draw);
|
||||
}
|
||||
|
||||
@@ -517,23 +527,6 @@ hb_raster_draw_set_clip_box (hb_raster_draw_t *draw,
|
||||
hb_raster_draw_update_flatten_clip (draw);
|
||||
}
|
||||
|
||||
void
|
||||
hb_raster_draw_set_external_work (hb_raster_draw_t *draw,
|
||||
int64_t *work_left)
|
||||
{
|
||||
draw->external_work = work_left;
|
||||
}
|
||||
|
||||
int64_t
|
||||
hb_raster_draw_get_edge_work (hb_raster_draw_t *draw, unsigned max_rows)
|
||||
{
|
||||
int64_t work = 0;
|
||||
for (const auto &e : draw->edges)
|
||||
work += 1 + hb_min (((int64_t) e.yH - (int64_t) e.yL) >> HB_RASTER_PIXEL_BITS,
|
||||
(int64_t) max_rows);
|
||||
return work;
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_raster_draw_recycle_image:
|
||||
* @draw: a rasterizer
|
||||
@@ -619,7 +612,7 @@ flatten_quadratic_recursive (hb_raster_draw_t *draw,
|
||||
unsigned top = 0;
|
||||
|
||||
bool check_clip = draw->flatten_clip_active;
|
||||
int64_t *work = draw->external_work ? draw->external_work : &draw->flatten_work_left;
|
||||
int64_t *work = draw->get_budget_remaining ();
|
||||
int64_t work_left = *work;
|
||||
|
||||
while (true)
|
||||
@@ -829,7 +822,7 @@ flatten_cubic_recursive (hb_raster_draw_t *draw,
|
||||
unsigned top = 0;
|
||||
|
||||
bool check_clip = draw->flatten_clip_active;
|
||||
int64_t *work = draw->external_work ? draw->external_work : &draw->flatten_work_left;
|
||||
int64_t *work = draw->get_budget_remaining ();
|
||||
int64_t work_left = *work;
|
||||
|
||||
while (true)
|
||||
@@ -1091,6 +1084,28 @@ hb_raster_close_path (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
/* no-op: hb_draw_funcs_t already emits closing line_to before us */
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_raster_draw_set_budget (hb_draw_funcs_t *, void *draw_data,
|
||||
int64_t budget, void *)
|
||||
{
|
||||
auto *draw = (hb_raster_draw_t *) draw_data;
|
||||
draw->budget = budget;
|
||||
draw->recharge_budget ();
|
||||
return true;
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_raster_draw_get_budget (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_raster_draw_t *) draw_data)->budget;
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_raster_draw_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_raster_draw_t *) draw_data)->get_budget_remaining ();
|
||||
}
|
||||
|
||||
|
||||
/* Lazy-loader singleton for draw funcs */
|
||||
|
||||
@@ -1107,6 +1122,9 @@ static struct hb_raster_draw_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t<h
|
||||
hb_draw_funcs_set_quadratic_to_func (funcs, hb_raster_quadratic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, hb_raster_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, hb_raster_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_set_budget_func (funcs, hb_raster_draw_set_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_func (funcs, hb_raster_draw_get_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_raster_draw_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
|
||||
|
||||
+56
-23
@@ -149,11 +149,12 @@ ensure_initialized (hb_raster_paint_t *c)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Session work budget: flat floor, or a few passes over the (possibly
|
||||
* client-sized) surface, whichever is larger. */
|
||||
c->work_left = hb_max ((int64_t) HB_RASTER_MAX_PAINT_WORK,
|
||||
(int64_t) HB_RASTER_MAX_PAINT_WORK_PASSES *
|
||||
c->fixed_extents.width * c->fixed_extents.height);
|
||||
/* Resolve the surface-sized pixel budget now that the surface size is
|
||||
* known. An unlimited policy disables the pixel budget, so leave it.
|
||||
* The outline budget is re-resolved to the same value it already holds
|
||||
* (nothing has been drawn yet). */
|
||||
if (c->budget != HB_BUDGET_UNLIMITED)
|
||||
c->recharge_budget ();
|
||||
|
||||
/* Initial clip: full coverage rectangle */
|
||||
hb_raster_clip_t clip;
|
||||
@@ -204,10 +205,11 @@ hb_raster_paint_color_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
|
||||
typedef void (*hb_raster_paint_clip_mask_emit_t) (hb_raster_draw_t *rdr, void *user_data);
|
||||
|
||||
/* Attach the surface box and the session work budget to @rdr before
|
||||
/* Attach the surface box to @rdr and seed its outline budget before
|
||||
* outlines are drawn into it: curves outside the surface collapse to
|
||||
* their chord, and flattening work is charged as it happens instead
|
||||
* of only after the whole outline has been emitted. */
|
||||
* their chord, and outline traversal and curve flattening charge the
|
||||
* seeded budget. hb_raster_paint_readback_budget() pulls the remainder
|
||||
* back into the session afterwards. */
|
||||
static void
|
||||
hb_raster_paint_attach_clip_rdr (hb_raster_paint_t *c,
|
||||
hb_raster_draw_t *rdr,
|
||||
@@ -218,7 +220,16 @@ hb_raster_paint_attach_clip_rdr (hb_raster_paint_t *c,
|
||||
(float) surf->extents.y_origin,
|
||||
(float) surf->extents.x_origin + (float) surf->extents.width,
|
||||
(float) surf->extents.y_origin + (float) surf->extents.height);
|
||||
hb_raster_draw_set_external_work (rdr, &c->work_left);
|
||||
hb_draw_set_budget (hb_raster_draw_get_funcs (rdr), rdr, c->budget_remaining);
|
||||
}
|
||||
|
||||
/* Pull the outline budget the rasterizer has consumed back into the
|
||||
* session, so it aggregates across every glyph in the paint walk. */
|
||||
static void
|
||||
hb_raster_paint_readback_budget (hb_raster_paint_t *c,
|
||||
hb_raster_draw_t *rdr)
|
||||
{
|
||||
c->budget_remaining = hb_draw_get_budget_remaining (hb_raster_draw_get_funcs (rdr), rdr);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -273,10 +284,6 @@ hb_raster_paint_finalize_path_clip (hb_raster_paint_t *c,
|
||||
hb_raster_image_t *surf,
|
||||
unsigned w, unsigned h)
|
||||
{
|
||||
/* Charge the scanline work of the accumulated outline before
|
||||
* rendering it. */
|
||||
c->work_left -= hb_raster_draw_get_edge_work (rdr, h);
|
||||
|
||||
hb_raster_image_t *mask_img = hb_raster_draw_render (rdr);
|
||||
|
||||
if (unlikely (!mask_img))
|
||||
@@ -416,7 +423,7 @@ hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c,
|
||||
/* Out of budget: skip the glyph-outline extraction entirely, so
|
||||
* per-glyph outline limits cannot multiply with the caller's
|
||||
* paint-graph traversal limits. */
|
||||
if (unlikely (c->work_left <= 0))
|
||||
if (unlikely (c->budget_remaining < 0))
|
||||
{
|
||||
hb_raster_paint_push_empty_clip (c, w, h);
|
||||
return;
|
||||
@@ -427,6 +434,7 @@ hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c,
|
||||
hb_raster_draw_set_transform (rdr, t.xx, t.yx, t.xy, t.yy, t.x0, t.y0);
|
||||
hb_raster_paint_attach_clip_rdr (c, rdr, surf);
|
||||
emit (rdr, emit_data);
|
||||
hb_raster_paint_readback_budget (c, rdr);
|
||||
|
||||
hb_raster_paint_finalize_path_clip (c, rdr, surf, w, h);
|
||||
}
|
||||
@@ -744,7 +752,8 @@ hb_raster_paint_push_clip_path_end (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
unsigned w = surf->extents.width;
|
||||
unsigned h = surf->extents.height;
|
||||
|
||||
if (unlikely (c->work_left <= 0))
|
||||
hb_raster_paint_readback_budget (c, c->clip_rdr);
|
||||
if (unlikely (c->budget_remaining < 0))
|
||||
{
|
||||
hb_raster_draw_clear (c->clip_rdr);
|
||||
hb_raster_paint_push_empty_clip (c, w, h);
|
||||
@@ -927,7 +936,7 @@ hb_raster_paint_fill_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
if (unlikely (!surf)) return;
|
||||
|
||||
/* Out of budget: skip the glyph-outline extraction entirely. */
|
||||
if (unlikely (c->work_left <= 0)) return;
|
||||
if (unlikely (c->budget_remaining < 0)) return;
|
||||
|
||||
hb_raster_draw_t *rdr = c->clip_rdr;
|
||||
hb_transform_t<> t = c->current_effective_transform ();
|
||||
@@ -936,10 +945,7 @@ hb_raster_paint_fill_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
|
||||
hb_raster_paint_glyph_clip_data_t data = {glyph, font};
|
||||
hb_raster_paint_emit_clip_glyph_mask (rdr, &data);
|
||||
|
||||
/* Charge the scanline work of the accumulated outline before
|
||||
* rendering it. */
|
||||
c->work_left -= hb_raster_draw_get_edge_work (rdr, surf->extents.height);
|
||||
hb_raster_paint_readback_budget (c, rdr);
|
||||
|
||||
hb_raster_image_t *mask_img = hb_raster_draw_render (rdr);
|
||||
if (unlikely (!mask_img)) return;
|
||||
@@ -967,8 +973,9 @@ hb_raster_paint_image (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
|
||||
ensure_initialized (c);
|
||||
|
||||
/* Out of budget: skip, including the image decode below. */
|
||||
if (unlikely (c->work_left <= 0)) return false;
|
||||
/* Out of pixel budget: skip, including the image decode below. Image
|
||||
* compositing is pixel work and does no outline traversal. */
|
||||
if (unlikely (c->pixel_remaining < 0)) return false;
|
||||
|
||||
unsigned src_width = width;
|
||||
unsigned src_height = height;
|
||||
@@ -1847,6 +1854,28 @@ hb_raster_paint_custom_palette_color (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
return false;
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_raster_paint_set_budget (hb_paint_funcs_t *, void *paint_data,
|
||||
int64_t budget, void *)
|
||||
{
|
||||
auto *paint = (hb_raster_paint_t *) paint_data;
|
||||
paint->budget = budget;
|
||||
paint->recharge_budget ();
|
||||
return true;
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_raster_paint_get_budget (hb_paint_funcs_t *, void *paint_data, void *)
|
||||
{
|
||||
return ((hb_raster_paint_t *) paint_data)->budget;
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_raster_paint_get_budget_remaining (hb_paint_funcs_t *, void *paint_data, void *)
|
||||
{
|
||||
return &((hb_raster_paint_t *) paint_data)->budget_remaining;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Lazy-loader singleton for paint funcs
|
||||
@@ -1877,6 +1906,9 @@ static struct hb_raster_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t
|
||||
hb_paint_funcs_set_radial_gradient_func (funcs, hb_raster_paint_radial_gradient, nullptr, nullptr);
|
||||
hb_paint_funcs_set_sweep_gradient_func (funcs, hb_raster_paint_sweep_gradient, nullptr, nullptr);
|
||||
hb_paint_funcs_set_custom_palette_color_func (funcs, hb_raster_paint_custom_palette_color, nullptr, nullptr);
|
||||
hb_paint_funcs_set_set_budget_func (funcs, hb_raster_paint_set_budget, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_func (funcs, hb_raster_paint_get_budget, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_raster_paint_get_budget_remaining, nullptr, nullptr);
|
||||
|
||||
hb_paint_funcs_make_immutable (funcs);
|
||||
|
||||
@@ -2549,12 +2581,12 @@ hb_raster_paint_clear (hb_raster_paint_t *paint)
|
||||
{
|
||||
paint->fixed_extents = {};
|
||||
paint->has_extents = false;
|
||||
paint->work_left = HB_RASTER_MAX_PAINT_WORK;
|
||||
paint->transform_stack.clear ();
|
||||
paint->release_all_clips ();
|
||||
for (auto *s : paint->surface_stack)
|
||||
paint->release_surface (s);
|
||||
paint->surface_stack.clear ();
|
||||
paint->recharge_budget ();
|
||||
hb_raster_draw_reset (paint->clip_rdr);
|
||||
}
|
||||
|
||||
@@ -2574,6 +2606,7 @@ hb_raster_paint_reset (hb_raster_paint_t *paint)
|
||||
paint->x_scale_factor = 1.f;
|
||||
paint->y_scale_factor = 1.f;
|
||||
paint->foreground = HB_COLOR (0, 0, 0, 255);
|
||||
paint->budget = HB_BUDGET_DEFAULT;
|
||||
hb_raster_paint_clear_custom_palette_colors (paint);
|
||||
hb_raster_paint_clear (paint);
|
||||
}
|
||||
|
||||
+36
-8
@@ -128,20 +128,48 @@ struct hb_raster_paint_t
|
||||
/* Internal rasterizer for clip-to-glyph */
|
||||
hb_raster_draw_t *clip_rdr = nullptr;
|
||||
|
||||
/* Cumulative work budget for the current paint session; reset by
|
||||
* hb_raster_paint_clear(). Bounds total pixel and outline work so
|
||||
* that per-node costs cannot multiply with the paint-graph traversal
|
||||
* limits of the font tables driving us (e.g. COLR). */
|
||||
int64_t work_left = HB_RASTER_MAX_PAINT_WORK;
|
||||
/* Two work budgets for the current paint session, both reset by
|
||||
* hb_raster_paint_clear(), so per-node costs cannot multiply with the
|
||||
* paint-graph traversal limits of the font tables driving us (e.g.
|
||||
* COLR). They bound different resources and must not share a counter:
|
||||
*
|
||||
* - The outline budget (policy + live) bounds glyph outline traversal
|
||||
* and curve flattening. It is the public draw/paint budget, seeded
|
||||
* into the clip rasterizer through the public draw-budget API and
|
||||
* read back after each glyph. Default HB_BUDGET_GLYPH.
|
||||
*
|
||||
* - The pixel budget bounds scanline/fill work, which scales with
|
||||
* surface area rather than outline complexity. It is sized from the
|
||||
* surface once known and is internal (not exposed through the API);
|
||||
* an unlimited outline policy disables it too. */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
int64_t pixel_remaining = HB_BUDGET_GLYPH;
|
||||
|
||||
/* Helpers */
|
||||
|
||||
/* Returns whether the operation should proceed. Allows a single
|
||||
int64_t get_default_pixel_budget () const
|
||||
{
|
||||
return hb_max ((int64_t) HB_BUDGET_GLYPH,
|
||||
(int64_t) HB_BUDGET_RASTER_PAINT_PASSES *
|
||||
fixed_extents.width * fixed_extents.height);
|
||||
}
|
||||
|
||||
void recharge_budget ()
|
||||
{
|
||||
budget_remaining = budget == HB_BUDGET_DEFAULT ?
|
||||
(int64_t) HB_BUDGET_GLYPH : budget;
|
||||
pixel_remaining = budget == HB_BUDGET_UNLIMITED ? budget :
|
||||
(surface_stack.length ? get_default_pixel_budget () :
|
||||
(int64_t) HB_BUDGET_GLYPH);
|
||||
}
|
||||
|
||||
/* Returns whether the pixel operation should proceed. Allows a single
|
||||
* overshoot past zero; callers skip work once the budget is spent. */
|
||||
bool charge_work (int64_t work)
|
||||
{
|
||||
if (unlikely (work_left <= 0)) return false;
|
||||
work_left -= work;
|
||||
if (unlikely (pixel_remaining < 0)) return false;
|
||||
pixel_remaining -= work;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,15 +31,6 @@
|
||||
|
||||
#include "hb-raster.h"
|
||||
|
||||
/* Scanline work of the edges accumulated in @draw since the last
|
||||
* render/clear: one unit per edge plus its span in rows, clamped to
|
||||
* @max_rows per edge. This is what rasterizing the edges costs, as
|
||||
* each edge is walked once per row it crosses. Used by the paint
|
||||
* layer to charge consumed outline work against its session work
|
||||
* budget. */
|
||||
HB_INTERNAL int64_t
|
||||
hb_raster_draw_get_edge_work (hb_raster_draw_t *draw, unsigned max_rows);
|
||||
|
||||
/* Visibility clip box for curve flattening, in device pixels. Curves
|
||||
* whose control-point bounding box falls entirely outside the box are
|
||||
* replaced by their chord, which is exact for coverage inside the box.
|
||||
@@ -49,15 +40,6 @@ hb_raster_draw_set_clip_box (hb_raster_draw_t *draw,
|
||||
float x0, float y0,
|
||||
float x1, float y1);
|
||||
|
||||
/* Points curve-flattening work charges at the caller's session budget
|
||||
* (one unit per Bézier subdivision) instead of the standalone
|
||||
* per-session HB_RASTER_MAX_DRAW_WORK budget. The rasterizer's local
|
||||
* accumulated-edge limit still applies. Cleared by hb_raster_draw_clear()
|
||||
* (and hence after every render). */
|
||||
HB_INTERNAL void
|
||||
hb_raster_draw_set_external_work (hb_raster_draw_t *draw,
|
||||
int64_t *work_left);
|
||||
|
||||
/* Shared pixel helpers (used by paint and image compositing). */
|
||||
|
||||
static HB_ALWAYS_INLINE uint8_t
|
||||
|
||||
+123
-114
@@ -35,6 +35,7 @@
|
||||
#include "graph/serialize.hh"
|
||||
|
||||
using graph::graph_t;
|
||||
using graph::graph_result_t;
|
||||
|
||||
/*
|
||||
* For a detailed writeup on the overflow resolution algorithm see:
|
||||
@@ -69,7 +70,7 @@ struct lookup_size_t
|
||||
};
|
||||
|
||||
static inline
|
||||
bool _presplit_subtables_if_needed (graph::gsubgpos_graph_context_t& ext_context)
|
||||
graph_result_t<void> _presplit_subtables_if_needed (graph::gsubgpos_graph_context_t& ext_context)
|
||||
{
|
||||
// For each lookup this will check the size of subtables and split them as needed
|
||||
// so that no subtable is at risk of overflowing. (where we support splitting for
|
||||
@@ -87,11 +88,10 @@ bool _presplit_subtables_if_needed (graph::gsubgpos_graph_context_t& ext_context
|
||||
for (unsigned lookup_index : lookup_indices)
|
||||
{
|
||||
graph::Lookup* lookup = ext_context.lookups.get(lookup_index);
|
||||
if (!lookup->split_subtables_if_needed (ext_context, lookup_index))
|
||||
return false;
|
||||
TRY (lookup->split_subtables_if_needed (ext_context, lookup_index));
|
||||
}
|
||||
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -99,7 +99,7 @@ bool _presplit_subtables_if_needed (graph::gsubgpos_graph_context_t& ext_context
|
||||
* to extension lookups.
|
||||
*/
|
||||
static inline
|
||||
bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context)
|
||||
graph_result_t<void> _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context)
|
||||
{
|
||||
// Simple Algorithm (v1, current):
|
||||
// 1. Calculate how many bytes each non-extension lookup consumes.
|
||||
@@ -117,7 +117,7 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context
|
||||
// TODO(garretrieger): also support extension promotion during iterative resolution phase, then
|
||||
// we can use a less conservative threshold here.
|
||||
// TODO(grieger): skip this for the 24 bit case.
|
||||
if (!ext_context.lookups) return true;
|
||||
if (!ext_context.lookups) return Ok();
|
||||
|
||||
unsigned total_lookup_table_sizes = 0;
|
||||
hb_vector_t<lookup_size_t> lookup_sizes;
|
||||
@@ -132,7 +132,7 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context
|
||||
hb_set_t visited;
|
||||
lookup_sizes.push (lookup_size_t {
|
||||
lookup_index,
|
||||
ext_context.graph.find_subgraph_size (lookup_index, visited),
|
||||
ext_context.graph.find_subgraph_size (lookup_index, visited).value_or (0),
|
||||
lookup->number_of_subtables (),
|
||||
});
|
||||
}
|
||||
@@ -167,7 +167,7 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context
|
||||
{
|
||||
size_t lookup_size = ext_context.graph.vertices_[p.lookup_index].table_size ();
|
||||
hb_set_t visited;
|
||||
size_t subtables_size = ext_context.graph.find_subgraph_size (p.lookup_index, visited, 1) - lookup_size;
|
||||
size_t subtables_size = ext_context.graph.find_subgraph_size (p.lookup_index, visited, 1).value_or (0) - lookup_size;
|
||||
size_t remaining_size = p.size - subtables_size - lookup_size;
|
||||
|
||||
l3_l4_size += subtables_size;
|
||||
@@ -181,16 +181,15 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context
|
||||
layers_full = true;
|
||||
}
|
||||
|
||||
if (!ext_context.lookups.get(p.lookup_index)->make_extension (ext_context, p.lookup_index))
|
||||
return false;
|
||||
TRY (ext_context.lookups.get(p.lookup_index)->make_extension (ext_context, p.lookup_index));
|
||||
}
|
||||
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
static inline
|
||||
bool _try_isolating_subgraphs (const hb_vector_t<graph::overflow_record_t>& overflows,
|
||||
graph_t& sorted_graph)
|
||||
graph_result_t<bool> _try_isolating_subgraphs (const hb_vector_t<graph::overflow_record_t>& overflows,
|
||||
graph_t& sorted_graph)
|
||||
{
|
||||
unsigned space = 0;
|
||||
hb_set_t roots_to_isolate;
|
||||
@@ -212,7 +211,7 @@ bool _try_isolating_subgraphs (const hb_vector_t<graph::overflow_record_t>& over
|
||||
roots_to_isolate.add(root);
|
||||
}
|
||||
|
||||
if (!roots_to_isolate) return false;
|
||||
if (!roots_to_isolate) return Ok(false);
|
||||
|
||||
unsigned maximum_to_move = hb_max ((sorted_graph.num_roots_for_space (space) / 2u), 1u);
|
||||
if (roots_to_isolate.get_population () > maximum_to_move) {
|
||||
@@ -238,16 +237,17 @@ bool _try_isolating_subgraphs (const hb_vector_t<graph::overflow_record_t>& over
|
||||
roots_to_isolate.get_population (),
|
||||
sorted_graph.next_space ());
|
||||
|
||||
sorted_graph.isolate_subgraph (roots_to_isolate);
|
||||
sorted_graph.move_to_new_space (roots_to_isolate);
|
||||
TRY_ASSIGN (bool isolated, sorted_graph.isolate_subgraph (roots_to_isolate));
|
||||
if (!isolated) return Ok(false);
|
||||
TRY (sorted_graph.move_to_new_space (roots_to_isolate));
|
||||
|
||||
return true;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
static inline
|
||||
bool _resolve_shared_overflow(const hb_vector_t<graph::overflow_record_t>& overflows,
|
||||
int overflow_index,
|
||||
graph_t& sorted_graph)
|
||||
graph_result_t<bool> _resolve_shared_overflow(const hb_vector_t<graph::overflow_record_t>& overflows,
|
||||
int overflow_index,
|
||||
graph_t& sorted_graph)
|
||||
{
|
||||
const graph::overflow_record_t& r = overflows[overflow_index];
|
||||
|
||||
@@ -263,8 +263,8 @@ bool _resolve_shared_overflow(const hb_vector_t<graph::overflow_record_t>& overf
|
||||
}
|
||||
}
|
||||
|
||||
unsigned result = sorted_graph.duplicate(&parents, r.child);
|
||||
if (result == (unsigned) -1 && parents.get_population() > 2) {
|
||||
auto result = sorted_graph.duplicate(&parents, r.child);
|
||||
if (!result.is_ok () && parents.get_population() > 2) {
|
||||
// All links to the child are overflowing, so we can't include all
|
||||
// in the duplication. Remove one parent from the duplication.
|
||||
// Remove the lowest index parent, which will be the closest to the child.
|
||||
@@ -272,7 +272,7 @@ bool _resolve_shared_overflow(const hb_vector_t<graph::overflow_record_t>& overf
|
||||
result = sorted_graph.duplicate(&parents, r.child);
|
||||
}
|
||||
|
||||
if (result == (unsigned) -1) return false;
|
||||
if (!result.is_ok ()) return Ok(false);
|
||||
|
||||
if (parents.get_population() > 1) {
|
||||
// If the duplicated node has more than one parent pre-emptively raise it's priority to the maximum.
|
||||
@@ -286,16 +286,16 @@ bool _resolve_shared_overflow(const hb_vector_t<graph::overflow_record_t>& overf
|
||||
// to move nodes closer, but only for non-shared nodes. Since this node is shared, it will simply be given
|
||||
// further duplication which defeats the attempt to duplicate with multiple parents. To fix this we
|
||||
// pre-emptively raise priority now which allows the duplicated node to pack into the same layer as it's parents.
|
||||
sorted_graph.vertices_[result].give_max_priority();
|
||||
sorted_graph.vertices_[*result].give_max_priority();
|
||||
}
|
||||
|
||||
return true;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
static inline
|
||||
bool _process_overflows (const hb_vector_t<graph::overflow_record_t>& overflows,
|
||||
hb_set_t& priority_bumped_parents,
|
||||
graph_t& sorted_graph)
|
||||
graph_result_t<bool> _process_overflows (const hb_vector_t<graph::overflow_record_t>& overflows,
|
||||
hb_set_t& priority_bumped_parents,
|
||||
graph_t& sorted_graph)
|
||||
{
|
||||
bool resolution_attempted = false;
|
||||
|
||||
@@ -303,19 +303,19 @@ bool _process_overflows (const hb_vector_t<graph::overflow_record_t>& overflows,
|
||||
for (int i = overflows.length - 1; i >= 0; i--)
|
||||
{
|
||||
const graph::overflow_record_t& r = overflows[i];
|
||||
const auto& child = sorted_graph.vertices_[r.child];
|
||||
if (child.is_shared ())
|
||||
if (sorted_graph.vertices_[r.child].is_shared ())
|
||||
{
|
||||
// The child object is shared, we may be able to eliminate the overflow
|
||||
// by duplicating it.
|
||||
if (_resolve_shared_overflow(overflows, i, sorted_graph))
|
||||
return true;
|
||||
TRY_ASSIGN (bool resolved, _resolve_shared_overflow(overflows, i, sorted_graph));
|
||||
if (resolved)
|
||||
return Ok(true);
|
||||
|
||||
// Sometimes we can't duplicate a node which looks shared because it's not actually shared
|
||||
// (eg. all links from the same parent) in this case continue on to other resolution options.
|
||||
}
|
||||
|
||||
if (child.is_leaf () && !priority_bumped_parents.has (r.parent))
|
||||
if (sorted_graph.vertices_[r.child].is_leaf () && !priority_bumped_parents.has (r.parent))
|
||||
{
|
||||
// This object is too far from it's parent, attempt to move it closer.
|
||||
//
|
||||
@@ -328,7 +328,8 @@ bool _process_overflows (const hb_vector_t<graph::overflow_record_t>& overflows,
|
||||
// is < then the total size of the children (and the parent can be moved).
|
||||
// Since in that case moving the parent will cause a smaller increase in
|
||||
// the length of other offsets.
|
||||
if (sorted_graph.raise_childrens_priority (r.parent)) {
|
||||
TRY_ASSIGN (bool raised, sorted_graph.raise_childrens_priority (r.parent));
|
||||
if (raised) {
|
||||
priority_bumped_parents.add (r.parent);
|
||||
resolution_attempted = true;
|
||||
}
|
||||
@@ -340,99 +341,106 @@ bool _process_overflows (const hb_vector_t<graph::overflow_record_t>& overflows,
|
||||
// - Table splitting.
|
||||
}
|
||||
|
||||
return resolution_attempted;
|
||||
return Ok(resolution_attempted);
|
||||
}
|
||||
|
||||
inline bool
|
||||
inline graph_result_t<void>
|
||||
_assign_spaces_and_sort (graph_t& sorted_graph /* IN/OUT */)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Assigning spaces to 32 bit subgraphs.");
|
||||
TRY_ASSIGN (bool assigned, sorted_graph.assign_spaces ());
|
||||
if (assigned)
|
||||
return sorted_graph.sort_shortest_distance ();
|
||||
else
|
||||
return sorted_graph.sort_shortest_distance_if_needed ();
|
||||
}
|
||||
|
||||
inline graph_result_t<void>
|
||||
_gsub_gpos_specialization (hb_tag_t table_tag,
|
||||
bool always_recalculate_extensions,
|
||||
graph_t& sorted_graph /* IN/OUT */)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Applying GSUB/GPOS repacking specializations.");
|
||||
if (!always_recalculate_extensions) return _assign_spaces_and_sort (sorted_graph);
|
||||
|
||||
auto context_res = graph::gsubgpos_graph_context_t::create (table_tag, sorted_graph);
|
||||
|
||||
if (unlikely (context_res.is_err())) {
|
||||
if (context_res.error() == graph::SANITIZE_FAILURE)
|
||||
// Sanitize failures are ignored, and we just skip splitting/extension promotion which needs a valid
|
||||
// GSUB/GPOS
|
||||
return _assign_spaces_and_sort (sorted_graph);
|
||||
else
|
||||
// All other errors are propagated.
|
||||
return Err(context_res.error());
|
||||
}
|
||||
|
||||
// Otherwise we have a valid GSUB/GPOS table and can try extension promotion and splitting
|
||||
auto& ext_context = *context_res;
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Splitting subtables if needed.");
|
||||
TRY (_presplit_subtables_if_needed (ext_context));
|
||||
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Promoting lookups to extensions if needed.");
|
||||
TRY (_promote_extensions_if_needed (ext_context));
|
||||
|
||||
// an additional sorting is needed before assign_spaces () which requires
|
||||
// correct topological ordering to find space roots
|
||||
TRY (sorted_graph.sort_shortest_distance_if_needed ());
|
||||
|
||||
TRY_ASSIGN (bool will_overflow, graph::will_overflow (sorted_graph));
|
||||
if (!will_overflow) return Ok();
|
||||
return _assign_spaces_and_sort (sorted_graph);
|
||||
}
|
||||
|
||||
inline graph_result_t<void>
|
||||
hb_resolve_graph_overflows (hb_tag_t table_tag,
|
||||
unsigned max_rounds ,
|
||||
bool always_recalculate_extensions,
|
||||
graph_t& sorted_graph /* IN/OUT */)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Repacking %c%c%c%c.", HB_UNTAG(table_tag));
|
||||
sorted_graph.sort_shortest_distance ();
|
||||
if (sorted_graph.in_error ())
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Sorted graph in error state after initial sort.");
|
||||
return false;
|
||||
}
|
||||
TRY (sorted_graph.sort_shortest_distance ());
|
||||
|
||||
bool will_overflow = graph::will_overflow (sorted_graph);
|
||||
TRY_ASSIGN (bool will_overflow, graph::will_overflow (sorted_graph));
|
||||
if (!will_overflow)
|
||||
return true;
|
||||
return Ok();
|
||||
|
||||
bool is_gsub_or_gpos = (table_tag == HB_OT_TAG_GPOS || table_tag == HB_OT_TAG_GSUB);
|
||||
graph::gsubgpos_graph_context_t ext_context (table_tag, sorted_graph);
|
||||
if (is_gsub_or_gpos && will_overflow)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Applying GSUB/GPOS repacking specializations.");
|
||||
if (always_recalculate_extensions)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Splitting subtables if needed.");
|
||||
if (!_presplit_subtables_if_needed (ext_context)) {
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Subtable splitting failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Promoting lookups to extensions if needed.");
|
||||
if (!_promote_extensions_if_needed (ext_context)) {
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Extensions promotion failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// an additional sorting is needed before assign_spaces () which requires
|
||||
// correct topological ordering to find space roots
|
||||
sorted_graph.sort_shortest_distance_if_needed ();
|
||||
if (sorted_graph.in_error ())
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Sorted graph in error state.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!graph::will_overflow (sorted_graph)) return true;
|
||||
}
|
||||
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Assigning spaces to 32 bit subgraphs.");
|
||||
if (sorted_graph.assign_spaces ())
|
||||
sorted_graph.sort_shortest_distance ();
|
||||
else
|
||||
sorted_graph.sort_shortest_distance_if_needed ();
|
||||
}
|
||||
if (is_gsub_or_gpos)
|
||||
TRY(_gsub_gpos_specialization (table_tag, always_recalculate_extensions, sorted_graph));
|
||||
|
||||
unsigned round = 0;
|
||||
unsigned total_iterations = 0;
|
||||
hb_vector_t<graph::overflow_record_t> overflows;
|
||||
// TODO(garretrieger): select a good limit for max rounds.
|
||||
while (!sorted_graph.in_error ()
|
||||
&& graph::will_overflow (sorted_graph, &overflows)
|
||||
&& round < max_rounds
|
||||
&& total_iterations < HB_REPACKER_MAX_ITERATIONS) {
|
||||
while (round < max_rounds && total_iterations < HB_REPACKER_MAX_ITERATIONS) {
|
||||
TRY_ASSIGN (bool overflows_exist, graph::will_overflow (sorted_graph, &overflows));
|
||||
if (!overflows_exist)
|
||||
break;
|
||||
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "=== Overflow resolution round %u ===", round);
|
||||
print_overflows (sorted_graph, overflows);
|
||||
|
||||
total_iterations++;
|
||||
hb_set_t priority_bumped_parents;
|
||||
|
||||
if (!_try_isolating_subgraphs (overflows, sorted_graph))
|
||||
TRY_ASSIGN (bool isolated, _try_isolating_subgraphs (overflows, sorted_graph));
|
||||
if (!isolated)
|
||||
{
|
||||
round++;
|
||||
if (!_process_overflows (overflows, priority_bumped_parents, sorted_graph))
|
||||
TRY_ASSIGN (bool processed, _process_overflows (overflows, priority_bumped_parents, sorted_graph));
|
||||
if (!processed)
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "No resolution available :(");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sorted_graph.sort_shortest_distance ();
|
||||
TRY (sorted_graph.sort_shortest_distance ());
|
||||
}
|
||||
|
||||
if (sorted_graph.in_error ())
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Sorted graph in error state.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (graph::will_overflow (sorted_graph))
|
||||
TRY_ASSIGN (bool has_overflow, graph::will_overflow (sorted_graph));
|
||||
if (unlikely (has_overflow))
|
||||
{
|
||||
if (is_gsub_or_gpos && !always_recalculate_extensions) {
|
||||
// If this a GSUB/GPOS table and we didn't try to extension promotion and table splitting then
|
||||
@@ -442,10 +450,10 @@ hb_resolve_graph_overflows (hb_tag_t table_tag,
|
||||
}
|
||||
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "Offset overflow resolution failed.");
|
||||
return false;
|
||||
return Err(graph::OVERFLOW_RESOLUTION_FAILED);
|
||||
}
|
||||
|
||||
return true;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -467,31 +475,32 @@ hb_resolve_overflows (const T& packed,
|
||||
hb_tag_t table_tag,
|
||||
unsigned max_rounds = 32,
|
||||
bool recalculate_extensions = false) {
|
||||
graph_t sorted_graph (packed);
|
||||
if (sorted_graph.in_error ())
|
||||
auto graph_res = graph_t::create (packed);
|
||||
if (!graph_res.is_ok ())
|
||||
{
|
||||
// Invalid graph definition.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!sorted_graph.is_fully_connected ())
|
||||
{
|
||||
sorted_graph.print_orphaned_nodes ();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (sorted_graph.in_error ())
|
||||
{
|
||||
// Allocations failed somewhere
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
"Graph is in error, likely due to a memory allocation error.");
|
||||
"Graph creation failed, cause: %s", graph::to_string(graph_res.error()));
|
||||
return nullptr;
|
||||
}
|
||||
graph_t sorted_graph = std::move (*graph_res);
|
||||
|
||||
auto resolve_res = hb_resolve_graph_overflows (table_tag, max_rounds, recalculate_extensions, sorted_graph);
|
||||
if (resolve_res.is_err ())
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
"Overflow resolution failed, cause: %s", graph::to_string(resolve_res.error()));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!hb_resolve_graph_overflows (table_tag, max_rounds, recalculate_extensions, sorted_graph))
|
||||
auto serialize_res = graph::serialize (sorted_graph);
|
||||
if (serialize_res.is_err ())
|
||||
{
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr,
|
||||
"Serialization failed, cause: %s", graph::to_string(serialize_res.error()));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return graph::serialize (sorted_graph);
|
||||
return *serialize_res;
|
||||
}
|
||||
|
||||
#endif /* HB_REPACKER_HH */
|
||||
@@ -0,0 +1,509 @@
|
||||
/*
|
||||
* Copyright © 2025 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): Garret Rieger
|
||||
*/
|
||||
|
||||
#ifndef HB_RESULT_HH
|
||||
#define HB_RESULT_HH
|
||||
|
||||
#include "hb.hh"
|
||||
|
||||
// Helper structs for Ok(...) and Err(...), not used directly
|
||||
// by users of hb_result_t.
|
||||
template <typename T>
|
||||
struct hb_result_ok_t
|
||||
{
|
||||
T value;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hb_result_ok_t<void> {};
|
||||
|
||||
template <typename E>
|
||||
struct hb_result_err_t
|
||||
{
|
||||
E error;
|
||||
|
||||
template <typename OtherE>
|
||||
constexpr bool operator == (const hb_result_err_t<OtherE>& other) const { return error == other.error; }
|
||||
template <typename OtherE>
|
||||
constexpr bool operator != (const hb_result_err_t<OtherE>& other) const { return error != other.error; }
|
||||
};
|
||||
|
||||
template <typename X> struct _hb_is_result_tag : hb_false_type {};
|
||||
template <typename X> struct _hb_is_result_tag<hb_result_ok_t<X>> : hb_true_type {};
|
||||
template <typename X> struct _hb_is_result_tag<hb_result_err_t<X>> : hb_true_type {};
|
||||
|
||||
template <typename T>
|
||||
static inline constexpr hb_result_ok_t<T&&> Ok (T&& v)
|
||||
{
|
||||
return hb_result_ok_t<T&&>{std::forward<T> (v)};
|
||||
}
|
||||
|
||||
static inline constexpr hb_result_ok_t<void> Ok ()
|
||||
{
|
||||
return hb_result_ok_t<void>{};
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
static inline constexpr hb_result_err_t<E&&> Err (E&& e)
|
||||
{
|
||||
return hb_result_err_t<E&&>{std::forward<E> (e)};
|
||||
}
|
||||
|
||||
template <typename T, typename E>
|
||||
struct HB_NODISCARD_STRUCT hb_result_t
|
||||
{
|
||||
private:
|
||||
union
|
||||
{
|
||||
T val_;
|
||||
E err_;
|
||||
};
|
||||
bool is_ok_;
|
||||
|
||||
void destroy ()
|
||||
{
|
||||
if (is_ok_)
|
||||
val_.~T ();
|
||||
else
|
||||
err_.~E ();
|
||||
}
|
||||
|
||||
void init(const hb_result_t& o) {
|
||||
is_ok_ = o.is_ok_;
|
||||
if (is_ok_)
|
||||
new (std::addressof (val_)) T (o.val_);
|
||||
else
|
||||
new (std::addressof (err_)) E (o.err_);
|
||||
}
|
||||
|
||||
void init(hb_result_t&& o) {
|
||||
is_ok_ = o.is_ok_;
|
||||
if (is_ok_)
|
||||
new (std::addressof (val_)) T (std::move (o.val_));
|
||||
else
|
||||
new (std::addressof (err_)) E (std::move (o.err_));
|
||||
}
|
||||
|
||||
public:
|
||||
~hb_result_t ()
|
||||
{
|
||||
destroy ();
|
||||
}
|
||||
|
||||
hb_result_t () = delete;
|
||||
|
||||
hb_result_t (const hb_result_t& o) : is_ok_ (false)
|
||||
{
|
||||
init (o);
|
||||
}
|
||||
|
||||
hb_result_t (hb_result_t&& o) noexcept (std::is_nothrow_move_constructible<T>::value &&
|
||||
std::is_nothrow_move_constructible<E>::value)
|
||||
: is_ok_ (false)
|
||||
{
|
||||
init (std::move (o));
|
||||
}
|
||||
|
||||
hb_result_t& operator = (const hb_result_t& o)
|
||||
{
|
||||
if (this == &o) return *this;
|
||||
if (is_ok_ && o.is_ok_)
|
||||
{
|
||||
val_ = o.val_;
|
||||
}
|
||||
else if (!is_ok_ && !o.is_ok_)
|
||||
{
|
||||
err_ = o.err_;
|
||||
}
|
||||
else
|
||||
{
|
||||
destroy ();
|
||||
init (o);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
hb_result_t& operator = (hb_result_t&& o) noexcept (std::is_nothrow_move_assignable<T>::value &&
|
||||
std::is_nothrow_move_assignable<E>::value)
|
||||
{
|
||||
if (this == &o) return *this;
|
||||
if (is_ok_ && o.is_ok_)
|
||||
{
|
||||
val_ = std::move (o.val_);
|
||||
}
|
||||
else if (!is_ok_ && !o.is_ok_)
|
||||
{
|
||||
err_ = std::move (o.err_);
|
||||
}
|
||||
else
|
||||
{
|
||||
destroy ();
|
||||
init (std::move (o));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Construct from Ok(...) tag
|
||||
template <typename U,
|
||||
hb_enable_if ((std::is_constructible<T, U>::value))>
|
||||
hb_result_t (hb_result_ok_t<U>&& o) : is_ok_ (true)
|
||||
{
|
||||
new (std::addressof (val_)) T (std::move (o.value));
|
||||
}
|
||||
|
||||
template <typename U,
|
||||
hb_enable_if ((std::is_constructible<T, const U&>::value))>
|
||||
hb_result_t (const hb_result_ok_t<U>& o) : is_ok_ (true)
|
||||
{
|
||||
new (std::addressof (val_)) T (o.value);
|
||||
}
|
||||
|
||||
// Construct from Err(...) tag
|
||||
template <typename F,
|
||||
hb_enable_if ((std::is_constructible<E, F>::value))>
|
||||
hb_result_t (hb_result_err_t<F>&& e) : is_ok_ (false)
|
||||
{
|
||||
new (std::addressof (err_)) E (std::move (e.error));
|
||||
}
|
||||
|
||||
template <typename F,
|
||||
hb_enable_if ((std::is_constructible<E, const F&>::value))>
|
||||
hb_result_t (const hb_result_err_t<F>& e) : is_ok_ (false)
|
||||
{
|
||||
new (std::addressof (err_)) E (e.error);
|
||||
}
|
||||
|
||||
// Construct directly from error E (when neither T or E are convertible into each other)
|
||||
template <typename F = E,
|
||||
hb_enable_if ((hb_is_same (F, E) &&
|
||||
!(hb_is_convertible (T, E) || hb_is_convertible (E, T))))>
|
||||
hb_result_t (F e) : is_ok_ (false)
|
||||
{
|
||||
new (std::addressof (err_)) E (std::move (e));
|
||||
}
|
||||
|
||||
// Construct directly from value T (when neither T or E are convertible into each other)
|
||||
template <typename U = T,
|
||||
hb_enable_if ((std::is_constructible<T, U>::value &&
|
||||
!hb_is_same (hb_decay<U>, E) &&
|
||||
!hb_is_same (hb_decay<U>, hb_result_t) &&
|
||||
!_hb_is_result_tag<hb_decay<U>>::value &&
|
||||
!(hb_is_convertible (T, E) || hb_is_convertible (E, T))))>
|
||||
hb_result_t (U&& v) : is_ok_ (true)
|
||||
{
|
||||
new (std::addressof (val_)) T (std::forward<U> (v));
|
||||
}
|
||||
|
||||
// Move fallible into a result if it's in_error() method returns false.
|
||||
static hb_result_t from (T&& fallible, E error_value) {
|
||||
if (fallible.in_error()) {
|
||||
return Err(error_value);
|
||||
}
|
||||
return Ok(fallible);
|
||||
}
|
||||
|
||||
bool is_ok () const { return is_ok_; }
|
||||
bool is_err () const { return !is_ok_; }
|
||||
explicit operator bool () const { return is_ok (); }
|
||||
|
||||
T& value () & { assert (is_ok_); return val_; }
|
||||
const T& value () const & { assert (is_ok_); return val_; }
|
||||
T value () && { assert (is_ok_); return std::move (val_); }
|
||||
|
||||
T& operator * () & { return value (); }
|
||||
const T& operator * () const & { return value (); }
|
||||
T operator * () && { return std::move (*this).value (); }
|
||||
|
||||
T* operator -> () { return std::addressof (value ()); }
|
||||
const T* operator -> () const { return std::addressof (value ()); }
|
||||
|
||||
template <typename U>
|
||||
T value_or (U&& default_value) const &
|
||||
{
|
||||
if (is_ok_) return val_;
|
||||
return std::forward<U> (default_value);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
T value_or (U&& default_value) &&
|
||||
{
|
||||
if (is_ok_) return std::move (val_);
|
||||
return std::forward<U> (default_value);
|
||||
}
|
||||
|
||||
T value_or_default () const &
|
||||
{
|
||||
if (is_ok_) return val_;
|
||||
return T ();
|
||||
}
|
||||
|
||||
T value_or_default () &&
|
||||
{
|
||||
if (is_ok_) return std::move (val_);
|
||||
return T ();
|
||||
}
|
||||
|
||||
const E& error () const & { assert (!is_ok_); return err_; }
|
||||
E& error () & { assert (!is_ok_); return err_; }
|
||||
E error () && { assert (!is_ok_); return std::move (err_); }
|
||||
|
||||
bool operator == (const hb_result_t& o) const
|
||||
{
|
||||
if (is_ok_ != o.is_ok_) return false;
|
||||
if (is_ok_) return val_ == o.val_;
|
||||
return err_ == o.err_;
|
||||
}
|
||||
|
||||
bool operator != (const hb_result_t& o) const
|
||||
{
|
||||
return !(*this == o);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
bool operator == (const hb_result_ok_t<U>& o) const
|
||||
{
|
||||
return is_ok_ && val_ == o.value;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
bool operator != (const hb_result_ok_t<U>& o) const
|
||||
{
|
||||
return !(*this == o);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
bool operator == (const hb_result_err_t<F>& e) const
|
||||
{
|
||||
return !is_ok_ && err_ == e.error;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
bool operator != (const hb_result_err_t<F>& e) const
|
||||
{
|
||||
return !(*this == e);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
bool operator == (const U&) const = delete;
|
||||
|
||||
template <typename U>
|
||||
bool operator != (const U&) const = delete;
|
||||
};
|
||||
|
||||
// Partial specialization for void
|
||||
template <typename E>
|
||||
struct HB_NODISCARD_STRUCT hb_result_t<void, E>
|
||||
{
|
||||
private:
|
||||
union
|
||||
{
|
||||
E err_;
|
||||
};
|
||||
bool is_ok_;
|
||||
|
||||
template <typename, typename> friend struct hb_result_t;
|
||||
|
||||
public:
|
||||
~hb_result_t ()
|
||||
{
|
||||
if (!is_ok_)
|
||||
err_.~E ();
|
||||
}
|
||||
|
||||
hb_result_t () : is_ok_ (true) {}
|
||||
hb_result_t (hb_result_ok_t<void>) : is_ok_ (true) {}
|
||||
|
||||
hb_result_t (const hb_result_t& o) : is_ok_ (o.is_ok_)
|
||||
{
|
||||
if (!is_ok_)
|
||||
new (std::addressof (err_)) E (o.err_);
|
||||
}
|
||||
|
||||
hb_result_t (hb_result_t&& o) noexcept (std::is_nothrow_move_constructible<E>::value)
|
||||
: is_ok_ (o.is_ok_)
|
||||
{
|
||||
if (!is_ok_)
|
||||
new (std::addressof (err_)) E (std::move (o.err_));
|
||||
}
|
||||
|
||||
hb_result_t& operator = (const hb_result_t& o)
|
||||
{
|
||||
if (this == &o) return *this;
|
||||
if (!is_ok_ && !o.is_ok_)
|
||||
{
|
||||
err_ = o.err_;
|
||||
}
|
||||
else if (!is_ok_ && o.is_ok_)
|
||||
{
|
||||
err_.~E ();
|
||||
is_ok_ = true;
|
||||
}
|
||||
else if (is_ok_ && !o.is_ok_)
|
||||
{
|
||||
new (std::addressof (err_)) E (o.err_);
|
||||
is_ok_ = false;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
hb_result_t& operator = (hb_result_t&& o) noexcept (std::is_nothrow_move_assignable<E>::value)
|
||||
{
|
||||
if (this == &o) return *this;
|
||||
if (!is_ok_ && !o.is_ok_)
|
||||
{
|
||||
err_ = std::move (o.err_);
|
||||
}
|
||||
else if (!is_ok_ && o.is_ok_)
|
||||
{
|
||||
err_.~E ();
|
||||
is_ok_ = true;
|
||||
}
|
||||
else if (is_ok_ && !o.is_ok_)
|
||||
{
|
||||
new (std::addressof (err_)) E (std::move (o.err_));
|
||||
is_ok_ = false;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename F,
|
||||
hb_enable_if ((std::is_constructible<E, F>::value))>
|
||||
hb_result_t (hb_result_err_t<F>&& e) : is_ok_ (false)
|
||||
{
|
||||
new (std::addressof (err_)) E (std::move (e.error));
|
||||
}
|
||||
|
||||
template <typename F,
|
||||
hb_enable_if ((std::is_constructible<E, const F&>::value))>
|
||||
hb_result_t (const hb_result_err_t<F>& e) : is_ok_ (false)
|
||||
{
|
||||
new (std::addressof (err_)) E (e.error);
|
||||
}
|
||||
|
||||
// Construct directly from error E
|
||||
hb_result_t (E e) : is_ok_ (false)
|
||||
{
|
||||
new (std::addressof (err_)) E (std::move(e));
|
||||
}
|
||||
|
||||
// V is any class which has an in_error() method. This checks the result
|
||||
// of in_error() and returns either Ok() or Err(error_value).
|
||||
template<typename V>
|
||||
static hb_result_t<void, E> from (const V& fallible, E error_value) {
|
||||
if (fallible.in_error()) {
|
||||
return Err(error_value);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
bool is_ok () const { return is_ok_; }
|
||||
bool is_err () const { return !is_ok_; }
|
||||
explicit operator bool () const { return is_ok (); }
|
||||
|
||||
const E& error () const & { assert (!is_ok_); return err_; }
|
||||
E& error () & { assert (!is_ok_); return err_; }
|
||||
E error () && { assert (!is_ok_); return std::move (err_); }
|
||||
|
||||
void operator * () & { return; }
|
||||
void operator * () const & { return; }
|
||||
void operator * () && { return; }
|
||||
|
||||
bool operator == (const hb_result_t<void, E>& o) const
|
||||
{
|
||||
return is_ok_ == o.is_ok_ && (is_ok_ || err_ == o.err_);
|
||||
}
|
||||
|
||||
bool operator != (const hb_result_t<void, E>& o) const
|
||||
{
|
||||
return !(*this == o);
|
||||
}
|
||||
|
||||
bool operator == (hb_result_ok_t<void>) const
|
||||
{
|
||||
return is_ok_;
|
||||
}
|
||||
|
||||
bool operator != (hb_result_ok_t<void>) const
|
||||
{
|
||||
return !is_ok_;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
bool operator == (const hb_result_err_t<F>& e) const
|
||||
{
|
||||
return !is_ok_ && err_ == e.error;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
bool operator != (const hb_result_err_t<F>& e) const
|
||||
{
|
||||
return !(*this == e);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
bool operator == (const U&) const = delete;
|
||||
|
||||
template <typename U>
|
||||
bool operator != (const U&) const = delete;
|
||||
};
|
||||
|
||||
template <typename U, typename T, typename E>
|
||||
static inline bool operator == (const hb_result_ok_t<U>& o, const hb_result_t<T, E>& r)
|
||||
{
|
||||
return r == o;
|
||||
}
|
||||
template <typename U, typename T, typename E>
|
||||
static inline bool operator != (const hb_result_ok_t<U>& o, const hb_result_t<T, E>& r)
|
||||
{
|
||||
return r != o;
|
||||
}
|
||||
template <typename F, typename T, typename E>
|
||||
static inline bool operator == (const hb_result_err_t<F>& e, const hb_result_t<T, E>& r)
|
||||
{
|
||||
return r == e;
|
||||
}
|
||||
template <typename F, typename T, typename E>
|
||||
static inline bool operator != (const hb_result_err_t<F>& e, const hb_result_t<T, E>& r)
|
||||
{
|
||||
return r != e;
|
||||
}
|
||||
|
||||
#ifndef TRY
|
||||
#define TRY(expr) \
|
||||
do { \
|
||||
auto _res = (expr); \
|
||||
if (unlikely (!_res.is_ok())) return Err(std::move(_res).error()); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef TRY_ASSIGN
|
||||
#define TRY_ASSIGN(var, ...) \
|
||||
auto HB_PASTE(_res_, __LINE__) = (__VA_ARGS__); \
|
||||
if (unlikely (!HB_PASTE(_res_, __LINE__).is_ok())) return Err(std::move(HB_PASTE(_res_, __LINE__)).error()); \
|
||||
var = *std::move(HB_PASTE(_res_, __LINE__))
|
||||
#endif
|
||||
|
||||
#endif /* HB_RESULT_HH */
|
||||
@@ -87,6 +87,11 @@ struct hb_serialize_context_t
|
||||
virtual_links.push (o.virtual_links[i]);
|
||||
}
|
||||
|
||||
bool in_error () const
|
||||
{
|
||||
return real_links.in_error() || virtual_links.in_error();
|
||||
}
|
||||
|
||||
bool add_virtual_link (objidx_t objidx)
|
||||
{
|
||||
if (!objidx)
|
||||
|
||||
+1
-1
@@ -366,7 +366,7 @@ hb_set_is_equal (const hb_set_t *set,
|
||||
*
|
||||
* Return value: `true` if the two sets intersect, `false` otherwise.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
* Since: 14.4.0
|
||||
**/
|
||||
hb_bool_t
|
||||
hb_set_intersects (const hb_set_t *set,
|
||||
|
||||
@@ -181,8 +181,8 @@ struct hb_subset_plan_t
|
||||
|
||||
os2_info_t os2_info;
|
||||
|
||||
const hb_subset_accelerator_t* accelerator;
|
||||
hb_subset_accelerator_t* inprogress_accelerator;
|
||||
const hb_subset_accelerator_t* accelerator = nullptr;
|
||||
hb_subset_accelerator_t* inprogress_accelerator = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
+1
-1
@@ -176,7 +176,7 @@ HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE
|
||||
case 0x03: return unlikely (ch == 0x034Fu);
|
||||
case 0x06: return unlikely (ch == 0x061Cu);
|
||||
case 0x17: return hb_in_range<hb_codepoint_t> (ch, 0x17B4u, 0x17B5u);
|
||||
case 0x18: return hb_in_range<hb_codepoint_t> (ch, 0x180Bu, 0x180Eu);
|
||||
case 0x18: return hb_in_range<hb_codepoint_t> (ch, 0x180Bu, 0x180Fu);
|
||||
case 0x20: return hb_in_ranges<hb_codepoint_t> (ch, 0x200Bu, 0x200Fu,
|
||||
0x202Au, 0x202Eu,
|
||||
0x2060u, 0x206Fu);
|
||||
|
||||
+43
-1
@@ -28,6 +28,7 @@
|
||||
#define HB_VECTOR_BUF_HH
|
||||
|
||||
#include "hb.hh"
|
||||
#include "hb-limits.hh"
|
||||
#include "hb-vector.hh"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
@@ -43,11 +44,47 @@ struct hb_vector_buf_t : hb_vector_t<char>
|
||||
{
|
||||
unsigned precision = 2;
|
||||
|
||||
/* Sticky flag set once the serialized document would exceed
|
||||
* HB_VECTOR_MAX_DOCUMENT_SIZE. Folded into in_error() so every emission
|
||||
* site that already checks it -- path commands, gradient meshes -- stops
|
||||
* cleanly. Bounds output that the outline work budget cannot see, most
|
||||
* importantly sweep-gradient meshes and embedded bitmaps. */
|
||||
bool overflowed = false;
|
||||
|
||||
/* Hides (does not override -- the base method is not virtual) the base
|
||||
* in_error(); every emission site uses hb_vector_buf_t directly, so the
|
||||
* cap is seen everywhere. clear() resets the sticky flag so a context
|
||||
* reused across renders recovers after one over-cap glyph. */
|
||||
bool in_error () const
|
||||
{ return hb_vector_t<char>::in_error () || overflowed; }
|
||||
|
||||
void clear ()
|
||||
{
|
||||
overflowed = false;
|
||||
hb_vector_t<char>::clear ();
|
||||
}
|
||||
|
||||
unsigned scale_precision () const
|
||||
{ return precision < 7 ? 7 : precision; }
|
||||
|
||||
bool would_overflow (unsigned add)
|
||||
{
|
||||
if (unlikely (in_error ()))
|
||||
return true;
|
||||
unsigned new_len;
|
||||
if (unlikely (hb_unsigned_add_overflows (length, add, &new_len) ||
|
||||
new_len > HB_VECTOR_MAX_DOCUMENT_SIZE))
|
||||
{
|
||||
overflowed = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool append_len (const char *s, unsigned l)
|
||||
{
|
||||
if (unlikely (would_overflow (l)))
|
||||
return false;
|
||||
unsigned old_len = length;
|
||||
unsigned new_len;
|
||||
if (unlikely (hb_unsigned_add_overflows (old_len, l, &new_len) ||
|
||||
@@ -58,7 +95,11 @@ struct hb_vector_buf_t : hb_vector_t<char>
|
||||
}
|
||||
|
||||
bool append_c (char ch)
|
||||
{ return push_or_fail (ch); }
|
||||
{
|
||||
if (unlikely (would_overflow (1)))
|
||||
return false;
|
||||
return push_or_fail (ch);
|
||||
}
|
||||
|
||||
bool append_str (const char *s)
|
||||
{ return append_len (s, (unsigned) strlen (s)); }
|
||||
@@ -206,6 +247,7 @@ struct hb_vector_buf_t : hb_vector_t<char>
|
||||
unsigned old_len = length;
|
||||
unsigned new_len;
|
||||
if (unlikely (hb_unsigned_mul_overflows (ngroups, 4, &out_len) ||
|
||||
would_overflow (out_len) ||
|
||||
hb_unsigned_add_overflows (old_len, out_len, &new_len) ||
|
||||
!resize_dirty ((int) new_len)))
|
||||
return false;
|
||||
|
||||
+48
-28
@@ -51,46 +51,41 @@ hb_vector_svg_buffer_contains (const hb_vector_buf_t &buf, const char *needle)
|
||||
static void hb_vector_draw_svg_move_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float x, float y, void *)
|
||||
{
|
||||
auto *d = (hb_vector_draw_t *) dd;
|
||||
unsigned before;
|
||||
if (unlikely (!d->begin_path_command (&before))) return;
|
||||
if (unlikely (!d->begin_path_command ())) return;
|
||||
d->path.append_c ('M'); d->append_xy_svg (x, y);
|
||||
d->end_path_command (before);
|
||||
d->end_path_command ();
|
||||
}
|
||||
|
||||
static void hb_vector_draw_svg_line_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float x, float y, void *)
|
||||
{
|
||||
auto *d = (hb_vector_draw_t *) dd;
|
||||
unsigned before;
|
||||
if (unlikely (!d->begin_path_command (&before))) return;
|
||||
if (unlikely (!d->begin_path_command ())) return;
|
||||
d->path.append_c ('L'); d->append_xy_svg (x, y);
|
||||
d->end_path_command (before);
|
||||
d->end_path_command ();
|
||||
}
|
||||
|
||||
static void hb_vector_draw_svg_quadratic_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float cx, float cy, float x, float y, void *)
|
||||
{
|
||||
auto *d = (hb_vector_draw_t *) dd;
|
||||
unsigned before;
|
||||
if (unlikely (!d->begin_path_command (&before))) return;
|
||||
if (unlikely (!d->begin_path_command ())) return;
|
||||
d->path.append_c ('Q'); d->append_xy_svg (cx, cy); d->path.append_c (' '); d->append_xy_svg (x, y);
|
||||
d->end_path_command (before);
|
||||
d->end_path_command ();
|
||||
}
|
||||
|
||||
static void hb_vector_draw_svg_cubic_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float c1x, float c1y, float c2x, float c2y, float x, float y, void *)
|
||||
{
|
||||
auto *d = (hb_vector_draw_t *) dd;
|
||||
unsigned before;
|
||||
if (unlikely (!d->begin_path_command (&before))) return;
|
||||
if (unlikely (!d->begin_path_command ())) return;
|
||||
d->path.append_c ('C'); d->append_xy_svg (c1x, c1y); d->path.append_c (' '); d->append_xy_svg (c2x, c2y); d->path.append_c (' '); d->append_xy_svg (x, y);
|
||||
d->end_path_command (before);
|
||||
d->end_path_command ();
|
||||
}
|
||||
|
||||
static void hb_vector_draw_svg_close_path (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, void *)
|
||||
{
|
||||
auto *d = (hb_vector_draw_t *) dd;
|
||||
unsigned before;
|
||||
if (unlikely (!d->begin_path_command (&before))) return;
|
||||
if (unlikely (!d->begin_path_command ())) return;
|
||||
d->path.append_c ('Z');
|
||||
d->end_path_command (before);
|
||||
d->end_path_command ();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,19 +94,17 @@ static void hb_vector_draw_svg_close_path (hb_draw_funcs_t *, void *dd, hb_draw_
|
||||
static void hb_vector_draw_pdf_move_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float x, float y, void *)
|
||||
{
|
||||
auto *d = (hb_vector_draw_t *) dd;
|
||||
unsigned before;
|
||||
if (unlikely (!d->begin_path_command (&before))) return;
|
||||
if (unlikely (!d->begin_path_command ())) return;
|
||||
d->append_xy_pdf (x, y); d->path.append_str (" m\n");
|
||||
d->end_path_command (before);
|
||||
d->end_path_command ();
|
||||
}
|
||||
|
||||
static void hb_vector_draw_pdf_line_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float x, float y, void *)
|
||||
{
|
||||
auto *d = (hb_vector_draw_t *) dd;
|
||||
unsigned before;
|
||||
if (unlikely (!d->begin_path_command (&before))) return;
|
||||
if (unlikely (!d->begin_path_command ())) return;
|
||||
d->append_xy_pdf (x, y); d->path.append_str (" l\n");
|
||||
d->end_path_command (before);
|
||||
d->end_path_command ();
|
||||
}
|
||||
|
||||
/* No quadratic_to — null fallback auto-promotes to cubic. */
|
||||
@@ -119,19 +112,39 @@ static void hb_vector_draw_pdf_line_to (hb_draw_funcs_t *, void *dd, hb_draw_sta
|
||||
static void hb_vector_draw_pdf_cubic_to (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, float c1x, float c1y, float c2x, float c2y, float x, float y, void *)
|
||||
{
|
||||
auto *d = (hb_vector_draw_t *) dd;
|
||||
unsigned before;
|
||||
if (unlikely (!d->begin_path_command (&before))) return;
|
||||
if (unlikely (!d->begin_path_command ())) return;
|
||||
d->append_xy_pdf (c1x, c1y); d->path.append_c (' '); d->append_xy_pdf (c2x, c2y); d->path.append_c (' '); d->append_xy_pdf (x, y); d->path.append_str (" c\n");
|
||||
d->end_path_command (before);
|
||||
d->end_path_command ();
|
||||
}
|
||||
|
||||
static void hb_vector_draw_pdf_close_path (hb_draw_funcs_t *, void *dd, hb_draw_state_t *, void *)
|
||||
{
|
||||
auto *d = (hb_vector_draw_t *) dd;
|
||||
unsigned before;
|
||||
if (unlikely (!d->begin_path_command (&before))) return;
|
||||
if (unlikely (!d->begin_path_command ())) return;
|
||||
d->path.append_str ("h\n");
|
||||
d->end_path_command (before);
|
||||
d->end_path_command ();
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_vector_draw_set_budget (hb_draw_funcs_t *, void *draw_data,
|
||||
int64_t budget, void *)
|
||||
{
|
||||
auto *draw = (hb_vector_draw_t *) draw_data;
|
||||
draw->budget = budget;
|
||||
draw->recharge_budget ();
|
||||
return true;
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_vector_draw_get_budget (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_vector_draw_t *) draw_data)->budget;
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_vector_draw_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return &((hb_vector_draw_t *) draw_data)->budget_remaining;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +162,9 @@ static struct hb_vector_draw_svg_funcs_lazy_loader_t
|
||||
hb_draw_funcs_set_quadratic_to_func (funcs, (hb_draw_quadratic_to_func_t) hb_vector_draw_svg_quadratic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_draw_svg_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_draw_svg_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_set_budget_func (funcs, hb_vector_draw_set_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_func (funcs, hb_vector_draw_get_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_vector_draw_get_budget_remaining, nullptr, nullptr);
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
hb_atexit (free_static_vector_draw_svg_funcs);
|
||||
return funcs;
|
||||
@@ -168,6 +184,9 @@ static struct hb_vector_draw_pdf_funcs_lazy_loader_t
|
||||
/* No quadratic_to: null fallback auto-promotes to cubic. */
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_draw_pdf_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_draw_pdf_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_set_budget_func (funcs, hb_vector_draw_set_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_func (funcs, hb_vector_draw_get_budget, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_vector_draw_get_budget_remaining, nullptr, nullptr);
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
hb_atexit (free_static_vector_draw_pdf_funcs);
|
||||
return funcs;
|
||||
@@ -949,7 +968,7 @@ hb_vector_draw_clear (hb_vector_draw_t *draw)
|
||||
draw->defs.clear ();
|
||||
draw->body.clear ();
|
||||
draw->path.clear ();
|
||||
draw->work_left = HB_VECTOR_MAX_DRAW_WORK;
|
||||
draw->recharge_budget ();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -967,6 +986,7 @@ hb_vector_draw_reset (hb_vector_draw_t *draw)
|
||||
draw->x_scale_factor = 1.f;
|
||||
draw->y_scale_factor = 1.f;
|
||||
draw->set_precision (2);
|
||||
draw->budget = HB_BUDGET_DEFAULT;
|
||||
hb_vector_draw_clear (draw);
|
||||
}
|
||||
|
||||
|
||||
+18
-13
@@ -54,25 +54,30 @@ struct hb_vector_draw_t
|
||||
hb_vector_buf_t pdf_extgstate_dict;
|
||||
unsigned pdf_extgstate_count = 0;
|
||||
|
||||
/* Cumulative output budget for the current draw session; reset by
|
||||
* hb_vector_draw_clear(). Charge complete path commands so budget
|
||||
* exhaustion cannot leave a syntactically partial command. */
|
||||
int64_t work_left = HB_VECTOR_MAX_DRAW_WORK;
|
||||
/* Cumulative work budget for the current draw session; reset by
|
||||
* hb_vector_draw_clear(). Outline traversal and complete path commands
|
||||
* charge the same live counter. */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
|
||||
bool begin_path_command (unsigned *before)
|
||||
void recharge_budget ()
|
||||
{
|
||||
if (unlikely (work_left <= 0 || path.in_error ()))
|
||||
return false;
|
||||
*before = path.length;
|
||||
return true;
|
||||
budget_remaining = budget == HB_BUDGET_DEFAULT ?
|
||||
HB_BUDGET_GLYPH : budget;
|
||||
}
|
||||
|
||||
void end_path_command (unsigned before)
|
||||
bool begin_path_command ()
|
||||
{
|
||||
return likely (budget_remaining >= 0 && !path.in_error ());
|
||||
}
|
||||
|
||||
void end_path_command ()
|
||||
{
|
||||
/* The serialized bytes are bounded by the output buffer's document-size
|
||||
* cap (in_error), not the outline work budget; stop outline traversal
|
||||
* once that cap or an allocation error trips. */
|
||||
if (unlikely (path.in_error ()))
|
||||
work_left = 0;
|
||||
else
|
||||
work_left -= path.length - before;
|
||||
budget_remaining = 0;
|
||||
}
|
||||
|
||||
void set_precision (unsigned p)
|
||||
|
||||
+13
-15
@@ -342,11 +342,11 @@ hb_pdf_emit_glyph_path (hb_vector_paint_t *paint,
|
||||
paint->path.clear ();
|
||||
/* Skip the outline extraction when the session work budget is
|
||||
* spent; an empty path keeps the document structure intact. */
|
||||
if (likely (paint->work_left > 0))
|
||||
if (likely (paint->budget_remaining >= 0))
|
||||
{
|
||||
hb_vector_path_sink_t sink = {&paint->path, paint->get_precision (),
|
||||
paint->x_scale_factor, paint->y_scale_factor,
|
||||
&paint->work_left};
|
||||
&paint->budget_remaining};
|
||||
hb_font_draw_glyph (font, glyph,
|
||||
hb_vector_pdf_path_draw_funcs_get (),
|
||||
&sink);
|
||||
@@ -512,7 +512,7 @@ hb_pdf_paint_push_clip_path_start (hb_paint_funcs_t *,
|
||||
paint->clip_path_sink = {&body, paint->get_precision (),
|
||||
paint->x_scale_factor,
|
||||
paint->y_scale_factor,
|
||||
&paint->work_left};
|
||||
&paint->budget_remaining};
|
||||
*draw_data = &paint->clip_path_sink;
|
||||
return hb_vector_pdf_path_draw_funcs_get ();
|
||||
}
|
||||
@@ -1376,7 +1376,6 @@ hb_pdf_add_sweep_patch (hb_vector_buf_t *mesh,
|
||||
|
||||
/* Callback context + trampoline for hb_paint_sweep_gradient_tiles. */
|
||||
struct hb_pdf_sweep_ctx_t {
|
||||
hb_vector_paint_t *paint;
|
||||
hb_vector_buf_t *mesh;
|
||||
hb_vector_buf_t *alpha_mesh;
|
||||
float cx, cy, xlo, xhi, ylo, yhi;
|
||||
@@ -1388,21 +1387,17 @@ hb_pdf_sweep_emit_patch (float a0, hb_color_t c0,
|
||||
void *user_data)
|
||||
{
|
||||
auto *ctx = (hb_pdf_sweep_ctx_t *) user_data;
|
||||
auto *paint = ctx->paint;
|
||||
/* Skip patch generation when the session work budget is spent, so
|
||||
* per-gradient patch counts cannot multiply with the paint-graph
|
||||
* traversal limits of the font tables driving us. */
|
||||
if (unlikely (paint->work_left <= 0))
|
||||
/* Sweep-gradient meshes are not outline-derived, so they are bounded by
|
||||
* the output document-size cap, not the outline work budget: stop once a
|
||||
* mesh buffer trips its cap so per-gradient patch counts cannot multiply
|
||||
* with the paint-graph traversal limits of the font tables driving us. */
|
||||
if (unlikely (ctx->mesh->in_error () ||
|
||||
(ctx->alpha_mesh && ctx->alpha_mesh->in_error ())))
|
||||
return;
|
||||
unsigned before = ctx->mesh->length +
|
||||
(ctx->alpha_mesh ? ctx->alpha_mesh->length : 0);
|
||||
hb_pdf_add_sweep_patch (ctx->mesh, ctx->alpha_mesh,
|
||||
ctx->cx, ctx->cy,
|
||||
ctx->xlo, ctx->xhi, ctx->ylo, ctx->yhi,
|
||||
a0, c0, a1, c1);
|
||||
unsigned after = ctx->mesh->length +
|
||||
(ctx->alpha_mesh ? ctx->alpha_mesh->length : 0);
|
||||
paint->work_left -= after - before;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1444,7 +1439,7 @@ hb_pdf_paint_sweep_gradient (hb_paint_funcs_t *,
|
||||
if (needs_alpha)
|
||||
alpha_mesh.alloc (256);
|
||||
|
||||
hb_pdf_sweep_ctx_t ctx { paint, &mesh, needs_alpha ? &alpha_mesh : nullptr,
|
||||
hb_pdf_sweep_ctx_t ctx { &mesh, needs_alpha ? &alpha_mesh : nullptr,
|
||||
scx, scy, xlo, xhi, ylo, yhi };
|
||||
hb_paint_sweep_gradient_tiles (stops.arrayZ, stops.length, extend,
|
||||
start_angle, end_angle,
|
||||
@@ -1619,6 +1614,9 @@ static struct hb_pdf_paint_funcs_lazy_loader_t
|
||||
hb_paint_funcs_set_push_group_func (funcs, (hb_paint_push_group_func_t) hb_pdf_paint_push_group, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_group_for_func (funcs, (hb_paint_push_group_for_func_t) hb_pdf_paint_push_group_for, nullptr, nullptr);
|
||||
hb_paint_funcs_set_pop_group_func (funcs, (hb_paint_pop_group_func_t) hb_pdf_paint_pop_group, nullptr, nullptr);
|
||||
hb_paint_funcs_set_set_budget_func (funcs, hb_vector_paint_set_budget_callback, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_func (funcs, hb_vector_paint_get_budget_callback, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_vector_paint_get_budget_remaining_callback, nullptr, nullptr);
|
||||
hb_paint_funcs_make_immutable (funcs);
|
||||
hb_atexit (free_static_pdf_paint_funcs);
|
||||
return funcs;
|
||||
|
||||
+14
-14
@@ -246,7 +246,6 @@ hb_vector_svg_add_sweep_patch (hb_vector_buf_t *body,
|
||||
/* Callback context + trampoline for hb_paint_sweep_gradient_tiles. */
|
||||
struct hb_vector_svg_sweep_ctx_t
|
||||
{
|
||||
hb_vector_paint_t *paint;
|
||||
hb_vector_buf_t *body;
|
||||
unsigned precision;
|
||||
float cx, cy, radius;
|
||||
@@ -258,18 +257,16 @@ hb_vector_svg_sweep_emit_patch (float a0, hb_color_t c0,
|
||||
void *user_data)
|
||||
{
|
||||
auto *ctx = (hb_vector_svg_sweep_ctx_t *) user_data;
|
||||
auto *paint = ctx->paint;
|
||||
/* Skip patch generation when the session work budget is spent, so
|
||||
* per-gradient patch counts cannot multiply with the paint-graph
|
||||
* traversal limits of the font tables driving us. */
|
||||
if (unlikely (paint->work_left <= 0))
|
||||
/* Sweep-gradient meshes are not outline-derived, so they are bounded by
|
||||
* the output document-size cap, not the outline work budget: stop once
|
||||
* the buffer trips its cap so per-gradient patch counts cannot multiply
|
||||
* with the paint-graph traversal limits of the font tables driving us. */
|
||||
if (unlikely (ctx->body->in_error ()))
|
||||
return;
|
||||
unsigned before = ctx->body->length;
|
||||
hb_vector_svg_add_sweep_patch (ctx->body, ctx->precision,
|
||||
ctx->cx, ctx->cy, ctx->radius,
|
||||
a0, hb_vector_svg_rgba_from_hb_color (c0),
|
||||
a1, hb_vector_svg_rgba_from_hb_color (c1));
|
||||
paint->work_left -= ctx->body->length - before;
|
||||
}
|
||||
|
||||
|
||||
@@ -333,6 +330,9 @@ static struct hb_vector_paint_funcs_lazy_loader_t
|
||||
hb_paint_funcs_set_pop_group_func (funcs, (hb_paint_pop_group_func_t) hb_vector_paint_pop_group, nullptr, nullptr);
|
||||
hb_paint_funcs_set_color_glyph_func (funcs, (hb_paint_color_glyph_func_t) hb_vector_paint_color_glyph, nullptr, nullptr);
|
||||
hb_paint_funcs_set_custom_palette_color_func (funcs, (hb_paint_custom_palette_color_func_t) hb_vector_paint_custom_palette_color, nullptr, nullptr);
|
||||
hb_paint_funcs_set_set_budget_func (funcs, hb_vector_paint_set_budget_callback, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_func (funcs, hb_vector_paint_get_budget_callback, nullptr, nullptr);
|
||||
hb_paint_funcs_set_get_budget_remaining_func (funcs, hb_vector_paint_get_budget_remaining_callback, nullptr, nullptr);
|
||||
hb_paint_funcs_make_immutable (funcs);
|
||||
hb_atexit (free_static_vector_paint_funcs);
|
||||
return funcs;
|
||||
@@ -440,11 +440,11 @@ hb_vector_paint_fill_glyph (hb_paint_funcs_t *,
|
||||
paint->path.clear ();
|
||||
/* Skip the outline extraction when the session work budget is
|
||||
* spent; an empty path keeps the document structure intact. */
|
||||
if (likely (paint->work_left > 0))
|
||||
if (likely (paint->budget_remaining >= 0))
|
||||
{
|
||||
hb_vector_path_sink_t sink = {&paint->path, paint->get_precision (),
|
||||
paint->x_scale_factor, paint->y_scale_factor,
|
||||
&paint->work_left};
|
||||
&paint->budget_remaining};
|
||||
hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink);
|
||||
}
|
||||
|
||||
@@ -473,11 +473,11 @@ hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *,
|
||||
paint->path.clear ();
|
||||
/* Skip the outline extraction when the session work budget is
|
||||
* spent; an empty clip path clips everything out. */
|
||||
if (likely (paint->work_left > 0))
|
||||
if (likely (paint->budget_remaining >= 0))
|
||||
{
|
||||
hb_vector_path_sink_t sink = {&paint->path, paint->get_precision (),
|
||||
paint->x_scale_factor, paint->y_scale_factor,
|
||||
&paint->work_left};
|
||||
&paint->budget_remaining};
|
||||
hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink);
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ hb_vector_paint_push_clip_path_start (hb_paint_funcs_t *,
|
||||
paint->clip_path_sink = {&paint->path, paint->get_precision (),
|
||||
paint->x_scale_factor,
|
||||
paint->y_scale_factor,
|
||||
&paint->work_left};
|
||||
&paint->budget_remaining};
|
||||
*draw_data = &paint->clip_path_sink;
|
||||
return hb_vector_svg_path_draw_funcs_get ();
|
||||
}
|
||||
@@ -829,7 +829,7 @@ hb_vector_paint_sweep_gradient (hb_paint_funcs_t *,
|
||||
float ga1 = start_angle + mx * (end_angle - start_angle);
|
||||
|
||||
hb_vector_svg_sweep_ctx_t ctx {
|
||||
paint, &paint->current_body (), paint->get_precision (), paint->sx (cx), paint->sy (cy), 32767.f
|
||||
&paint->current_body (), paint->get_precision (), paint->sx (cx), paint->sy (cy), 32767.f
|
||||
};
|
||||
hb_paint_sweep_gradient_tiles (stops.arrayZ, stops.length,
|
||||
hb_color_line_get_extend (color_line),
|
||||
|
||||
@@ -744,7 +744,7 @@ hb_vector_paint_clear (hb_vector_paint_t *paint)
|
||||
paint->transform_group_overflow_depth = 0;
|
||||
paint->clip_rect_counter = 0;
|
||||
paint->clip_path_counter = 0;
|
||||
paint->work_left = HB_VECTOR_MAX_PAINT_WORK;
|
||||
paint->recharge_budget ();
|
||||
paint->gradient_counter = 0;
|
||||
paint->color_glyph_depth = 0;
|
||||
paint->path_def_count = 0;
|
||||
@@ -797,6 +797,7 @@ hb_vector_paint_reset (hb_vector_paint_t *paint)
|
||||
paint->foreground = HB_COLOR (0, 0, 0, 255);
|
||||
paint->palette = 0;
|
||||
paint->set_precision (2);
|
||||
paint->budget = HB_BUDGET_DEFAULT;
|
||||
hb_vector_paint_clear (paint);
|
||||
}
|
||||
|
||||
|
||||
+35
-5
@@ -67,11 +67,12 @@ struct hb_vector_paint_t
|
||||
unsigned clip_path_counter = 0;
|
||||
/* Cumulative work budget for the current paint session; reset by
|
||||
* hb_vector_paint_clear(). Charged with the bytes of path data
|
||||
* generated by each glyph-outline extraction and of sweep-gradient
|
||||
* patch data, so per-glyph and per-gradient limits cannot multiply
|
||||
* with the paint-graph traversal limits of the font tables driving
|
||||
* us (e.g. COLR). */
|
||||
int64_t work_left = HB_VECTOR_MAX_PAINT_WORK;
|
||||
* generated by each glyph-outline extraction, outline traversal, and
|
||||
* sweep-gradient patch data, so per-glyph and per-gradient limits cannot
|
||||
* multiply with the paint-graph traversal limits of the font tables
|
||||
* driving us (e.g. COLR). */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
hb_vector_path_sink_t clip_path_sink = {nullptr, 0, 1.f, 1.f, nullptr};
|
||||
unsigned gradient_counter = 0;
|
||||
unsigned color_glyph_depth = 0;
|
||||
@@ -83,6 +84,12 @@ struct hb_vector_paint_t
|
||||
|
||||
hb_vector_buf_t ¤t_body () { return group_stack.tail (); }
|
||||
|
||||
void recharge_budget ()
|
||||
{
|
||||
budget_remaining = budget == HB_BUDGET_DEFAULT ?
|
||||
HB_BUDGET_GLYPH : budget;
|
||||
}
|
||||
|
||||
float sx (float v) const { return v / x_scale_factor; }
|
||||
float sy (float v) const { return v / y_scale_factor; }
|
||||
|
||||
@@ -124,6 +131,29 @@ struct hb_vector_paint_t
|
||||
}
|
||||
};
|
||||
|
||||
static inline hb_bool_t
|
||||
hb_vector_paint_set_budget_callback (hb_paint_funcs_t *, void *paint_data,
|
||||
int64_t budget, void *)
|
||||
{
|
||||
auto *paint = (hb_vector_paint_t *) paint_data;
|
||||
paint->budget = budget;
|
||||
paint->recharge_budget ();
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline int64_t
|
||||
hb_vector_paint_get_budget_callback (hb_paint_funcs_t *, void *paint_data, void *)
|
||||
{
|
||||
return ((hb_vector_paint_t *) paint_data)->budget;
|
||||
}
|
||||
|
||||
static inline int64_t *
|
||||
hb_vector_paint_get_budget_remaining_callback (hb_paint_funcs_t *,
|
||||
void *paint_data, void *)
|
||||
{
|
||||
return &((hb_vector_paint_t *) paint_data)->budget_remaining;
|
||||
}
|
||||
|
||||
/* Implemented in hb-vector-paint-svg.cc */
|
||||
HB_INTERNAL hb_paint_funcs_t * hb_vector_paint_svg_funcs_get ();
|
||||
HB_INTERNAL hb_blob_t * hb_vector_paint_render_svg (hb_vector_paint_t *paint);
|
||||
|
||||
+26
-27
@@ -48,11 +48,10 @@ hb_vector_svg_path_move_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t
|
||||
float to_x, float to_y, void *)
|
||||
{
|
||||
auto *s = (hb_vector_path_sink_t *) draw_data;
|
||||
unsigned before;
|
||||
if (unlikely (!s->begin_command (&before))) return;
|
||||
if (unlikely (!s->begin_command ())) return;
|
||||
s->path->append_c ('M');
|
||||
hb_vector_svg_path_append_xy (s, to_x, to_y);
|
||||
s->end_command (before);
|
||||
s->end_command ();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -60,11 +59,10 @@ hb_vector_svg_path_line_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t
|
||||
float to_x, float to_y, void *)
|
||||
{
|
||||
auto *s = (hb_vector_path_sink_t *) draw_data;
|
||||
unsigned before;
|
||||
if (unlikely (!s->begin_command (&before))) return;
|
||||
if (unlikely (!s->begin_command ())) return;
|
||||
s->path->append_c ('L');
|
||||
hb_vector_svg_path_append_xy (s, to_x, to_y);
|
||||
s->end_command (before);
|
||||
s->end_command ();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -72,13 +70,12 @@ hb_vector_svg_path_quadratic_to (hb_draw_funcs_t *, void *draw_data, hb_draw_sta
|
||||
float cx, float cy, float to_x, float to_y, void *)
|
||||
{
|
||||
auto *s = (hb_vector_path_sink_t *) draw_data;
|
||||
unsigned before;
|
||||
if (unlikely (!s->begin_command (&before))) return;
|
||||
if (unlikely (!s->begin_command ())) return;
|
||||
s->path->append_c ('Q');
|
||||
hb_vector_svg_path_append_xy (s, cx, cy);
|
||||
s->path->append_c (' ');
|
||||
hb_vector_svg_path_append_xy (s, to_x, to_y);
|
||||
s->end_command (before);
|
||||
s->end_command ();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -87,25 +84,23 @@ hb_vector_svg_path_cubic_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t
|
||||
float to_x, float to_y, void *)
|
||||
{
|
||||
auto *s = (hb_vector_path_sink_t *) draw_data;
|
||||
unsigned before;
|
||||
if (unlikely (!s->begin_command (&before))) return;
|
||||
if (unlikely (!s->begin_command ())) return;
|
||||
s->path->append_c ('C');
|
||||
hb_vector_svg_path_append_xy (s, c1x, c1y);
|
||||
s->path->append_c (' ');
|
||||
hb_vector_svg_path_append_xy (s, c2x, c2y);
|
||||
s->path->append_c (' ');
|
||||
hb_vector_svg_path_append_xy (s, to_x, to_y);
|
||||
s->end_command (before);
|
||||
s->end_command ();
|
||||
}
|
||||
|
||||
static void
|
||||
hb_vector_svg_path_close_path (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t *, void *)
|
||||
{
|
||||
auto *s = (hb_vector_path_sink_t *) draw_data;
|
||||
unsigned before;
|
||||
if (unlikely (!s->begin_command (&before))) return;
|
||||
if (unlikely (!s->begin_command ())) return;
|
||||
s->path->append_c ('Z');
|
||||
s->end_command (before);
|
||||
s->end_command ();
|
||||
}
|
||||
|
||||
|
||||
@@ -124,11 +119,10 @@ hb_vector_pdf_path_move_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t
|
||||
float to_x, float to_y, void *)
|
||||
{
|
||||
auto *s = (hb_vector_path_sink_t *) draw_data;
|
||||
unsigned before;
|
||||
if (unlikely (!s->begin_command (&before))) return;
|
||||
if (unlikely (!s->begin_command ())) return;
|
||||
hb_vector_pdf_path_append_xy (s, to_x, to_y);
|
||||
s->path->append_str (" m\n");
|
||||
s->end_command (before);
|
||||
s->end_command ();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -136,11 +130,10 @@ hb_vector_pdf_path_line_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t
|
||||
float to_x, float to_y, void *)
|
||||
{
|
||||
auto *s = (hb_vector_path_sink_t *) draw_data;
|
||||
unsigned before;
|
||||
if (unlikely (!s->begin_command (&before))) return;
|
||||
if (unlikely (!s->begin_command ())) return;
|
||||
hb_vector_pdf_path_append_xy (s, to_x, to_y);
|
||||
s->path->append_str (" l\n");
|
||||
s->end_command (before);
|
||||
s->end_command ();
|
||||
}
|
||||
|
||||
/* No quadratic_to — the null fallback auto-promotes to cubic. */
|
||||
@@ -151,25 +144,29 @@ hb_vector_pdf_path_cubic_to (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t
|
||||
float to_x, float to_y, void *)
|
||||
{
|
||||
auto *s = (hb_vector_path_sink_t *) draw_data;
|
||||
unsigned before;
|
||||
if (unlikely (!s->begin_command (&before))) return;
|
||||
if (unlikely (!s->begin_command ())) return;
|
||||
hb_vector_pdf_path_append_xy (s, c1x, c1y);
|
||||
s->path->append_c (' ');
|
||||
hb_vector_pdf_path_append_xy (s, c2x, c2y);
|
||||
s->path->append_c (' ');
|
||||
hb_vector_pdf_path_append_xy (s, to_x, to_y);
|
||||
s->path->append_str (" c\n");
|
||||
s->end_command (before);
|
||||
s->end_command ();
|
||||
}
|
||||
|
||||
static void
|
||||
hb_vector_pdf_path_close_path (hb_draw_funcs_t *, void *draw_data, hb_draw_state_t *, void *)
|
||||
{
|
||||
auto *s = (hb_vector_path_sink_t *) draw_data;
|
||||
unsigned before;
|
||||
if (unlikely (!s->begin_command (&before))) return;
|
||||
if (unlikely (!s->begin_command ())) return;
|
||||
s->path->append_str ("h\n");
|
||||
s->end_command (before);
|
||||
s->end_command ();
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_vector_path_get_budget_remaining (hb_draw_funcs_t *, void *draw_data, void *)
|
||||
{
|
||||
return ((hb_vector_path_sink_t *) draw_data)->budget;
|
||||
}
|
||||
|
||||
|
||||
@@ -187,6 +184,7 @@ static struct hb_vector_svg_path_draw_funcs_lazy_loader_t
|
||||
hb_draw_funcs_set_quadratic_to_func (funcs, (hb_draw_quadratic_to_func_t) hb_vector_svg_path_quadratic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_svg_path_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_svg_path_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_vector_path_get_budget_remaining, nullptr, nullptr);
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
hb_atexit (free_static_vector_svg_path_draw_funcs);
|
||||
return funcs;
|
||||
@@ -214,6 +212,7 @@ static struct hb_vector_pdf_path_draw_funcs_lazy_loader_t
|
||||
/* No quadratic_to: the null fallback auto-promotes to cubic. */
|
||||
hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_pdf_path_cubic_to, nullptr, nullptr);
|
||||
hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_pdf_path_close_path, nullptr, nullptr);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (funcs, hb_vector_path_get_budget_remaining, nullptr, nullptr);
|
||||
hb_draw_funcs_make_immutable (funcs);
|
||||
hb_atexit (free_static_vector_pdf_path_draw_funcs);
|
||||
return funcs;
|
||||
|
||||
+9
-12
@@ -44,24 +44,21 @@ struct hb_vector_path_sink_t
|
||||
unsigned precision;
|
||||
float x_scale;
|
||||
float y_scale;
|
||||
int64_t *work_left;
|
||||
int64_t *budget;
|
||||
|
||||
bool begin_command (unsigned *before)
|
||||
bool begin_command ()
|
||||
{
|
||||
if (unlikely (path->in_error () ||
|
||||
(work_left && *work_left <= 0)))
|
||||
return false;
|
||||
*before = path->length;
|
||||
return true;
|
||||
return likely (!path->in_error () && !(budget && *budget < 0));
|
||||
}
|
||||
|
||||
void end_command (unsigned before)
|
||||
void end_command ()
|
||||
{
|
||||
if (!work_left) return;
|
||||
/* Serialized bytes are bounded by the output buffer's document-size
|
||||
* cap (in_error), not the outline work budget; stop outline traversal
|
||||
* once that cap or an allocation error trips. */
|
||||
if (!budget) return;
|
||||
if (unlikely (path->in_error ()))
|
||||
*work_left = 0;
|
||||
else
|
||||
*work_left -= path->length - before;
|
||||
*budget = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+3
-3
@@ -47,20 +47,20 @@ HB_BEGIN_DECLS
|
||||
*
|
||||
* The minor component of the library version available at compile-time.
|
||||
*/
|
||||
#define HB_VERSION_MINOR 3
|
||||
#define HB_VERSION_MINOR 4
|
||||
/**
|
||||
* HB_VERSION_MICRO:
|
||||
*
|
||||
* The micro component of the library version available at compile-time.
|
||||
*/
|
||||
#define HB_VERSION_MICRO 1
|
||||
#define HB_VERSION_MICRO 0
|
||||
|
||||
/**
|
||||
* HB_VERSION_STRING:
|
||||
*
|
||||
* A string literal containing the library version available at compile-time.
|
||||
*/
|
||||
#define HB_VERSION_STRING "14.3.1"
|
||||
#define HB_VERSION_STRING "14.4.0"
|
||||
|
||||
/**
|
||||
* HB_VERSION_ATLEAST:
|
||||
|
||||
@@ -160,7 +160,6 @@
|
||||
|
||||
|
||||
#include "hb-config.hh"
|
||||
#include "hb-limits.hh"
|
||||
|
||||
|
||||
/*
|
||||
@@ -385,6 +384,13 @@
|
||||
# define HB_NODISCARD
|
||||
#endif
|
||||
|
||||
/* Like HB_NODISCARD but can be used on structs */
|
||||
#if __cplusplus >= 201703L
|
||||
# define HB_NODISCARD_STRUCT [[nodiscard]]
|
||||
#else
|
||||
# define HB_NODISCARD_STRUCT
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
/* We need Windows Vista for both Uniscribe backend and for
|
||||
* MemoryBarrier. We don't support compiling on Windows XP,
|
||||
@@ -557,6 +563,7 @@ extern "C" void hb_free_impl(void *ptr);
|
||||
/* Headers we include for everyone. Keep topologically sorted by dependency.
|
||||
* They express dependency amongst themselves, but no other file should include
|
||||
* them directly.*/
|
||||
#include "hb-limits.hh"
|
||||
#include "hb-cplusplus.hh"
|
||||
#include "hb-meta.hh"
|
||||
#include "hb-mutex.hh"
|
||||
|
||||
@@ -394,6 +394,7 @@ hb_subset_sources = files(
|
||||
'hb-number.hh',
|
||||
'hb-ot-cff1-table.cc',
|
||||
'hb-ot-cff2-table.cc',
|
||||
'hb-result.hh',
|
||||
'hb-static.cc',
|
||||
'hb-subset-accelerator.hh',
|
||||
'hb-subset-cff-common.cc',
|
||||
@@ -419,6 +420,7 @@ hb_subset_sources = files(
|
||||
'hb-subset-table-cff.cc',
|
||||
'hb-subset-table-color.cc',
|
||||
'hb-subset-table-other.cc',
|
||||
'graph/graph-result.hh',
|
||||
'graph/gsubgpos-context.cc',
|
||||
'graph/gsubgpos-context.hh',
|
||||
'graph/gsubgpos-graph.hh',
|
||||
@@ -993,6 +995,7 @@ if get_option('tests').enabled()
|
||||
'test-bimap': ['test-bimap.cc', 'hb-static.cc'],
|
||||
'test-cff': ['test-cff.cc', 'hb-static.cc'],
|
||||
'test-classdef-graph': ['graph/test-classdef-graph.cc', 'hb-static.cc', 'graph/gsubgpos-context.cc'],
|
||||
'test-result': ['test-result.cc', 'hb-static.cc'],
|
||||
'test-decycler': ['test-decycler.cc', 'hb-static.cc'],
|
||||
'test-iter': ['test-iter.cc', 'hb-static.cc'],
|
||||
'test-geometry': ['test-geometry.cc', 'hb-static.cc'],
|
||||
@@ -1001,6 +1004,7 @@ if get_option('tests').enabled()
|
||||
'test-multimap': ['test-multimap.cc', 'hb-static.cc'],
|
||||
'test-number': ['test-number.cc', 'hb-number.cc'],
|
||||
'test-ot-tag': ['hb-ot-tag.cc'],
|
||||
'test-paint-extents': ['test-paint-extents.cc', 'hb-paint-extents.cc', 'hb-static.cc'],
|
||||
'test-set': ['test-set.cc', 'hb-static.cc'],
|
||||
'test-serialize': ['test-serialize.cc', 'hb-static.cc'],
|
||||
'test-vector': ['test-vector.cc', 'hb-static.cc'],
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
# Updated for Unicode 15.0 by Andrew Glass 2022-09-16
|
||||
# Updated for Unicode 15.1 by Andrew Glass 2023-09-14
|
||||
# Updated for Unicode 16.0 by Andrew Glass 2024-09-11
|
||||
# Updated for Unicode 17.0 by Andrew Glass 2025-09-15
|
||||
# Updated for Unicode 18.0 by Andrew Glass 2026-09-04
|
||||
|
||||
# ================================================
|
||||
# ================================================
|
||||
@@ -54,7 +56,7 @@ AA35 ; Top # Mn CHAM CONSONANT SIGN
|
||||
AAB4 ; Top # Mn TAI VIET VOWEL U # Override: ccc controls order, USE issue #58
|
||||
1112A..1112B ; Top # Mn [2] CHAKMA VOWEL SIGN U..CHAKMA VOWEL SIGN UU # see USE issue #25
|
||||
11131..11132 ; Top # Mn [2] CHAKMA O MARK..CHAKMA AU MARK # see USE issue #25
|
||||
1E4EC..1E4EF ; Top # Mn [4] NAG MUNDARI SIGN MUHOR..NAG MUNDARI SIGN SUTUH # 1E4EE is below, but made to for ccc
|
||||
1E4EC..1E4EF ; Top # Mn [4] NAG MUNDARI SIGN MUHOR..NAG MUNDARI SIGN SUTUH # 1E4EE is below, but made to for ccc
|
||||
|
||||
# ================================================
|
||||
|
||||
@@ -100,7 +102,7 @@ AAB4 ; Top # Mn TAI VIET VOWEL U # Override: ccc controls ord
|
||||
07EB..07F3 ; Top # Mn [9] NKO COMBINING SHORT HIGH TONE..NKO COMBINING DOUBLE DOT ABOVE
|
||||
07FD ; Top # Mn NKO DANTAYALAN # Not really top, but assigned here to allow ccc to control mark order
|
||||
1885..1886 ; Top # Mn [2] MONGOLIAN LETTER ALI GALI BALUDA..MONGOLIAN LETTER ALI GALI THREE BALUDA
|
||||
1B6C ; Top # Mn BALINESE MUSICAL SYMBOL COMBINING ENDEP
|
||||
1B6C ; Top # Mn BALINESE MUSICAL SYMBOL COMBINING ENDEP
|
||||
1CF8..1CF9 ; Top # Mn [2] VEDIC TONE RING ABOVE..VEDIC TONE DOUBLE RING ABOVE
|
||||
10D24..10D27 ; Top # Mn [4] HANIFI ROHINGYA SIGN HARBAHAY..HANIFI ROHINGYA SIGN TASSI
|
||||
10EAB..10EAC ; Top # Mn [2] YEZIDI COMBINING HAMZA MARK..YEZIDI COMBINING MADDA MARK
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
# Updated for Unicode 15.0 by Andrew Glass 2022-09-16
|
||||
# Updated for Unicode 15.1 by Andrew Glass 2023-09-14
|
||||
# Updated for Unicode 16.0 by Andrew Glass 2024-09-11
|
||||
# Updated for Unicode 17.0 by Andrew Glass 2025-09-15
|
||||
# Updated for Unicode 18.0 by Andrew Glass 2026-09-04
|
||||
|
||||
# ================================================
|
||||
# OVERRIDES TO ASSIGNED VALUES
|
||||
# ================================================
|
||||
|
||||
# Indic_Syllabic_Category=Bindu
|
||||
# Indic_Syllabic_Category=Bindu
|
||||
193A ; Bindu # Mn LIMBU SIGN KEMPHRENG
|
||||
AA29 ; Bindu # Mn CHAM VOWEL SIGN AA
|
||||
10A0D ; Bindu # Mn KHAROSHTHI SIGN DOUBLE RING BELOW
|
||||
@@ -32,11 +34,6 @@ AA29 ; Bindu # Mn CHAM VOWEL SIGN AA
|
||||
|
||||
# ================================================
|
||||
|
||||
# Indic_Syllabic_Category=Consonant_With_Stacker
|
||||
11A3A ; Consonant_With_Stacker # Lo ZANABAZAR SQUARE CLUSTER-INITIAL LETTER RA
|
||||
|
||||
# ================================================
|
||||
|
||||
# Indic_Syllabic_Category=Consonant_Subjoined
|
||||
11A3B..11A3E ; Consonant_Subjoined # Mn [4] ZANABAZAR SQUARE CLUSTER-FINAL LETTER YA..ZANABAZAR SQUARE CLUSTER-FINAL LETTER VA
|
||||
|
||||
@@ -47,12 +44,12 @@ AA29 ; Bindu # Mn CHAM VOWEL SIGN AA
|
||||
|
||||
# ================================================
|
||||
|
||||
# Indic_Syllabic_Category=Gemination_Mark
|
||||
# Indic_Syllabic_Category=Gemination_Mark
|
||||
11134 ; Gemination_Mark # Mc CHAKMA MAAYYAA
|
||||
|
||||
# ================================================
|
||||
|
||||
# Indic_Syllabic_Category=Nukta
|
||||
# Indic_Syllabic_Category=Nukta
|
||||
0F71 ; Nukta # Mn TIBETAN VOWEL SIGN AA # Reassigned to get this before an above vowel, but see #22
|
||||
113CF ; Nukta # Mc TULU-TIGALARI SIGN LOOPED VIRAMA
|
||||
|
||||
@@ -114,7 +111,7 @@ AABD ; Vowel_Independent # Lo TAI VIET VOWEL AN
|
||||
18B00..18CD5 ; Consonant # Lo [470] KHITAN SMALL SCRIPT CHARACTER-18B00..KHITAN SMALL SCRIPT CHARACTER-18CD5
|
||||
18CFF ; Consonant # Lo KHITAN SMALL SCRIPT CHARACTER-18CFF
|
||||
1BC00..1BC6A ; Consonant # Lo [107] DUPLOYAN LETTER H..DUPLOYAN LETTER VOCALIC M
|
||||
1BC70..1BC7C ; Consonant # Lo [13] DUPLOYAN AFFIX LEFT HORIZONTAL SECANT..DUPLOYAN AFFIX ATTACHED TANGENT HOOK
|
||||
1BC70..1BC7C ; Consonant # Lo [13] DUPLOYAN AFFIX LEFT HORIZONTAL SECANT..DUPLOYAN AFFIX ATTACHED TANGENT HOOK
|
||||
1BC80..1BC88 ; Consonant # Lo [9] DUPLOYAN AFFIX HIGH ACUTE..DUPLOYAN AFFIX HIGH VERTICAL
|
||||
1BC90..1BC99 ; Consonant # Lo [10] DUPLOYAN AFFIX LOW ACUTE..DUPLOYAN AFFIX LOW ARROW
|
||||
1E100..1E12C ; Consonant # Lo [45] NYIAKENG PUACHUE HMONG LETTER MA..NYIAKENG PUACHUE HMONG LETTER W
|
||||
@@ -259,7 +256,7 @@ FE00..FE0F ; Modifying_Letter # Mn [16] VARIATION SELECTOR-1..VARIATION SEL
|
||||
# ================================================
|
||||
|
||||
# USE, Extended_Syllabic_Category=Hieroglyph_Segment_End
|
||||
13438 ; Hieroglyph_Segment_End # Cf EGYPTIAN HIEROGLYPH END SEGMENT
|
||||
13438 ; Hieroglyph_Segment_End # Cf EGYPTIAN HIEROGLYPH END SEGMENT
|
||||
|
||||
# ================================================
|
||||
|
||||
|
||||
+165
-10
@@ -7,6 +7,7 @@ use std::ptr::null_mut;
|
||||
use std::sync::atomic::{AtomicPtr, AtomicU32, Ordering};
|
||||
use std::sync::Mutex;
|
||||
|
||||
use skrifa::bitmap::{BitmapFormat, BitmapGlyph, BitmapStrikes, Origin};
|
||||
use skrifa::charmap::Charmap;
|
||||
use skrifa::charmap::MapVariant::{UseDefault, Variant};
|
||||
use skrifa::color::ColorGlyphCollection;
|
||||
@@ -25,6 +26,7 @@ use skrifa::outline::{pen::OutlinePen, DrawSettings};
|
||||
|
||||
#[cfg(feature = "paint")]
|
||||
use skrifa::{
|
||||
bitmap::BitmapData,
|
||||
color::{Brush, ColorPainter, ColorStop, CompositeMode, Extend, Transform},
|
||||
metrics::BoundingBox,
|
||||
raw::tables::cpal::ColorRecord,
|
||||
@@ -39,6 +41,8 @@ struct FontationsData<'a> {
|
||||
char_map: Charmap<'a>,
|
||||
outline_glyphs: OutlineGlyphCollection<'a>,
|
||||
color_glyphs: ColorGlyphCollection<'a>,
|
||||
cbdt_strikes: Option<BitmapStrikes<'a>>,
|
||||
sbix_strikes: Option<BitmapStrikes<'a>>,
|
||||
glyph_names: GlyphNames<'a>,
|
||||
size: Size,
|
||||
vert_metrics: Option<Vmtx<'a>>,
|
||||
@@ -77,6 +81,9 @@ impl FontationsData<'_> {
|
||||
|
||||
let color_glyphs = font_ref.color_glyphs();
|
||||
|
||||
let cbdt_strikes = BitmapStrikes::with_format(&font_ref, BitmapFormat::Cbdt);
|
||||
let sbix_strikes = BitmapStrikes::with_format(&font_ref, BitmapFormat::Sbix);
|
||||
|
||||
let glyph_names = font_ref.glyph_names();
|
||||
|
||||
let upem = hb_face_get_upem(hb_font_get_face(font));
|
||||
@@ -92,6 +99,8 @@ impl FontationsData<'_> {
|
||||
char_map,
|
||||
outline_glyphs,
|
||||
color_glyphs,
|
||||
cbdt_strikes,
|
||||
sbix_strikes,
|
||||
glyph_names,
|
||||
size: Size::new(upem as f32),
|
||||
vert_metrics,
|
||||
@@ -176,6 +185,60 @@ fn struct_at_offset_mut<T: Copy>(first: *mut T, index: u32, stride: u32) -> &'st
|
||||
unsafe { &mut *((first as *mut u8).offset((index * stride) as isize) as *mut T) }
|
||||
}
|
||||
|
||||
fn bitmap_size(font: *mut hb_font_t) -> Size {
|
||||
let mut x_ppem = 0;
|
||||
let mut y_ppem = 0;
|
||||
unsafe { hb_font_get_ppem(font, &mut x_ppem, &mut y_ppem) };
|
||||
let ppem = x_ppem.max(y_ppem);
|
||||
if ppem == 0 {
|
||||
Size::unscaled()
|
||||
} else {
|
||||
Size::new(ppem as f32)
|
||||
}
|
||||
}
|
||||
|
||||
fn bitmap_glyph_extents(
|
||||
data: &FontationsData,
|
||||
bitmap_glyph: &BitmapGlyph,
|
||||
) -> Option<hb_glyph_extents_t> {
|
||||
if !bitmap_glyph.ppem_x.is_finite()
|
||||
|| !bitmap_glyph.ppem_y.is_finite()
|
||||
|| bitmap_glyph.ppem_x <= 0.0
|
||||
|| bitmap_glyph.ppem_y <= 0.0
|
||||
|| bitmap_glyph.width >= 65536
|
||||
|| bitmap_glyph.height >= 65536
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let upem = data.size.ppem()?;
|
||||
let x_scale = upem / bitmap_glyph.ppem_x;
|
||||
let y_scale = upem / bitmap_glyph.ppem_y;
|
||||
|
||||
let x_bearing = (bitmap_glyph.bearing_x + bitmap_glyph.inner_bearing_x * x_scale).round();
|
||||
let inner_y = bitmap_glyph.inner_bearing_y
|
||||
+ if bitmap_glyph.placement_origin == Origin::BottomLeft {
|
||||
bitmap_glyph.height as f32
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let y_bearing = (bitmap_glyph.bearing_y + inner_y * y_scale).round();
|
||||
let width = (bitmap_glyph.width as f32 * x_scale).round();
|
||||
let height = -(bitmap_glyph.height as f32 * y_scale).round();
|
||||
|
||||
let scaled_x_bearing = (x_bearing * data.x_mult).floor() as hb_position_t;
|
||||
let scaled_y_bearing = (y_bearing * data.y_mult).floor() as hb_position_t;
|
||||
let scaled_x_end = ((x_bearing + width) * data.x_mult).ceil() as hb_position_t;
|
||||
let scaled_y_end = ((y_bearing + height) * data.y_mult).ceil() as hb_position_t;
|
||||
|
||||
Some(hb_glyph_extents_t {
|
||||
x_bearing: scaled_x_bearing,
|
||||
y_bearing: scaled_y_bearing,
|
||||
width: scaled_x_end.saturating_sub(scaled_x_bearing),
|
||||
height: scaled_y_end.saturating_sub(scaled_y_bearing),
|
||||
})
|
||||
}
|
||||
|
||||
extern "C" fn _hb_fontations_get_nominal_glyphs(
|
||||
_font: *mut hb_font_t,
|
||||
font_data: *mut ::std::os::raw::c_void,
|
||||
@@ -393,7 +456,7 @@ extern "C" fn _hb_fontations_get_glyph_v_origin(
|
||||
}
|
||||
|
||||
extern "C" fn _hb_fontations_get_glyph_extents(
|
||||
_font: *mut hb_font_t,
|
||||
font: *mut hb_font_t,
|
||||
font_data: *mut ::std::os::raw::c_void,
|
||||
glyph: hb_codepoint_t,
|
||||
extents: *mut hb_glyph_extents_t,
|
||||
@@ -404,15 +467,36 @@ extern "C" fn _hb_fontations_get_glyph_extents(
|
||||
|
||||
let glyph_id = GlyphId::new(glyph);
|
||||
|
||||
// COLRv1 color glyphs are not supported by glyph_metrics.
|
||||
let color_glyphs = &data.color_glyphs;
|
||||
if color_glyphs.get(glyph_id).is_some() {
|
||||
return false as hb_bool_t;
|
||||
};
|
||||
let size = bitmap_size(font);
|
||||
let bitmap_glyph = data
|
||||
.sbix_strikes
|
||||
.as_ref()
|
||||
.and_then(|strikes| strikes.glyph_for_size(size, glyph_id))
|
||||
.or_else(|| {
|
||||
data.cbdt_strikes
|
||||
.as_ref()
|
||||
.and_then(|strikes| strikes.glyph_for_size(size, glyph_id))
|
||||
});
|
||||
if let Some(bitmap_glyph) = bitmap_glyph {
|
||||
let Some(bitmap_extents) = bitmap_glyph_extents(data, &bitmap_glyph) else {
|
||||
return false as hb_bool_t;
|
||||
};
|
||||
unsafe { *extents = bitmap_extents };
|
||||
return true as hb_bool_t;
|
||||
}
|
||||
|
||||
let glyph_metrics = &data.glyph_metrics.as_ref().unwrap();
|
||||
let Some(glyph_extents) = glyph_metrics.bounds(glyph_id) else {
|
||||
return false as hb_bool_t;
|
||||
let color_glyphs = &data.color_glyphs;
|
||||
let glyph_extents = if let Some(color_glyph) = color_glyphs.get(glyph_id) {
|
||||
let Some(glyph_extents) = color_glyph.bounding_box(&data.location, data.size) else {
|
||||
return false as hb_bool_t;
|
||||
};
|
||||
glyph_extents
|
||||
} else {
|
||||
let glyph_metrics = &data.glyph_metrics.as_ref().unwrap();
|
||||
let Some(glyph_extents) = glyph_metrics.bounds(glyph_id) else {
|
||||
return false as hb_bool_t;
|
||||
};
|
||||
glyph_extents
|
||||
};
|
||||
|
||||
let x_bearing = (glyph_extents.x_min * data.x_mult).round() as hb_position_t;
|
||||
@@ -935,6 +1019,77 @@ impl ColorPainter for HbColorPainter<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "paint")]
|
||||
unsafe extern "C" fn destroy_bitmap_blob(user_data: *mut c_void) {
|
||||
hb_blob_destroy(user_data.cast());
|
||||
}
|
||||
|
||||
#[cfg(feature = "paint")]
|
||||
fn paint_bitmap_glyph(
|
||||
font: *mut hb_font_t,
|
||||
data: &FontationsData,
|
||||
glyph_id: GlyphId,
|
||||
paint_funcs: *mut hb_paint_funcs_t,
|
||||
paint_data: *mut ::std::os::raw::c_void,
|
||||
) -> hb_bool_t {
|
||||
let size = bitmap_size(font);
|
||||
let bitmap_glyph = data
|
||||
.cbdt_strikes
|
||||
.as_ref()
|
||||
.and_then(|strikes| strikes.glyph_for_size(size, glyph_id))
|
||||
.or_else(|| {
|
||||
data.sbix_strikes
|
||||
.as_ref()
|
||||
.and_then(|strikes| strikes.glyph_for_size(size, glyph_id))
|
||||
});
|
||||
let Some(bitmap_glyph) = bitmap_glyph else {
|
||||
return false as hb_bool_t;
|
||||
};
|
||||
let Some(mut extents) = bitmap_glyph_extents(data, &bitmap_glyph) else {
|
||||
return false as hb_bool_t;
|
||||
};
|
||||
|
||||
let (image, format) = match &bitmap_glyph.data {
|
||||
BitmapData::Png(image) => (*image, u32::from_be_bytes(*b"png ")),
|
||||
BitmapData::Bgra(image) => (*image, u32::from_be_bytes(*b"BGRA")),
|
||||
BitmapData::Mask(_) => return false as hb_bool_t,
|
||||
};
|
||||
if image.is_empty() {
|
||||
return false as hb_bool_t;
|
||||
}
|
||||
let Ok(image_length) = image.len().try_into() else {
|
||||
return false as hb_bool_t;
|
||||
};
|
||||
let face_blob = unsafe { hb_blob_reference(data.face_blob) };
|
||||
let blob = unsafe {
|
||||
hb_blob_create_or_fail(
|
||||
image.as_ptr().cast(),
|
||||
image_length,
|
||||
hb_memory_mode_t_HB_MEMORY_MODE_READONLY,
|
||||
face_blob.cast(),
|
||||
Some(destroy_bitmap_blob),
|
||||
)
|
||||
};
|
||||
if blob.is_null() {
|
||||
return false as hb_bool_t;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
hb_paint_image(
|
||||
paint_funcs,
|
||||
paint_data,
|
||||
blob,
|
||||
bitmap_glyph.width,
|
||||
bitmap_glyph.height,
|
||||
format,
|
||||
0.0,
|
||||
&mut extents,
|
||||
);
|
||||
hb_blob_destroy(blob);
|
||||
}
|
||||
true as hb_bool_t
|
||||
}
|
||||
|
||||
#[cfg(feature = "paint")]
|
||||
extern "C" fn _hb_fontations_paint_glyph_or_fail(
|
||||
font: *mut hb_font_t,
|
||||
@@ -955,7 +1110,7 @@ extern "C" fn _hb_fontations_paint_glyph_or_fail(
|
||||
|
||||
let glyph_id = GlyphId::new(glyph);
|
||||
let Some(color_glyph) = color_glyphs.get(glyph_id) else {
|
||||
return false as hb_bool_t;
|
||||
return paint_bitmap_glyph(font, data, glyph_id, paint_funcs, paint_data);
|
||||
};
|
||||
|
||||
let cpal = font_ref.cpal();
|
||||
|
||||
@@ -106,6 +106,23 @@ main (int argc, char **argv)
|
||||
hb_always_assert (hb_clamp_to<int> ((int64_t) INT_MAX + 1) == INT_MAX);
|
||||
hb_always_assert (hb_clamp_to<int> ((int64_t) INT_MIN - 1) == INT_MIN);
|
||||
|
||||
int64_t budget = 10;
|
||||
hb_always_assert (hb_budget_spend (budget, 4, 2));
|
||||
hb_always_assert (budget == 2);
|
||||
hb_always_assert (!hb_budget_spend (budget, 3));
|
||||
hb_always_assert (budget == -1);
|
||||
hb_always_assert (!hb_budget_spend (budget, 1));
|
||||
hb_always_assert (budget == -2);
|
||||
|
||||
budget = 0;
|
||||
hb_always_assert (hb_budget_spend (budget, 0));
|
||||
hb_always_assert (!hb_budget_spend (budget, 1));
|
||||
hb_always_assert (budget == -1);
|
||||
|
||||
budget = INT64_MAX;
|
||||
hb_always_assert (hb_budget_spend (budget, 1024));
|
||||
hb_always_assert (budget == INT64_MAX - 1024);
|
||||
|
||||
x = 1;
|
||||
hb_always_assert (++hb_inc (x) == 3);
|
||||
hb_always_assert (x == 3);
|
||||
|
||||
Loaded 100 of 131 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user