diff --git a/.ci/requirements.in b/.ci/requirements.in index b796847e1..5d21fe92b 100644 --- a/.ci/requirements.in +++ b/.ci/requirements.in @@ -1,4 +1,4 @@ -r requirements-fonttools.in -meson==1.11.1 +meson==1.11.2 ninja setuptools # https://github.com/harfbuzz/harfbuzz/issues/4475 diff --git a/.ci/requirements.txt b/.ci/requirements.txt index 4114ca843..6ada8c3cf 100644 --- a/.ci/requirements.txt +++ b/.ci/requirements.txt @@ -106,9 +106,9 @@ fonttools==4.63.0 \ --hash=sha256:fd1e3094f42d806d3d7c79162fc59e5910fcbe3a7360c385b8da969bc4493745 \ --hash=sha256:fd1e3094f42d806d3d7c79162fc59e5910fcbe3a7360c385b8da969bc4493745 # via -r requirements-fonttools.in -meson==1.11.1 \ - --hash=sha256:9b3a023657e393dbc5335b95c561337d49b7a458f5541e47ec44f2cc566e0d80 \ - --hash=sha256:9b3a023657e393dbc5335b95c561337d49b7a458f5541e47ec44f2cc566e0d80 +meson==1.11.2 \ + --hash=sha256:698feae069cef3ecd4d7aaf281d7df359bdfcf555a9a1564383d3b913fa8a736 \ + --hash=sha256:7e4f6e83fec83e3eaac928e058b073c7557b282c35b6a2024cea143a39926a39 # via -r requirements.in ninja==1.13.0 \ --hash=sha256:11be2d22027bde06f14c343f01d31446747dbb51e72d00decca2eb99be911e2f \ @@ -133,7 +133,7 @@ ninja==1.13.0 \ # via -r requirements.in # The following packages are considered to be unsafe in a requirements file: -setuptools==82.0.1 \ - --hash=sha256:7d872682c5d01cfde07da7bccc7b65469d3dca203318515ada1de5eda35efbf9 \ - --hash=sha256:a59e362652f08dcd477c78bb6e7bd9d80a7995bc73ce773050228a348ce2e5bb +setuptools==83.0.0 \ + --hash=sha256:025bccbbf0fa05b6192bc64ae1e7b16e001fd6d6d4d5de03c97b1c1ade523bef \ + --hash=sha256:29b23c360f22f414dc7336bb39178cc7bcbf6021ed2733cde173f09dba19abb3 # via -r requirements.in diff --git a/.github/workflows/arm.yml b/.github/workflows/arm.yml index 11d69114a..6bb28247e 100644 --- a/.github/workflows/arm.yml +++ b/.github/workflows/arm.yml @@ -15,7 +15,7 @@ jobs: container: image: devkitpro/devkitarm:latest steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Configure CMake run: | cmake -S . -B build \ diff --git a/.github/workflows/c++-versions.yml b/.github/workflows/c++-versions.yml index 6d1350148..63f9e0233 100644 --- a/.github/workflows/c++-versions.yml +++ b/.github/workflows/c++-versions.yml @@ -36,7 +36,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install Dependencies run: | sudo apt-get update diff --git a/.github/workflows/configs-build.yml b/.github/workflows/configs-build.yml index 92bf3f8ed..c7b059a7a 100644 --- a/.github/workflows/configs-build.yml +++ b/.github/workflows/configs-build.yml @@ -26,7 +26,7 @@ jobs: name: ${{ matrix.config }} steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Create main.cc run: | cat < main.cc diff --git a/.github/workflows/coverity-scan.yml b/.github/workflows/coverity-scan.yml index 210a12150..efdcb4fac 100644 --- a/.github/workflows/coverity-scan.yml +++ b/.github/workflows/coverity-scan.yml @@ -11,7 +11,7 @@ jobs: latest: runs-on: ubuntu-latest steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - run: sudo apt-get install gcc clang wget git curl pkg-config libfreetype6-dev libglib2.0-dev libicu-dev libgraphite2-dev diff --git a/.github/workflows/crossbuild-mingw.yml b/.github/workflows/crossbuild-mingw.yml index 81b0212cd..9a027e24f 100644 --- a/.github/workflows/crossbuild-mingw.yml +++ b/.github/workflows/crossbuild-mingw.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Ccache uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 - name: Install Dependencies @@ -38,7 +38,7 @@ jobs: zip \ ${{ matrix.PACKAGES }} - name: Setup Python - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: '3.12' - name: Install Python Dependencies @@ -64,7 +64,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Download artifacts uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 3d15a86b2..9f81db62f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Ccache uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 with: @@ -43,7 +43,7 @@ jobs: with: version: latest - name: Setup Python - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: '3.12' - name: Install Python Dependencies diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 01dc6c4ff..365b21861 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Ccache uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 with: @@ -42,7 +42,7 @@ jobs: zlib1g-dev \ help2man - name: Setup Python - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: '3.12' - name: Install Python Dependencies @@ -82,7 +82,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Download artifacts uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 5c336ac02..bcd050373 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Ccache uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 with: @@ -40,7 +40,7 @@ jobs: ninja \ pkgconf - name: Setup Python - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: '3.12' - name: Install Python Dependencies diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml index 9570acd55..b36fadc33 100644 --- a/.github/workflows/msvc.yml +++ b/.github/workflows/msvc.yml @@ -27,14 +27,14 @@ jobs: steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Ccache uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 with: variant: sccache key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.ARCH }} - name: Setup Python - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: '3.12' - name: Setup MSVC diff --git a/.github/workflows/msys2.yml b/.github/workflows/msys2.yml index 394e33e66..cb55c993f 100644 --- a/.github/workflows/msys2.yml +++ b/.github/workflows/msys2.yml @@ -28,7 +28,7 @@ jobs: shell: msys2 {0} steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup MSYS2 uses: msys2/setup-msys2@cf96e00c0aab3788743aaf63b64146f0d383cee9 # v2 with: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d699e416b..5c4ee3a94 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Ccache uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 with: @@ -45,7 +45,7 @@ jobs: zlib1g-dev \ bindgen - name: Setup Python - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: '3.12' - name: Install Python Dependencies diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index f43633981..e06da904e 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -33,7 +33,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Ccache uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 - name: Install Dependencies @@ -50,7 +50,7 @@ jobs: libicu-dev \ libgraphite2-dev - name: Setup Python - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: '3.12' - name: Install Python Dependencies diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index b87fa176c..be53b1be7 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -29,12 +29,12 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: "Run analysis" - uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3 + uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4 with: results_file: results.sarif results_format: sarif @@ -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@7211b7c8077ea37d8641b6271f6a365a22a5fbfa # v3.29.5 + uses: github/codeql-action/upload-sarif@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3 with: sarif_file: results.sarif diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index e67d291ee..d02f16893 100644 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Ccache uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 - name: Install Dependencies @@ -31,7 +31,7 @@ jobs: libicu-dev \ libgraphite2-dev - name: Setup Python - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: '3.12' - name: Install Python Dependencies diff --git a/CMakeLists.txt b/CMakeLists.txt index 71a54067b..b3c19612d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,9 @@ if(POLICY CMP0063) cmake_policy(SET CMP0063 NEW) endif() -set(CMAKE_CXX_STANDARD 11) +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) ## Disallow in-source builds, as CMake generated make files can collide with autotools ones @@ -58,6 +60,18 @@ option(HB_BUILD_SUBSET "Build harfbuzz-subset" ON) option(HB_BUILD_RASTER "Build harfbuzz-raster" ON) option(HB_BUILD_VECTOR "Build harfbuzz-vector" ON) option(HB_BUILD_GPU "Build harfbuzz-gpu" ON) +set(HB_BUILD_GPU_DEMO "AUTO" CACHE STRING "Build hb-gpu demo tool (AUTO, ON, or OFF)") +set_property(CACHE HB_BUILD_GPU_DEMO PROPERTY STRINGS AUTO ON OFF) +string(TOUPPER "${HB_BUILD_GPU_DEMO}" HB_BUILD_GPU_DEMO) +if (NOT HB_BUILD_GPU_DEMO MATCHES "^(AUTO|ON|OFF)$") + message(FATAL_ERROR "HB_BUILD_GPU_DEMO must be AUTO, ON, or OFF") +endif () +if (HB_BUILD_GPU_DEMO STREQUAL "ON" AND NOT HB_BUILD_GPU) + message(FATAL_ERROR "HB_BUILD_GPU_DEMO is ON but HB_BUILD_GPU is OFF") +endif () +if (HB_BUILD_GPU_DEMO STREQUAL "ON" AND NOT HB_BUILD_UTILS) + message(FATAL_ERROR "HB_BUILD_GPU_DEMO is ON but HB_BUILD_UTILS is OFF") +endif () set(HB_HAVE_SUBSET ${HB_BUILD_SUBSET}) set(HB_HAVE_RASTER ${HB_BUILD_RASTER}) set(HB_HAVE_VECTOR ${HB_BUILD_VECTOR}) @@ -246,7 +260,6 @@ set (subset_project_headers ${PROJECT_SOURCE_DIR}/src/hb-subset-serialize.h ) set (raster_project_sources - ${PROJECT_SOURCE_DIR}/src/hb-raster.cc ${PROJECT_SOURCE_DIR}/src/hb-raster-image.cc ${PROJECT_SOURCE_DIR}/src/hb-raster-image.hh ${PROJECT_SOURCE_DIR}/src/hb-raster.hh @@ -352,7 +365,8 @@ if (HB_HAVE_ICU) find_package(ICU REQUIRED COMPONENTS uc) - if (ICU_VERSION VERSION_GREATER_EQUAL 75.1) + if (ICU_VERSION VERSION_GREATER_EQUAL 75.1 AND + CMAKE_CXX_STANDARD LESS 17) set(CMAKE_CXX_STANDARD 17) endif () @@ -760,13 +774,6 @@ if (UNIX OR MINGW OR VITA) # No threadsafe statics as we do it ourselves set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics") endif () - - CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) - if (COMPILER_SUPPORTS_CXX11) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - else() - message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") - endif() endif () @@ -1037,7 +1044,7 @@ if (HB_BUILD_UTILS) target_link_libraries(hb-info harfbuzz-gobject harfbuzz) endif() - if (HB_BUILD_GPU) + if (HB_BUILD_GPU AND NOT HB_BUILD_GPU_DEMO STREQUAL "OFF") find_package(OpenGL QUIET) find_package(GLEW QUIET) find_package(glfw3 QUIET) @@ -1071,6 +1078,23 @@ if (HB_BUILD_UTILS) "${D3D11_LIBRARY}" "${D3DCOMPILER_LIBRARY}") endif () + else () + set(_hb_gpu_demo_missing_deps) + if (NOT OpenGL_FOUND) + list(APPEND _hb_gpu_demo_missing_deps OpenGL) + endif () + if (NOT GLEW_FOUND) + list(APPEND _hb_gpu_demo_missing_deps GLEW) + endif () + if (NOT glfw3_FOUND) + list(APPEND _hb_gpu_demo_missing_deps glfw3) + endif () + string(REPLACE ";" ", " _hb_gpu_demo_missing_deps "${_hb_gpu_demo_missing_deps}") + if (HB_BUILD_GPU_DEMO STREQUAL "ON") + message(FATAL_ERROR "HB_BUILD_GPU_DEMO is ON but missing dependencies: ${_hb_gpu_demo_missing_deps}") + else () + message(STATUS "Not building hb-gpu: missing dependencies: ${_hb_gpu_demo_missing_deps}") + endif () endif () endif () endif () diff --git a/README.mingw.md b/README.mingw.md index 4f7163e99..a67101259 100644 --- a/README.mingw.md +++ b/README.mingw.md @@ -119,10 +119,14 @@ You can make Wine less verbose, without hiding all errors, by setting: Add this to your `.bashrc` or `.zshrc` file as well. -Next, let's try some non-Latin text. Unfortunately, the command-line parsing of -our cross-compiled glib is not quite Unicode-aware, at least when run under -Wine. So you will need to find some other way to feed Unicode text to the -shaper. There are three different ways you can try: +Next, let's try some non-Latin text. You can pass Unicode text to the commands +and they /should/ just work: + + - `wine build-win/util/hb-shape.exe perf/fonts/Amiri-Regular.ttf حرف` + +If not, there are other ways to pass them to the commands that do not involve +parsing Unicode-aware command-line arguments. There are three different ways +you can try: - `echo حرف | wine build-win/util/hb-shape.exe perf/fonts/Amiri-Regular.ttf` - `wine build-win/util/hb-shape.exe perf/fonts/Amiri-Regular.ttf -u 062D,0631,0641` diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 4e5209361..02683add9 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -267,6 +267,8 @@ hb_paint_pop_transform_func_t hb_paint_funcs_set_pop_transform_func hb_paint_color_glyph_func_t hb_paint_funcs_set_color_glyph_func +hb_paint_fill_glyph_func_t +hb_paint_funcs_set_fill_glyph_func hb_paint_push_clip_glyph_func_t hb_paint_funcs_set_push_clip_glyph_func hb_paint_push_clip_rectangle_func_t @@ -312,6 +314,7 @@ hb_paint_push_font_transform hb_paint_push_inverse_font_transform hb_paint_pop_transform hb_paint_color_glyph +hb_paint_fill_glyph hb_paint_push_clip_glyph hb_paint_push_clip_rectangle hb_paint_push_clip_path_start @@ -997,6 +1000,7 @@ hb_subset_serialize_link_t hb_subset_serialize_object_t hb_subset_serialize_or_fail +hb_subset_input_to_string_or_fail hb_subset_input_override_name_table hb_subset_cff_get_charstring_data hb_subset_cff_get_charstrings_index diff --git a/src/OT/Color/CBDT/CBDT.hh b/src/OT/Color/CBDT/CBDT.hh index 2d8f1da52..0bfaf8c46 100644 --- a/src/OT/Color/CBDT/CBDT.hh +++ b/src/OT/Color/CBDT/CBDT.hh @@ -207,8 +207,8 @@ struct IndexSubtable hb_barrier (); switch (u.header.indexFormat) { - case 1: return_trace (u.format1.sanitize (c, glyph_count)); - case 3: return_trace (u.format3.sanitize (c, glyph_count)); + case 1: hb_barrier (); return_trace (u.format1.sanitize (c, glyph_count)); + case 3: hb_barrier (); return_trace (u.format3.sanitize (c, glyph_count)); default:return_trace (true); } } @@ -224,8 +224,9 @@ struct IndexSubtable unsigned int local_offset = cbdt_prime_len - u.header.imageDataOffset; switch (u.header.indexFormat) { - case 1: return_trace (u.format1.add_offset (c, local_offset, size)); + case 1: hb_barrier (); return_trace (u.format1.add_offset (c, local_offset, size)); case 3: { + hb_barrier (); if (!u.format3.add_offset (c, local_offset, size)) return_trace (false); if (!(num_glyphs & 0x01)) // Pad to 32-bit alignment if needed. @@ -252,6 +253,7 @@ struct IndexSubtable switch (u.header.indexFormat) { case 1: { + hb_barrier (); for (unsigned int i = 0; i < num_missing; i++) { if (unlikely (!u.format1.add_offset (c, local_offset, size))) @@ -261,6 +263,7 @@ struct IndexSubtable return_trace (true); } case 3: { + hb_barrier (); for (unsigned int i = 0; i < num_missing; i++) { if (unlikely (!u.format3.add_offset (c, local_offset, size))) @@ -303,8 +306,8 @@ struct IndexSubtable TRACE_SERIALIZE (this); switch (u.header.indexFormat) { - case 1: return_trace (u.format1.add_offset (c, local_offset, size)); - case 3: return_trace (u.format3.add_offset (c, local_offset, size)); + case 1: hb_barrier (); return_trace (u.format1.add_offset (c, local_offset, size)); + case 3: hb_barrier (); return_trace (u.format3.add_offset (c, local_offset, size)); // TODO: Implement tables 2, 4, 5 case 2: // Should be a no-op. case 4: case 5: // Handle sparse cases. @@ -329,8 +332,8 @@ struct IndexSubtable *format = u.header.imageFormat; switch (u.header.indexFormat) { - case 1: return u.format1.get_image_data (idx, offset, length); - case 3: return u.format3.get_image_data (idx, offset, length); + case 1: hb_barrier (); return u.format1.get_image_data (idx, offset, length); + case 3: hb_barrier (); return u.format3.get_image_data (idx, offset, length); default: return false; } } diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index c7d3055a8..aacd76bb1 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -123,7 +123,9 @@ public: static unsigned color_alpha (hb_color_t color, float alpha) { - return roundf (hb_color_get_alpha (color) * alpha); + /* Font-supplied alpha is F2DOT14 plus variation deltas, so it can be + * negative or greater than one; converting that to unsigned is UB. */ + return roundf (hb_color_get_alpha (color) * hb_clamp (alpha, 0.f, 1.f)); } hb_color_t get_color (unsigned int color_index, float alpha, hb_bool_t *is_foreground) @@ -391,6 +393,12 @@ struct Variable value.get_color_stop (c, stop, varIdxBase, instancer); } + void get_solid_color (hb_paint_context_t *c, + hb_bool_t *is_foreground, hb_color_t *color) const + { + value.get_solid_color (c, varIdxBase, is_foreground, color); + } + hb_paint_extend_t get_extend () const { return value.get_extend (); @@ -449,6 +457,12 @@ struct NoVariable value.get_color_stop (c, stop, VarIdx::NO_VARIATION, instancer); } + void get_solid_color (hb_paint_context_t *c, + hb_bool_t *is_foreground, hb_color_t *color) const + { + value.get_solid_color (c, VarIdx::NO_VARIATION, is_foreground, color); + } + hb_paint_extend_t get_extend () const { return value.get_extend (); @@ -624,44 +638,6 @@ struct ColorLine // or all of the specified modes. struct CompositeMode : HBUINT8 { - enum { - // Porter-Duff modes - // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators - COMPOSITE_CLEAR = 0, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_clear - COMPOSITE_SRC = 1, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_src - COMPOSITE_DEST = 2, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dst - COMPOSITE_SRC_OVER = 3, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcover - COMPOSITE_DEST_OVER = 4, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstover - COMPOSITE_SRC_IN = 5, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcin - COMPOSITE_DEST_IN = 6, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstin - COMPOSITE_SRC_OUT = 7, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcout - COMPOSITE_DEST_OUT = 8, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstout - COMPOSITE_SRC_ATOP = 9, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcatop - COMPOSITE_DEST_ATOP = 10, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstatop - COMPOSITE_XOR = 11, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_xor - COMPOSITE_PLUS = 12, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_plus - - // Blend modes - // https://www.w3.org/TR/compositing-1/#blending - COMPOSITE_SCREEN = 13, // https://www.w3.org/TR/compositing-1/#blendingscreen - COMPOSITE_OVERLAY = 14, // https://www.w3.org/TR/compositing-1/#blendingoverlay - COMPOSITE_DARKEN = 15, // https://www.w3.org/TR/compositing-1/#blendingdarken - COMPOSITE_LIGHTEN = 16, // https://www.w3.org/TR/compositing-1/#blendinglighten - COMPOSITE_COLOR_DODGE = 17, // https://www.w3.org/TR/compositing-1/#blendingcolordodge - COMPOSITE_COLOR_BURN = 18, // https://www.w3.org/TR/compositing-1/#blendingcolorburn - COMPOSITE_HARD_LIGHT = 19, // https://www.w3.org/TR/compositing-1/#blendinghardlight - COMPOSITE_SOFT_LIGHT = 20, // https://www.w3.org/TR/compositing-1/#blendingsoftlight - COMPOSITE_DIFFERENCE = 21, // https://www.w3.org/TR/compositing-1/#blendingdifference - COMPOSITE_EXCLUSION = 22, // https://www.w3.org/TR/compositing-1/#blendingexclusion - COMPOSITE_MULTIPLY = 23, // https://www.w3.org/TR/compositing-1/#blendingmultiply - - // Modes that, uniquely, do not operate on components - // https://www.w3.org/TR/compositing-1/#blendingnonseparable - COMPOSITE_HSL_HUE = 24, // https://www.w3.org/TR/compositing-1/#blendinghue - COMPOSITE_HSL_SATURATION = 25, // https://www.w3.org/TR/compositing-1/#blendingsaturation - COMPOSITE_HSL_COLOR = 26, // https://www.w3.org/TR/compositing-1/#blendingcolor - COMPOSITE_HSL_LUMINOSITY = 27, // https://www.w3.org/TR/compositing-1/#blendingluminosity - }; public: DEFINE_SIZE_STATIC (1); }; @@ -785,15 +761,21 @@ struct PaintSolid return_trace (c->check_struct (this)); } + void get_solid_color (hb_paint_context_t *c, uint32_t varIdxBase, + hb_bool_t *is_foreground, hb_color_t *color) const + { + *color = c->get_color (paletteIndex, + alpha.to_float (c->instancer (varIdxBase, 0)), + is_foreground); + } + void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { TRACE_PAINT (this); hb_bool_t is_foreground; hb_color_t color; - color = c->get_color (paletteIndex, - alpha.to_float (c->instancer (varIdxBase, 0)), - &is_foreground); + get_solid_color (c, varIdxBase, &is_foreground, &color); c->funcs->color (c->data, is_foreground, color); } @@ -899,10 +881,10 @@ struct PaintRadialGradient { out->x0 = x0 + (int) roundf (instancer (varIdxBase, 0)); out->y0 = y0 + (int) roundf (instancer (varIdxBase, 1)); - out->radius0 = radius0 + (unsigned) roundf (instancer (varIdxBase, 2)); + out->radius0 = hb_clamp ((int) radius0 + (int) roundf (instancer (varIdxBase, 2)), 0, 0xFFFF); out->x1 = x1 + (int) roundf (instancer (varIdxBase, 3)); out->y1 = y1 + (int) roundf (instancer (varIdxBase, 4)); - out->radius1 = radius1 + (unsigned) roundf (instancer (varIdxBase, 5)); + out->radius1 = hb_clamp ((int) radius1 + (int) roundf (instancer (varIdxBase, 5)), 0, 0xFFFF); } if (format == 7 && c->plan->all_axes_pinned) @@ -1040,17 +1022,7 @@ struct PaintGlyph return_trace (c->check_struct (this) && paint.sanitize (c, this)); } - void paint_glyph (hb_paint_context_t *c) const - { - TRACE_PAINT (this); - c->funcs->push_inverse_font_transform (c->data, c->font); - c->funcs->push_clip_glyph (c->data, gid, c->font); - c->funcs->push_font_transform (c->data, c->font); - c->recurse (this+paint); - c->funcs->pop_transform (c->data); - c->funcs->pop_clip (c->data); - c->funcs->pop_transform (c->data); - } + inline void paint_glyph (hb_paint_context_t *c) const; HBUINT8 format; /* format = 10 */ Offset24To paint; /* Offset (from beginning of PaintGlyph table) to Paint subtable. */ @@ -1618,11 +1590,49 @@ struct PaintComposite void paint_glyph (hb_paint_context_t *c) const { TRACE_PAINT (this); + hb_paint_composite_mode_t composite_mode; + switch ((unsigned int) mode) + { + case HB_PAINT_COMPOSITE_MODE_CLEAR: + case HB_PAINT_COMPOSITE_MODE_SRC: + case HB_PAINT_COMPOSITE_MODE_DEST: + case HB_PAINT_COMPOSITE_MODE_SRC_OVER: + case HB_PAINT_COMPOSITE_MODE_DEST_OVER: + case HB_PAINT_COMPOSITE_MODE_SRC_IN: + case HB_PAINT_COMPOSITE_MODE_DEST_IN: + case HB_PAINT_COMPOSITE_MODE_SRC_OUT: + case HB_PAINT_COMPOSITE_MODE_DEST_OUT: + case HB_PAINT_COMPOSITE_MODE_SRC_ATOP: + case HB_PAINT_COMPOSITE_MODE_DEST_ATOP: + case HB_PAINT_COMPOSITE_MODE_XOR: + case HB_PAINT_COMPOSITE_MODE_PLUS: + case HB_PAINT_COMPOSITE_MODE_SCREEN: + case HB_PAINT_COMPOSITE_MODE_OVERLAY: + case HB_PAINT_COMPOSITE_MODE_DARKEN: + case HB_PAINT_COMPOSITE_MODE_LIGHTEN: + case HB_PAINT_COMPOSITE_MODE_COLOR_DODGE: + case HB_PAINT_COMPOSITE_MODE_COLOR_BURN: + case HB_PAINT_COMPOSITE_MODE_HARD_LIGHT: + case HB_PAINT_COMPOSITE_MODE_SOFT_LIGHT: + case HB_PAINT_COMPOSITE_MODE_DIFFERENCE: + case HB_PAINT_COMPOSITE_MODE_EXCLUSION: + case HB_PAINT_COMPOSITE_MODE_MULTIPLY: + case HB_PAINT_COMPOSITE_MODE_HSL_HUE: + case HB_PAINT_COMPOSITE_MODE_HSL_SATURATION: + case HB_PAINT_COMPOSITE_MODE_HSL_COLOR: + case HB_PAINT_COMPOSITE_MODE_HSL_LUMINOSITY: + composite_mode = (hb_paint_composite_mode_t) (unsigned int) mode; + break; + default: + composite_mode = HB_PAINT_COMPOSITE_MODE_CLEAR; + break; + } + c->funcs->push_group_for (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER); c->recurse (this+backdrop); - c->funcs->push_group_for (c->data, (hb_paint_composite_mode_t) (int) mode); + c->funcs->push_group_for (c->data, composite_mode); c->recurse (this+src); - c->funcs->pop_group (c->data, (hb_paint_composite_mode_t) (int) mode); + c->funcs->pop_group (c->data, composite_mode); c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER); } @@ -1712,8 +1722,8 @@ struct ClipBox { TRACE_SUBSET (this); switch (u.format.v) { - case 1: return_trace (u.format1.subset (c, instancer, VarIdx::NO_VARIATION)); - case 2: return_trace (u.format2.subset (c, instancer)); + case 1: hb_barrier (); return_trace (u.format1.subset (c, instancer, VarIdx::NO_VARIATION)); + case 2: hb_barrier (); return_trace (u.format2.subset (c, instancer)); default:return_trace (c->default_return_value ()); } } @@ -1721,7 +1731,7 @@ struct ClipBox void closurev1 (hb_colrv1_closure_context_t* c) const { switch (u.format.v) { - case 2: u.format2.closurev1 (c); return; + case 2: hb_barrier (); u.format2.closurev1 (c); return; default:return; } } @@ -1732,8 +1742,8 @@ struct ClipBox if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1744,9 +1754,11 @@ struct ClipBox ClipBoxData clip_box; switch (u.format.v) { case 1: + hb_barrier (); u.format1.get_clip_box (clip_box, instancer); break; case 2: + hb_barrier (); u.format2.get_clip_box (clip_box, instancer); break; default: @@ -1942,42 +1954,52 @@ struct Paint if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.paintformat1, std::forward (ds)...)); - case 2: return_trace (c->dispatch (u.paintformat2, std::forward (ds)...)); - case 3: return_trace (c->dispatch (u.paintformat3, std::forward (ds)...)); - case 4: return_trace (c->dispatch (u.paintformat4, std::forward (ds)...)); - case 5: return_trace (c->dispatch (u.paintformat5, std::forward (ds)...)); - case 6: return_trace (c->dispatch (u.paintformat6, std::forward (ds)...)); - case 7: return_trace (c->dispatch (u.paintformat7, std::forward (ds)...)); - case 8: return_trace (c->dispatch (u.paintformat8, std::forward (ds)...)); - case 9: return_trace (c->dispatch (u.paintformat9, std::forward (ds)...)); - case 10: return_trace (c->dispatch (u.paintformat10, std::forward (ds)...)); - case 11: return_trace (c->dispatch (u.paintformat11, std::forward (ds)...)); - case 12: return_trace (c->dispatch (u.paintformat12, std::forward (ds)...)); - case 13: return_trace (c->dispatch (u.paintformat13, std::forward (ds)...)); - case 14: return_trace (c->dispatch (u.paintformat14, std::forward (ds)...)); - case 15: return_trace (c->dispatch (u.paintformat15, std::forward (ds)...)); - case 16: return_trace (c->dispatch (u.paintformat16, std::forward (ds)...)); - case 17: return_trace (c->dispatch (u.paintformat17, std::forward (ds)...)); - case 18: return_trace (c->dispatch (u.paintformat18, std::forward (ds)...)); - case 19: return_trace (c->dispatch (u.paintformat19, std::forward (ds)...)); - case 20: return_trace (c->dispatch (u.paintformat20, std::forward (ds)...)); - case 21: return_trace (c->dispatch (u.paintformat21, std::forward (ds)...)); - case 22: return_trace (c->dispatch (u.paintformat22, std::forward (ds)...)); - case 23: return_trace (c->dispatch (u.paintformat23, std::forward (ds)...)); - case 24: return_trace (c->dispatch (u.paintformat24, std::forward (ds)...)); - case 25: return_trace (c->dispatch (u.paintformat25, std::forward (ds)...)); - case 26: return_trace (c->dispatch (u.paintformat26, std::forward (ds)...)); - case 27: return_trace (c->dispatch (u.paintformat27, std::forward (ds)...)); - case 28: return_trace (c->dispatch (u.paintformat28, std::forward (ds)...)); - case 29: return_trace (c->dispatch (u.paintformat29, std::forward (ds)...)); - case 30: return_trace (c->dispatch (u.paintformat30, std::forward (ds)...)); - case 31: return_trace (c->dispatch (u.paintformat31, std::forward (ds)...)); - case 32: return_trace (c->dispatch (u.paintformat32, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.paintformat1, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.paintformat2, std::forward (ds)...)); + case 3: hb_barrier (); return_trace (c->dispatch (u.paintformat3, std::forward (ds)...)); + case 4: hb_barrier (); return_trace (c->dispatch (u.paintformat4, std::forward (ds)...)); + case 5: hb_barrier (); return_trace (c->dispatch (u.paintformat5, std::forward (ds)...)); + case 6: hb_barrier (); return_trace (c->dispatch (u.paintformat6, std::forward (ds)...)); + case 7: hb_barrier (); return_trace (c->dispatch (u.paintformat7, std::forward (ds)...)); + case 8: hb_barrier (); return_trace (c->dispatch (u.paintformat8, std::forward (ds)...)); + case 9: hb_barrier (); return_trace (c->dispatch (u.paintformat9, std::forward (ds)...)); + case 10: hb_barrier (); return_trace (c->dispatch (u.paintformat10, std::forward (ds)...)); + case 11: hb_barrier (); return_trace (c->dispatch (u.paintformat11, std::forward (ds)...)); + case 12: hb_barrier (); return_trace (c->dispatch (u.paintformat12, std::forward (ds)...)); + case 13: hb_barrier (); return_trace (c->dispatch (u.paintformat13, std::forward (ds)...)); + case 14: hb_barrier (); return_trace (c->dispatch (u.paintformat14, std::forward (ds)...)); + case 15: hb_barrier (); return_trace (c->dispatch (u.paintformat15, std::forward (ds)...)); + case 16: hb_barrier (); return_trace (c->dispatch (u.paintformat16, std::forward (ds)...)); + case 17: hb_barrier (); return_trace (c->dispatch (u.paintformat17, std::forward (ds)...)); + case 18: hb_barrier (); return_trace (c->dispatch (u.paintformat18, std::forward (ds)...)); + case 19: hb_barrier (); return_trace (c->dispatch (u.paintformat19, std::forward (ds)...)); + case 20: hb_barrier (); return_trace (c->dispatch (u.paintformat20, std::forward (ds)...)); + case 21: hb_barrier (); return_trace (c->dispatch (u.paintformat21, std::forward (ds)...)); + case 22: hb_barrier (); return_trace (c->dispatch (u.paintformat22, std::forward (ds)...)); + case 23: hb_barrier (); return_trace (c->dispatch (u.paintformat23, std::forward (ds)...)); + case 24: hb_barrier (); return_trace (c->dispatch (u.paintformat24, std::forward (ds)...)); + case 25: hb_barrier (); return_trace (c->dispatch (u.paintformat25, std::forward (ds)...)); + case 26: hb_barrier (); return_trace (c->dispatch (u.paintformat26, std::forward (ds)...)); + case 27: hb_barrier (); return_trace (c->dispatch (u.paintformat27, std::forward (ds)...)); + case 28: hb_barrier (); return_trace (c->dispatch (u.paintformat28, std::forward (ds)...)); + case 29: hb_barrier (); return_trace (c->dispatch (u.paintformat29, std::forward (ds)...)); + case 30: hb_barrier (); return_trace (c->dispatch (u.paintformat30, std::forward (ds)...)); + case 31: hb_barrier (); return_trace (c->dispatch (u.paintformat31, std::forward (ds)...)); + case 32: hb_barrier (); return_trace (c->dispatch (u.paintformat32, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } + bool get_solid_color (hb_paint_context_t *c, + hb_bool_t *is_foreground, hb_color_t *color) const + { + switch (u.format.v) { + case 2: hb_barrier (); u.paintformat2.get_solid_color (c, is_foreground, color); return true; + case 3: hb_barrier (); u.paintformat3.get_solid_color (c, is_foreground, color); return true; + default: return false; + } + } + protected: union { struct { HBUINT8 v; } format; @@ -2207,7 +2229,7 @@ struct COLR hb_array_t all_layers = (this+layersZ).as_array (numLayers); hb_array_t glyph_layers = all_layers.sub_array (record.firstLayerIdx, record.numLayers); - if (count) + if (count && layers) { + glyph_layers.sub_array (start_offset, count) | hb_sink (hb_array (layers, *count)) @@ -2882,9 +2904,7 @@ struct COLR { hb_bool_t is_foreground; hb_color_t color = c.get_color (r.colorIdx, 1., &is_foreground); - c.funcs->push_clip_glyph (c.data, r.glyphId, c.font); - c.funcs->color (c.data, is_foreground, color); - c.funcs->pop_clip (c.data); + c.funcs->fill_glyph (c.data, r.glyphId, c.font, is_foreground, color); } return true; @@ -2926,6 +2946,32 @@ hb_paint_context_t::recurse (const Paint &paint) depth_left++; } +void PaintGlyph::paint_glyph (hb_paint_context_t *c) const +{ + TRACE_PAINT (this); + + hb_bool_t is_foreground; + hb_color_t color; + /* Optimize cases that can use a simple fill-glyph operation. */ + if (likely (c->depth_left > 0 && c->edge_count > 0) && + (this+paint).get_solid_color (c, &is_foreground, &color)) + { + c->edge_count--; + c->funcs->push_inverse_font_transform (c->data, c->font); + c->funcs->fill_glyph (c->data, gid, c->font, is_foreground, color); + c->funcs->pop_transform (c->data); + return; + } + + c->funcs->push_inverse_font_transform (c->data, c->font); + c->funcs->push_clip_glyph (c->data, gid, c->font); + c->funcs->push_font_transform (c->data, c->font); + c->recurse (this+paint); + c->funcs->pop_transform (c->data); + c->funcs->pop_clip (c->data); + c->funcs->pop_transform (c->data); +} + void PaintColrLayers::paint_glyph (hb_paint_context_t *c) const { TRACE_PAINT (this); diff --git a/src/OT/Color/CPAL/CPAL.hh b/src/OT/Color/CPAL/CPAL.hh index 9364fd939..ade2c1f86 100644 --- a/src/OT/Color/CPAL/CPAL.hh +++ b/src/OT/Color/CPAL/CPAL.hh @@ -209,7 +209,7 @@ struct CPAL hb_array_t all_colors ((this+colorRecordsZ).arrayZ, numColorRecords); hb_array_t palette_colors = all_colors.sub_array (start_index, numColors); - if (color_count) + if (color_count && colors) { + palette_colors.sub_array (start_offset, color_count) | hb_sink (hb_array (colors, *color_count)) diff --git a/src/OT/Color/svg/svg.hh b/src/OT/Color/svg/svg.hh index b89894c64..e0096d5bf 100644 --- a/src/OT/Color/svg/svg.hh +++ b/src/OT/Color/svg/svg.hh @@ -499,7 +499,7 @@ parse_cache_entries_linear (const char *svg, while (p + name_len < gt) { unsigned char c = (unsigned char) name[name_len]; - if (!(isalnum (c) || c == '_' || c == '-' || c == ':')) + if (!(ISALNUM (c) || c == '_' || c == '-' || c == ':')) break; name_len++; } diff --git a/src/OT/Layout/Common/Coverage.hh b/src/OT/Layout/Common/Coverage.hh index 93ca1b2f7..be7444d50 100644 --- a/src/OT/Layout/Common/Coverage.hh +++ b/src/OT/Layout/Common/Coverage.hh @@ -67,11 +67,11 @@ struct Coverage hb_barrier (); switch (u.format.v) { - case 1: return_trace (u.format1.sanitize (c)); - case 2: return_trace (u.format2.sanitize (c)); + case 1: hb_barrier (); return_trace (u.format1.sanitize (c)); + case 2: hb_barrier (); return_trace (u.format2.sanitize (c)); #ifndef HB_NO_BEYOND_64K - case 3: return_trace (u.format3.sanitize (c)); - case 4: return_trace (u.format4.sanitize (c)); + case 3: hb_barrier (); return_trace (u.format3.sanitize (c)); + case 4: hb_barrier (); return_trace (u.format4.sanitize (c)); #endif default:return_trace (true); } @@ -87,11 +87,11 @@ struct Coverage unsigned int get_coverage (hb_codepoint_t glyph_id) const { switch (u.format.v) { - case 1: return u.format1.get_coverage (glyph_id); - case 2: return u.format2.get_coverage (glyph_id); + case 1: hb_barrier (); return u.format1.get_coverage (glyph_id); + case 2: hb_barrier (); return u.format2.get_coverage (glyph_id); #ifndef HB_NO_BEYOND_64K - case 3: return u.format3.get_coverage (glyph_id); - case 4: return u.format4.get_coverage (glyph_id); + case 3: hb_barrier (); return u.format3.get_coverage (glyph_id); + case 4: hb_barrier (); return u.format4.get_coverage (glyph_id); #endif default:return NOT_COVERED; } @@ -129,11 +129,11 @@ struct Coverage unsigned get_population () const { switch (u.format.v) { - case 1: return u.format1.get_population (); - case 2: return u.format2.get_population (); + case 1: hb_barrier (); return u.format1.get_population (); + case 2: hb_barrier (); return u.format2.get_population (); #ifndef HB_NO_BEYOND_64K - case 3: return u.format3.get_population (); - case 4: return u.format4.get_population (); + case 3: hb_barrier (); return u.format3.get_population (); + case 4: hb_barrier (); return u.format4.get_population (); #endif default:return NOT_COVERED; } @@ -176,11 +176,11 @@ struct Coverage switch (u.format.v) { - case 1: return_trace (u.format1.serialize (c, glyphs)); - case 2: return_trace (u.format2.serialize (c, glyphs)); + case 1: hb_barrier (); return_trace (u.format1.serialize (c, glyphs)); + case 2: hb_barrier (); return_trace (u.format2.serialize (c, glyphs)); #ifndef HB_NO_BEYOND_64K - case 3: return_trace (u.format3.serialize (c, glyphs)); - case 4: return_trace (u.format4.serialize (c, glyphs)); + case 3: hb_barrier (); return_trace (u.format3.serialize (c, glyphs)); + case 4: hb_barrier (); return_trace (u.format4.serialize (c, glyphs)); #endif default:return_trace (false); } @@ -207,11 +207,11 @@ struct Coverage { switch (u.format.v) { - case 1: return u.format1.intersects (glyphs); - case 2: return u.format2.intersects (glyphs); + case 1: hb_barrier (); return u.format1.intersects (glyphs); + case 2: hb_barrier (); return u.format2.intersects (glyphs); #ifndef HB_NO_BEYOND_64K - case 3: return u.format3.intersects (glyphs); - case 4: return u.format4.intersects (glyphs); + case 3: hb_barrier (); return u.format3.intersects (glyphs); + case 4: hb_barrier (); return u.format4.intersects (glyphs); #endif default:return false; } @@ -220,11 +220,11 @@ struct Coverage { switch (u.format.v) { - case 1: return u.format1.intersects_coverage (glyphs, index); - case 2: return u.format2.intersects_coverage (glyphs, index); + case 1: hb_barrier (); return u.format1.intersects_coverage (glyphs, index); + case 2: hb_barrier (); return u.format2.intersects_coverage (glyphs, index); #ifndef HB_NO_BEYOND_64K - case 3: return u.format3.intersects_coverage (glyphs, index); - case 4: return u.format4.intersects_coverage (glyphs, index); + case 3: hb_barrier (); return u.format3.intersects_coverage (glyphs, index); + case 4: hb_barrier (); return u.format4.intersects_coverage (glyphs, index); #endif default:return false; } @@ -250,11 +250,11 @@ struct Coverage { switch (u.format.v) { - case 1: return u.format1.collect_coverage (glyphs); - case 2: return u.format2.collect_coverage (glyphs); + case 1: hb_barrier (); return u.format1.collect_coverage (glyphs); + case 2: hb_barrier (); return u.format2.collect_coverage (glyphs); #ifndef HB_NO_BEYOND_64K - case 3: return u.format3.collect_coverage (glyphs); - case 4: return u.format4.collect_coverage (glyphs); + case 3: hb_barrier (); return u.format3.collect_coverage (glyphs); + case 4: hb_barrier (); return u.format4.collect_coverage (glyphs); #endif default:return false; } @@ -266,11 +266,11 @@ struct Coverage { switch (u.format.v) { - case 1: return u.format1.intersect_set (glyphs, intersect_glyphs); - case 2: return u.format2.intersect_set (glyphs, intersect_glyphs); + case 1: hb_barrier (); return u.format1.intersect_set (glyphs, intersect_glyphs); + case 2: hb_barrier (); return u.format2.intersect_set (glyphs, intersect_glyphs); #ifndef HB_NO_BEYOND_64K - case 3: return u.format3.intersect_set (glyphs, intersect_glyphs); - case 4: return u.format4.intersect_set (glyphs, intersect_glyphs); + case 3: hb_barrier (); return u.format3.intersect_set (glyphs, intersect_glyphs); + case 4: hb_barrier (); return u.format4.intersect_set (glyphs, intersect_glyphs); #endif default:return ; } @@ -285,11 +285,11 @@ struct Coverage format = c_.u.format.v; switch (format) { - case 1: u.format1.init (c_.u.format1); return; - case 2: u.format2.init (c_.u.format2); return; + case 1: hb_barrier (); u.format1.init (c_.u.format1); return; + case 2: hb_barrier (); u.format2.init (c_.u.format2); return; #ifndef HB_NO_BEYOND_64K - case 3: u.format3.init (c_.u.format3); return; - case 4: u.format4.init (c_.u.format4); return; + case 3: hb_barrier (); u.format3.init (c_.u.format3); return; + case 4: hb_barrier (); u.format4.init (c_.u.format4); return; #endif default: return; } @@ -298,11 +298,11 @@ struct Coverage { switch (format) { - case 1: return u.format1.__more__ (); - case 2: return u.format2.__more__ (); + case 1: hb_barrier (); return u.format1.__more__ (); + case 2: hb_barrier (); return u.format2.__more__ (); #ifndef HB_NO_BEYOND_64K - case 3: return u.format3.__more__ (); - case 4: return u.format4.__more__ (); + case 3: hb_barrier (); return u.format3.__more__ (); + case 4: hb_barrier (); return u.format4.__more__ (); #endif default:return false; } @@ -311,11 +311,11 @@ struct Coverage { switch (format) { - case 1: u.format1.__next__ (); break; - case 2: u.format2.__next__ (); break; + case 1: hb_barrier (); u.format1.__next__ (); break; + case 2: hb_barrier (); u.format2.__next__ (); break; #ifndef HB_NO_BEYOND_64K - case 3: u.format3.__next__ (); break; - case 4: u.format4.__next__ (); break; + case 3: hb_barrier (); u.format3.__next__ (); break; + case 4: hb_barrier (); u.format4.__next__ (); break; #endif default: break; } @@ -327,11 +327,11 @@ struct Coverage { switch (format) { - case 1: return u.format1.get_glyph (); - case 2: return u.format2.get_glyph (); + case 1: hb_barrier (); return u.format1.get_glyph (); + case 2: hb_barrier (); return u.format2.get_glyph (); #ifndef HB_NO_BEYOND_64K - case 3: return u.format3.get_glyph (); - case 4: return u.format4.get_glyph (); + case 3: hb_barrier (); return u.format3.get_glyph (); + case 4: hb_barrier (); return u.format4.get_glyph (); #endif default:return 0; } @@ -341,11 +341,11 @@ struct Coverage if (unlikely (format != o.format)) return true; switch (format) { - case 1: return u.format1 != o.u.format1; - case 2: return u.format2 != o.u.format2; + case 1: hb_barrier (); return u.format1 != o.u.format1; + case 2: hb_barrier (); return u.format2 != o.u.format2; #ifndef HB_NO_BEYOND_64K - case 3: return u.format3 != o.u.format3; - case 4: return u.format4 != o.u.format4; + case 3: hb_barrier (); return u.format3 != o.u.format3; + case 4: hb_barrier (); return u.format4 != o.u.format4; #endif default:return false; } @@ -356,11 +356,11 @@ struct Coverage it.format = format; switch (format) { - case 1: it.u.format1 = u.format1.__end__ (); break; - case 2: it.u.format2 = u.format2.__end__ (); break; + case 1: hb_barrier (); it.u.format1 = u.format1.__end__ (); break; + case 2: hb_barrier (); it.u.format2 = u.format2.__end__ (); break; #ifndef HB_NO_BEYOND_64K - case 3: it.u.format3 = u.format3.__end__ (); break; - case 4: it.u.format4 = u.format4.__end__ (); break; + case 3: hb_barrier (); it.u.format3 = u.format3.__end__ (); break; + case 4: hb_barrier (); it.u.format4 = u.format4.__end__ (); break; #endif default: break; } diff --git a/src/OT/Layout/GDEF/GDEF.hh b/src/OT/Layout/GDEF/GDEF.hh index 01d72b129..5bea1c4e5 100644 --- a/src/OT/Layout/GDEF/GDEF.hh +++ b/src/OT/Layout/GDEF/GDEF.hh @@ -70,7 +70,7 @@ struct AttachList const AttachPoint &points = this+attachPoint[index]; - if (point_count) + if (point_count && point_array) { + points.as_array ().sub_array (start_offset, point_count) | hb_sink (hb_array (point_array, *point_count)) @@ -253,9 +253,9 @@ struct CaretValue const ItemVariationStore &var_store) const { switch (u.format.v) { - case 1: return u.format1.get_caret_value (font, direction); - case 2: return u.format2.get_caret_value (font, direction, glyph_id); - case 3: return u.format3.get_caret_value (font, direction, var_store); + case 1: hb_barrier (); return u.format1.get_caret_value (font, direction); + case 2: hb_barrier (); return u.format2.get_caret_value (font, direction, glyph_id); + case 3: hb_barrier (); return u.format3.get_caret_value (font, direction, var_store); default:return 0; } } @@ -266,9 +266,9 @@ struct CaretValue if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); - case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 3: hb_barrier (); return_trace (c->dispatch (u.format3, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -280,6 +280,7 @@ struct CaretValue case 2: return; case 3: + hb_barrier (); u.format3.collect_variation_indices (c); return; default: return; @@ -292,9 +293,9 @@ struct CaretValue if (!u.format.v.sanitize (c)) return_trace (false); hb_barrier (); switch (u.format.v) { - case 1: return_trace (u.format1.sanitize (c)); - case 2: return_trace (u.format2.sanitize (c)); - case 3: return_trace (u.format3.sanitize (c)); + case 1: hb_barrier (); return_trace (u.format1.sanitize (c)); + case 2: hb_barrier (); return_trace (u.format2.sanitize (c)); + case 3: hb_barrier (); return_trace (u.format3.sanitize (c)); default:return_trace (true); } } @@ -320,7 +321,7 @@ struct LigGlyph unsigned *caret_count /* IN/OUT */, hb_position_t *caret_array /* OUT */) const { - if (caret_count) + if (caret_count && caret_array) { + carets.as_array ().sub_array (start_offset, caret_count) | hb_map (hb_add (this)) @@ -520,7 +521,7 @@ struct MarkGlyphSets bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const { switch (u.format.v) { - case 1: return u.format1.covers (set_index, glyph_id); + case 1: hb_barrier (); return u.format1.covers (set_index, glyph_id); default:return false; } } @@ -529,7 +530,7 @@ struct MarkGlyphSets void collect_coverage (hb_vector_t &sets) const { switch (u.format.v) { - case 1: u.format1.collect_coverage (sets); return; + case 1: hb_barrier (); u.format1.collect_coverage (sets); return; default:return; } } @@ -538,7 +539,7 @@ struct MarkGlyphSets hb_set_t& used_mark_sets /* OUT */) const { switch (u.format.v) { - case 1: u.format1.collect_used_mark_sets (glyph_set, used_mark_sets); return; + case 1: hb_barrier (); u.format1.collect_used_mark_sets (glyph_set, used_mark_sets); return; default:return; } } @@ -547,7 +548,7 @@ struct MarkGlyphSets { TRACE_SUBSET (this); switch (u.format.v) { - case 1: return_trace (u.format1.subset (c)); + case 1: hb_barrier (); return_trace (u.format1.subset (c)); default:return_trace (false); } } @@ -558,7 +559,7 @@ struct MarkGlyphSets if (!u.format.v.sanitize (c)) return_trace (false); hb_barrier (); switch (u.format.v) { - case 1: return_trace (u.format1.sanitize (c)); + case 1: hb_barrier (); return_trace (u.format1.sanitize (c)); default:return_trace (true); } } @@ -721,7 +722,7 @@ struct GDEFVersion1_2 out->version.minor = 3; c->plan->has_gdef_varstore = true; } else if (subset_markglyphsetsdef) { - out->version.minor = 2; + out->version.minor = 2; } else { out->version.minor = 0; c->serializer->revert (snapshot_version0); @@ -758,9 +759,9 @@ struct GDEF size_t get_size () const { switch (u.version.major) { - case 1: return u.version1.get_size (); + case 1: hb_barrier (); return u.version1.get_size (); #ifndef HB_NO_BEYOND_64K - case 2: return u.version2.get_size (); + case 2: hb_barrier (); return u.version2.get_size (); #endif default: return u.version.static_size; } @@ -772,9 +773,9 @@ struct GDEF if (unlikely (!u.version.sanitize (c))) return_trace (false); hb_barrier (); switch (u.version.major) { - case 1: return_trace (u.version1.sanitize (c)); + case 1: hb_barrier (); return_trace (u.version1.sanitize (c)); #ifndef HB_NO_BEYOND_64K - case 2: return_trace (u.version2.sanitize (c)); + case 2: hb_barrier (); return_trace (u.version2.sanitize (c)); #endif default: return_trace (true); } @@ -783,9 +784,9 @@ struct GDEF bool subset (hb_subset_context_t *c) const { switch (u.version.major) { - case 1: return u.version1.subset (c); + case 1: hb_barrier (); return u.version1.subset (c); #ifndef HB_NO_BEYOND_64K - case 2: return u.version2.subset (c); + case 2: hb_barrier (); return u.version2.subset (c); #endif default: return false; } @@ -794,9 +795,9 @@ struct GDEF bool has_glyph_classes () const { switch (u.version.major) { - case 1: return u.version1.glyphClassDef != 0; + case 1: hb_barrier (); return u.version1.glyphClassDef != 0; #ifndef HB_NO_BEYOND_64K - case 2: return u.version2.glyphClassDef != 0; + case 2: hb_barrier (); return u.version2.glyphClassDef != 0; #endif default: return false; } @@ -804,9 +805,9 @@ struct GDEF const ClassDef &get_glyph_class_def () const { switch (u.version.major) { - case 1: return this+u.version1.glyphClassDef; + case 1: hb_barrier (); return this+u.version1.glyphClassDef; #ifndef HB_NO_BEYOND_64K - case 2: return this+u.version2.glyphClassDef; + case 2: hb_barrier (); return this+u.version2.glyphClassDef; #endif default: return Null(ClassDef); } @@ -814,9 +815,9 @@ struct GDEF bool has_attach_list () const { switch (u.version.major) { - case 1: return u.version1.attachList != 0; + case 1: hb_barrier (); return u.version1.attachList != 0; #ifndef HB_NO_BEYOND_64K - case 2: return u.version2.attachList != 0; + case 2: hb_barrier (); return u.version2.attachList != 0; #endif default: return false; } @@ -824,9 +825,9 @@ struct GDEF const AttachList &get_attach_list () const { switch (u.version.major) { - case 1: return this+u.version1.attachList; + case 1: hb_barrier (); return this+u.version1.attachList; #ifndef HB_NO_BEYOND_64K - case 2: return this+u.version2.attachList; + case 2: hb_barrier (); return this+u.version2.attachList; #endif default: return Null(AttachList); } @@ -834,9 +835,9 @@ struct GDEF bool has_lig_carets () const { switch (u.version.major) { - case 1: return u.version1.ligCaretList != 0; + case 1: hb_barrier (); return u.version1.ligCaretList != 0; #ifndef HB_NO_BEYOND_64K - case 2: return u.version2.ligCaretList != 0; + case 2: hb_barrier (); return u.version2.ligCaretList != 0; #endif default: return false; } @@ -844,9 +845,9 @@ struct GDEF const LigCaretList &get_lig_caret_list () const { switch (u.version.major) { - case 1: return this+u.version1.ligCaretList; + case 1: hb_barrier (); return this+u.version1.ligCaretList; #ifndef HB_NO_BEYOND_64K - case 2: return this+u.version2.ligCaretList; + case 2: hb_barrier (); return this+u.version2.ligCaretList; #endif default: return Null(LigCaretList); } @@ -854,9 +855,9 @@ struct GDEF bool has_mark_attachment_types () const { switch (u.version.major) { - case 1: return u.version1.markAttachClassDef != 0; + case 1: hb_barrier (); return u.version1.markAttachClassDef != 0; #ifndef HB_NO_BEYOND_64K - case 2: return u.version2.markAttachClassDef != 0; + case 2: hb_barrier (); return u.version2.markAttachClassDef != 0; #endif default: return false; } @@ -864,9 +865,9 @@ struct GDEF const ClassDef &get_mark_attach_class_def () const { switch (u.version.major) { - case 1: return this+u.version1.markAttachClassDef; + case 1: hb_barrier (); return this+u.version1.markAttachClassDef; #ifndef HB_NO_BEYOND_64K - case 2: return this+u.version2.markAttachClassDef; + case 2: hb_barrier (); return this+u.version2.markAttachClassDef; #endif default: return Null(ClassDef); } @@ -876,7 +877,7 @@ struct GDEF switch (u.version.major) { case 1: return u.version.to_int () >= 0x00010002u && hb_barrier () && u.version1.markGlyphSetsDef != 0; #ifndef HB_NO_BEYOND_64K - case 2: return u.version2.markGlyphSetsDef != 0; + case 2: hb_barrier (); return u.version2.markGlyphSetsDef != 0; #endif default: return false; } @@ -886,7 +887,7 @@ struct GDEF switch (u.version.major) { case 1: return u.version.to_int () >= 0x00010002u && hb_barrier () ? this+u.version1.markGlyphSetsDef : Null(MarkGlyphSets); #ifndef HB_NO_BEYOND_64K - case 2: return this+u.version2.markGlyphSetsDef; + case 2: hb_barrier (); return this+u.version2.markGlyphSetsDef; #endif default: return Null(MarkGlyphSets); } @@ -896,7 +897,7 @@ struct GDEF switch (u.version.major) { case 1: return u.version.to_int () >= 0x00010003u && hb_barrier () && u.version1.varStore != 0; #ifndef HB_NO_BEYOND_64K - case 2: return u.version2.varStore != 0; + case 2: hb_barrier (); return u.version2.varStore != 0; #endif default: return false; } @@ -906,7 +907,7 @@ struct GDEF switch (u.version.major) { case 1: return u.version.to_int () >= 0x00010003u && hb_barrier () ? this+u.version1.varStore : Null(ItemVariationStore); #ifndef HB_NO_BEYOND_64K - case 2: return this+u.version2.varStore; + case 2: hb_barrier (); return this+u.version2.varStore; #endif default: return Null(ItemVariationStore); } @@ -1003,14 +1004,14 @@ struct GDEF } HB_ALWAYS_INLINE - bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const + bool mark_set_may_cover (unsigned int set_index, hb_codepoint_t glyph_id) const { return #ifndef HB_NO_GDEF_CACHE // We can access arrayZ directly because of sanitize_lookup_props() guarantee. mark_glyph_sets.arrayZ[set_index].may_have (glyph_id) && #endif - table->mark_set_covers (set_index, glyph_id) + true ; } diff --git a/src/OT/Layout/GPOS/Anchor.hh b/src/OT/Layout/GPOS/Anchor.hh index 1938803fa..48c509c25 100644 --- a/src/OT/Layout/GPOS/Anchor.hh +++ b/src/OT/Layout/GPOS/Anchor.hh @@ -27,9 +27,9 @@ struct Anchor if (!u.format.v.sanitize (c)) return_trace (false); hb_barrier (); switch (u.format.v) { - case 1: return_trace (u.format1.sanitize (c)); - case 2: return_trace (u.format2.sanitize (c)); - case 3: return_trace (u.format3.sanitize (c)); + case 1: hb_barrier (); return_trace (u.format1.sanitize (c)); + case 2: hb_barrier (); return_trace (u.format2.sanitize (c)); + case 3: hb_barrier (); return_trace (u.format3.sanitize (c)); default:return_trace (true); } } @@ -39,9 +39,9 @@ struct Anchor { *x = *y = 0; switch (u.format.v) { - case 1: u.format1.get_anchor (c, glyph_id, x, y); return; - case 2: u.format2.get_anchor (c, glyph_id, x, y); return; - case 3: u.format3.get_anchor (c, glyph_id, x, y); return; + case 1: hb_barrier (); u.format1.get_anchor (c, glyph_id, x, y); return; + case 2: hb_barrier (); u.format2.get_anchor (c, glyph_id, x, y); return; + case 3: hb_barrier (); u.format3.get_anchor (c, glyph_id, x, y); return; default: return; } } @@ -50,8 +50,9 @@ struct Anchor { TRACE_SUBSET (this); switch (u.format.v) { - case 1: return_trace (bool (reinterpret_cast (u.format1.copy (c->serializer)))); + case 1: hb_barrier (); return_trace (bool (reinterpret_cast (u.format1.copy (c->serializer)))); case 2: + hb_barrier (); if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING) { // AnchorFormat 2 just containins extra hinting information, so @@ -59,7 +60,7 @@ struct Anchor return_trace (bool (reinterpret_cast (u.format1.copy (c->serializer)))); } return_trace (bool (reinterpret_cast (u.format2.copy (c->serializer)))); - case 3: return_trace (u.format3.subset (c)); + case 3: hb_barrier (); return_trace (u.format3.subset (c)); default:return_trace (false); } } @@ -70,6 +71,7 @@ struct Anchor case 1: case 2: return; case 3: + hb_barrier (); u.format3.collect_variation_indices (c); return; default: return; diff --git a/src/OT/Layout/GPOS/CursivePos.hh b/src/OT/Layout/GPOS/CursivePos.hh index 38a29dd9e..e5e99cfaf 100644 --- a/src/OT/Layout/GPOS/CursivePos.hh +++ b/src/OT/Layout/GPOS/CursivePos.hh @@ -22,7 +22,7 @@ struct CursivePos if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/OT/Layout/GPOS/MarkBasePos.hh b/src/OT/Layout/GPOS/MarkBasePos.hh index 32476663b..c0c9be9b1 100644 --- a/src/OT/Layout/GPOS/MarkBasePos.hh +++ b/src/OT/Layout/GPOS/MarkBasePos.hh @@ -25,9 +25,9 @@ struct MarkBasePos if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); #ifndef HB_NO_BEYOND_64K - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); #endif default:return_trace (c->default_return_value ()); } diff --git a/src/OT/Layout/GPOS/MarkLigPos.hh b/src/OT/Layout/GPOS/MarkLigPos.hh index 5c686f576..c3e56e2bf 100644 --- a/src/OT/Layout/GPOS/MarkLigPos.hh +++ b/src/OT/Layout/GPOS/MarkLigPos.hh @@ -25,9 +25,9 @@ struct MarkLigPos if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); #ifndef HB_NO_BEYOND_64K - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); #endif default:return_trace (c->default_return_value ()); } diff --git a/src/OT/Layout/GPOS/MarkMarkPos.hh b/src/OT/Layout/GPOS/MarkMarkPos.hh index dbd8419ca..ba1acc82e 100644 --- a/src/OT/Layout/GPOS/MarkMarkPos.hh +++ b/src/OT/Layout/GPOS/MarkMarkPos.hh @@ -25,9 +25,9 @@ struct MarkMarkPos if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); #ifndef HB_NO_BEYOND_64K - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); #endif default:return_trace (c->default_return_value ()); } diff --git a/src/OT/Layout/GPOS/PairPos.hh b/src/OT/Layout/GPOS/PairPos.hh index 1b3b70090..765db3a24 100644 --- a/src/OT/Layout/GPOS/PairPos.hh +++ b/src/OT/Layout/GPOS/PairPos.hh @@ -28,11 +28,11 @@ struct PairPos if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); #ifndef HB_NO_BEYOND_64K - case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); - case 4: return_trace (c->dispatch (u.format4, std::forward (ds)...)); + case 3: hb_barrier (); return_trace (c->dispatch (u.format3, std::forward (ds)...)); + case 4: hb_barrier (); return_trace (c->dispatch (u.format4, std::forward (ds)...)); #endif default:return_trace (c->default_return_value ()); } diff --git a/src/OT/Layout/GPOS/PosLookupSubTable.hh b/src/OT/Layout/GPOS/PosLookupSubTable.hh index c19fbc323..4238f98f4 100644 --- a/src/OT/Layout/GPOS/PosLookupSubTable.hh +++ b/src/OT/Layout/GPOS/PosLookupSubTable.hh @@ -37,15 +37,15 @@ struct PosLookupSubTable { TRACE_DISPATCH (this, lookup_type); switch (lookup_type) { - case Single: return_trace (u.single.dispatch (c, std::forward (ds)...)); - case Pair: return_trace (u.pair.dispatch (c, std::forward (ds)...)); - case Cursive: return_trace (u.cursive.dispatch (c, std::forward (ds)...)); - case MarkBase: return_trace (u.markBase.dispatch (c, std::forward (ds)...)); - case MarkLig: return_trace (u.markLig.dispatch (c, std::forward (ds)...)); - case MarkMark: return_trace (u.markMark.dispatch (c, std::forward (ds)...)); - case Context: return_trace (u.context.dispatch (c, std::forward (ds)...)); - case ChainContext: return_trace (u.chainContext.dispatch (c, std::forward (ds)...)); - case Extension: return_trace (u.extension.dispatch (c, std::forward (ds)...)); + case Single: hb_barrier (); return_trace (u.single.dispatch (c, std::forward (ds)...)); + case Pair: hb_barrier (); return_trace (u.pair.dispatch (c, std::forward (ds)...)); + case Cursive: hb_barrier (); return_trace (u.cursive.dispatch (c, std::forward (ds)...)); + case MarkBase: hb_barrier (); return_trace (u.markBase.dispatch (c, std::forward (ds)...)); + case MarkLig: hb_barrier (); return_trace (u.markLig.dispatch (c, std::forward (ds)...)); + case MarkMark: hb_barrier (); return_trace (u.markMark.dispatch (c, std::forward (ds)...)); + case Context: hb_barrier (); return_trace (u.context.dispatch (c, std::forward (ds)...)); + case ChainContext: hb_barrier (); return_trace (u.chainContext.dispatch (c, std::forward (ds)...)); + case Extension: hb_barrier (); return_trace (u.extension.dispatch (c, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } diff --git a/src/OT/Layout/GPOS/SinglePos.hh b/src/OT/Layout/GPOS/SinglePos.hh index 30fc1aacd..ddf25e643 100644 --- a/src/OT/Layout/GPOS/SinglePos.hh +++ b/src/OT/Layout/GPOS/SinglePos.hh @@ -51,13 +51,13 @@ struct SinglePos u.format.v = format; switch (u.format.v) { - case 1: u.format1.serialize (c, + case 1: hb_barrier (); u.format1.serialize (c, src, glyph_val_iter_pairs, new_format, layout_variation_idx_delta_map); return; - case 2: u.format2.serialize (c, + case 2: hb_barrier (); u.format2.serialize (c, src, glyph_val_iter_pairs, new_format, @@ -73,8 +73,8 @@ struct SinglePos if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/OT/Layout/GSUB/AlternateSet.hh b/src/OT/Layout/GSUB/AlternateSet.hh index 1fc2265d9..9420f3460 100644 --- a/src/OT/Layout/GSUB/AlternateSet.hh +++ b/src/OT/Layout/GSUB/AlternateSet.hh @@ -89,7 +89,7 @@ struct AlternateSet unsigned *alternate_count /* IN/OUT. May be NULL. */, hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const { - if (alternates.len && alternate_count) + if (alternates.len && alternate_count && alternate_glyphs) { + alternates.as_array ().sub_array (start_offset, alternate_count) | hb_sink (hb_array (alternate_glyphs, *alternate_count)) diff --git a/src/OT/Layout/GSUB/AlternateSubst.hh b/src/OT/Layout/GSUB/AlternateSubst.hh index 08b1dbbee..ffe6432f2 100644 --- a/src/OT/Layout/GSUB/AlternateSubst.hh +++ b/src/OT/Layout/GSUB/AlternateSubst.hh @@ -26,9 +26,9 @@ struct AlternateSubst if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); #ifndef HB_NO_BEYOND_64K - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); #endif default:return_trace (c->default_return_value ()); } @@ -46,7 +46,7 @@ struct AlternateSubst unsigned int format = 1; u.format.v = format; switch (u.format.v) { - case 1: return_trace (u.format1.serialize (c, glyphs, alternate_len_list, alternate_glyphs_list)); + case 1: hb_barrier (); return_trace (u.format1.serialize (c, glyphs, alternate_len_list, alternate_glyphs_list)); default:return_trace (false); } } diff --git a/src/OT/Layout/GSUB/LigatureSubst.hh b/src/OT/Layout/GSUB/LigatureSubst.hh index 406d91eca..45e949299 100644 --- a/src/OT/Layout/GSUB/LigatureSubst.hh +++ b/src/OT/Layout/GSUB/LigatureSubst.hh @@ -26,9 +26,9 @@ struct LigatureSubst if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); #ifndef HB_NO_BEYOND_64K - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); #endif default:return_trace (c->default_return_value ()); } @@ -49,7 +49,7 @@ struct LigatureSubst unsigned int format = 1; u.format.v = format; switch (u.format.v) { - case 1: return_trace (u.format1.serialize (c, + case 1: hb_barrier (); return_trace (u.format1.serialize (c, first_glyphs, ligature_per_first_glyph_count_list, ligatures_list, diff --git a/src/OT/Layout/GSUB/MultipleSubst.hh b/src/OT/Layout/GSUB/MultipleSubst.hh index 2ff59ad97..adfb20aa8 100644 --- a/src/OT/Layout/GSUB/MultipleSubst.hh +++ b/src/OT/Layout/GSUB/MultipleSubst.hh @@ -27,9 +27,9 @@ struct MultipleSubst if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); #ifndef HB_NO_BEYOND_64K - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); #endif default:return_trace (c->default_return_value ()); } @@ -45,7 +45,7 @@ struct MultipleSubst unsigned int format = 1; u.format.v = format; switch (u.format.v) { - case 1: return_trace (u.format1.serialize (c, it)); + case 1: hb_barrier (); return_trace (u.format1.serialize (c, it)); default:return_trace (false); } } diff --git a/src/OT/Layout/GSUB/ReverseChainSingleSubst.hh b/src/OT/Layout/GSUB/ReverseChainSingleSubst.hh index e33148d77..0643a4870 100644 --- a/src/OT/Layout/GSUB/ReverseChainSingleSubst.hh +++ b/src/OT/Layout/GSUB/ReverseChainSingleSubst.hh @@ -23,7 +23,7 @@ struct ReverseChainSingleSubst if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/OT/Layout/GSUB/SingleSubst.hh b/src/OT/Layout/GSUB/SingleSubst.hh index 7ffe3a68b..a7b35369f 100644 --- a/src/OT/Layout/GSUB/SingleSubst.hh +++ b/src/OT/Layout/GSUB/SingleSubst.hh @@ -30,11 +30,11 @@ struct SingleSubst if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value (); TRACE_DISPATCH (this, u.format.v); switch (u.format.v) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); #ifndef HB_NO_BEYOND_64K - case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); - case 4: return_trace (c->dispatch (u.format4, std::forward (ds)...)); + case 3: hb_barrier (); return_trace (c->dispatch (u.format3, std::forward (ds)...)); + case 4: hb_barrier (); return_trace (c->dispatch (u.format4, std::forward (ds)...)); #endif default:return_trace (c->default_return_value ()); } @@ -73,17 +73,17 @@ struct SingleSubst u.format.v = format; switch (u.format.v) { - case 1: return_trace (u.format1.serialize (c, + case 1: hb_barrier (); return_trace (u.format1.serialize (c, + glyphs | hb_map_retains_sorting (hb_first), delta)); - case 2: return_trace (u.format2.serialize (c, glyphs)); + case 2: hb_barrier (); return_trace (u.format2.serialize (c, glyphs)); #ifndef HB_NO_BEYOND_64K - case 3: return_trace (u.format3.serialize (c, + case 3: hb_barrier (); return_trace (u.format3.serialize (c, + glyphs | hb_map_retains_sorting (hb_first), delta)); - case 4: return_trace (u.format4.serialize (c, glyphs)); + case 4: hb_barrier (); return_trace (u.format4.serialize (c, glyphs)); #endif default:return_trace (false); } diff --git a/src/OT/Layout/GSUB/SingleSubstFormat1.hh b/src/OT/Layout/GSUB/SingleSubstFormat1.hh index a8528ea06..bc18a8f32 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat1.hh @@ -126,7 +126,7 @@ struct SingleSubstFormat1_3 return 0; } - if (alternate_count && *alternate_count) + if (alternate_count && *alternate_count && alternate_glyphs) { hb_codepoint_t d = deltaGlyphID; hb_codepoint_t mask = get_mask (); diff --git a/src/OT/Layout/GSUB/SingleSubstFormat2.hh b/src/OT/Layout/GSUB/SingleSubstFormat2.hh index 49e56665a..3836fb585 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat2.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat2.hh @@ -114,7 +114,7 @@ struct SingleSubstFormat2_4 return 0; } - if (alternate_count && *alternate_count) + if (alternate_count && *alternate_count && alternate_glyphs) { glyph_id = substitute[index]; diff --git a/src/OT/Layout/GSUB/SubstLookup.hh b/src/OT/Layout/GSUB/SubstLookup.hh index e0b3f6fdd..d3b1d1081 100644 --- a/src/OT/Layout/GSUB/SubstLookup.hh +++ b/src/OT/Layout/GSUB/SubstLookup.hh @@ -24,7 +24,7 @@ struct SubstLookup : Lookup bool is_reverse () const { unsigned int type = get_type (); - if (unlikely (type == SubTable::Extension)) + if (unlikely (type == SubTable::Extension) && hb_barrier ()) return get_subtable (0).u.extension.is_reverse (); return lookup_type_is_reverse (type); } diff --git a/src/OT/Layout/GSUB/SubstLookupSubTable.hh b/src/OT/Layout/GSUB/SubstLookupSubTable.hh index a525fba03..c36f0d7bf 100644 --- a/src/OT/Layout/GSUB/SubstLookupSubTable.hh +++ b/src/OT/Layout/GSUB/SubstLookupSubTable.hh @@ -50,14 +50,14 @@ struct SubstLookupSubTable { TRACE_DISPATCH (this, lookup_type); switch (lookup_type) { - case Single: return_trace (u.single.dispatch (c, std::forward (ds)...)); - case Multiple: return_trace (u.multiple.dispatch (c, std::forward (ds)...)); - case Alternate: return_trace (u.alternate.dispatch (c, std::forward (ds)...)); - case Ligature: return_trace (u.ligature.dispatch (c, std::forward (ds)...)); - case Context: return_trace (u.context.dispatch (c, std::forward (ds)...)); - case ChainContext: return_trace (u.chainContext.dispatch (c, std::forward (ds)...)); - case Extension: return_trace (u.extension.dispatch (c, std::forward (ds)...)); - case ReverseChainSingle: return_trace (u.reverseChainContextSingle.dispatch (c, std::forward (ds)...)); + case Single: hb_barrier (); return_trace (u.single.dispatch (c, std::forward (ds)...)); + case Multiple: hb_barrier (); return_trace (u.multiple.dispatch (c, std::forward (ds)...)); + case Alternate: hb_barrier (); return_trace (u.alternate.dispatch (c, std::forward (ds)...)); + case Ligature: hb_barrier (); return_trace (u.ligature.dispatch (c, std::forward (ds)...)); + case Context: hb_barrier (); return_trace (u.context.dispatch (c, std::forward (ds)...)); + case ChainContext: hb_barrier (); return_trace (u.chainContext.dispatch (c, std::forward (ds)...)); + case Extension: hb_barrier (); return_trace (u.extension.dispatch (c, std::forward (ds)...)); + case ReverseChainSingle: hb_barrier (); return_trace (u.reverseChainContextSingle.dispatch (c, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } diff --git a/src/OT/glyf/glyf-helpers.hh b/src/OT/glyf/glyf-helpers.hh index f157bf002..5dca10cbb 100644 --- a/src/OT/glyf/glyf-helpers.hh +++ b/src/OT/glyf/glyf-helpers.hh @@ -94,7 +94,7 @@ _add_loca_and_head (hb_subset_context_t *c, unsigned num_offsets = c->plan->num_output_glyphs () + 1; unsigned entry_size = use_short_loca ? 2 : 4; - char *loca_prime_data = (char *) hb_malloc (entry_size * num_offsets); + char *loca_prime_data = (char *) hb_malloc2 (num_offsets, entry_size); if (unlikely (!loca_prime_data)) return false; diff --git a/src/gen-def.py b/src/gen-def.py index 7bf6bd401..62ccf7752 100755 --- a/src/gen-def.py +++ b/src/gen-def.py @@ -21,6 +21,7 @@ if '--experimental-api' not in sys.argv: experimental_symbols = \ """hb_shape_justify hb_subset_input_override_name_table +hb_subset_input_to_string_or_fail hb_subset_cff_get_charstring_data hb_subset_cff_get_charstrings_index hb_subset_cff2_get_charstring_data diff --git a/src/graph/classdef-graph.hh b/src/graph/classdef-graph.hh index df06e00e7..fa604c90e 100644 --- a/src/graph/classdef-graph.hh +++ b/src/graph/classdef-graph.hh @@ -34,7 +34,7 @@ namespace graph { struct ClassDefFormat1 : public OT::ClassDefFormat1_3 { - bool sanitize (graph_t::vertex_t& vertex) const + bool sanitize (const graph_t::vertex_t& vertex) const { size_t vertex_len = vertex.obj.tail - vertex.obj.head; constexpr unsigned min_size = OT::ClassDefFormat1_3::min_size; @@ -46,7 +46,7 @@ struct ClassDefFormat1 : public OT::ClassDefFormat1_3 struct ClassDefFormat2 : public OT::ClassDefFormat2_4 { - bool sanitize (graph_t::vertex_t& vertex) const + bool sanitize (const graph_t::vertex_t& vertex) const { size_t vertex_len = vertex.obj.tail - vertex.obj.head; constexpr unsigned min_size = OT::ClassDefFormat2_4::min_size; @@ -112,7 +112,7 @@ struct ClassDef : public OT::ClassDef return true; } - bool sanitize (graph_t::vertex_t& vertex) const + bool 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; diff --git a/src/graph/coverage-graph.hh b/src/graph/coverage-graph.hh index 5778ee9e1..457aab771 100644 --- a/src/graph/coverage-graph.hh +++ b/src/graph/coverage-graph.hh @@ -34,7 +34,7 @@ namespace graph { static bool sanitize ( const OT::Layout::Common::CoverageFormat1_3* thiz, - graph_t::vertex_t& vertex + const graph_t::vertex_t& vertex ) { size_t vertex_len = vertex.obj.tail - vertex.obj.head; constexpr unsigned min_size = OT::Layout::Common::CoverageFormat1_3::min_size; @@ -45,7 +45,7 @@ static bool sanitize ( static bool sanitize ( const OT::Layout::Common::CoverageFormat2_4* thiz, - graph_t::vertex_t& vertex + const graph_t::vertex_t& vertex ) { size_t vertex_len = vertex.obj.tail - vertex.obj.head; constexpr unsigned min_size = OT::Layout::Common::CoverageFormat2_4::min_size; @@ -156,7 +156,7 @@ struct Coverage : public OT::Layout::Common::Coverage return true; } - bool sanitize (graph_t::vertex_t& vertex) const + bool 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; diff --git a/src/graph/graph.hh b/src/graph/graph.hh index 7dc633afc..94e0e4ba1 100644 --- a/src/graph/graph.hh +++ b/src/graph/graph.hh @@ -52,6 +52,7 @@ struct graph_t unsigned single_parent = (unsigned) -1; bool has_incoming_virtual_edges_ = false; hb_hashmap_t parents; + hb_set_t virtual_parents; public: auto parents_iter () const HB_AUTO_RETURN @@ -64,7 +65,7 @@ struct graph_t bool in_error () const { - return parents.in_error (); + return parents.in_error () || virtual_parents.in_error (); } bool has_incoming_virtual_edges () const @@ -171,6 +172,7 @@ struct graph_t hb_swap (a.space, b.space); hb_swap (a.single_parent, b.single_parent); hb_swap (a.parents, b.parents); + hb_swap (a.virtual_parents, b.virtual_parents); hb_swap (a.incoming_edges_, b.incoming_edges_); hb_swap (a.has_incoming_virtual_edges_, b.has_incoming_virtual_edges_); hb_swap (a.start, b.start); @@ -193,7 +195,7 @@ struct graph_t bool is_shared () const { - return parents.get_population () > 1; + return parents.get_population () > virtual_parents.get_population () + 1; } unsigned incoming_edges () const @@ -221,12 +223,15 @@ struct graph_t has_incoming_virtual_edges_ = false; single_parent = (unsigned) -1; parents.reset (); + virtual_parents.reset (); } void add_parent (unsigned parent_index, bool is_virtual) { assert (parent_index != (unsigned) -1); has_incoming_virtual_edges_ |= is_virtual; + if (is_virtual) + virtual_parents.add (parent_index); if (incoming_edges_ == 0) { @@ -258,6 +263,7 @@ struct graph_t { single_parent = (unsigned) -1; incoming_edges_--; + virtual_parents.reset (); return; } @@ -268,7 +274,10 @@ struct graph_t if (*v > 1) (*v)--; else + { parents.del (parent_index); + virtual_parents.del (parent_index); + } if (incoming_edges_ == 1) { @@ -295,37 +304,19 @@ struct graph_t } } - bool remap_parents (const hb_vector_t& id_map) - { - if (single_parent != (unsigned) -1) - { - assert (single_parent < id_map.length); - single_parent = id_map[single_parent]; - return true; - } - - hb_hashmap_t new_parents; - new_parents.alloc (parents.get_population ()); - for (auto _ : parents) - { - assert (_.first < id_map.length); - assert (!new_parents.has (id_map[_.first])); - new_parents.set (id_map[_.first], _.second); - } - - if (parents.in_error() || new_parents.in_error ()) - return false; - - parents = std::move (new_parents); - return true; - } - void remap_parent (unsigned old_index, unsigned new_index) { if (single_parent != (unsigned) -1) { if (single_parent == old_index) + { single_parent = new_index; + if (virtual_parents.has (old_index)) + { + virtual_parents.del (old_index); + virtual_parents.add (new_index); + } + } return; } @@ -343,6 +334,12 @@ struct graph_t parents.reset (); } } + + if (virtual_parents.has (old_index)) + { + virtual_parents.del (old_index); + virtual_parents.add (new_index); + } } bool is_leaf () const @@ -437,19 +434,29 @@ struct graph_t } }; - template + enum vertex_mutability_t + { + Immutable, + Mutable + }; + + template struct vertex_and_table_t { vertex_and_table_t () : index (0), vertex (nullptr), table (nullptr) {} - unsigned index; - vertex_t* vertex; - T* table; + template + vertex_and_table_t (const vertex_and_table_t& o) + : index (o.index), vertex (o.vertex), table (o.table) + {} - operator bool () { - return table && vertex; - } + unsigned index; + typename std::conditional::type vertex; + typename std::conditional::type table; + + operator bool () const + { return table && vertex; } }; /* @@ -712,32 +719,32 @@ struct graph_t } template - vertex_and_table_t as_table (unsigned parent, const void* offset, Ts... ds) + const vertex_and_table_t as_table (unsigned parent, const void* offset, Ts... ds) { return as_table_from_index (index_for_offset (parent, offset), std::forward(ds)...); } template - vertex_and_table_t as_mutable_table (unsigned parent, const void* offset, Ts... ds) + vertex_and_table_t as_mutable_table (unsigned parent, const void* offset, Ts... ds) { - return as_table_from_index (mutable_index_for_offset (parent, offset), std::forward(ds)...); + return as_table_from_index (mutable_index_for_offset (parent, offset), std::forward(ds)...); } - template - vertex_and_table_t as_table_from_index (unsigned index, Ts... ds) + template + vertex_and_table_t as_table_from_index (unsigned index, Ts... ds) { if (index >= vertices_.length) - return vertex_and_table_t (); + return vertex_and_table_t (); - vertex_and_table_t r; - r.vertex = &vertices_[index]; - r.table = (T*) r.vertex->obj.head; + vertex_and_table_t r; + r.vertex = (typename std::conditional::type) &vertices_[index]; + r.table = (typename std::conditional::type) r.vertex->obj.head; r.index = index; if (!r.table) - return vertex_and_table_t (); + return vertex_and_table_t (); if (!r.table->sanitize (*(r.vertex), std::forward(ds)...)) - return vertex_and_table_t (); + return vertex_and_table_t (); return r; } @@ -773,7 +780,7 @@ struct graph_t for (unsigned p : child.parents_iter ()) { if (p != node_idx) { - return duplicate (node_idx, child_idx); + return duplicate (node_idx, child_idx, true); } } @@ -816,6 +823,9 @@ struct graph_t unsigned next_space = this->next_space (); if (next_space >= HB_REPACKER_MAX_SPACES) { + DEBUG_MSG (SUBSET_REPACK, nullptr, + "num of spaces %u exceeds HB_REPACKER_MAX_SPACES.", + next_space); check_success (false); break; } @@ -1065,10 +1075,13 @@ struct graph_t /* * Creates a copy of node_idx and returns it's new index. */ - unsigned duplicate (unsigned node_idx) + unsigned duplicate (unsigned node_idx, bool copy_table = false) { if (vertices_.length >= HB_REPACKER_MAX_VERTICES) { + DEBUG_MSG (SUBSET_REPACK, nullptr, + "duplicating node: num of vertices %u exceeds HB_REPACKER_MAX_VERTICES.", + vertices_.length); check_success (false); return -1; } @@ -1085,8 +1098,24 @@ struct graph_t return -1; } - clone->obj.head = child.obj.head; - clone->obj.tail = child.obj.tail; + unsigned table_size = child.obj.tail - child.obj.head; + if (copy_table && table_size) + { + char* buffer = (char*) hb_malloc (table_size); + if (!check_success (buffer && add_buffer (buffer))) + { + hb_free (buffer); + return -1; + } + hb_memcpy (buffer, child.obj.head, table_size); + clone->obj.head = buffer; + clone->obj.tail = buffer + table_size; + } + else + { + clone->obj.head = child.obj.head; + clone->obj.tail = child.obj.tail; + } clone->distance = child.distance; clone->space = child.space; clone->reset_parents (); @@ -1118,7 +1147,7 @@ struct graph_t * If the child_idx only has incoming edges from parent_idx, * duplication isn't possible and this will return -1. */ - unsigned duplicate (unsigned parent_idx, unsigned child_idx) + unsigned duplicate (unsigned parent_idx, unsigned child_idx, bool copy_table = false) { update_parents (); @@ -1142,7 +1171,7 @@ struct graph_t DEBUG_MSG (SUBSET_REPACK, nullptr, " Duplicating %u => %u", parent_idx, child_idx); - unsigned clone_idx = duplicate (child_idx); + unsigned clone_idx = duplicate (child_idx, copy_table); if (clone_idx == (unsigned) -1) return -1; // duplicate shifts the root node idx, so if parent_idx was root update it. if (parent_idx == clone_idx) parent_idx++; @@ -1234,6 +1263,9 @@ struct graph_t { if (vertices_.length >= HB_REPACKER_MAX_VERTICES) { + DEBUG_MSG (SUBSET_REPACK, nullptr, + "creating new node: num of vertices %u exceeds HB_REPACKER_MAX_VERTICES.", + vertices_.length); check_success (false); return -1; } @@ -1285,31 +1317,6 @@ struct graph_t return new_child_idx; } - /* - * Creates a new child node and remap the old child at specified position to it. - * - * Returns the index of the newly created child. - * - */ - unsigned remap_child_at_position (unsigned parent_idx, unsigned old_child_idx, const void* offset) - { - const auto& parent = object (parent_idx); - if (!offset || offset < parent.head || offset >= parent.tail) return -1; - - for (auto& l : parent.real_links) - { - if (l.objidx != old_child_idx || offset != parent.head + l.position) - continue; - - unsigned new_child_idx = duplicate (old_child_idx); - if (new_child_idx == (unsigned) -1) return -1; - reassign_link (l, parent_idx, new_child_idx, false); - return new_child_idx; - } - - return -1; - } - /* * Raises the sorting priority of all children. */ @@ -1428,6 +1435,9 @@ struct graph_t { if (num_roots_for_space_.length >= HB_REPACKER_MAX_SPACES) { + DEBUG_MSG (SUBSET_REPACK, nullptr, + "move_to_new_space: num of spaces %u exceeds HB_REPACKER_MAX_SPACES.", + num_roots_for_space_.length); check_success (false); return; } diff --git a/src/graph/gsubgpos-graph.hh b/src/graph/gsubgpos-graph.hh index 73f4b1566..dd6ed1bdd 100644 --- a/src/graph/gsubgpos-graph.hh +++ b/src/graph/gsubgpos-graph.hh @@ -50,7 +50,7 @@ struct ExtensionFormat1 : public OT::ExtensionFormat1 this->extensionOffset = 0; } - bool sanitize (graph_t::vertex_t& vertex) const + bool sanitize (const graph_t::vertex_t& vertex) const { size_t vertex_len = vertex.obj.tail - vertex.obj.head; return vertex_len >= OT::ExtensionFormat1::static_size; @@ -74,7 +74,7 @@ struct Lookup : public OT::Lookup return subTable.len; } - bool sanitize (graph_t::vertex_t& vertex) const + bool 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; @@ -414,9 +414,9 @@ struct GSTAR : public OT::GSUBGPOS const void* get_lookup_list_field_offset () const { switch (u.version.major) { - case 1: return u.version1.get_lookup_list_offset (); + case 1: hb_barrier (); return u.version1.get_lookup_list_offset (); #ifndef HB_NO_BEYOND_64K - case 2: return u.version2.get_lookup_list_offset (); + case 2: hb_barrier (); return u.version2.get_lookup_list_offset (); #endif default: return 0; } diff --git a/src/graph/ligature-graph.hh b/src/graph/ligature-graph.hh index cfcd11f27..44f777be6 100644 --- a/src/graph/ligature-graph.hh +++ b/src/graph/ligature-graph.hh @@ -1,3 +1,4 @@ + /* * Copyright © 2025 Google, Inc. * @@ -39,7 +40,7 @@ namespace graph { struct LigatureSet : public OT::Layout::GSUB_impl::LigatureSet { - bool sanitize (graph_t::vertex_t& vertex) const + bool 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::min_size) return false; @@ -55,7 +56,7 @@ struct LigatureSet : public OT::Layout::GSUB_impl::LigatureSet struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1_2 { - bool sanitize (graph_t::vertex_t& vertex) const + bool sanitize (const graph_t::vertex_t& vertex) const { size_t vertex_len = vertex.obj.tail - vertex.obj.head; unsigned min_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2::min_size; @@ -70,7 +71,7 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 unsigned this_index) { auto split_points = compute_split_points(c, this_index); - if (!split_points || !duplicate_shared_liga_sets(c, this_index)) + if (!split_points) return hb_vector_t (); split_context_t split_context { @@ -107,7 +108,8 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 return result; } - hb_vector_t ligature_index_to_object_id(const graph_t::vertex_and_table_t& liga_set) const { + template + hb_vector_t ligature_index_to_object_id(const graph_t::vertex_and_table_t& liga_set) const { hb_vector_t map; map.resize_exact(liga_set.table->ligature.len); if (map.in_error()) return map; @@ -124,28 +126,6 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 return map; } - bool duplicate_shared_liga_sets(gsubgpos_graph_context_t& c, unsigned this_index) const - { - hb_set_t visited; - for (unsigned i = 0; i < ligatureSet.len; i++) - { - auto liga_set = c.graph.as_table(this_index, &ligatureSet[i]); - if (!liga_set.table) return false; - - unsigned liga_set_index = liga_set.index; - if (visited.has (liga_set_index)) - { - unsigned new_index = c.graph.remap_child_at_position (this_index, liga_set_index, &ligatureSet[i]); - if (new_index == (unsigned) -1) return false; - } - else - { - visited.add (liga_set_index); - } - } - return true; - } - hb_vector_t compute_split_points(gsubgpos_graph_context_t& c, unsigned this_index) const { @@ -342,12 +322,12 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 continue; } - auto liga_set_index = c.graph.index_for_offset(this_index, &ligatureSet[i]); - auto liga_set = c.graph.as_table(this_index, &ligatureSet[i]); + auto liga_set = c.graph.as_mutable_table(this_index, &ligatureSet[i]); if (!liga_set.table) { return -1; } + unsigned liga_set_index = liga_set.index; // Bounds may need to be adjusted if some ligas have been previously removed. hb_pair_t liga_bounds = current_liga_set_bounds(c, liga_set_index, liga_set.vertex->obj); current_start = hb_max(count + liga_bounds.first, current_start); @@ -428,7 +408,7 @@ struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1 unsigned new_liga_set_count = 0; for (unsigned i = 0; i < liga_counts.length; i++) { - auto liga_set = c.graph.as_table(this_index, &ligatureSet[i]); + auto liga_set = c.graph.as_mutable_table(this_index, &ligatureSet[i]); if (!liga_set.table) { return false; } @@ -505,6 +485,7 @@ struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst { switch (u.format.v) { case 1: + hb_barrier (); return ((LigatureSubstFormat1*)(&u.format1))->split_subtables (c, this_index); #ifndef HB_NO_BEYOND_64K case 2: HB_FALLTHROUGH; @@ -515,7 +496,7 @@ struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst } } - bool sanitize (graph_t::vertex_t& vertex) const + bool 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; @@ -523,6 +504,7 @@ struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst switch (u.format.v) { case 1: + hb_barrier (); return ((LigatureSubstFormat1*)(&u.format1))->sanitize (vertex); #ifndef HB_NO_BEYOND_64K case 2: HB_FALLTHROUGH; diff --git a/src/graph/markbasepos-graph.hh b/src/graph/markbasepos-graph.hh index a653f402a..e476a90b8 100644 --- a/src/graph/markbasepos-graph.hh +++ b/src/graph/markbasepos-graph.hh @@ -36,7 +36,7 @@ namespace graph { struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix { - bool sanitize (graph_t::vertex_t& vertex, unsigned class_count) const + bool 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; @@ -124,7 +124,7 @@ struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix struct MarkArray : public OT::Layout::GPOS_impl::MarkArray { - bool sanitize (graph_t::vertex_t& vertex) const + bool sanitize (const graph_t::vertex_t& vertex) const { size_t vertex_len = vertex.obj.tail - vertex.obj.head; unsigned min_size = MarkArray::min_size; @@ -205,7 +205,7 @@ struct MarkArray : public OT::Layout::GPOS_impl::MarkArray struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2 { - bool sanitize (graph_t::vertex_t& vertex) const + bool sanitize (const graph_t::vertex_t& vertex) const { size_t vertex_len = vertex.obj.tail - vertex.obj.head; return vertex_len >= MarkBasePosFormat1::static_size; @@ -448,7 +448,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2 (sc.this_index, &markArray); + graph.as_mutable_table (sc.this_index, &markArray); if (!mark_array) return -1; unsigned new_mark_array = mark_array.table->clone (sc.c, @@ -460,7 +460,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2 (sc.this_index, &baseArray, class_count); + graph.as_mutable_table (sc.this_index, &baseArray, class_count); if (!base_array) return -1; unsigned new_base_array = base_array.table->clone (sc.c, @@ -480,6 +480,7 @@ struct MarkBasePos : public OT::Layout::GPOS_impl::MarkBasePos { switch (u.format.v) { case 1: + hb_barrier (); return ((MarkBasePosFormat1*)(&u.format1))->split_subtables (c, this_index); #ifndef HB_NO_BEYOND_64K case 2: HB_FALLTHROUGH; @@ -490,7 +491,7 @@ struct MarkBasePos : public OT::Layout::GPOS_impl::MarkBasePos } } - bool sanitize (graph_t::vertex_t& vertex) const + bool 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; @@ -498,6 +499,7 @@ struct MarkBasePos : public OT::Layout::GPOS_impl::MarkBasePos switch (u.format.v) { case 1: + hb_barrier (); return ((MarkBasePosFormat1*)(&u.format1))->sanitize (vertex); #ifndef HB_NO_BEYOND_64K case 2: HB_FALLTHROUGH; diff --git a/src/graph/pairpos-graph.hh b/src/graph/pairpos-graph.hh index 7c3b04819..65b170017 100644 --- a/src/graph/pairpos-graph.hh +++ b/src/graph/pairpos-graph.hh @@ -37,7 +37,7 @@ namespace graph { struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 { - bool sanitize (graph_t::vertex_t& vertex) const + bool sanitize (const graph_t::vertex_t& vertex) const { size_t vertex_len = vertex.obj.tail - vertex.obj.head; unsigned min_size = OT::Layout::GPOS_impl::PairPosFormat1_3::min_size; @@ -193,7 +193,7 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 { - bool sanitize (graph_t::vertex_t& vertex) const + bool sanitize (const graph_t::vertex_t& vertex) const { size_t vertex_len = vertex.table_size (); unsigned min_size = OT::Layout::GPOS_impl::PairPosFormat2_4::min_size; @@ -608,8 +608,10 @@ struct PairPos : public OT::Layout::GPOS_impl::PairPos { switch (u.format.v) { case 1: + hb_barrier (); return ((PairPosFormat1*)(&u.format1))->split_subtables (c, this_index); case 2: + hb_barrier (); return ((PairPosFormat2*)(&u.format2))->split_subtables (c, this_index); #ifndef HB_NO_BEYOND_64K case 3: HB_FALLTHROUGH; @@ -621,7 +623,7 @@ struct PairPos : public OT::Layout::GPOS_impl::PairPos } } - bool sanitize (graph_t::vertex_t& vertex) const + bool 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; @@ -629,8 +631,10 @@ struct PairPos : public OT::Layout::GPOS_impl::PairPos switch (u.format.v) { case 1: + hb_barrier (); return ((PairPosFormat1*)(&u.format1))->sanitize (vertex); case 2: + hb_barrier (); return ((PairPosFormat2*)(&u.format2))->sanitize (vertex); #ifndef HB_NO_BEYOND_64K case 3: HB_FALLTHROUGH; diff --git a/src/graph/serialize.hh b/src/graph/serialize.hh index 4f89f1011..4ad4b0b06 100644 --- a/src/graph/serialize.hh +++ b/src/graph/serialize.hh @@ -176,7 +176,12 @@ serialize_link_of_type (const hb_serialize_context_t::object_t::link_t& link, const hb_vector_t& id_map, hb_serialize_context_t* c) { - assert(link.position + link.width <= size); + // A link must never write outside the bounds of its parent object. + if (unlikely (link.position + link.width > size)) + { + c->err (HB_SERIALIZE_ERROR_OTHER); + return; + } OT::Offset* offset = reinterpret_cast*> (head + link.position); *offset = 0; diff --git a/src/harfbuzz-config.cmake.in b/src/harfbuzz-config.cmake.in index 2d990efab..fc4774b45 100644 --- a/src/harfbuzz-config.cmake.in +++ b/src/harfbuzz-config.cmake.in @@ -4,31 +4,40 @@ set_and_check(HARFBUZZ_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") set(HARFBUZZ_VERSION "@HARFBUZZ_VERSION@") +function(_harfbuzz_set_imported_library target library_name) + set_target_properties("${target}" PROPERTIES + IMPORTED_LOCATION "@HB_LIB_DIR@/@HB_LIB_PREFIX@${library_name}@HB_LIB_SUFFIX@") + if (@HB_HAS_IMPORT_LIBRARY@) + set_target_properties("${target}" PROPERTIES + IMPORTED_IMPLIB "@PACKAGE_CMAKE_INSTALL_LIBDIR@/@HB_IMPLIB_PREFIX@${library_name}@HB_IMPLIB_SUFFIX@") + endif () +endfunction() + # Add the libraries. add_library(harfbuzz::harfbuzz @HB_LIBRARY_TYPE@ IMPORTED) set_target_properties(harfbuzz::harfbuzz PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "@PACKAGE_INCLUDE_INSTALL_DIR@" - IMPORTED_LOCATION "@PACKAGE_CMAKE_INSTALL_LIBDIR@/@HB_LIB_PREFIX@harfbuzz@HB_LIB_SUFFIX@") + INTERFACE_INCLUDE_DIRECTORIES "@PACKAGE_INCLUDE_INSTALL_DIR@") +_harfbuzz_set_imported_library(harfbuzz::harfbuzz harfbuzz) add_library(harfbuzz::icu @HB_LIBRARY_TYPE@ IMPORTED) set_target_properties(harfbuzz::icu PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@PACKAGE_INCLUDE_INSTALL_DIR@" - INTERFACE_LINK_LIBRARIES "harfbuzz::harfbuzz" - IMPORTED_LOCATION "@PACKAGE_CMAKE_INSTALL_LIBDIR@/@HB_LIB_PREFIX@harfbuzz-icu@HB_LIB_SUFFIX@") + INTERFACE_LINK_LIBRARIES "harfbuzz::harfbuzz") +_harfbuzz_set_imported_library(harfbuzz::icu harfbuzz-icu) add_library(harfbuzz::subset @HB_LIBRARY_TYPE@ IMPORTED) set_target_properties(harfbuzz::subset PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@PACKAGE_INCLUDE_INSTALL_DIR@" - INTERFACE_LINK_LIBRARIES "harfbuzz::harfbuzz" - IMPORTED_LOCATION "@PACKAGE_CMAKE_INSTALL_LIBDIR@/@HB_LIB_PREFIX@harfbuzz-subset@HB_LIB_SUFFIX@") + INTERFACE_LINK_LIBRARIES "harfbuzz::harfbuzz") +_harfbuzz_set_imported_library(harfbuzz::subset harfbuzz-subset) # Only add the gobject library if it was built. if (@HB_HAVE_GOBJECT@) add_library(harfbuzz::gobject @HB_LIBRARY_TYPE@ IMPORTED) set_target_properties(harfbuzz::gobject PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@PACKAGE_INCLUDE_INSTALL_DIR@" - INTERFACE_LINK_LIBRARIES "harfbuzz::harfbuzz" - IMPORTED_LOCATION "@PACKAGE_CMAKE_INSTALL_LIBDIR@/@HB_LIB_PREFIX@harfbuzz-gobject@HB_LIB_SUFFIX@") + INTERFACE_LINK_LIBRARIES "harfbuzz::harfbuzz") + _harfbuzz_set_imported_library(harfbuzz::gobject harfbuzz-gobject) endif () check_required_components(harfbuzz) diff --git a/src/harfbuzz-subset.cc b/src/harfbuzz-subset.cc index de924b997..fb517fe01 100644 --- a/src/harfbuzz-subset.cc +++ b/src/harfbuzz-subset.cc @@ -55,7 +55,6 @@ #include "hb-style.cc" #include "hb-subset-cff-common.cc" #include "hb-subset-cff1.cc" -#include "hb-subset-cff2-to-cff1.cc" #include "hb-subset-cff2.cc" #include "hb-subset-input.cc" #include "hb-subset-instancer-iup.cc" diff --git a/src/harfbuzz-world.cc b/src/harfbuzz-world.cc index b0d121aa5..7bae7399f 100644 --- a/src/harfbuzz-world.cc +++ b/src/harfbuzz-world.cc @@ -137,7 +137,6 @@ #include "hb-raster-draw.cc" #include "hb-raster-image.cc" #include "hb-raster-paint.cc" -#include "hb-raster.cc" #include "hb-static.cc" #endif @@ -150,7 +149,6 @@ #include "hb-static.cc" #include "hb-subset-cff-common.cc" #include "hb-subset-cff1.cc" -#include "hb-subset-cff2-to-cff1.cc" #include "hb-subset-cff2.cc" #include "hb-subset-input.cc" #include "hb-subset-instancer-iup.cc" diff --git a/src/hb-aat-layout-bsln-table.hh b/src/hb-aat-layout-bsln-table.hh index 8e42fab2e..02e5f9439 100644 --- a/src/hb-aat-layout-bsln-table.hh +++ b/src/hb-aat-layout-bsln-table.hh @@ -127,10 +127,10 @@ struct bsln switch (format) { - case 0: return_trace (parts.format0.sanitize (c)); - case 1: return_trace (parts.format1.sanitize (c)); - case 2: return_trace (parts.format2.sanitize (c)); - case 3: return_trace (parts.format3.sanitize (c)); + case 0: hb_barrier (); return_trace (parts.format0.sanitize (c)); + case 1: hb_barrier (); return_trace (parts.format1.sanitize (c)); + case 2: hb_barrier (); return_trace (parts.format2.sanitize (c)); + case 3: hb_barrier (); return_trace (parts.format3.sanitize (c)); default:return_trace (true); } } diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index 5f4bc2352..1a35363c7 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -797,7 +797,7 @@ struct Lookup public: DEFINE_SIZE_UNION (2, format.v); }; -DECLARE_NULL_NAMESPACE_BYTES_TEMPLATE1 (AAT, Lookup, 2); +DECLARE_NULL_NAMESPACE_BYTES_TEMPLATE1 (AAT, Lookup, 13); /* * (Extended) State Table diff --git a/src/hb-aat-layout-feat-table.hh b/src/hb-aat-layout-feat-table.hh index 4fbec332e..2f02de338 100644 --- a/src/hb-aat-layout-feat-table.hh +++ b/src/hb-aat-layout-feat-table.hh @@ -114,7 +114,7 @@ struct FeatureName if (pdefault_index) *pdefault_index = default_index; - if (selectors_count) + if (selectors_count && selectors) { + settings_table.sub_array (start_offset, selectors_count) | hb_map ([=] (const SettingName& setting) { return setting.get_info (default_selector); }) @@ -168,7 +168,7 @@ struct feat unsigned int *count, hb_aat_layout_feature_type_t *features) const { - if (count) + if (count && features) { + namesZ.as_array (featureNameCount).sub_array (start_offset, count) | hb_map (&FeatureName::get_feature_type) diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index 7ff003f71..10ef74b9c 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -870,11 +870,11 @@ struct KerxSubTable unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case 0: return_trace (c->dispatch (u.format0, std::forward (ds)...)); - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); - case 4: return_trace (c->dispatch (u.format4, std::forward (ds)...)); - case 6: return_trace (c->dispatch (u.format6, std::forward (ds)...)); + case 0: hb_barrier (); return_trace (c->dispatch (u.format0, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 4: hb_barrier (); return_trace (c->dispatch (u.format4, std::forward (ds)...)); + case 6: hb_barrier (); return_trace (c->dispatch (u.format6, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } @@ -884,11 +884,11 @@ struct KerxSubTable { unsigned int subtable_type = get_type (); switch (subtable_type) { - case 0: u.format0.collect_glyphs (first_set, second_set, num_glyphs); return; - case 1: u.format1.collect_glyphs (first_set, second_set, num_glyphs); return; - case 2: u.format2.collect_glyphs (first_set, second_set, num_glyphs); return; - case 4: u.format4.collect_glyphs (first_set, second_set, num_glyphs); return; - case 6: u.format6.collect_glyphs (first_set, second_set, num_glyphs); return; + case 0: hb_barrier (); u.format0.collect_glyphs (first_set, second_set, num_glyphs); return; + case 1: hb_barrier (); u.format1.collect_glyphs (first_set, second_set, num_glyphs); return; + case 2: hb_barrier (); u.format2.collect_glyphs (first_set, second_set, num_glyphs); return; + case 4: hb_barrier (); u.format4.collect_glyphs (first_set, second_set, num_glyphs); return; + case 6: hb_barrier (); u.format6.collect_glyphs (first_set, second_set, num_glyphs); return; default: return; } } diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index fc09af240..4811f12be 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -1078,11 +1078,11 @@ struct ChainSubtable unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case Rearrangement: return_trace (c->dispatch (u.rearrangement, std::forward (ds)...)); - case Contextual: return_trace (c->dispatch (u.contextual, std::forward (ds)...)); - case Ligature: return_trace (c->dispatch (u.ligature, std::forward (ds)...)); - case Noncontextual: return_trace (c->dispatch (u.noncontextual, std::forward (ds)...)); - case Insertion: return_trace (c->dispatch (u.insertion, std::forward (ds)...)); + case Rearrangement: hb_barrier (); return_trace (c->dispatch (u.rearrangement, std::forward (ds)...)); + case Contextual: hb_barrier (); return_trace (c->dispatch (u.contextual, std::forward (ds)...)); + case Ligature: hb_barrier (); return_trace (c->dispatch (u.ligature, std::forward (ds)...)); + case Noncontextual: hb_barrier (); return_trace (c->dispatch (u.noncontextual, std::forward (ds)...)); + case Insertion: hb_barrier (); return_trace (c->dispatch (u.insertion, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index a48c4e0bc..d6e758612 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -411,7 +411,7 @@ hb_aat_layout_track (const hb_ot_shape_plan_t *plan, * @start_offset: offset of the first feature type to retrieve * @feature_count: (inout) (optional): Input = the maximum number of feature types to return; * Output = the actual number of feature types returned (may be zero) - * @features: (out caller-allocates) (array length=feature_count): Array of feature types found + * @features: (out caller-allocates) (array length=feature_count) (nullable): Array of feature types found * * Fetches a list of the AAT feature types included in the specified face. * diff --git a/src/hb-algs.hh b/src/hb-algs.hh index ebd7e9e6c..c441f4a1d 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -39,6 +39,19 @@ #include #include +static HB_ALWAYS_INLINE void * +hb_malloc2 (size_t nmemb, size_t size) +{ + if (size && nmemb > SIZE_MAX / size) return nullptr; + return hb_malloc (nmemb * size); +} +static HB_ALWAYS_INLINE void * +hb_realloc2 (void *ptr, size_t nmemb, size_t size) +{ + if (size && nmemb > SIZE_MAX / size) return nullptr; + return hb_realloc (ptr, nmemb * size); +} + /* * Flags */ @@ -877,6 +890,18 @@ struct } HB_FUNCOBJ (hb_clamp); +/* Convert a floating-point value to integer type T, saturating to T's + * range instead of relying on the undefined behavior of an out-of-range + * float-to-int conversion. NaN saturates to the minimum of T. */ +template +static inline T +hb_clamp_to (double v) +{ + return (T) hb_clamp (v, + (double) hb_int_min (T), + (double) hb_int_max (T)); +} + /* * Bithacks. */ diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 3c00808e4..f5d4efd6c 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -662,7 +662,7 @@ _hb_blob_try_mmap (const char *file_name) if (unlikely (!file)) return nullptr; auto file_guard = hb_make_scope_guard ([&]() { hb_free (file); }); - unsigned int size = strlen (file_name) + 1; + size_t size = strlen (file_name) + 1; wchar_t *wchar_file_name = (wchar_t *) hb_malloc (sizeof (wchar_t) * size); if (unlikely (!wchar_file_name)) return nullptr; diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc index 923524d70..3aa48b69b 100644 --- a/src/hb-buffer-serialize.cc +++ b/src/hb-buffer-serialize.cc @@ -796,19 +796,19 @@ hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, return false; } - hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_GLYPHS); - if (!font) font = hb_font_get_empty (); switch (format) { case HB_BUFFER_SERIALIZE_FORMAT_TEXT: + hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_GLYPHS); return _hb_buffer_deserialize_text_glyphs (buffer, buf, buf_len, end_ptr, font); case HB_BUFFER_SERIALIZE_FORMAT_JSON: + hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_GLYPHS); return _hb_buffer_deserialize_json (buffer, buf, buf_len, end_ptr, font); @@ -867,18 +867,18 @@ hb_buffer_deserialize_unicode (hb_buffer_t *buffer, return false; } - hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_UNICODE); - hb_font_t* font = hb_font_get_empty (); switch (format) { case HB_BUFFER_SERIALIZE_FORMAT_TEXT: + hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_UNICODE); return _hb_buffer_deserialize_text_unicode (buffer, buf, buf_len, end_ptr, font); case HB_BUFFER_SERIALIZE_FORMAT_JSON: + hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_UNICODE); return _hb_buffer_deserialize_json (buffer, buf, buf_len, end_ptr, font); diff --git a/src/hb-buffer-verify.cc b/src/hb-buffer-verify.cc index 4f102f17b..69c85e991 100644 --- a/src/hb-buffer-verify.cc +++ b/src/hb-buffer-verify.cc @@ -167,7 +167,7 @@ buffer_verify_unsafe_to_break (hb_buffer_t *buffer, hb_buffer_append (fragment, text_buffer, text_start, text_end); if (!hb_shape_full (font, fragment, features, num_features, shapers) || - fragment->successful) + !fragment->successful) return true; hb_buffer_append (reconstruction, fragment, 0, -1); diff --git a/src/hb-cairo-utils.cc b/src/hb-cairo-utils.cc index d0888d4c5..9e45f41d0 100644 --- a/src/hb-cairo-utils.cc +++ b/src/hb-cairo-utils.cc @@ -94,6 +94,32 @@ _hb_cairo_destroy_blob (void *p) hb_blob_destroy ((hb_blob_t *) p); } +void +_hb_cairo_set_source_color (hb_cairo_context_t *c, + hb_bool_t use_foreground, + hb_color_t color) +{ + cairo_t *cr = c->cr; + + if (use_foreground) + { +#ifdef HAVE_CAIRO_USER_SCALED_FONT_GET_FOREGROUND_SOURCE + double r, g, b, a; + cairo_pattern_t *foreground = cairo_user_scaled_font_get_foreground_source (c->scaled_font); + if (cairo_pattern_get_rgba (foreground, &r, &g, &b, &a) == CAIRO_STATUS_SUCCESS) + cairo_set_source_rgba (cr, r, g, b, a * hb_color_get_alpha (color) / 255.); + else +#endif + cairo_set_source_rgba (cr, 0, 0, 0, hb_color_get_alpha (color) / 255.); + } + else + cairo_set_source_rgba (cr, + hb_color_get_red (color) / 255., + hb_color_get_green (color) / 255., + hb_color_get_blue (color) / 255., + hb_color_get_alpha (color) / 255.); +} + hb_bool_t _hb_cairo_paint_glyph_image (hb_cairo_context_t *c, hb_blob_t *blob, @@ -211,7 +237,7 @@ _hb_cairo_get_color_stops (hb_cairo_context_t *c, return false; if (len > *count) { - *stops = (hb_color_stop_t *) hb_malloc (len * sizeof (hb_color_stop_t)); + *stops = (hb_color_stop_t *) hb_malloc2 (len, sizeof (hb_color_stop_t)); if (unlikely (!*stops)) return false; allocated = true; diff --git a/src/hb-cairo-utils.hh b/src/hb-cairo-utils.hh index a26bf59d9..c9e380120 100644 --- a/src/hb-cairo-utils.hh +++ b/src/hb-cairo-utils.hh @@ -75,6 +75,11 @@ _hb_paint_composite_mode_to_cairo (hb_paint_composite_mode_t mode) } } +HB_INTERNAL void +_hb_cairo_set_source_color (hb_cairo_context_t *c, + hb_bool_t use_foreground, + hb_color_t color); + HB_INTERNAL hb_bool_t _hb_cairo_paint_glyph_image (hb_cairo_context_t *c, hb_blob_t *blob, diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc index ddb5d23dc..add26bea7 100644 --- a/src/hb-cairo.cc +++ b/src/hb-cairo.cc @@ -166,6 +166,29 @@ hb_cairo_pop_transform (hb_paint_funcs_t *pfuncs HB_UNUSED, cairo_restore (cr); } +static void +hb_cairo_fill_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t use_foreground, + hb_color_t color, + void *user_data HB_UNUSED) +{ + hb_cairo_context_t *c = (hb_cairo_context_t *) paint_data; + cairo_t *cr = c->cr; + + cairo_save (cr); + + cairo_new_path (cr); + hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), cr); + cairo_close_path (cr); + _hb_cairo_set_source_color (c, use_foreground, color); + cairo_fill (cr); + + cairo_restore (cr); +} + static hb_bool_t hb_cairo_paint_color_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, void *paint_data, @@ -303,23 +326,7 @@ hb_cairo_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, hb_cairo_context_t *c = (hb_cairo_context_t *) paint_data; cairo_t *cr = c->cr; - if (use_foreground) - { -#ifdef HAVE_CAIRO_USER_SCALED_FONT_GET_FOREGROUND_SOURCE - double r, g, b, a; - cairo_pattern_t *foreground = cairo_user_scaled_font_get_foreground_source (c->scaled_font); - if (cairo_pattern_get_rgba (foreground, &r, &g, &b, &a) == CAIRO_STATUS_SUCCESS) - cairo_set_source_rgba (cr, r, g, b, a * hb_color_get_alpha (color) / 255.); - else -#endif - cairo_set_source_rgba (cr, 0, 0, 0, hb_color_get_alpha (color) / 255.); - } - else - cairo_set_source_rgba (cr, - hb_color_get_red (color) / 255., - hb_color_get_green (color) / 255., - hb_color_get_blue (color) / 255., - hb_color_get_alpha (color) / 255.); + _hb_cairo_set_source_color (c, use_foreground, color); cairo_paint (cr); } @@ -452,6 +459,7 @@ static struct hb_cairo_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t< hb_paint_funcs_set_push_transform_func (funcs, hb_cairo_push_transform, nullptr, nullptr); hb_paint_funcs_set_pop_transform_func (funcs, hb_cairo_pop_transform, nullptr, nullptr); + hb_paint_funcs_set_fill_glyph_func (funcs, hb_cairo_fill_glyph, nullptr, nullptr); hb_paint_funcs_set_color_glyph_func (funcs, hb_cairo_paint_color_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_cairo_push_clip_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_rectangle_func (funcs, hb_cairo_push_clip_rectangle, nullptr, nullptr); @@ -675,10 +683,9 @@ hb_cairo_render_color_glyph (cairo_scaled_font_t *scaled_font, c.color_cache = (hb_map_t *) cairo_scaled_font_get_user_data (scaled_font, &color_cache_key); /* Synthesizing variant: mono glyphs render here too via the - * push_clip_glyph + foreground-fill fallback inside - * hb_font_paint_glyph. Callers that want the cheaper - * outline path for mono fonts set CAIRO_COLOR_MODE_NO_COLOR - * on the font options instead. */ + * fill_glyph foreground fallback inside hb_font_paint_glyph. + * Callers that want the cheaper outline path for mono fonts set + * CAIRO_COLOR_MODE_NO_COLOR on the font options instead. */ hb_font_paint_glyph (font, glyph, hb_cairo_paint_get_funcs (), &c, palette, color); return CAIRO_STATUS_SUCCESS; diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index df90fb99a..9ca8bf56d 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -220,16 +220,32 @@ inline unsigned int OpCode_Size (op_code_t op) { return Is_OpCode_ESC (op) ? 2: struct number_t { void set_int (int v) { value = v; } - int to_int () const { return value; } + bool to_int (int *v) const + { + if (unlikely (!(value >= INT_MIN && value <= INT_MAX))) + { + *v = 0; + return false; + } + *v = (int) value; + return true; + } + int to_int () const + { + int v; + if (likely (to_int (&v))) return v; + return value < 0 ? INT_MIN : value > 0 ? INT_MAX : 0; + } void set_fixed (int32_t v) { value = v / 65536.0; } - int32_t to_fixed () const { return value * 65536.0; } + int32_t to_fixed () const + { return (int32_t) hb_clamp (value * 65536.0, (double) INT32_MIN, (double) INT32_MAX); } void set_real (double v) { value = v; } double to_real () const { return value; } bool in_int_range () const - { return ((double) (int16_t) to_int () == value); } + { return value >= INT16_MIN && value <= INT16_MAX && (double) (int16_t) value == value; } bool operator > (const number_t &n) const { return value > n.to_real (); } bool operator < (const number_t &n) const { return n > *this; } @@ -446,7 +462,13 @@ struct arg_stack_t : cff_stack_t ARG& pop_num () { return this->pop (); } - int pop_int () { return this->pop ().to_int (); } + int pop_int () + { + int v; + if (unlikely (!this->pop ().to_int (&v))) + S::set_error (); + return v; + } unsigned int pop_uint () { diff --git a/src/hb-cff2-interp-cs.hh b/src/hb-cff2-interp-cs.hh index 6a338b462..770a4ae36 100644 --- a/src/hb-cff2-interp-cs.hh +++ b/src/hb-cff2-interp-cs.hh @@ -78,7 +78,8 @@ struct cff2_cs_interp_env_t : cs_interp_env_t num_coords = num_coords_; varStore = acc.varStore; do_blend = num_coords && varStore->size; - set_ivs (acc.privateDicts[fd].ivs); + orig_ivs = acc.privateDicts[fd].ivs; + set_ivs (orig_ivs); } ~cff2_cs_interp_env_t () @@ -179,6 +180,8 @@ struct cff2_cs_interp_env_t : cs_interp_env_t void set_region_count (unsigned int region_count_) { region_count = region_count_; } unsigned int get_ivs () const { return ivs; } void set_ivs (unsigned int ivs_) { ivs = ivs_; } + /* The FD's private-dict ivs, before any vsindex op in the charstring. */ + unsigned int get_orig_ivs () const { return orig_ivs; } bool seen_vsindex () const { return seen_vsindex_; } double blend_deltas (hb_array_t deltas) const @@ -204,6 +207,7 @@ struct cff2_cs_interp_env_t : cs_interp_env_t const CFF2ItemVariationStore *varStore; unsigned int region_count; unsigned int ivs; + unsigned int orig_ivs; hb_vector_t *scalars = nullptr; hb_atomic_t *> *cached_scalars_vector = nullptr; bool do_blend; @@ -260,6 +264,19 @@ struct cff2_cs_opset_t : cs_opset_t, PAR { if (env.have_coords ()) arg.set_int (round (arg.to_real () + env.blend_deltas (blends))); + else if (unlikely (arg.blending ())) + { + /* A blend result used as an operand of a later blend: the value is + * default + inner deltas + outer deltas, so accumulate the deltas. */ + hb_vector_t inner = std::move (arg.deltas); + arg.set_blends (n, i, blends); + if (likely (inner.length == arg.deltas.length)) + for (unsigned j = 0; j < inner.length; j++) + arg.deltas.arrayZ[j].set_real (arg.deltas.arrayZ[j].to_real () + + inner.arrayZ[j].to_real ()); + else + env.set_error (); + } else arg.set_blends (n, i, blends); } diff --git a/src/hb-config.hh b/src/hb-config.hh index e7195e2ab..dca05b728 100644 --- a/src/hb-config.hh +++ b/src/hb-config.hh @@ -41,10 +41,6 @@ #define HB_NO_SUBSET_DEPEND #endif -#ifdef HB_SUBSET_DEPEND_API -#undef HB_NO_SUBSET_DEPEND -#endif - #ifdef HB_TINY #define HB_LEAN #define HB_MINI @@ -147,10 +143,6 @@ #define HB_NO_PAINT #endif -#if defined(HB_TINY) && defined(HB_NO_DRAW) -#define HB_NO_CFF -#endif - #ifdef HB_NO_CFF #define HB_NO_OT_FONT_CFF #define HB_NO_SUBSET_CFF diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 7466c5bc7..e257b8cee 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -107,11 +107,12 @@ _hb_cg_get_table_tags (const hb_face_t *face HB_UNUSED, end_offset = hb_min (end_offset, (unsigned) population); *table_count = end_offset - start_offset; - for (unsigned i = start_offset; i < end_offset; i++) - { - CTFontTableTag tag = (CTFontTableTag)(uintptr_t) CFArrayGetValueAtIndex (arr, i); - table_tags[i - start_offset] = tag; - } + if (table_tags) + for (unsigned i = start_offset; i < end_offset; i++) + { + CTFontTableTag tag = (CTFontTableTag)(uintptr_t) CFArrayGetValueAtIndex (arr, i); + table_tags[i - start_offset] = tag; + } return population; } @@ -446,7 +447,7 @@ hb_coretext_face_create_from_file_or_fail (const char *file_name, * Creates an #hb_face_t face object from the specified * blob and face index. * - * This is similar in functionality to hb_face_create_from_blob_or_fail(), + * This is similar in functionality to hb_face_create_or_fail(), * but uses the CoreText library for loading the font data. * * Return value: (transfer full): The new face object, or `NULL` if diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index d94104971..e2b16685c 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -315,7 +315,7 @@ hb_directwrite_face_create_from_file_or_fail (const char *file_name, * Creates an #hb_face_t face object from the specified * blob and face index. * - * This is similar in functionality to hb_face_create_from_blob_or_fail(), + * This is similar in functionality to hb_face_create_or_fail(), * but uses the DirectWrite library for loading the font data. * * Return value: (transfer full): The new face object, or `NULL` if diff --git a/src/hb-draw.cc b/src/hb-draw.cc index 0997153f8..11f4e9a1f 100644 --- a/src/hb-draw.cc +++ b/src/hb-draw.cc @@ -65,12 +65,20 @@ hb_draw_quadratic_to_nil (hb_draw_funcs_t *dfuncs, void *draw_data, float to_x, float to_y, void *user_data HB_UNUSED) { -#define HB_TWO_THIRD 0.66666666666666666666666667f + /* Compute in double precision, so that the result does not depend + * on how the compiler evaluates float expressions. */ +#define HB_TWO_THIRD 0.66666666666666666666666667 + double current_x = (double) st->current_x; + double current_y = (double) st->current_y; + double cx = (double) control_x; + double cy = (double) control_y; + double tx = (double) to_x; + double ty = (double) to_y; dfuncs->emit_cubic_to (draw_data, *st, - st->current_x + (control_x - st->current_x) * HB_TWO_THIRD, - st->current_y + (control_y - st->current_y) * HB_TWO_THIRD, - to_x + (control_x - to_x) * HB_TWO_THIRD, - to_y + (control_y - to_y) * HB_TWO_THIRD, + (float) (current_x + (cx - current_x) * HB_TWO_THIRD), + (float) (current_y + (cy - current_y) * HB_TWO_THIRD), + (float) (tx + (cx - tx) * HB_TWO_THIRD), + (float) (ty + (cy - ty) * HB_TWO_THIRD), to_x, to_y); #undef HB_TWO_THIRD } diff --git a/src/hb-face-builder.cc b/src/hb-face-builder.cc index 579ef2747..cb55e4b8f 100644 --- a/src/hb-face-builder.cc +++ b/src/hb-face-builder.cc @@ -185,11 +185,14 @@ _hb_face_builder_get_table_tags (const hb_face_t *face HB_UNUSED, }); auto array = sorted_tags.as_array ().sub_array (start_offset, table_count); - auto out = hb_array (table_tags, *table_count); + if (table_tags) + { + auto out = hb_array (table_tags, *table_count); - + array.iter () - | hb_sink (out) - ; + + array.iter () + | hb_sink (out) + ; + } return population; } diff --git a/src/hb-face.cc b/src/hb-face.cc index b0cc787d0..ee633a624 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -909,7 +909,7 @@ hb_face_set_get_table_tags_func (hb_face_t *face, * @start_offset: The index of first table tag to retrieve * @table_count: (inout): Input = the maximum number of table tags to return; * Output = the actual number of table tags returned (may be zero) - * @table_tags: (out) (array length=table_count): The array of table tags found + * @table_tags: (out) (array length=table_count) (nullable): The array of table tags found * * Fetches a list of all table tags for a face, if possible. The list returned will * begin at the offset provided diff --git a/src/hb-face.h b/src/hb-face.h index b8386f0af..4e0902cfd 100644 --- a/src/hb-face.h +++ b/src/hb-face.h @@ -169,7 +169,7 @@ hb_face_get_glyph_count (const hb_face_t *face); * @start_offset: The index of first table tag to retrieve * @table_count: (inout): Input = the maximum number of table tags to return; * Output = the actual number of table tags returned (may be zero) - * @table_tags: (out) (array length=table_count): The array of table tags found + * @table_tags: (out) (array length=table_count) (nullable): The array of table tags found * @user_data: User data pointer passed by the caller * * Callback function for hb_face_get_table_tags(). diff --git a/src/hb-font.cc b/src/hb-font.cc index 96fcff501..ecb148361 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1670,9 +1670,7 @@ hb_font_t::paint_glyph (hb_codepoint_t glyph, return; /* Fallback for outline glyph. */ - paint_funcs->push_clip_glyph (paint_data, glyph, this); - paint_funcs->color (paint_data, true, foreground); - paint_funcs->pop_clip (paint_data); + paint_funcs->fill_glyph (paint_data, glyph, this, true, foreground); } @@ -2500,9 +2498,9 @@ hb_font_get_face (hb_font_t *font) /** * hb_font_set_funcs: * @font: #hb_font_t to work upon - * @klass: (closure font_data) (destroy destroy) (scope notified): The font-functions structure. + * @klass: The font-functions structure. * @font_data: Data to attach to @font - * @destroy: (nullable): The function to call when @font_data is not needed anymore + * @destroy: (nullable) (scope async) (closure font_data): The function to call when @font_data is not needed anymore * * Replaces the font-functions structure attached to a font, updating * the font's user-data with @font-data and the @destroy callback. @@ -2540,8 +2538,8 @@ hb_font_set_funcs (hb_font_t *font, /** * hb_font_set_funcs_data: * @font: #hb_font_t to work upon - * @font_data: (destroy destroy) (scope notified): Data to attach to @font - * @destroy: (nullable): The function to call when @font_data is not needed anymore + * @font_data: Data to attach to @font + * @destroy: (nullable) (scope async) (closure font_data): The function to call when @font_data is not needed anymore * * Replaces the user data attached to a font, updating the font's * @destroy callback. diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index af45ca754..090ebf087 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -250,6 +250,42 @@ _hb_ft_color_line_get_extend (hb_color_line_t *color_line, } } +static void +_hb_ft_get_solid_color (hb_ft_paint_context_t *c, + const FT_ColorIndex &color_index, + hb_bool_t *is_foreground, + hb_color_t *color) +{ + *is_foreground = color_index.palette_index == 0xFFFF; + + if (*is_foreground) + { + *color = HB_COLOR (hb_color_get_blue (c->foreground), + hb_color_get_green (c->foreground), + hb_color_get_red (c->foreground), + _hb_ft_color_alpha (hb_color_get_alpha (c->foreground), + color_index.alpha)); + return; + } + + if (c->funcs->custom_palette_color (c->data, color_index.palette_index, color)) + { + *color = HB_COLOR (hb_color_get_blue (*color), + hb_color_get_green (*color), + hb_color_get_red (*color), + _hb_ft_color_alpha (hb_color_get_alpha (*color), + color_index.alpha)); + return; + } + + FT_Color ft_color = c->palette[color_index.palette_index]; + *color = HB_COLOR (ft_color.blue, + ft_color.green, + ft_color.red, + _hb_ft_color_alpha (ft_color.alpha, + color_index.alpha)); +} + void _hb_ft_paint (hb_ft_paint_context_t *c, FT_OpaquePaint opaque_paint) @@ -280,34 +316,9 @@ _hb_ft_paint (hb_ft_paint_context_t *c, break; case FT_COLR_PAINTFORMAT_SOLID: { - bool is_foreground = paint.u.solid.color.palette_index == 0xFFFF; + hb_bool_t is_foreground; hb_color_t color; - if (is_foreground) - color = HB_COLOR (hb_color_get_blue (c->foreground), - hb_color_get_green (c->foreground), - hb_color_get_red (c->foreground), - _hb_ft_color_alpha (hb_color_get_alpha (c->foreground), - paint.u.solid.color.alpha)); - else - { - if (c->funcs->custom_palette_color (c->data, paint.u.solid.color.palette_index, &color)) - { - color = HB_COLOR (hb_color_get_blue (color), - hb_color_get_green (color), - hb_color_get_red (color), - _hb_ft_color_alpha (hb_color_get_alpha (color), - paint.u.solid.color.alpha)); - } - else - { - FT_Color ft_color = c->palette[paint.u.solid.color.palette_index]; - color = HB_COLOR (ft_color.blue, - ft_color.green, - ft_color.red, - _hb_ft_color_alpha (ft_color.alpha, - paint.u.solid.color.alpha)); - } - } + _hb_ft_get_solid_color (c, paint.u.solid.color, &is_foreground, &color); c->funcs->color (c->data, is_foreground, color); } break; @@ -362,6 +373,26 @@ _hb_ft_paint (hb_ft_paint_context_t *c, break; case FT_COLR_PAINTFORMAT_GLYPH: { + /* Optimize cases that can use a simple fill-glyph operation. */ + FT_COLR_Paint fill; + if (likely (c->depth_left > 0 && c->edge_count > 0) && + FT_Get_Paint (ft_face, paint.u.glyph.paint, &fill) && + fill.format == FT_COLR_PAINTFORMAT_SOLID) + { + hb_bool_t is_foreground; + hb_color_t color; + _hb_ft_get_solid_color (c, fill.u.solid.color, &is_foreground, &color); + + c->edge_count--; + c->funcs->push_inverse_font_transform (c->data, c->font); + c->ft_font->lock.unlock (); + c->funcs->fill_glyph (c->data, paint.u.glyph.glyphID, c->font, + is_foreground, color); + c->ft_font->lock.lock (); + c->funcs->pop_transform (c->data); + break; + } + c->funcs->push_inverse_font_transform (c->data, c->font); c->ft_font->lock.unlock (); c->funcs->push_clip_glyph (c->data, paint.u.glyph.glyphID, c->font); @@ -600,10 +631,8 @@ hb_ft_paint_glyph_colr (hb_font_t *font, } ft_font->lock.unlock (); - paint_funcs->push_clip_glyph (paint_data, layer_glyph_index, font); + paint_funcs->fill_glyph (paint_data, layer_glyph_index, font, is_foreground, color); ft_font->lock.lock (); - paint_funcs->color (paint_data, is_foreground, color); - paint_funcs->pop_clip (paint_data); } while (FT_Get_Color_Glyph_Layer(ft_face, gid, diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 8ac5db774..b8c0c8519 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -1152,23 +1152,29 @@ _hb_ft_get_table_tags (const hb_face_t *face HB_UNUSED, if (!table_count) return population; - else - *table_count = 0; if (unlikely (start_offset >= population)) + { + *table_count = 0; return population; + } - unsigned end_offset = hb_min (start_offset + *table_count, (unsigned) population); - if (unlikely (end_offset < start_offset)) + unsigned end_offset = start_offset + *table_count; + if (unlikely (end_offset < start_offset)) /* Overflow. */ + { + *table_count = 0; return population; + } + end_offset = hb_min (end_offset, (unsigned) population); *table_count = end_offset - start_offset; - for (unsigned i = start_offset; i < end_offset; i++) - { - FT_ULong tag = 0, length; - FT_Sfnt_Table_Info (ft_face, i, &tag, &length); - table_tags[i - start_offset] = tag; - } + if (table_tags) + for (unsigned i = start_offset; i < end_offset; i++) + { + FT_ULong tag = 0, length; + FT_Sfnt_Table_Info (ft_face, i, &tag, &length); + table_tags[i - start_offset] = tag; + } return population; } @@ -1176,8 +1182,8 @@ _hb_ft_get_table_tags (const hb_face_t *face HB_UNUSED, /** * hb_ft_face_create: - * @ft_face: (destroy destroy) (scope notified): FT_Face to work upon - * @destroy: (nullable): A callback to call when the face object is not needed anymore + * @ft_face: FT_Face to work upon + * @destroy: (nullable) (scope async): A callback to call when the face object is not needed anymore * * Creates an #hb_face_t face object from the specified FT_Face. * @@ -1300,8 +1306,8 @@ hb_ft_face_create_cached (FT_Face ft_face) /** * hb_ft_font_create: - * @ft_face: (destroy destroy) (scope notified): FT_Face to work upon - * @destroy: (nullable): A callback to call when the font object is not needed anymore + * @ft_face: FT_Face to work upon + * @destroy: (nullable) (scope async): A callback to call when the font object is not needed anymore * * Creates an #hb_font_t font object from the specified FT_Face. * @@ -1609,7 +1615,7 @@ _destroy_blob (void *p) * Creates an #hb_face_t face object from the specified * font blob and face index. * - * This is similar in functionality to hb_face_create_from_blob_or_fail(), + * This is similar in functionality to hb_face_create_or_fail(), * but uses the FreeType library for loading the font blob. This can * be useful, for example, to load WOFF and WOFF2 font data. * diff --git a/src/hb-gobject-enums.h.tmpl b/src/hb-gobject-enums.h.tmpl index 6dd98f7fe..3f491d9b3 100644 --- a/src/hb-gobject-enums.h.tmpl +++ b/src/hb-gobject-enums.h.tmpl @@ -43,7 +43,7 @@ HB_BEGIN_DECLS /*** BEGIN value-header ***/ HB_EXTERN GType -@enum_name@_get_type (void) G_GNUC_CONST; +@enum_name@_get_type (void); #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) /*** END value-header ***/ diff --git a/src/hb-gpu-draw.cc b/src/hb-gpu-draw.cc index a05996e2c..710b14552 100644 --- a/src/hb-gpu-draw.cc +++ b/src/hb-gpu-draw.cc @@ -446,6 +446,16 @@ hb_gpu_draw_encode (hb_gpu_draw_t *draw, if (unlikely (!s.curve_infos.resize (num_curves))) return nullptr; + /* Validate the extents fit in i16 before quantizing: the casts in + * quantize_down()/quantize_up() are undefined for out-of-range + * values, and every later i16 conversion of a curve point is bounded + * by these extents. */ + if (!quantize_down_fits_i16 (draw->ext_min_x) || + !quantize_down_fits_i16 (draw->ext_min_y) || + !quantize_up_fits_i16 (draw->ext_max_x) || + !quantize_up_fits_i16 (draw->ext_max_y)) + return nullptr; + int16_t min_x_q = quantize_down (draw->ext_min_x); int16_t min_y_q = quantize_down (draw->ext_min_y); int16_t max_x_q = quantize_up (draw->ext_max_x); @@ -653,12 +663,6 @@ hb_gpu_draw_encode (hb_gpu_draw_t *draw, if (total_len > (unsigned) UINT16_MAX + 1u) return nullptr; - if (!quantize_down_fits_i16 (draw->ext_min_x) || - !quantize_down_fits_i16 (draw->ext_min_y) || - !quantize_up_fits_i16 (draw->ext_max_x) || - !quantize_up_fits_i16 (draw->ext_max_y)) - return nullptr; - /* Allocate or reuse encode buffer */ unsigned needed_bytes; if (unlikely (hb_unsigned_mul_overflows (total_len, diff --git a/src/hb-gpu-paint.cc b/src/hb-gpu-paint.cc index ee8d9f6c1..0936475da 100644 --- a/src/hb-gpu-paint.cc +++ b/src/hb-gpu-paint.cc @@ -165,6 +165,13 @@ hb_gpu_paint_push_clip_path_end (hb_paint_funcs_t *funcs HB_UNUSED, } int idx = (int) (c->sub_blobs.length - 1); + if (unlikely (c->clip_depth >= HB_GPU_PAINT_MAX_CLIP_DEPTH)) + { + c->unsupported = true; + c->clip_depth++; + return; + } + int x0 = ext.x_bearing; int x1 = (int) ((int64_t) ext.x_bearing + ext.width); int y0 = ext.y_bearing; @@ -870,7 +877,7 @@ hb_gpu_paint_emit_sweep (hb_gpu_paint_t *c, hb_color_stop_t *heap_stops = nullptr; if (count > 16) { - heap_stops = (hb_color_stop_t *) hb_malloc (count * sizeof (hb_color_stop_t)); + heap_stops = (hb_color_stop_t *) hb_malloc2 (count, sizeof (hb_color_stop_t)); if (unlikely (!heap_stops)) { c->unsupported = true; return; } stops = heap_stops; } diff --git a/src/hb-limits.hh b/src/hb-limits.hh index a59091477..460d4c8a4 100644 --- a/src/hb-limits.hh +++ b/src/hb-limits.hh @@ -81,7 +81,7 @@ #endif #ifndef HB_MAX_FEATURE_INDICES -#define HB_MAX_FEATURE_INDICES 1500 +#define HB_MAX_FEATURE_INDICES 8000 #endif #ifndef HB_MAX_LOOKUP_VISIT_COUNT @@ -130,7 +130,7 @@ #endif #ifndef HB_REPACKER_MAX_VERTICES -#define HB_REPACKER_MAX_VERTICES 100000 +#define HB_REPACKER_MAX_VERTICES 800000 #endif #ifndef HB_REPACKER_MAX_SPACES diff --git a/src/hb-map.hh b/src/hb-map.hh index 37cc2460b..56c0e4e44 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -204,7 +204,7 @@ struct hb_hashmap_t unsigned int power = hb_bit_storage (hb_max (hb_max ((unsigned) population, new_population) * 2, 4u)); unsigned int new_size = 1u << power; - item_t *new_items = (item_t *) hb_malloc ((size_t) new_size * sizeof (item_t)); + item_t *new_items = (item_t *) hb_malloc2 ((size_t) new_size, sizeof (item_t)); if (unlikely (!new_items)) { successful = false; diff --git a/src/hb-open-file.hh b/src/hb-open-file.hh index 6a53a7eb3..a1c6b4289 100644 --- a/src/hb-open-file.hh +++ b/src/hb-open-file.hh @@ -88,7 +88,7 @@ typedef struct OpenTypeOffsetTable unsigned int *table_count, /* IN/OUT */ hb_tag_t *table_tags /* OUT */) const { - if (table_count) + if (table_count && table_tags) { + tables.as_array ().sub_array (start_offset, table_count) | hb_map (&TableRecord::tag) @@ -474,8 +474,8 @@ struct OpenTypeFontFile case TrueTag: case Typ1Tag: case TrueTypeTag: return 1; - case TTCTag: return u.ttcHeader.get_face_count (); - case DFontTag: return u.rfHeader.get_face_count (); + case TTCTag: hb_barrier (); return u.ttcHeader.get_face_count (); + case DFontTag: hb_barrier (); return u.rfHeader.get_face_count (); default: return 0; } } @@ -490,9 +490,9 @@ struct OpenTypeFontFile case CFFTag: /* All the non-collection tags */ case TrueTag: case Typ1Tag: - case TrueTypeTag: return u.fontFace; - case TTCTag: return u.ttcHeader.get_face (i); - case DFontTag: return u.rfHeader.get_face (i, base_offset); + case TrueTypeTag: hb_barrier (); return u.fontFace; + case TTCTag: hb_barrier (); return u.ttcHeader.get_face (i); + case DFontTag: hb_barrier (); return u.rfHeader.get_face (i, base_offset); default: return Null (OpenTypeFontFace); } } @@ -518,9 +518,9 @@ struct OpenTypeFontFile case CFFTag: /* All the non-collection tags */ case TrueTag: case Typ1Tag: - case TrueTypeTag: return_trace (u.fontFace.sanitize (c)); - case TTCTag: return_trace (u.ttcHeader.sanitize (c)); - case DFontTag: return_trace (u.rfHeader.sanitize (c)); + case TrueTypeTag: hb_barrier (); return_trace (u.fontFace.sanitize (c)); + case TTCTag: hb_barrier (); return_trace (u.ttcHeader.sanitize (c)); + case DFontTag: hb_barrier (); return_trace (u.rfHeader.sanitize (c)); default: return_trace (true); } } diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index 061863835..e46ea5a87 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -346,6 +346,12 @@ struct cff2_private_dict_opset_subset_t : dict_opset_t env.clear_args (); break; + case OpCode_vsindexdict: + env.process_vsindex (); + dictval.ivs = env.get_ivs (); + env.clear_args (); + break; + default: SUPER::process_op (op, env); if (!env.argStack.is_empty ()) return; diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 6765c557f..91be90fe5 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -658,6 +658,7 @@ struct CmapSubtableFormat4 hb_codepoint_t gid = this->glyphIdArray[index]; if (unlikely (!gid)) continue; + gid = (gid + this->idDelta[i]) & 0xFFFFu; unicodes->add (codepoint); mapping->set (codepoint, gid); } @@ -2058,7 +2059,7 @@ struct cmap this->subtable_uvs = &Null (CmapSubtableFormat14); { const CmapSubtable *st = table->find_subtable (0, 5); - if (st && st->u.format.v == 14) + if (st && st->u.format.v == 14 && hb_barrier ()) subtable_uvs = &st->u.format14; } @@ -2140,6 +2141,7 @@ struct cmap break; case 4: { + hb_barrier (); this->format4_accel.init (&subtable->u.format4, get_subtable_data_size (subtable)); this->get_glyph_data = &this->format4_accel; diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index f42f679df..d91ee7af2 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -289,7 +289,7 @@ struct hb_ot_font_t void check_serial (hb_font_t *font) const { - int font_serial = font->serial_coords.get_acquire (); + int font_serial = font->serial.get_acquire (); if (cached_serial.get_acquire () != font_serial) { /* These caches are dependent on scale and synthetic settings. @@ -644,6 +644,8 @@ hb_ot_get_glyph_v_origins (hb_font_t *font, const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_face_t *ot_face = ot_font->ot_face; + ot_font->check_serial (font); + /* First, set all the x values to half the advance width. */ font->get_glyph_h_advances (count, first_glyph, glyph_stride, diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index d042c8805..26480b4c9 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -144,13 +144,13 @@ struct KernSubTable unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case 0: return_trace (c->dispatch (u.format0)); + case 0: hb_barrier (); return_trace (c->dispatch (u.format0)); #ifndef HB_NO_AAT_SHAPE - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...)); #endif - case 2: return_trace (c->dispatch (u.format2)); + case 2: hb_barrier (); return_trace (c->dispatch (u.format2)); #ifndef HB_NO_AAT_SHAPE - case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); + case 3: hb_barrier (); return_trace (c->dispatch (u.format3, std::forward (ds)...)); #endif default: return_trace (c->default_return_value ()); } @@ -161,10 +161,10 @@ struct KernSubTable { unsigned int subtable_type = get_type (); switch (subtable_type) { - case 0: u.format0.collect_glyphs (left_set, right_set, num_glyphs); return; - case 1: u.format1.collect_glyphs (left_set, right_set, num_glyphs); return; - case 2: u.format2.collect_glyphs (left_set, right_set, num_glyphs); return; - case 3: u.format3.collect_glyphs (left_set, right_set, num_glyphs); return; + case 0: hb_barrier (); u.format0.collect_glyphs (left_set, right_set, num_glyphs); return; + case 1: hb_barrier (); u.format1.collect_glyphs (left_set, right_set, num_glyphs); return; + case 2: hb_barrier (); u.format2.collect_glyphs (left_set, right_set, num_glyphs); return; + case 3: hb_barrier (); u.format3.collect_glyphs (left_set, right_set, num_glyphs); return; default: return; } } @@ -352,9 +352,9 @@ struct kern unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case 0: return_trace (c->dispatch (u.ot, std::forward (ds)...)); + case 0: hb_barrier (); return_trace (c->dispatch (u.ot, std::forward (ds)...)); #ifndef HB_NO_AAT_SHAPE - case 1: return_trace (c->dispatch (u.aat, std::forward (ds)...)); + case 1: hb_barrier (); return_trace (c->dispatch (u.aat, std::forward (ds)...)); #endif default: return_trace (c->default_return_value ()); } diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 14873cb7b..84543e131 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -441,7 +441,7 @@ struct IndexArray : Array16Of unsigned int *_count /* IN/OUT */, unsigned int *_indexes /* OUT */) const { - if (_count) + if (_count && _indexes) { + this->as_array ().sub_array (start_offset, _count) | hb_sink (hb_array (_indexes, *_count)) @@ -628,7 +628,7 @@ struct FeatureParamsCharacterVariants unsigned get_characters (unsigned start_offset, unsigned *char_count, hb_codepoint_t *chars) const { - if (char_count) + if (char_count && chars) { + characters.as_array ().sub_array (start_offset, char_count) | hb_sink (hb_array (chars, *char_count)) @@ -706,7 +706,7 @@ struct FeatureParams return true; #endif TRACE_SANITIZE (this); - if (tag == HB_TAG ('s','i','z','e')) + if (tag == HB_TAG ('s','i','z','e') && hb_barrier ()) return_trace (u.size.sanitize (c)); if ((tag & 0xFFFF0000u) == HB_TAG ('s','s','\0','\0')) /* ssXX */ return_trace (u.stylisticSet.sanitize (c)); @@ -720,7 +720,7 @@ struct FeatureParams #ifdef HB_NO_LAYOUT_FEATURE_PARAMS return; #endif - if (tag == HB_TAG ('s','i','z','e')) + if (tag == HB_TAG ('s','i','z','e') && hb_barrier ()) return (u.size.collect_name_ids (nameids_to_retain)); if ((tag & 0xFFFF0000u) == HB_TAG ('s','s','\0','\0')) /* ssXX */ return (u.stylisticSet.collect_name_ids (nameids_to_retain)); @@ -732,7 +732,7 @@ struct FeatureParams { TRACE_SUBSET (this); if (!tag) return_trace (false); - if (*tag == HB_TAG ('s','i','z','e')) + if (*tag == HB_TAG ('s','i','z','e') && hb_barrier ()) return_trace (u.size.subset (c)); if ((*tag & 0xFFFF0000u) == HB_TAG ('s','s','\0','\0')) /* ssXX */ return_trace (u.stylisticSet.subset (c)); @@ -744,7 +744,7 @@ struct FeatureParams #ifndef HB_NO_LAYOUT_FEATURE_PARAMS const FeatureParamsSize& get_size_params (hb_tag_t tag) const { - if (tag == HB_TAG ('s','i','z','e')) + if (tag == HB_TAG ('s','i','z','e') && hb_barrier ()) return u.size; return Null (FeatureParamsSize); } @@ -900,7 +900,7 @@ struct RecordArrayOf : SortedArray16Of> unsigned int *record_count /* IN/OUT */, hb_tag_t *record_tags /* OUT */) const { - if (record_count) + if (record_count && record_tags) { + this->as_array ().sub_array (start_offset, record_count) | hb_map (&Record::tag) @@ -2633,8 +2633,9 @@ struct hb_scalar_cache_t *cached_value = roundf(value * MULTIPLIER); } - private: + public: unsigned length; + private: mutable hb_atomic_t static_values[STATIC_LENGTH]; }; @@ -4959,10 +4960,12 @@ struct Device { #ifndef HB_NO_HINTING case 1: case 2: case 3: + hb_barrier (); return u.hinting.get_x_delta (font); #endif #ifndef HB_NO_VAR case 0x8000: + hb_barrier (); return u.variation.get_x_delta (font, store, store_cache); #endif default: @@ -4977,10 +4980,12 @@ struct Device { case 1: case 2: case 3: #ifndef HB_NO_HINTING + hb_barrier (); return u.hinting.get_y_delta (font); #endif #ifndef HB_NO_VAR case 0x8000: + hb_barrier (); return u.variation.get_y_delta (font, store, store_cache); #endif default: @@ -4995,10 +5000,12 @@ struct Device switch (u.b.format) { #ifndef HB_NO_HINTING case 1: case 2: case 3: + hb_barrier (); return_trace (u.hinting.sanitize (c)); #endif #ifndef HB_NO_VAR case 0x8000: + hb_barrier (); return_trace (u.variation.sanitize (c)); #endif default: @@ -5015,10 +5022,12 @@ struct Device case 1: case 2: case 3: + hb_barrier (); return_trace (reinterpret_cast (u.hinting.copy (c))); #endif #ifndef HB_NO_VAR case 0x8000: + hb_barrier (); return_trace (reinterpret_cast (u.variation.copy (c, layout_variation_idx_delta_map))); #endif default: @@ -5037,6 +5046,7 @@ struct Device #endif #ifndef HB_NO_VAR case 0x8000: + hb_barrier (); u.variation.collect_variation_index (c); return; #endif @@ -5050,6 +5060,7 @@ struct Device switch (u.b.format) { #ifndef HB_NO_VAR case 0x8000: + hb_barrier (); return u.variation.varIdx; #endif default: diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index bb9729d53..9742a3458 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -675,9 +675,6 @@ struct skipping_iterator_t return SKIP; } -#ifndef HB_OPTIMIZE_SIZE - HB_ALWAYS_INLINE -#endif bool next (unsigned *unsafe_to = nullptr) { auto *info = c->buffer->info; @@ -706,9 +703,6 @@ struct skipping_iterator_t *unsafe_to = end; return false; } -#ifndef HB_OPTIMIZE_SIZE - HB_ALWAYS_INLINE -#endif bool prev (unsigned *unsafe_from = nullptr) { auto *out_info = c->buffer->out_info; @@ -949,7 +943,11 @@ struct hb_ot_apply_context_t : * match_props has the set index. */ if (match_props & LookupFlag::UseMarkFilteringSet) - return gdef_accel.mark_set_covers (match_props >> 16, info->codepoint); + { + unsigned set_index = match_props >> 16; + return gdef_accel.mark_set_may_cover (set_index, info->codepoint) && + gdef.mark_set_covers (set_index, info->codepoint); + } /* The second byte of match_props has the meaning * "ignore marks of attachment type different than diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index c11d0e465..72d5c49b4 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -345,7 +345,7 @@ hb_ot_layout_get_glyphs_in_class (hb_face_t *face, * @start_offset: offset of the first attachment point to retrieve * @point_count: (inout) (nullable): Input = the maximum number of attachment points to return; * Output = the actual number of attachment points returned (may be zero) - * @point_array: (out) (array length=point_count): The array of attachment points found for the query + * @point_array: (out) (array length=point_count) (nullable): The array of attachment points found for the query * * Fetches a list of all attachment points for the specified glyph in the GDEF * table of the face. The list returned will begin at the offset provided. @@ -375,7 +375,7 @@ hb_ot_layout_get_attach_points (hb_face_t *face, * @start_offset: offset of the first caret position to retrieve * @caret_count: (inout) (nullable): Input = the maximum number of caret positions to return; * Output = the actual number of caret positions returned (may be zero) - * @caret_array: (out) (array length=caret_count): The array of caret positions found for the query + * @caret_array: (out) (array length=caret_count) (nullable): The array of caret positions found for the query * * Fetches a list of the caret positions defined for a ligature glyph in the GDEF * table of the font. The list returned will begin at the offset provided. @@ -446,7 +446,7 @@ get_gsubgpos_table (hb_face_t *face, * @start_offset: offset of the first script tag to retrieve * @script_count: (inout) (nullable): Input = the maximum number of script tags to return; * Output = the actual number of script tags returned (may be zero) - * @script_tags: (out) (array length=script_count): The array of #hb_tag_t script tags found for the query + * @script_tags: (out) (array length=script_count) (nullable): The array of #hb_tag_t script tags found for the query * * Fetches a list of all scripts enumerated in the specified face's GSUB table * or GPOS table. The list returned will begin at the offset provided. @@ -615,7 +615,7 @@ hb_ot_layout_table_select_script (hb_face_t *face, * @start_offset: offset of the first feature tag to retrieve * @feature_count: (inout) (nullable): Input = the maximum number of feature tags to return; * Output = the actual number of feature tags returned (may be zero) - * @feature_tags: (out) (array length=feature_count): Array of feature tags found in the table + * @feature_tags: (out) (array length=feature_count) (nullable): Array of feature tags found in the table * * Fetches a list of all feature tags in the given face's GSUB or GPOS table. * Note that there might be duplicate feature tags, belonging to different @@ -685,7 +685,7 @@ hb_ot_layout_table_find_feature (hb_face_t *face, * @start_offset: offset of the first language tag to retrieve * @language_count: (inout) (nullable): Input = the maximum number of language tags to return; * Output = the actual number of language tags returned (may be zero) - * @language_tags: (out) (array length=language_count): Array of language tags found in the table + * @language_tags: (out) (array length=language_count) (nullable): Array of language tags found in the table * * Fetches a list of language tags in the given face's GSUB or GPOS table, underneath * the specified script index. The list returned will begin at the offset provided. @@ -913,7 +913,7 @@ hb_ot_layout_language_get_required_feature (hb_face_t *face, * @start_offset: offset of the first feature tag to retrieve * @feature_count: (inout) (nullable): Input = the maximum number of feature tags to return; * Output: the actual number of feature tags returned (may be zero) - * @feature_indexes: (out) (array length=feature_count): The array of feature indexes found for the query + * @feature_indexes: (out) (array length=feature_count) (nullable): The array of feature indexes found for the query * * Fetches a list of all features in the specified face's GSUB table * or GPOS table, underneath the specified script and language. The list @@ -949,7 +949,7 @@ hb_ot_layout_language_get_feature_indexes (hb_face_t *face, * @start_offset: offset of the first feature tag to retrieve * @feature_count: (inout) (nullable): Input = the maximum number of feature tags to return; * Output = the actual number of feature tags returned (may be zero) - * @feature_tags: (out) (array length=feature_count): The array of #hb_tag_t feature tags found for the query + * @feature_tags: (out) (array length=feature_count) (nullable): The array of #hb_tag_t feature tags found for the query * * Fetches a list of all features in the specified face's GSUB table * or GPOS table, underneath the specified script and language. The list @@ -975,7 +975,7 @@ hb_ot_layout_language_get_feature_tags (hb_face_t *face, static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), ""); unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags); - if (feature_tags) { + if (feature_count && feature_tags) { unsigned int count = *feature_count; for (unsigned int i = 0; i < count; i++) feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]); @@ -1037,7 +1037,7 @@ hb_ot_layout_language_find_feature (hb_face_t *face, * @start_offset: offset of the first lookup to retrieve * @lookup_count: (inout) (nullable): Input = the maximum number of lookups to return; * Output = the actual number of lookups returned (may be zero) - * @lookup_indexes: (out) (array length=lookup_count): The array of lookup indexes found for the query + * @lookup_indexes: (out) (array length=lookup_count) (nullable): The array of lookup indexes found for the query * * Fetches a list of all lookups enumerated for the specified feature, in * the specified face's GSUB table or GPOS table. The list returned will @@ -1475,7 +1475,7 @@ hb_ot_layout_table_find_feature_variations (hb_face_t *face, * @start_offset: offset of the first lookup to retrieve * @lookup_count: (inout) (nullable): Input = the maximum number of lookups to return; * Output = the actual number of lookups returned (may be zero) - * @lookup_indexes: (out) (array length=lookup_count): The array of lookups found for the query + * @lookup_indexes: (out) (array length=lookup_count) (nullable): The array of lookups found for the query * * Fetches a list of all lookups enumerated for the specified feature, in * the specified face's GSUB table or GPOS table, enabled at the specified @@ -1854,7 +1854,7 @@ hb_ot_layout_feature_get_name_ids (hb_face_t *face, * @start_offset: offset of the first character to retrieve * @char_count: (inout) (nullable): Input = the maximum number of characters to return; * Output = the actual number of characters returned (may be zero) - * @characters: (out caller-allocates) (array length=char_count): A buffer pointer. + * @characters: (out caller-allocates) (array length=char_count) (nullable): A buffer pointer. * The Unicode codepoints of the characters for which this feature provides * glyph variants. * @@ -2288,7 +2288,7 @@ hb_ot_layout_get_horizontal_baseline_tag_for_script (hb_script_t script) * @language_tag: language tag, currently unused. * @coord: (out) (nullable): baseline value if found. * - * Fetches a baseline value from the face. + * Fetches a baseline value from the font. * * Return value: `true` if found baseline value in the font. * @@ -2314,7 +2314,7 @@ hb_ot_layout_get_baseline (hb_font_t *font, * @language: (nullable): language, currently unused. * @coord: (out) (nullable): baseline value if found. * - * Fetches a baseline value from the face. + * Fetches a baseline value from the font. * * This function is like hb_ot_layout_get_baseline() but takes * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t. @@ -2350,7 +2350,7 @@ hb_ot_layout_get_baseline2 (hb_font_t *font, * @language_tag: language tag, currently unused. * @coord: (out): baseline value if found. * - * Fetches a baseline value from the face, and synthesizes + * Fetches a baseline value from the font, and synthesizes * it if the font does not have it. * * Since: 4.0.0 @@ -2572,7 +2572,7 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, * @language: (nullable): language, currently unused. * @coord: (out): baseline value if found. * - * Fetches a baseline value from the face, and synthesizes + * Fetches a baseline value from the font, and synthesizes * it if the font does not have it. * * This function is like hb_ot_layout_get_baseline_with_fallback() but takes @@ -2629,7 +2629,7 @@ struct hb_get_glyph_alternates_dispatch_t : * @start_offset: starting offset. * @alternate_count: (inout) (nullable): Input = the maximum number of alternate glyphs to return; * Output = the actual number of alternate glyphs returned (may be zero). - * @alternate_glyphs: (out caller-allocates) (array length=alternate_count): A glyphs buffer. + * @alternate_glyphs: (out caller-allocates) (array length=alternate_count) (nullable): A glyphs buffer. * Alternate glyphs associated with the glyph id. * * Fetches alternates of a glyph from a given GSUB lookup index. Note that for one-to-one GSUB diff --git a/src/hb-ot-math-table.hh b/src/hb-ot-math-table.hh index c26b0fd0f..4cdc7168c 100644 --- a/src/hb-ot-math-table.hh +++ b/src/hb-ot-math-table.hh @@ -373,7 +373,7 @@ struct MathKern const MathValueRecord* kernValue = mathValueRecordsZ.arrayZ + heightCount; const unsigned int entriesCount = heightCount + 1; - if (entries_count) + if (entries_count && kern_entries) { unsigned int start = hb_min (start_offset, entriesCount); unsigned int end = hb_min (start + *entries_count, entriesCount); @@ -783,7 +783,7 @@ struct MathGlyphAssembly hb_ot_math_glyph_part_t *parts /* OUT */, hb_position_t *italics_correction /* OUT */) const { - if (parts_count) + if (parts_count && parts) { int64_t mult = font->dir_mult (direction); for (auto _ : hb_zip (partRecords.as_array ().sub_array (start_offset, parts_count), @@ -858,7 +858,7 @@ struct MathGlyphConstruction unsigned int *variants_count, /* IN/OUT */ hb_ot_math_glyph_variant_t *variants /* OUT */) const { - if (variants_count) + if (variants_count && variants) { int64_t mult = font->dir_mult (direction); for (auto _ : hb_zip (mathGlyphVariantRecord.as_array ().sub_array (start_offset, variants_count), @@ -980,7 +980,7 @@ struct MathVariants bool subset (hb_subset_context_t *c) const { TRACE_SUBSET (this); - const hb_set_t &glyphset = c->plan->_glyphset_mathed; + const hb_set_t &glyphset = c->plan->_glyphset_cmaped; const hb_map_t &glyph_map = *c->plan->glyph_map; auto *out = c->serializer->start_embed (*this); diff --git a/src/hb-ot-math.cc b/src/hb-ot-math.cc index 719a802d5..91ef8a894 100644 --- a/src/hb-ot-math.cc +++ b/src/hb-ot-math.cc @@ -206,7 +206,7 @@ hb_ot_math_get_glyph_kerning (hb_font_t *font, * @start_offset: offset of the first kern entry to retrieve * @entries_count: (inout) (optional): Input = the maximum number of kern entries to return; * Output = the actual number of kern entries returned - * @kern_entries: (out caller-allocates) (array length=entries_count): array of kern entries returned + * @kern_entries: (out caller-allocates) (array length=entries_count) (nullable): array of kern entries returned * * Fetches the raw MathKern (cut-in) data for the specified font, glyph index, * and @kern. The corresponding list of kern values and correction heights is @@ -251,7 +251,7 @@ hb_ot_math_get_glyph_kernings (hb_font_t *font, * @start_offset: offset of the first variant to retrieve * @variants_count: (inout): Input = the maximum number of variants to return; * Output = the actual number of variants returned - * @variants: (out) (array length=variants_count): array of variants returned + * @variants: (out) (array length=variants_count) (nullable): array of variants returned * * Fetches the MathGlyphConstruction for the specified font, glyph index, and * direction. The corresponding list of size variants is returned as a list of @@ -313,7 +313,7 @@ hb_ot_math_get_min_connector_overlap (hb_font_t *font, * @start_offset: offset of the first glyph part to retrieve * @parts_count: (inout): Input = maximum number of glyph parts to return; * Output = actual number of parts returned - * @parts: (out) (array length=parts_count): the glyph parts returned + * @parts: (out) (array length=parts_count) (nullable): the glyph parts returned * @italics_correction: (out): italics correction of the glyph assembly * * Fetches the GlyphAssembly for the specified font, glyph index, and direction. diff --git a/src/hb-ot-meta-table.hh b/src/hb-ot-meta-table.hh index 658db584c..5365774de 100644 --- a/src/hb-ot-meta-table.hh +++ b/src/hb-ot-meta-table.hh @@ -83,7 +83,7 @@ struct meta unsigned int *count, hb_ot_meta_tag_t *entries) const { - if (count) + if (count && entries) { + table->dataMaps.as_array ().sub_array (start_offset, count) | hb_map (&DataMap::get_tag) diff --git a/src/hb-ot-meta.cc b/src/hb-ot-meta.cc index 35c8eb523..99ada452b 100644 --- a/src/hb-ot-meta.cc +++ b/src/hb-ot-meta.cc @@ -42,7 +42,7 @@ * @face: a face object * @start_offset: iteration's start offset * @entries_count:(inout) (optional): buffer size as input, filled size as output - * @entries: (out caller-allocates) (array length=entries_count): entries tags buffer + * @entries: (out caller-allocates) (array length=entries_count) (nullable): entries tags buffer * * Fetches all available feature types. * diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 4536c7738..d89a45475 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -188,7 +188,7 @@ struct post if (unlikely (!gids)) { - gids = (uint16_t *) hb_malloc (count * sizeof (gids[0])); + gids = (uint16_t *) hb_malloc2 (count, sizeof (gids[0])); if (unlikely (!gids)) return false; /* Anything better?! */ diff --git a/src/hb-ot-shaper-hangul.cc b/src/hb-ot-shaper-hangul.cc index ce87a9156..514b078bf 100644 --- a/src/hb-ot-shaper-hangul.cc +++ b/src/hb-ot-shaper-hangul.cc @@ -67,14 +67,23 @@ static void override_features_hangul (hb_ot_shape_planner_t *plan) { /* Uniscribe does not apply 'calt' for Hangul, and certain fonts - * (Noto Sans CJK, Source Sans Han, etc) apply all of jamo lookups - * in calt, which is not desirable. */ - plan->map.disable_feature (HB_TAG('c','a','l','t')); + * (Noto Sans CJK, Source Han Sans, etc) apply all of jamo lookups + * in calt, which is not desirable. + * + * Rather than disabling 'calt' for the entire run, which also turns + * it off for any other characters in the run, allocate a mask for it + * and clear that mask on jamo only (in setup_masks_hangul). That + * keeps jamo out of reach of such lookups while letting the rest of + * the run shape with 'calt' as usual. + * + * https://github.com/harfbuzz/harfbuzz/discussions/4853 */ + plan->map.add_feature (HB_TAG('c','a','l','t')); } struct hangul_shape_plan_t { hb_mask_t mask_array[HANGUL_FEATURE_COUNT]; + hb_mask_t calt_mask; }; static void * @@ -87,6 +96,8 @@ data_create_hangul (const hb_ot_shape_plan_t *plan) for (unsigned int i = 0; i < HANGUL_FEATURE_COUNT; i++) hangul_plan->mask_array[i] = plan->map.get_1_mask (hangul_features[i]); + hangul_plan->calt_mask = plan->map.get_1_mask (HB_TAG('c','a','l','t')); + return hangul_plan; } @@ -405,7 +416,14 @@ setup_masks_hangul (const hb_ot_shape_plan_t *plan, unsigned int count = buffer->len; hb_glyph_info_t *info = buffer->info; for (unsigned int i = 0; i < count; i++, info++) + { info->mask |= hangul_plan->mask_array[info->hangul_shaping_feature()]; + + /* Keep 'calt' away from jamo; see override_features_hangul(). */ + hb_codepoint_t u = info->codepoint; + if (isL (u) || isV (u) || isT (u)) + info->mask &= ~hangul_plan->calt_mask; + } } HB_BUFFER_DEALLOCATE_VAR (buffer, hangul_shaping_feature); diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc index 6ae6c8287..807de522c 100644 --- a/src/hb-ot-tag.cc +++ b/src/hb-ot-tag.cc @@ -668,10 +668,10 @@ hb_ot_tags_to_script_and_language (hb_tag_t script_tag, primary_script_tag, nullptr, nullptr); *language = hb_ot_tag_to_language (language_tag); - if (script_count == 0 || primary_script_tag[0] != script_tag) + const char *lang_str = *language ? hb_language_to_string (*language) : nullptr; + if (lang_str && (script_count == 0 || primary_script_tag[0] != script_tag)) { unsigned char *buf; - const char *lang_str = hb_language_to_string (*language); size_t len = strlen (lang_str); buf = (unsigned char *) hb_malloc (len + 16); if (unlikely (!buf)) diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index 0c1c4fc17..2121dd234 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -112,9 +112,22 @@ struct TupleVariationHeader HB_ALWAYS_INLINE double calculate_scalar (hb_array_t coords, unsigned int coord_count, const hb_array_t shared_tuples, - hb_scalar_cache_t *shared_tuple_scalar_cache = nullptr) const + hb_scalar_cache_t *shared_tuple_scalar_cache = (hb_scalar_cache_t *) &Null(hb_scalar_cache_t)) const { unsigned tuple_index = tupleIndex; + unsigned int index = tuple_index & TupleIndex::TupleIndexMask; + + /* The gvar shared-tuple cache is clamped to the 12-bit tuple-index range. + * Only PrivatePointNumbers may accompany a cached shared-tuple index; any + * other flag sets a bit at or above 0x1000, making this range test fail. + */ + bool plain_shared_tuple = (tuple_index & ~TupleIndex::PrivatePointNumbers) < shared_tuple_scalar_cache->length; + if (likely (plain_shared_tuple)) + { + float scalar; + if (likely (shared_tuple_scalar_cache->get (index, &scalar))) + return (double) scalar; + } const F2DOT14 *peak_tuple; @@ -127,10 +140,9 @@ struct TupleVariationHeader } else { - unsigned int index = tuple_index & TupleIndex::TupleIndexMask; // Inlined for performance - float scalar; - if (shared_tuple_scalar_cache && + if (!plain_shared_tuple && + shared_tuple_scalar_cache->length && shared_tuple_scalar_cache->get (index, &scalar)) { if (has_interm && (scalar != 0 && scalar != 1.f)) @@ -201,7 +213,7 @@ struct TupleVariationHeader scalar *= (double) v / peak; } if (shared_tuple_scalar_cache) - shared_tuple_scalar_cache->set (get_index (), scalar); + shared_tuple_scalar_cache->set (index, scalar); return scalar; } @@ -209,6 +221,7 @@ struct TupleVariationHeader bool has_intermediate () const { return tupleIndex & TupleIndex::IntermediateRegion; } bool has_private_points () const { return tupleIndex & TupleIndex::PrivatePointNumbers; } unsigned get_index () const { return tupleIndex & TupleIndex::TupleIndexMask; } + static constexpr unsigned max_shared_tuple_count = 0x1000u; protected: struct TupleIndex : HBUINT16 @@ -1951,10 +1964,16 @@ struct item_variations_t if (!front_mapping.set ((major<<16) + minor, &row)) return false; - if (delta_rows_map.has (&row)) - continue; + /* Duplicate rows may only be dropped when optimizing: without a + * varidx_map the caller relies on original VariationIndex values + * staying valid (e.g. HVAR/VVAR with an implicit advance mapping). */ + if (optimize) + { + if (delta_rows_map.has (&row)) + continue; - delta_rows_map.set (&row, 1); + delta_rows_map.set (&row, 1); + } major_rows.push (&row); } diff --git a/src/hb-ot-var-cvar-table.hh b/src/hb-ot-var-cvar-table.hh index 358a95539..1e7532bca 100644 --- a/src/hb-ot-var-cvar-table.hh +++ b/src/hb-ot-var-cvar-table.hh @@ -79,12 +79,12 @@ struct cvar unsigned num_cvt_item, const TupleVariationData<> *tuple_var_data, const void *base, + unsigned var_data_length, hb_vector_t& cvt_deltas /* OUT */) { if (!coords) return true; hb_vector_t shared_indices; TupleVariationData<>::tuple_iterator_t iterator; - unsigned var_data_length = tuple_var_data->get_size (axis_count * 2); hb_bytes_t var_data_bytes = hb_bytes_t (reinterpret_cast (tuple_var_data), var_data_length); if (!TupleVariationData<>::get_tuple_iterator (var_data_bytes, axis_count, base, shared_indices, &iterator)) @@ -191,8 +191,17 @@ struct cvar return false; } + /* Bound the tuple variation data by the actual cvar table length rather + * than trusting tupleVarCount to walk the headers; an inflated count would + * otherwise run get_size() off the end of the table. */ + hb_blob_t *cvar_blob = hb_face_reference_table (plan->source, cvar::tableTag); + unsigned cvar_length = hb_blob_get_length (cvar_blob); + hb_blob_destroy (cvar_blob); + unsigned var_data_offset = (unsigned) ((const char *) tuple_var_data - (const char *) base); + unsigned var_data_length = var_data_offset < cvar_length ? cvar_length - var_data_offset : 0; + if (!calculate_cvt_deltas (plan->normalized_coords.length, plan->normalized_coords.as_array (), - num_cvt_item, tuple_var_data, base, cvt_deltas)) + num_cvt_item, tuple_var_data, base, var_data_length, cvt_deltas)) { hb_blob_destroy (cvt_prime_blob); return false; diff --git a/src/hb-ot-var-fvar-table.hh b/src/hb-ot-var-fvar-table.hh index 4b4410f9b..dc92d5b64 100644 --- a/src/hb-ot-var-fvar-table.hh +++ b/src/hb-ot-var-fvar-table.hh @@ -285,7 +285,7 @@ struct fvar unsigned int *axes_count /* IN/OUT */, hb_ot_var_axis_t *axes_array /* OUT */) const { - if (axes_count) + if (axes_count && axes_array) { hb_array_t arr = get_axes ().sub_array (start_offset, axes_count); for (unsigned i = 0; i < arr.length; ++i) @@ -299,7 +299,7 @@ struct fvar unsigned int *axes_count /* IN/OUT */, hb_ot_var_axis_info_t *axes_array /* OUT */) const { - if (axes_count) + if (axes_count && axes_array) { hb_array_t arr = get_axes ().sub_array (start_offset, axes_count); for (unsigned i = 0; i < arr.length; ++i) @@ -360,7 +360,7 @@ struct fvar return 0; } - if (coords_length && *coords_length) + if (coords_length && *coords_length && coords) { hb_array_t instanceCoords = instance->get_coordinates (axisCount) .sub_array (0, coords_length); diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index da60de2e2..af1e6b860 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -589,7 +589,8 @@ struct gvar_GVAR hb_scalar_cache_t *create_cache () const { - return hb_scalar_cache_t::create (table->sharedTupleCount); + return hb_scalar_cache_t::create (hb_min ((unsigned) table->sharedTupleCount, + +TupleVariationHeader::max_shared_tuple_count)); } static void destroy_cache (hb_scalar_cache_t *cache) @@ -721,6 +722,9 @@ struct gvar_GVAR bool phantom_only = false) const { if (unlikely (glyph >= glyphCount)) return true; + hb_scalar_cache_t *scalar_cache = gvar_cache ? + gvar_cache : + (hb_scalar_cache_t *) &Null(hb_scalar_cache_t); hb_bytes_t var_data_bytes = table->get_glyph_var_data_bytes (table.get_blob (), glyphCount, glyph); if (!var_data_bytes.as ()->has_data ()) return true; @@ -760,7 +764,7 @@ struct gvar_GVAR do { float scalar = iterator.current_tuple->calculate_scalar (coords, num_coords, shared_tuples, - gvar_cache); + scalar_cache); if (scalar == 0.f) continue; diff --git a/src/hb-ot-var-hvar-table.hh b/src/hb-ot-var-hvar-table.hh index f7be19e93..dda30eca8 100644 --- a/src/hb-ot-var-hvar-table.hh +++ b/src/hb-ot-var-hvar-table.hh @@ -49,6 +49,12 @@ struct index_map_subset_plan_t bool bypass_empty = true) { map_count = 0; + full_map_count = plan->new_to_old_gid_list.length ? + plan->new_to_old_gid_list.tail ().first + 1 : 0; + /* Only the advance mapping may be dropped in favor of implicit + * glyph-id indexing (for the others a null offset means no deltas), + * and only when the source was map-less too, preserving its form. */ + can_drop_to_implicit = !bypass_empty && !index_map; max_inners.init (); output_map.init (); @@ -187,11 +193,24 @@ struct index_map_subset_plan_t DeltaSetIndexMap::min_size); } - bool is_identity () const { return get_output_map ().length == 0; } + bool is_identity () const + { + if (!output_map) return true; + /* An advance map whose entries are the identity over every output + * glyph is equivalent to implicit glyph-id indexing; drop it. A + * truncated map doesn't qualify: glyphs past its end share its last + * value, not their own ids. */ + if (!can_drop_to_implicit || map_count != full_map_count) return false; + for (unsigned i = 0; i < map_count; i++) + if (output_map.arrayZ[i] != i) return false; + return true; + } hb_array_t get_output_map () const { return output_map.as_array (); } protected: unsigned int map_count; + unsigned int full_map_count; + bool can_drop_to_implicit; hb_vector_t max_inners; unsigned int outer_bit_count; unsigned int inner_bit_count; diff --git a/src/hb-ot-var.cc b/src/hb-ot-var.cc index 72ef9fbbd..5c2016fe4 100644 --- a/src/hb-ot-var.cc +++ b/src/hb-ot-var.cc @@ -89,7 +89,7 @@ hb_ot_var_get_axis_count (hb_face_t *face) * @start_offset: offset of the first lookup to retrieve * @axes_count: (inout) (optional): Input = the maximum number of variation axes to return; * Output = the actual number of variation axes returned (may be zero) - * @axes_array: (out caller-allocates) (array length=axes_count): The array of variation axes found + * @axes_array: (out caller-allocates) (array length=axes_count) (nullable): The array of variation axes found * * Fetches a list of all variation axes in the specified face. The list returned will begin * at the offset provided. @@ -135,7 +135,7 @@ hb_ot_var_find_axis (hb_face_t *face, * @start_offset: offset of the first lookup to retrieve * @axes_count: (inout) (optional): Input = the maximum number of variation axes to return; * Output = the actual number of variation axes returned (may be zero) - * @axes_array: (out caller-allocates) (array length=axes_count): The array of variation axes found + * @axes_array: (out caller-allocates) (array length=axes_count) (nullable): The array of variation axes found * * Fetches a list of all variation axes in the specified face. The list returned will begin * at the offset provided. @@ -239,7 +239,7 @@ hb_ot_var_named_instance_get_postscript_name_id (hb_face_t *face, * @instance_index: The index of the named instance to query * @coords_length: (inout) (optional): Input = the maximum number of coordinates to return; * Output = the actual number of coordinates returned (may be zero) - * @coords: (out) (array length=coords_length): The array of coordinates found for the query + * @coords: (out) (array length=coords_length) (nullable): The array of coordinates found for the query * * Fetches the design-space coordinates corresponding to the given * named instance in the face. diff --git a/src/hb-paint.cc b/src/hb-paint.cc index e272ec39b..9e84fbbb9 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -60,6 +60,20 @@ hb_paint_color_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_font_t *font, void *user_data) { return false; } +static void +hb_paint_fill_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color, + void *user_data) +{ + /* Decompose into the equivalent general sequence. */ + funcs->push_clip_glyph (paint_data, glyph, font); + funcs->color (paint_data, is_foreground, color); + funcs->pop_clip (paint_data); +} + static void hb_paint_push_clip_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, @@ -551,6 +565,30 @@ hb_paint_color_glyph (hb_paint_funcs_t *funcs, void *paint_data, return funcs->color_glyph (paint_data, glyph, font); } +/** + * hb_paint_fill_glyph: + * @funcs: paint functions + * @paint_data: associated data passed by the caller + * @glyph: the glyph ID + * @font: the font + * @is_foreground: whether the color is the foreground + * @color: The color to use + * + * Perform a "fill-glyph" paint operation: fill the glyph's shape + * with a solid color. + * + * XSince: REPLACEME + */ +void +hb_paint_fill_glyph (hb_paint_funcs_t *funcs, void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color) +{ + funcs->fill_glyph (paint_data, glyph, font, is_foreground, color); +} + /** * hb_paint_push_clip_glyph: * @funcs: paint functions diff --git a/src/hb-paint.h b/src/hb-paint.h index 9057e3b72..c5e4add22 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -157,6 +157,31 @@ typedef hb_bool_t (*hb_paint_color_glyph_func_t) (hb_paint_funcs_t *funcs, hb_font_t *font, void *user_data); +/** + * hb_paint_fill_glyph_func_t: + * @funcs: paint functions object + * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() + * @glyph: the glyph ID + * @font: the font + * @is_foreground: whether the color is the foreground + * @color: The color to use, unpremultiplied + * @user_data: User data pointer passed to hb_paint_funcs_set_fill_glyph_func() + * + * A virtual method for the #hb_paint_funcs_t to fill a glyph's shape with + * a solid color. If not implemented, a sequence of "push-clip-glyph", + * "color", "pop-clip" paint operations, in that order, will be emitted + * instead. + * + * XSince: REPLACEME + */ +typedef void (*hb_paint_fill_glyph_func_t) (hb_paint_funcs_t *funcs, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color, + void *user_data); + /** * hb_paint_push_clip_glyph_func_t: * @funcs: paint functions object @@ -854,6 +879,23 @@ hb_paint_funcs_set_color_glyph_func (hb_paint_funcs_t *funcs, void *user_data, hb_destroy_func_t destroy); +/** + * hb_paint_funcs_set_fill_glyph_func: + * @funcs: A paint functions struct + * @func: (closure user_data) (destroy destroy) (scope notified): The fill-glyph callback + * @user_data: Data to pass to @func + * @destroy: (nullable): Function to call when @user_data is no longer needed + * + * Sets the fill-glyph callback on the paint functions struct. + * + * XSince: REPLACEME + */ +HB_EXTERN void +hb_paint_funcs_set_fill_glyph_func (hb_paint_funcs_t *funcs, + hb_paint_fill_glyph_func_t func, + void *user_data, + hb_destroy_func_t destroy); + /** * hb_paint_funcs_set_push_clip_glyph_func: * @funcs: A paint functions struct @@ -1117,6 +1159,13 @@ hb_paint_color_glyph (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, hb_font_t *font); +HB_EXTERN void +hb_paint_fill_glyph (hb_paint_funcs_t *funcs, void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color); + HB_EXTERN void hb_paint_push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 148bfc974..39135a536 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -48,6 +48,7 @@ HB_PAINT_FUNC_IMPLEMENT (push_group_for) \ HB_PAINT_FUNC_IMPLEMENT (pop_group) \ HB_PAINT_FUNC_IMPLEMENT (custom_palette_color) \ + HB_PAINT_FUNC_IMPLEMENT (fill_glyph) \ /* ^--- Add new callbacks here */ struct hb_paint_funcs_t @@ -92,7 +93,7 @@ struct hb_paint_funcs_t { return func.color_glyph (this, paint_data, glyph, font, - !user_data ? nullptr : user_data->push_clip_glyph); } + !user_data ? nullptr : user_data->color_glyph); } void push_clip_glyph (void *paint_data, hb_codepoint_t glyph, hb_font_t *font) @@ -121,6 +122,15 @@ struct hb_paint_funcs_t { func.color (this, paint_data, is_foreground, color, !user_data ? nullptr : user_data->color); } + void fill_glyph (void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color) + { func.fill_glyph (this, paint_data, + glyph, font, + is_foreground, color, + !user_data ? nullptr : user_data->fill_glyph); } bool image (void *paint_data, hb_blob_t *image, unsigned width, unsigned height, diff --git a/src/hb-raster-draw.cc b/src/hb-raster-draw.cc index ba067561a..3b77fea1b 100644 --- a/src/hb-raster-draw.cc +++ b/src/hb-raster-draw.cc @@ -382,10 +382,10 @@ hb_raster_draw_set_glyph_extents (hb_raster_draw_t *draw, ty_max = hb_max (ty_max, ty); } - int ex0 = (int) floorf (tx_min); - int ey0 = (int) floorf (ty_min); - int ex1 = (int) ceilf (tx_max); - int ey1 = (int) ceilf (ty_max); + int32_t ex0 = hb_clamp_to (floorf (tx_min)); + int32_t ey0 = hb_clamp_to (floorf (ty_min)); + int32_t ex1 = hb_clamp_to (ceilf (tx_max)); + int32_t ey1 = hb_clamp_to (ceilf (ty_max)); if (ex1 <= ex0 || ey1 <= ey0) { @@ -396,8 +396,8 @@ hb_raster_draw_set_glyph_extents (hb_raster_draw_t *draw, draw->fixed_extents = { ex0, ey0, - (unsigned) (ex1 - ex0), - (unsigned) (ey1 - ey0), + (unsigned) ((int64_t) ex1 - ex0), + (unsigned) ((int64_t) ey1 - ey0), 0 }; draw->has_extents = true; @@ -483,10 +483,10 @@ emit_segment (hb_raster_draw_t *draw, float x0, float y0, float x1, float y1) { - int32_t X0 = (int32_t) roundf (x0 * HB_RASTER_ONE_PIXEL); - int32_t Y0 = (int32_t) roundf (y0 * HB_RASTER_ONE_PIXEL); - int32_t X1 = (int32_t) roundf (x1 * HB_RASTER_ONE_PIXEL); - int32_t Y1 = (int32_t) roundf (y1 * HB_RASTER_ONE_PIXEL); + int32_t X0 = hb_clamp_to (roundf (x0 * HB_RASTER_ONE_PIXEL)); + int32_t Y0 = hb_clamp_to (roundf (y0 * HB_RASTER_ONE_PIXEL)); + int32_t X1 = hb_clamp_to (roundf (x1 * HB_RASTER_ONE_PIXEL)); + int32_t Y1 = hb_clamp_to (roundf (y1 * HB_RASTER_ONE_PIXEL)); if (Y0 == Y1) return; /* horizontal — skip */ diff --git a/src/hb-raster-image.cc b/src/hb-raster-image.cc index baf825279..16b7aa789 100644 --- a/src/hb-raster-image.cc +++ b/src/hb-raster-image.cc @@ -30,6 +30,45 @@ #include +/** + * SECTION:hb-raster + * @title: hb-raster + * @short_description: Glyph rasterization + * @include: hb-raster.h + * + * Functions for rasterizing glyph outlines into pixel buffers. + * + * #hb_raster_draw_t rasterizes outline geometry and always outputs + * @HB_RASTER_FORMAT_A8. Typical flow: + * + * |[ + * hb_raster_draw_t *draw = hb_raster_draw_create_or_fail (); + * hb_raster_draw_set_scale_factor (draw, 64.f, 64.f); + * hb_raster_draw_set_transform (draw, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); + * hb_raster_draw_set_glyph_extents (draw, &glyph_extents); + * hb_raster_draw_glyph (draw, font, gid, pen_x, pen_y); + * hb_raster_image_t *mask = hb_raster_draw_render (draw); + * ]| + * + * #hb_raster_paint_t renders color paint graphs and always outputs + * @HB_RASTER_FORMAT_BGRA32. Typical flow: + * + * |[ + * hb_raster_paint_t *paint = hb_raster_paint_create_or_fail (); + * hb_raster_paint_set_scale_factor (paint, 64.f, 64.f); + * hb_raster_paint_set_transform (paint, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); + * hb_raster_paint_set_foreground (paint, foreground); + * hb_glyph_extents_t glyph_extents; + * hb_font_get_glyph_extents (font, gid, &glyph_extents); + * hb_raster_paint_set_glyph_extents (paint, &glyph_extents); + * hb_raster_paint_glyph (paint, font, gid, pen_x, pen_y); + * hb_raster_image_t *img = hb_raster_paint_render (paint); + * ]| + * + * In both modes, set extents explicitly (or via glyph extents) before + * rendering to avoid implicit allocations and to get deterministic bounds. + **/ + #ifdef HAVE_PNG #include #endif diff --git a/src/hb-raster-paint.cc b/src/hb-raster-paint.cc index d5bcdd8b3..779c3d99c 100644 --- a/src/hb-raster-paint.cc +++ b/src/hb-raster-paint.cc @@ -196,6 +196,35 @@ hb_raster_paint_push_empty_clip (hb_raster_paint_t *c, unsigned w, unsigned h) (void) c->clip_stack.push (std::move (new_clip)); } +static bool +hb_raster_paint_intersect_mask (const hb_raster_image_t *surf, + const hb_raster_extents_t &mask_ext, + const hb_raster_clip_t &clip, + unsigned w, unsigned h, + int64_t *mask_x0, int64_t *mask_y0, + unsigned *ix0, unsigned *iy0, + unsigned *ix1, unsigned *iy1) +{ + /* Convert mask extents from surface coordinates to clip-buffer coordinates. */ + int64_t mx0 = (int64_t) mask_ext.x_origin - (int64_t) surf->extents.x_origin; + int64_t my0 = (int64_t) mask_ext.y_origin - (int64_t) surf->extents.y_origin; + + int64_t x0 = hb_max ((int64_t) clip.min_x, hb_max (mx0, (int64_t) 0)); + int64_t y0 = hb_max ((int64_t) clip.min_y, hb_max (my0, (int64_t) 0)); + int64_t x1 = hb_min ((int64_t) clip.max_x, hb_min (mx0 + mask_ext.width, (int64_t) w)); + int64_t y1 = hb_min ((int64_t) clip.max_y, hb_min (my0 + mask_ext.height, (int64_t) h)); + + if (x0 >= x1 || y0 >= y1) return false; + + *mask_x0 = mx0; + *mask_y0 = my0; + *ix0 = (unsigned) x0; + *iy0 = (unsigned) y0; + *ix1 = (unsigned) x1; + *iy1 = (unsigned) y1; + return true; +} + /* Render whatever edges have been accumulated into @rdr and * push the result as a new clip on the stack, intersecting * with the existing clip. Used by the emitter-based clip @@ -239,29 +268,17 @@ hb_raster_paint_finalize_path_clip (hb_raster_paint_t *c, return; } - /* Convert mask extents from surface coordinates to clip-buffer coordinates. */ - int mask_x0 = mask_ext.x_origin - surf->extents.x_origin; - int mask_y0 = mask_ext.y_origin - surf->extents.y_origin; - int mask_x1 = mask_x0 + (int) mask_ext.width; - int mask_y1 = mask_y0 + (int) mask_ext.height; - - int ix0_i = hb_max ((int) old_clip.min_x, hb_max (mask_x0, 0)); - int iy0_i = hb_max ((int) old_clip.min_y, hb_max (mask_y0, 0)); - int ix1_i = hb_min ((int) old_clip.max_x, hb_min (mask_x1, (int) w)); - int iy1_i = hb_min ((int) old_clip.max_y, hb_min (mask_y1, (int) h)); - - if (ix0_i >= ix1_i || iy0_i >= iy1_i) + int64_t mask_x0, mask_y0; + unsigned ix0, iy0, ix1, iy1; + if (!hb_raster_paint_intersect_mask (surf, mask_ext, old_clip, w, h, + &mask_x0, &mask_y0, + &ix0, &iy0, &ix1, &iy1)) { hb_raster_draw_recycle_image (rdr, mask_img); hb_raster_paint_push_empty_clip (c, w, h); return; } - unsigned ix0 = (unsigned) ix0_i; - unsigned iy0 = (unsigned) iy0_i; - unsigned ix1 = (unsigned) ix1_i; - unsigned iy1 = (unsigned) iy1_i; - new_clip.min_x = w; new_clip.min_y = h; new_clip.max_x = 0; new_clip.max_y = 0; @@ -269,11 +286,11 @@ hb_raster_paint_finalize_path_clip (hb_raster_paint_t *c, { for (unsigned y = iy0; y < iy1; y++) { - const uint8_t *mask_row = mask_buf + (unsigned) ((int) y - mask_y0) * mask_ext.stride; + const uint8_t *mask_row = mask_buf + (unsigned) ((int64_t) y - mask_y0) * mask_ext.stride; uint8_t *out_row = new_clip.alpha.arrayZ + y * new_clip.stride; unsigned row_min = ix1; unsigned row_max = ix0; - unsigned mx = (unsigned) ((int) ix0 - mask_x0); + unsigned mx = (unsigned) ((int64_t) ix0 - mask_x0); for (unsigned x = ix0; x < ix1; x++) { uint8_t a = mask_row[mx++]; @@ -300,13 +317,13 @@ hb_raster_paint_finalize_path_clip (hb_raster_paint_t *c, for (unsigned y = iy0; y < iy1; y++) { const uint8_t *old_row = old_clip.alpha.arrayZ + y * old_clip.stride; - const uint8_t *mask_row = mask_buf + (unsigned) ((int) y - mask_y0) * mask_ext.stride; + const uint8_t *mask_row = mask_buf + (unsigned) ((int64_t) y - mask_y0) * mask_ext.stride; uint8_t *out_row = new_clip.alpha.arrayZ + y * new_clip.stride; unsigned row_min = ix1; unsigned row_max = ix0; for (unsigned x = ix0; x < ix1; x++) { - unsigned mx = (unsigned) ((int) x - mask_x0); + unsigned mx = (unsigned) ((int64_t) x - mask_x0); uint8_t a = hb_raster_div255 (mask_row[mx] * old_row[x]); out_row[x] = a; if (a) @@ -697,19 +714,11 @@ hb_raster_paint_pop_group (hb_paint_funcs_t *pfuncs HB_UNUSED, } static void -hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, - void *paint_data, - hb_bool_t is_foreground HB_UNUSED, +hb_raster_paint_solid (hb_raster_paint_t *c, + hb_raster_image_t *surf, hb_color_t color, - void *user_data HB_UNUSED) + hb_raster_image_t *mask_img) { - hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data; - - ensure_initialized (c); - - hb_raster_image_t *surf = c->current_surface (); - if (unlikely (!surf)) return; - uint32_t premul = color_to_premul_pixel (color); uint8_t premul_a = (uint8_t) (premul >> 24); const hb_raster_clip_t &clip = c->current_clip (); @@ -718,15 +727,36 @@ hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, if (clip.min_x >= clip.max_x || clip.min_y >= clip.max_y) return; if (premul_a == 0) return; + unsigned ix0 = clip.min_x, iy0 = clip.min_y; + unsigned ix1 = clip.max_x, iy1 = clip.max_y; + const uint8_t *mask_buf = nullptr; + hb_raster_extents_t mask_ext; + int64_t mask_x0 = 0, mask_y0 = 0; + if (mask_img) + { + mask_buf = hb_raster_image_get_buffer (mask_img); + hb_raster_image_get_extents (mask_img, &mask_ext); + if (!hb_raster_paint_intersect_mask (surf, mask_ext, clip, + surf->extents.width, surf->extents.height, + &mask_x0, &mask_y0, + &ix0, &iy0, &ix1, &iy1)) + return; + } + if (likely (!clip.is_rect)) { - for (unsigned y = clip.min_y; y < clip.max_y; y++) + for (unsigned y = iy0; y < iy1; y++) { hb_packed_t *__restrict row = (hb_packed_t *) (surf->buffer.arrayZ + y * stride); const uint8_t *__restrict clip_row = clip.alpha.arrayZ + y * clip.stride; - for (unsigned x = clip.min_x; x < clip.max_x; x++) + const uint8_t *__restrict mask_row = mask_buf ? mask_buf + (unsigned) ((int64_t) y - mask_y0) * mask_ext.stride + : nullptr; + unsigned mx = (unsigned) ((int64_t) ix0 - mask_x0); + for (unsigned x = ix0; x < ix1; x++) { uint8_t clip_alpha = clip_row[x]; + if (mask_row) + clip_alpha = hb_raster_div255 (mask_row[mx++] * clip_alpha); if (clip_alpha == 0) continue; if (clip_alpha == 255) { @@ -743,6 +773,22 @@ hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, } } } + else if (mask_buf) + { + for (unsigned y = iy0; y < iy1; y++) + { + hb_packed_t *__restrict row = (hb_packed_t *) (surf->buffer.arrayZ + y * stride); + const uint8_t *__restrict mask_row = mask_buf + (unsigned) ((int64_t) y - mask_y0) * mask_ext.stride; + unsigned mx = (unsigned) ((int64_t) ix0 - mask_x0); + for (unsigned x = ix0; x < ix1; x++) + { + uint8_t mask_alpha = mask_row[mx++]; + if (mask_alpha == 0) continue; + uint32_t src = hb_raster_alpha_mul (premul, mask_alpha); + row[x] = hb_packed_t (hb_raster_src_over (src, (uint32_t) row[x])); + } + } + } else { for (unsigned y = clip.min_y; y < clip.max_y; y++) @@ -754,6 +800,54 @@ hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, } } +static void +hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + hb_bool_t is_foreground HB_UNUSED, + hb_color_t color, + void *user_data HB_UNUSED) +{ + hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data; + + ensure_initialized (c); + + hb_raster_image_t *surf = c->current_surface (); + if (unlikely (!surf)) return; + + hb_raster_paint_solid (c, surf, color, nullptr); +} + +static void +hb_raster_paint_fill_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground HB_UNUSED, + hb_color_t color, + void *user_data HB_UNUSED) +{ + hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data; + + ensure_initialized (c); + + hb_raster_image_t *surf = c->current_surface (); + if (unlikely (!surf)) return; + + hb_raster_draw_t *rdr = c->clip_rdr; + hb_transform_t<> t = c->current_effective_transform (); + hb_raster_draw_set_transform (rdr, t.xx, t.yx, t.xy, t.yy, t.x0, t.y0); + + hb_raster_paint_glyph_clip_data_t data = {glyph, font}; + hb_raster_paint_emit_clip_glyph_mask (rdr, &data); + + hb_raster_image_t *mask_img = hb_raster_draw_render (rdr); + if (unlikely (!mask_img)) return; + + hb_raster_paint_solid (c, surf, color, mask_img); + + hb_raster_draw_recycle_image (rdr, mask_img); +} + static hb_bool_t hb_raster_paint_image (hb_paint_funcs_t *pfuncs HB_UNUSED, void *paint_data, @@ -852,7 +946,8 @@ hb_raster_paint_image (hb_paint_funcs_t *pfuncs HB_UNUSED, float ix = (gx - img_x) / img_sx; float iy = (float) (src_height - 1) - (gy - img_y) / img_sy; - if (ix < 0.f || iy < 0.f || + if (unlikely (!std::isfinite (ix) || !std::isfinite (iy)) || + ix < 0.f || iy < 0.f || ix > (float) (src_width - 1) || iy > (float) (src_height - 1)) { gx += inv_xx; @@ -890,7 +985,8 @@ hb_raster_paint_image (hb_paint_funcs_t *pfuncs HB_UNUSED, float ix = (gx - img_x) / img_sx; float iy = (float) (src_height - 1) - (gy - img_y) / img_sy; - if (ix < 0.f || iy < 0.f || + if (unlikely (!std::isfinite (ix) || !std::isfinite (iy)) || + ix < 0.f || iy < 0.f || ix > (float) (src_width - 1) || iy > (float) (src_height - 1)) { gx += inv_xx; @@ -1645,6 +1741,7 @@ static struct hb_raster_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t hb_paint_funcs_set_push_transform_func (funcs, hb_raster_paint_push_transform, nullptr, nullptr); hb_paint_funcs_set_pop_transform_func (funcs, hb_raster_paint_pop_transform, nullptr, nullptr); + hb_paint_funcs_set_fill_glyph_func (funcs, hb_raster_paint_fill_glyph, nullptr, nullptr); hb_paint_funcs_set_color_glyph_func (funcs, hb_raster_paint_color_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_raster_paint_push_clip_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_rectangle_func (funcs, hb_raster_paint_push_clip_rectangle, nullptr, nullptr); @@ -1984,10 +2081,10 @@ hb_raster_paint_set_glyph_extents (hb_raster_paint_t *paint, ty_max = hb_max (ty_max, py[i]); } - int ex0 = (int) floorf (tx_min); - int ey0 = (int) floorf (ty_min); - int ex1 = (int) ceilf (tx_max); - int ey1 = (int) ceilf (ty_max); + int32_t ex0 = hb_clamp_to (floorf (tx_min)); + int32_t ey0 = hb_clamp_to (floorf (ty_min)); + int32_t ex1 = hb_clamp_to (ceilf (tx_max)); + int32_t ey1 = hb_clamp_to (ceilf (ty_max)); if (ex1 <= ex0 || ey1 <= ey0) { @@ -1998,8 +2095,8 @@ hb_raster_paint_set_glyph_extents (hb_raster_paint_t *paint, paint->fixed_extents = { ex0, ey0, - (unsigned) (ex1 - ex0), - (unsigned) (ey1 - ey0), + (unsigned) ((int64_t) ex1 - ex0), + (unsigned) ((int64_t) ey1 - ey0), 0 }; paint->has_extents = true; diff --git a/src/hb-raster.cc b/src/hb-raster.cc deleted file mode 100644 index 815ce2b71..000000000 --- a/src/hb-raster.cc +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright © 2026 Behdad Esfahbod - * - * 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. - * - * Author(s): Behdad Esfahbod - */ - -#include "hb.hh" - -#include "hb-raster.h" - -/** - * SECTION:hb-raster - * @title: hb-raster - * @short_description: Glyph rasterization - * @include: hb-raster.h - * - * Functions for rasterizing glyph outlines into pixel buffers. - * - * #hb_raster_draw_t rasterizes outline geometry and always outputs - * @HB_RASTER_FORMAT_A8. Typical flow: - * - * |[ - * hb_raster_draw_t *draw = hb_raster_draw_create_or_fail (); - * hb_raster_draw_set_scale_factor (draw, 64.f, 64.f); - * hb_raster_draw_set_transform (draw, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); - * hb_raster_draw_set_glyph_extents (draw, &glyph_extents); - * hb_raster_draw_glyph (draw, font, gid, pen_x, pen_y); - * hb_raster_image_t *mask = hb_raster_draw_render (draw); - * ]| - * - * #hb_raster_paint_t renders color paint graphs and always outputs - * @HB_RASTER_FORMAT_BGRA32. Typical flow: - * - * |[ - * hb_raster_paint_t *paint = hb_raster_paint_create_or_fail (); - * hb_raster_paint_set_scale_factor (paint, 64.f, 64.f); - * hb_raster_paint_set_transform (paint, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); - * hb_raster_paint_set_foreground (paint, foreground); - * hb_glyph_extents_t glyph_extents; - * hb_font_get_glyph_extents (font, gid, &glyph_extents); - * hb_raster_paint_set_glyph_extents (paint, &glyph_extents); - * hb_raster_paint_glyph (paint, font, gid, pen_x, pen_y); - * hb_raster_image_t *img = hb_raster_paint_render (paint); - * ]| - * - * In both modes, set extents explicitly (or via glyph extents) before - * rendering to avoid implicit allocations and to get deterministic bounds. - **/ diff --git a/src/hb-repacker.hh b/src/hb-repacker.hh index b5dfae199..dbf65c309 100644 --- a/src/hb-repacker.hh +++ b/src/hb-repacker.hh @@ -379,6 +379,17 @@ hb_resolve_graph_overflows (hb_tag_t table_tag, 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."); diff --git a/src/hb-shape.cc b/src/hb-shape.cc index 2a8086fde..400404421 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -316,7 +316,7 @@ hb_shape_justify (hb_font_t *font, /* Copy buffer text as we need it so we can shape multiple times. */ unsigned text_len = buffer->len; - auto *text_info = (hb_glyph_info_t *) hb_malloc (text_len * sizeof (buffer->info[0])); + auto *text_info = (hb_glyph_info_t *) hb_malloc2 (text_len, sizeof (buffer->info[0])); if (unlikely (text_len && !text_info)) return false; hb_memcpy (text_info, buffer->info, text_len * sizeof (buffer->info[0])); diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index 3140b9ca3..7abeafa1d 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -334,6 +334,8 @@ struct cs_command_t typedef hb_vector_t *cs_command_vec_t; +struct cff2_instancing_plan_t; + struct flatten_param_t { flatten_param_t (str_buff_t &flatStr_, @@ -346,6 +348,11 @@ struct flatten_param_t bool drop_hints; const hb_subset_plan_t *plan; cs_command_vec_t commands; /* Optional: capture parsed commands for specialization */ + + /* CFF2 partial instancing: when set, blends are rewritten against the + * instanced variation store instead of being copied or flattened. */ + const cff2_instancing_plan_t *instancer = nullptr; + bool emitted_blend = false; }; template diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index ba71e4cc8..4c2da6b40 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -529,7 +529,7 @@ struct cff1_subset_plan if (it->first == 0) it++; auto _ = *it; bool not_is_cid = !acc.is_CID (); - bool skip = !not_is_cid && glyph_to_sid_map; + bool skip = !not_is_cid && glyph_to_sid_map && !identity_charset; if (not_is_cid) sidmap.alloc (num_glyphs); for (hb_codepoint_t glyph = 1; glyph < num_glyphs; glyph++) @@ -545,12 +545,18 @@ struct cff1_subset_plan /* Retain the SID for the old missing glyph ID */ old_glyph = glyph; } - unsigned sid = glyph_to_sid_map ? - glyph_to_sid_map->arrayZ[old_glyph].code : - acc.glyph_to_sid (old_glyph, &glyph_to_sid_cache); + unsigned sid; + if (identity_charset) + sid = glyph; + else + { + sid = glyph_to_sid_map ? + glyph_to_sid_map->arrayZ[old_glyph].code : + acc.glyph_to_sid (old_glyph, &glyph_to_sid_cache); - if (not_is_cid) - sid = sidmap.add (sid); + if (not_is_cid) + sid = sidmap.add (sid); + } if (sid != last_sid + 1) subset_charset_ranges.push (code_pair_t {sid, glyph}); @@ -621,6 +627,7 @@ struct cff1_subset_plan orig_fdcount = acc.fdCount; drop_hints = plan->flags & HB_SUBSET_FLAGS_NO_HINTING; desubroutinize = plan->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE; + identity_charset = (plan->flags & HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET) && acc.is_CID (); #ifdef HB_EXPERIMENTAL_API min_charstrings_off_size = (plan->flags & HB_SUBSET_FLAGS_IFTB_REQUIREMENTS) ? 4 : 0; @@ -628,7 +635,7 @@ struct cff1_subset_plan min_charstrings_off_size = 0; #endif - subset_charset = !acc.is_predef_charset (); + subset_charset = !acc.is_predef_charset () || identity_charset; if (!subset_charset) /* check whether the subset renumbers any glyph IDs */ for (const auto &_ : plan->new_to_old_gid_list) @@ -786,6 +793,7 @@ struct cff1_subset_plan unsigned int topDictModSIDs[name_dict_values_t::ValCount]; bool desubroutinize = false; + bool identity_charset = false; unsigned min_charstrings_off_size = 0; }; diff --git a/src/hb-subset-cff2-to-cff1.cc b/src/hb-subset-cff2-to-cff1.cc deleted file mode 100644 index 6a65bf5d8..000000000 --- a/src/hb-subset-cff2-to-cff1.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright © 2026 Behdad Esfahbod - * - * 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. - */ - -/* - * CFF2 to CFF1 Converter - * - * The actual implementation is in hb-subset-cff2.cc where it has access - * to the full cff2_subset_plan definition. - * - * This file just exists to keep the build system happy. - */ - -#include "hb.hh" - -#ifndef HB_NO_SUBSET_CFF - -#include "hb-subset-cff2-to-cff1.hh" - -#endif /* HB_NO_SUBSET_CFF */ diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index 262eeb1ab..9725daf21 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -30,6 +30,7 @@ #include "hb-open-type.hh" #include "hb-ot-cff2-table.hh" +#include "hb-ot-var-common.hh" #include "hb-set.h" #include "hb-subset-plan.hh" #include "hb-subset-cff-common.hh" @@ -38,6 +39,353 @@ using namespace CFF; +namespace CFF { + +/* + * Partial instancing (some axes pinned or limited, others kept). + * + * This is a port of fontTools' instantiateCFF2 (fonttools/fonttools#3506), + * with one simplification: the variation-store instancing solver acts on + * regions independently of the per-blend delta values, so instead of lifting + * every blend's deltas into the store, instancing it, and reading the rows + * back, we instance each VarData once with identity delta rows. The + * instantiated tuples then give, per VarData, a fixed linear map from old + * per-region deltas to new per-region deltas. The contribution that folds + * into each blend's default value is the old store's region scalars + * evaluated at the new default location (plan->normalized_coords); the + * surviving rebased regions all evaluate to zero there. + * + * Use: create (), then note_use () for every blend the retained charstrings + * and private dicts hold, then finalize (); only VarDatas that are both + * still variable and actually used survive into the new store. + */ +struct cff2_instancing_plan_t +{ + struct vardata_transform_t + { + /* new_deltas[j] = Σ_i matrix[j][i] * old_deltas[i] */ + hb_vector_t> matrix; + /* Default-value fold-in scalars, one per old region: the old store's + * region scalars at the new default location. */ + hb_vector_t gains; + /* Surviving regions, parallel to matrix rows. */ + hb_vector_t> regions; + /* Index into the new global region list, per new region (finalize). */ + hb_vector_t region_indices; + unsigned new_major = 0; + bool alive_ = false; + bool alive () const { return alive_; } + + /* One value's delta for new region j, from its old per-region deltas. */ + double transform_delta (unsigned j, hb_array_t deltas) const + { + const hb_vector_t &col = matrix.arrayZ[j]; + double d = 0.; + unsigned count = hb_min (col.length, deltas.length); + for (unsigned c = 0; c < count; c++) + d += (double) col.arrayZ[c] * deltas.arrayZ[c].to_real (); + return d; + } + }; + + hb_vector_t transforms; /* per old VarData (vsindex) */ + hb_vector_t> new_regions; /* global region list */ + hb_set_t used_majors; + unsigned new_major_count = 0; + + bool has_variations () const { return new_major_count; } + + const vardata_transform_t *get_transform (unsigned major) const + { return major < transforms.length ? &transforms.arrayZ[major] : nullptr; } + + /* Record that a retained blend references this VarData. */ + void note_use (unsigned major) { used_majors.add (major); } + + /* The new vsindex a private dict's (or charstring's) old ivs maps to; + * dead VarDatas fall back to 0, their blends having become static. */ + unsigned remap_ivs (unsigned old_ivs) const + { + const vardata_transform_t *t = get_transform (old_ivs); + return (t && t->alive ()) ? t->new_major : 0; + } + + double fold_deltas (unsigned old_ivs, hb_array_t deltas) const + { + const vardata_transform_t *t = get_transform (old_ivs); + if (unlikely (!t || t->gains.length != deltas.length)) return 0.; + double v = 0.; + for (unsigned i = 0; i < deltas.length; i++) + v += (double) t->gains.arrayZ[i] * deltas.arrayZ[i].to_real (); + return v; + } + + bool create (const CFF2ItemVariationStore *cff2VarStore, + const hb_subset_plan_t *plan) + { + const OT::ItemVariationStore &varStore = cff2VarStore->varStore; + unsigned major_count = varStore.get_sub_table_count (); + if (!transforms.resize (major_count)) return false; + + if (!varStore.get_region_list ().get_var_regions (plan->axes_old_index_tag_map, orig_regions)) + return false; + + /* Instance each VarData with identity delta rows; the surviving tuples' + * delta columns are the old-region → new-region transform. */ + OT::optimize_scratch_t scratch; + for (unsigned m = 0; m < major_count; m++) + { + const OT::VarData &var_data = varStore.get_sub_table (m); + unsigned k = var_data.get_region_index_count (); + vardata_transform_t &t = transforms.arrayZ[m]; + + if (!t.gains.resize_exact (k)) return false; + varStore.get_region_scalars (m, plan->normalized_coords.arrayZ, + plan->normalized_coords.length, + t.gains.arrayZ, k); + + OT::tuple_variations_t tuples; + for (unsigned r = 0; r < k; r++) + { + OT::tuple_delta_t tuple; + if (!tuple.deltas_x.resize (k) || + !tuple.indices.resize (k)) + return false; + for (unsigned i = 0; i < k; i++) + tuple.indices.arrayZ[i] = true; + tuple.deltas_x.arrayZ[r] = 1.f; + unsigned region_index = var_data.get_region_index (r); + if (unlikely (region_index >= orig_regions.length)) return false; + tuple.axis_tuples = orig_regions.arrayZ[region_index]; + if (unlikely (tuple.axis_tuples.in_error ())) return false; + tuples.tuple_vars.push (std::move (tuple)); + } + if (unlikely (tuples.tuple_vars.in_error ())) return false; + + if (!tuples.instantiate (plan->axes_location, plan->axes_triple_distances, scratch)) + return false; + + for (auto &tuple : tuples.tuple_vars) + { + if (unlikely (tuple.deltas_x.length != k)) return false; + hb_vector_t col; + if (unlikely (!col.resize_exact (k))) return false; + for (unsigned i = 0; i < k; i++) + col.arrayZ[i] = tuple.deltas_x.arrayZ[i]; + t.matrix.push (std::move (col)); + t.regions.push (std::move (tuple.axis_tuples)); + } + if (unlikely (t.matrix.in_error () || t.regions.in_error ())) return false; + } + + return true; + } + + /* Decide which VarDatas survive, number them, and build the new global + * region list: surviving original regions first, in their original order, + * then solver-split new regions in order of appearance (fontTools' + * rebuildRegions + prune_regions). */ + bool finalize () + { + for (unsigned m = 0; m < transforms.length; m++) + { + vardata_transform_t &t = transforms.arrayZ[m]; + t.alive_ = t.matrix.length && used_majors.has (m); + if (t.alive_) + t.new_major = new_major_count++; + } + + /* Keys hash by content, so pointers into different owners compare fine. */ + hb_hashmap_t*, unsigned> region_idx_map; + hb_vector_t*> region_ptrs; + for (const vardata_transform_t &t : transforms) + { + if (!t.alive ()) continue; + for (const auto ®ion : t.regions) + if (!region_idx_map.has (®ion)) + if (unlikely (!region_idx_map.set (®ion, (unsigned) -1))) + return false; + } + for (const auto &r : orig_regions) + { + unsigned *idx; + if (region_idx_map.has (&r, &idx) && *idx == (unsigned) -1) + { + if (unlikely (!region_idx_map.set (&r, region_ptrs.length))) return false; + region_ptrs.push (&r); + } + } + for (const vardata_transform_t &t : transforms) + { + if (!t.alive ()) continue; + for (const auto ®ion : t.regions) + { + unsigned *idx; + if (region_idx_map.has (®ion, &idx) && *idx == (unsigned) -1) + { + if (unlikely (!region_idx_map.set (®ion, region_ptrs.length))) return false; + region_ptrs.push (®ion); + } + } + } + if (unlikely (region_ptrs.in_error ())) return false; + + for (vardata_transform_t &t : transforms) + { + if (!t.alive ()) continue; + for (const auto ®ion : t.regions) + { + unsigned *idx; + if (unlikely (!region_idx_map.has (®ion, &idx))) return false; + t.region_indices.push (*idx); + } + if (unlikely (t.region_indices.in_error ())) return false; + } + + if (!new_regions.resize (region_ptrs.length)) return false; + for (unsigned i = 0; i < region_ptrs.length; i++) + { + new_regions.arrayZ[i] = *region_ptrs.arrayZ[i]; + if (unlikely (new_regions.arrayZ[i].in_error ())) return false; + } + + return true; + } + + /* Serialize the instanced store: a CFF2ItemVariationStore whose VarDatas + * carry no items, just region indexes (blend deltas live in charstrings). + * Laid out manually since all sizes are known up front. */ + bool serialize_var_store (hb_serialize_context_t *c, + const hb_vector_t &axis_tags) const + { + unsigned data_count = new_major_count; + unsigned header_size = 2 + 4 + 2 + 4 * data_count; + + uint64_t offset = header_size; + hb_vector_t data_offsets; + for (const vardata_transform_t &t : transforms) + { + if (!t.alive ()) continue; + data_offsets.push ((unsigned) offset); + offset += 6 + 2 * (uint64_t) t.region_indices.length; + } + if (unlikely (data_offsets.in_error () || data_offsets.length != data_count)) + return false; + unsigned regions_offset = (unsigned) offset; + uint64_t total = offset + 4 + (uint64_t) new_regions.length * axis_tags.length * 6; + if (unlikely (total > 0xFFFFu)) return false; + + HBUINT16 *size_field = c->allocate_size (HBUINT16::static_size); + if (unlikely (!size_field)) return false; + *size_field = total; + + char *header = c->allocate_size (header_size); + if (unlikely (!header)) return false; + * (HBUINT16 *) (header + 0) = 1; /* format */ + * (HBUINT32 *) (header + 2) = regions_offset; + * (HBUINT16 *) (header + 6) = data_count; + for (unsigned i = 0; i < data_count; i++) + * (HBUINT32 *) (header + 8 + 4 * i) = data_offsets.arrayZ[i]; + + for (const vardata_transform_t &t : transforms) + { + if (!t.alive ()) continue; + unsigned k = t.region_indices.length; + HBUINT16 *v = (HBUINT16 *) c->allocate_size (6 + 2 * k); + if (unlikely (!v)) return false; + v[0] = 0; /* itemCount */ + v[1] = 0; /* wordSizeCount */ + v[2] = k; /* regionIndices.len */ + for (unsigned j = 0; j < k; j++) + v[3 + j] = t.region_indices.arrayZ[j]; + } + + hb_vector_t*> region_ptrs; + if (unlikely (!region_ptrs.alloc_exact (new_regions.length))) return false; + for (const auto &r : new_regions) + region_ptrs.push (&r); + auto *region_list = c->start_embed (); + return region_list->serialize (c, axis_tags, region_ptrs); + } + + private: + hb_vector_t> orig_regions; +}; + +/* Usage-collection pass for partial instancing: record which VarDatas the + * retained charstrings' and private dicts' blends reference. Mirrors the + * emission pass: blends consumed by dropped hint ops don't count. */ +struct cff2_usage_param_t +{ + void init () {} + + cff2_instancing_plan_t *instancing = nullptr; + bool drop_hints = false; + unsigned ivs = 0; /* dict-side current vsindex */ +}; + +struct cff2_cs_opset_usage_t : cff2_cs_opset_t +{ + static void flush_args_and_op (op_code_t op, cff2_cs_interp_env_t &env, cff2_usage_param_t& param) + { + bool counts = true; + switch (op) + { + case OpCode_return: + case OpCode_endchar: + counts = false; + break; + + case OpCode_hstem: + case OpCode_hstemhm: + case OpCode_vstem: + case OpCode_vstemhm: + case OpCode_hintmask: + case OpCode_cntrmask: + if (param.drop_hints) + counts = false; + break; + + default: + break; + } + + if (counts) + for (unsigned int i = 0; i < env.argStack.get_count (); i++) + if (env.argStack[i].blending ()) + { + param.instancing->note_use (env.get_ivs ()); + break; + } + + env.clear_args (); + } +}; + +struct cff2_private_dict_usage_opset_t : dict_opset_t +{ + static void process_op (op_code_t op, cff2_priv_dict_interp_env_t& env, cff2_usage_param_t& param) + { + switch (op) { + case OpCode_vsindexdict: + env.process_vsindex (); + param.ivs = env.get_ivs (); + env.clear_args (); + return; + case OpCode_blenddict: + param.instancing->note_use (param.ivs); + env.clear_args (); + return; + default: + dict_opset_t::process_op (op, env); + if (!env.argStack.is_empty ()) return; + env.clear_args (); + return; + } + } +}; + +} /* namespace CFF */ + struct cff2_sub_table_info_t : cff_sub_table_info_t { cff2_sub_table_info_t () @@ -129,6 +477,8 @@ struct cff2_cs_opset_flatten_t : cff2_cs_opset_t &env, flatten_param_t& param) + { + const cff2_instancing_plan_t &instancer = *param.instancer; + unsigned ivs = env.get_ivs (); + const cff2_instancing_plan_t::vardata_transform_t *t = instancer.get_transform (ivs); + if (unlikely (!t)) + { + env.set_error (); + return; + } + + unsigned n = arg.numValues; + for (unsigned int j = 0; j < n; j++) + { + const blend_arg_t &arg1 = env.argStack[i + j]; + if (unlikely (!(arg1.blending () && (arg1.numValues == n) && (arg1.valueIndex == j) && + (arg1.deltas.length == env.get_region_count ()) && + (arg1.deltas.length == t->gains.length)))) + { + env.set_error (); + return; + } + } + + str_encoder_t encoder (param.flatStr); + unsigned k_new = t->alive () ? t->matrix.length : 0; + + if (!k_new) + { + /* All of this VarData's regions died; blends dissolve into statics. */ + for (unsigned int j = 0; j < n; j++) + { + const blend_arg_t &arg1 = env.argStack[i + j]; + number_t v; + v.set_real (arg1.to_real () + round (instancer.fold_deltas (ivs, arg1.deltas.as_array ()))); + encoder.encode_num_cs (v); + } + return; + } + + /* Emit in chunks so the output charstring stays within the argument + * stack limit: values already emitted for this op, plus this chunk's + * defaults, deltas and count, must not exceed 513. */ + unsigned done = 0; + while (done < n) + { + unsigned avail = 512 > (i + done) ? 512 - (i + done) : 0; + unsigned chunk = hb_min (avail / (k_new + 1), n - done); + if (unlikely (!chunk)) + { + env.set_error (); + return; + } + + for (unsigned int j = done; j < done + chunk; j++) + { + const blend_arg_t &arg1 = env.argStack[i + j]; + number_t v; + v.set_real (arg1.to_real () + round (instancer.fold_deltas (ivs, arg1.deltas.as_array ()))); + encoder.encode_num_cs (v); + } + for (unsigned int j = done; j < done + chunk; j++) + { + const blend_arg_t &arg1 = env.argStack[i + j]; + for (unsigned r = 0; r < k_new; r++) + { + number_t v; + v.set_int ((int) round (t->transform_delta (r, arg1.deltas.as_array ()))); + encoder.encode_num_cs (v); + } + } + encoder.encode_int (chunk); + encoder.encode_op (OpCode_blendcs); + done += chunk; + } + param.emitted_blend = true; + } + + /* Partial instancing: prepend a vsindex op when the charstring's + * (remapped) ivs differs from its FD's (remapped) private-dict ivs. */ + static void emit_vsindex_prefix (cff2_cs_interp_env_t &env, flatten_param_t& param) + { + if (!param.emitted_blend) return; + const cff2_instancing_plan_t &instancer = *param.instancer; + unsigned new_ivs = instancer.remap_ivs (env.get_ivs ()); + unsigned fd_ivs = instancer.remap_ivs (env.get_orig_ivs ()); + if (new_ivs == fd_ivs) return; + + str_buff_t prefix; + str_encoder_t enc (prefix); + enc.encode_int ((int) new_ivs); + enc.encode_op (OpCode_vsindexcs); + + str_buff_t &buf = param.flatStr; + unsigned old_len = buf.length; + if (unlikely (prefix.in_error () || !buf.resize (old_len + prefix.length))) + { + env.set_error (); + return; + } + memmove (buf.arrayZ + prefix.length, buf.arrayZ, old_len); + hb_memcpy (buf.arrayZ, prefix.arrayZ, prefix.length); + } + static void flush_op (op_code_t op, cff2_cs_interp_env_t &env, flatten_param_t& param) { switch (op) @@ -326,7 +786,12 @@ struct cff2_private_blend_encoder_param_t if (!seen_blend) { region_count = varStore->varStore.get_region_index_count (ivs); - scalars.resize_exact (region_count); + if (unlikely (!scalars.resize_exact (region_count))) + { + if (c) c->err (HB_SERIALIZE_ERROR_OTHER); + seen_blend = true; + return; + } varStore->varStore.get_region_scalars (ivs, normalized_coords.arrayZ, normalized_coords.length, &scalars[0], region_count); seen_blend = true; @@ -353,6 +818,13 @@ struct cff2_private_blend_encoder_param_t hb_vector_t scalars; const CFF2ItemVariationStore *varStore = nullptr; hb_array_t normalized_coords; + + /* CFF2 partial instancing: when set, blends are rewritten against the + * instanced variation store instead of being flattened. */ + const cff2_instancing_plan_t *instancer = nullptr; + /* Error-compensated fold rounding state, per dict operator. */ + double fold_exact = 0.; + double fold_emitted = 0.; }; struct cff2_private_dict_blend_opset_t : dict_opset_t @@ -365,6 +837,98 @@ struct cff2_private_dict_blend_opset_t : dict_opset_t arg.set_int (round (arg.to_real () + param.blend_deltas (blends))); } + /* The fold added to a value, error-compensated across the operator: most + * blended private-dict values (BlueValues, StemSnap*, ...) are + * delta-encoded, so independently rounded folds would accumulate in the + * decoded absolutes; keeping the emitted cumulative fold equal to the + * rounded exact cumulative fold bounds every absolute within ±0.5. */ + static double fold (cff2_private_blend_encoder_param_t& param, + const hb_array_t blends) + { + double f = param.blend_deltas (blends); + double emit = round (param.fold_exact + f) - param.fold_emitted; + param.fold_exact += f; + param.fold_emitted += emit; + return emit; + } + + /* Partial instancing: emit the args preceding this blend group, then the + * group itself rewritten against the instanced store, and clear the + * stack. The op's remaining args are flushed at process_op time. */ + static void rewrite_blends (cff2_priv_dict_interp_env_t& env, + cff2_private_blend_encoder_param_t& param, + unsigned start, unsigned n, unsigned k) + { + const cff2_instancing_plan_t &instancer = *param.instancer; + const cff2_instancing_plan_t::vardata_transform_t *t = instancer.get_transform (param.ivs); + if (unlikely (!t || t->gains.length != k)) + { + env.set_error (); + return; + } + + str_buff_t str; + str_encoder_t encoder (str); + + for (unsigned idx = 0; idx < start; idx++) + encoder.encode_num_tp (env.argStack[idx]); + + unsigned k_new = t->alive () ? t->matrix.length : 0; + if (!k_new) + { + /* This VarData died (or is unused by any retained charstring, which + * can happen for FDs kept only for retain-gids holes); blends + * dissolve into statics. */ + for (unsigned j = 0; j < n; j++) + { + const hb_array_t blends = env.argStack.sub_array (start + n + (j * k), k); + number_t v; + v.set_real (env.argStack[start + j].to_real () + fold (param, blends)); + encoder.encode_num_tp (v); + } + } + else + { + unsigned done = 0; + while (done < n) + { + unsigned avail = 512 > (start + done) ? 512 - (start + done) : 0; + unsigned chunk = hb_min (avail / (k_new + 1), n - done); + if (unlikely (!chunk)) + { + env.set_error (); + return; + } + + for (unsigned j = done; j < done + chunk; j++) + { + const hb_array_t blends = env.argStack.sub_array (start + n + (j * k), k); + number_t v; + v.set_real (env.argStack[start + j].to_real () + fold (param, blends)); + encoder.encode_num_tp (v); + } + for (unsigned j = done; j < done + chunk; j++) + { + const hb_array_t blends = env.argStack.sub_array (start + n + (j * k), k); + for (unsigned r = 0; r < k_new; r++) + { + number_t v; + v.set_int ((int) round (t->transform_delta (r, blends))); + encoder.encode_num_tp (v); + } + } + encoder.encode_int (chunk); + encoder.encode_op (OpCode_blenddict); + done += chunk; + } + } + + auto bytes = str.as_bytes (); + param.c->embed (&bytes, bytes.length); + + env.clear_args (); + } + static void process_blend (cff2_priv_dict_interp_env_t& env, cff2_private_blend_encoder_param_t& param) { unsigned int n, k; @@ -380,6 +944,13 @@ struct cff2_private_dict_blend_opset_t : dict_opset_t env.set_error (); return; } + + if (param.instancer && k) + { + rewrite_blends (env, param, start, n, k); + return; + } + for (unsigned int i = 0; i < n; i++) { const hb_array_t blends = env.argStack.sub_array (start + n + (i * k), k); @@ -410,6 +981,20 @@ struct cff2_private_dict_blend_opset_t : dict_opset_t case OpCode_vsindexdict: env.process_vsindex (); param.ivs = env.get_ivs (); + if (param.instancer) + { + /* Re-emit with the remapped vsindex; 0 is the dict default. */ + unsigned new_ivs = param.instancer->remap_ivs (param.ivs); + if (new_ivs) + { + str_buff_t str; + str_encoder_t encoder (str); + encoder.encode_int ((int) new_ivs); + encoder.encode_op (OpCode_vsindexdict); + auto bytes = str.as_bytes (); + param.c->embed (&bytes, bytes.length); + } + } env.clear_args (); return; case OpCode_blenddict: @@ -439,6 +1024,7 @@ struct cff2_private_dict_blend_opset_t : dict_opset_t param.c->embed (&bytes, bytes.length); env.clear_args (); + param.fold_exact = param.fold_emitted = 0.; } }; @@ -446,9 +1032,11 @@ struct cff2_private_dict_op_serializer_t : op_serializer_t { cff2_private_dict_op_serializer_t (bool desubroutinize_, bool drop_hints_, bool pinned_, const CFF::CFF2ItemVariationStore* varStore_, - hb_array_t normalized_coords_) + hb_array_t normalized_coords_, + const cff2_instancing_plan_t *instancer_ = nullptr) : desubroutinize (desubroutinize_), drop_hints (drop_hints_), pinned (pinned_), - varStore (varStore_), normalized_coords (normalized_coords_) {} + param (nullptr, varStore_, normalized_coords_) + { param.instancer = instancer_; } bool serialize (hb_serialize_context_t *c, const op_str_t &opstr, @@ -467,11 +1055,13 @@ struct cff2_private_dict_op_serializer_t : op_serializer_t return_trace (FontDict::serialize_link2_op (c, opstr.op, subrs_link)); } - if (pinned) + if (pinned || param.instancer) { - // Reinterpret opstr and process blends. + /* Reinterpret opstr and process blends. The param persists across + * this dict's opstrs, so that an ivs set by a vsindexdict opstr is + * still in effect when a later opstr's blends are processed. */ cff2_priv_dict_interp_env_t env {hb_ubytes_t (opstr.ptr, opstr.length)}; - cff2_private_blend_encoder_param_t param (c, varStore, normalized_coords); + param.c = c; dict_interpreter_t interp (env); return_trace (interp.interpret (param)); } @@ -483,11 +1073,11 @@ struct cff2_private_dict_op_serializer_t : op_serializer_t const bool desubroutinize; const bool drop_hints; const bool pinned; - const CFF::CFF2ItemVariationStore* varStore; - hb_array_t normalized_coords; + mutable cff2_private_blend_encoder_param_t param; }; + namespace OT { struct cff2_subset_plan { @@ -502,12 +1092,21 @@ struct cff2_subset_plan orig_fdcount = acc.fdArray->count; drop_hints = plan->flags & HB_SUBSET_FLAGS_NO_HINTING; - pinned = (bool) plan->normalized_coords; + bool instancing_requested = (bool) plan->normalized_coords; + pinned = instancing_requested && plan->all_axes_pinned; normalized_coords = plan->normalized_coords; head_maxp_info = plan->head_maxp_info; hmtx_map = &plan->hmtx_map; desubroutinize = plan->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE || - pinned; // For instancing we need this path + instancing_requested; // For instancing we need this path + + /* Partial instancing: some axes pinned or limited, others kept. */ + partial_instancing = instancing_requested && !pinned && + acc.varStore != &Null (CFF2ItemVariationStore); + if (partial_instancing && + unlikely (!instancing.create (acc.varStore, plan))) + return false; + axis_tags = &plan->axis_tags; /* Enable command capture for CFF2→CFF1 conversion (for specialization) */ capture_commands = pinned; @@ -520,6 +1119,77 @@ struct cff2_subset_plan if (desubroutinize) { + if (partial_instancing) + { + /* Pass 1: collect which VarDatas the retained blends reference, so + * unused ones get pruned and the survivors renumbered. */ + hb_set_t used_fds; + for (unsigned int i = 0; i < num_glyphs; i++) + { + hb_codepoint_t glyph; + if (!plan->old_gid_for_new_gid (i, &glyph)) + continue; + const hb_ubytes_t str = (*acc.charStrings)[glyph]; + unsigned int fd = acc.fdSelect->get_fd (glyph); + if (unlikely (fd >= acc.fdCount)) + return false; + used_fds.add (fd); + + cff2_cs_interp_env_t env (str, acc, fd); + cs_interpreter_t, cff2_cs_opset_usage_t, cff2_usage_param_t> interp (env); + cff2_usage_param_t param; + param.instancing = &instancing; + param.drop_hints = drop_hints; + if (unlikely (!interp.interpret (param))) + return false; + } + for (unsigned fd : used_fds) + { + cff2_usage_param_t param; + param.instancing = &instancing; + unsigned count = acc.privateDicts[fd].get_count (); + for (unsigned j = 0; j < count; j++) + { + const op_str_t &opstr = acc.privateDicts[fd][j]; + if (drop_hints && dict_opset_t::is_hint_op (opstr.op)) + continue; + cff2_priv_dict_interp_env_t env {hb_ubytes_t (opstr.ptr, opstr.length)}; + dict_interpreter_t interp (env); + if (unlikely (!interp.interpret (param))) + return false; + } + } + if (unlikely (!instancing.finalize ())) + return false; + + /* Pass 2: like subr_flattener_t, but blends stay symbolic (no coords + * fed to the env) and get rewritten against the instanced store. */ + if (!subset_charstrings.resize_exact (num_glyphs)) + return false; + for (unsigned int i = 0; i < num_glyphs; i++) + { + hb_codepoint_t glyph; + if (!plan->old_gid_for_new_gid (i, &glyph)) + continue; + const hb_ubytes_t str = (*acc.charStrings)[glyph]; + unsigned int fd = acc.fdSelect->get_fd (glyph); + if (unlikely (fd >= acc.fdCount)) + return false; + + cff2_cs_interp_env_t env (str, acc, fd); + cs_interpreter_t, cff2_cs_opset_flatten_t, flatten_param_t> interp (env); + flatten_param_t param = { + subset_charstrings.arrayZ[i], + (bool) (plan->flags & HB_SUBSET_FLAGS_NO_HINTING), + plan + }; + param.instancer = &instancing; + if (unlikely (!interp.interpret (param))) + return false; + } + } + else + { /* Flatten global & local subrs */ subr_flattener_t, cff2_cs_opset_flatten_t> flattener(acc, plan); @@ -538,6 +1208,7 @@ struct cff2_subset_plan if (!flattener.flatten (subset_charstrings)) return false; } + } } else { @@ -603,6 +1274,10 @@ struct cff2_subset_plan bool drop_hints = false; bool desubroutinize = false; + bool partial_instancing = false; + cff2_instancing_plan_t instancing; + const hb_vector_t *axis_tags = nullptr; + unsigned min_charstrings_off_size = 0; hb_array_t normalized_coords; // For instantiation @@ -1138,7 +1813,8 @@ OT::cff2::accelerator_subset_t::serialize (hb_serialize_context_t *c, } auto *pd = c->push (); cff2_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints, plan.pinned, - varStore, normalized_coords); + varStore, normalized_coords, + plan.partial_instancing ? &plan.instancing : nullptr); if (likely (pd->serialize (c, privateDicts[i], privSzr, subrs_link))) { unsigned fd = plan.fdmap[i]; @@ -1191,13 +1867,30 @@ OT::cff2::accelerator_subset_t::serialize (hb_serialize_context_t *c, if (varStore != &Null (CFF2ItemVariationStore) && !plan.pinned) { - auto *dest = c->push (); - if (unlikely (!dest->serialize (c, varStore))) + if (plan.partial_instancing) { - c->pop_discard (); - return false; + if (plan.instancing.has_variations ()) + { + c->push (); + if (unlikely (!plan.instancing.serialize_var_store (c, *plan.axis_tags))) + { + c->pop_discard (); + return false; + } + plan.info.var_store_link = c->pop_pack (false); + } + /* else: the store emptied; the vstore op gets dropped along with it. */ + } + else + { + auto *dest = c->push (); + if (unlikely (!dest->serialize (c, varStore))) + { + c->pop_discard (); + return false; + } + plan.info.var_store_link = c->pop_pack (false); } - plan.info.var_store_link = c->pop_pack (false); } OT::cff2 *cff2 = c->allocate_min (); diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 12d3c36e3..117a45fec 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -426,8 +426,7 @@ hb_subset_input_keep_everything (hb_subset_input_t *input) * * Pin all axes to default locations in the given subset input object. * - * All axes in a font must be pinned. Additionally, `CFF2` table, if present, - * will be de-subroutinized. + * The `CFF2` table, if present, will be de-subroutinized. * * Return value: `true` if success, `false` otherwise * @@ -467,8 +466,7 @@ hb_subset_input_pin_all_axes_to_default (hb_subset_input_t *input, * * Pin an axis to its default location in the given subset input object. * - * All axes in a font must be pinned. Additionally, `CFF2` table, if present, - * will be de-subroutinized. + * The `CFF2` table, if present, will be de-subroutinized. * * Return value: `true` if success, `false` otherwise * @@ -496,8 +494,7 @@ hb_subset_input_pin_axis_to_default (hb_subset_input_t *input, * * Pin an axis to a fixed location in the given subset input object. * - * All axes in a font must be pinned. Additionally, `CFF2` table, if present, - * will be de-subroutinized. + * The `CFF2` table, if present, will be de-subroutinized. * * Return value: `true` if success, `false` otherwise * @@ -737,6 +734,376 @@ hb_subset_axis_range_to_string (hb_subset_input_t *input, } #endif +#ifdef HB_EXPERIMENTAL_API +static void +_append_arg (hb_vector_t &sb, const char *arg) +{ + if (sb.in_error ()) return; + if (sb.length) + sb.push (' '); + unsigned len = strlen (arg); + sb.extend (hb_bytes_t (arg, len)); +} +static void +_format_number_set (const hb_set_t *set, hb_vector_t &out, unsigned base = 10) +{ + assert (base == 10 || base == 16); + if (unlikely (base != 10 && base != 16)) return; + + hb_codepoint_t first = HB_SET_VALUE_INVALID, last = HB_SET_VALUE_INVALID; + bool first_range = true; + while (hb_set_next_range (set, &first, &last)) + { + if (!first_range) + out.push (','); + first_range = false; + + char buf[64]; + int len; + if (first == last) + { + if (base == 16) + len = snprintf (buf, sizeof (buf), "%X", first); + else + len = snprintf (buf, sizeof (buf), "%u", first); + } + else + { + if (base == 16) + len = snprintf (buf, sizeof (buf), "%X-%X", first, last); + else + len = snprintf (buf, sizeof (buf), "%u-%u", first, last); + } + if (unlikely (len < 0 || (size_t) len >= sizeof (buf))) return; + out.extend (hb_bytes_t (buf, len)); + } +} + +static void +_format_tag (hb_tag_t tag, hb_vector_t &out) +{ + char buf[4]; + hb_tag_to_string (tag, buf); + + unsigned len = 4; + while (len > 0 && buf[len - 1] == ' ') + len--; + + for (unsigned i = 0; i < len; i++) + { + char c = buf[i]; + if (!((c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9') || + c == '-' || c == '_')) + { + c = '_'; + } + out.push (c); + } +} + +static void +_format_tag_set (const hb_set_t *set, hb_vector_t &out) +{ + hb_codepoint_t tag = HB_SET_VALUE_INVALID; + bool first_tag = true; + while (hb_set_next (set, &tag)) + { + if (!first_tag) + out.push (','); + first_tag = false; + + _format_tag (tag, out); + } +} + +static bool +_is_set_default (const hb_set_t *set, const hb_set_t *default_set) +{ + return hb_set_is_inverted (set) == hb_set_is_inverted (default_set) && + hb_set_is_equal (set, default_set); +} + +template +static void +_format_set_arg (const hb_set_t *set, + const char *opt_name, + Formatter &&formatter, + hb_vector_t &sb) +{ + if (hb_set_is_inverted (set)) + { + hb_set_t *excluded = hb_set_copy (set); + hb_set_invert (excluded); + + hb_vector_t opt; + opt.extend (hb_bytes_t ("--", 2)); + opt.extend (hb_bytes_t (opt_name, strlen (opt_name))); + opt.extend (hb_bytes_t ("=*", 2)); + opt.push ('\0'); + if (opt.arrayZ) _append_arg (sb, opt.arrayZ); + + if (!hb_set_is_empty (excluded)) + { + hb_vector_t formatted; + formatter (excluded, formatted); + if (formatted.length) + { + hb_vector_t opt2; + opt2.extend (hb_bytes_t ("--", 2)); + opt2.extend (hb_bytes_t (opt_name, strlen (opt_name))); + opt2.extend (hb_bytes_t ("-=", 2)); + opt2.extend (formatted.as_array ()); + opt2.push ('\0'); + if (opt2.arrayZ) _append_arg (sb, opt2.arrayZ); + } + } + hb_set_destroy (excluded); + } + else if (hb_set_is_empty (set)) + { + hb_vector_t opt; + opt.extend (hb_bytes_t ("--", 2)); + opt.extend (hb_bytes_t (opt_name, strlen (opt_name))); + opt.extend (hb_bytes_t ("-=*", 3)); + opt.push ('\0'); + if (opt.arrayZ) _append_arg (sb, opt.arrayZ); + } + else + { + hb_vector_t formatted; + formatter (set, formatted); + if (formatted.length) + { + hb_vector_t opt; + opt.extend (hb_bytes_t ("--", 2)); + opt.extend (hb_bytes_t (opt_name, strlen (opt_name))); + opt.extend (hb_bytes_t ("=", 1)); + opt.extend (formatted.as_array ()); + opt.push ('\0'); + if (opt.arrayZ) _append_arg (sb, opt.arrayZ); + } + } +} + +static void +_format_number_set_arg (const hb_set_t *set, + const char *opt_name, + hb_vector_t &sb, + unsigned base = 10) +{ + _format_set_arg (set, opt_name, [base] (const hb_set_t *s, hb_vector_t &out) { + _format_number_set (s, out, base); + }, sb); +} + +static void +_format_tag_set_arg (const hb_set_t *set, + const char *opt_name, + hb_vector_t &sb) +{ + _format_set_arg (set, opt_name, _format_tag_set, sb); +} + +static bool +_format_glyph_map_arg (const hb_map_t &glyph_map, + hb_vector_t &sb) +{ + if (glyph_map.is_empty ()) + return true; + + hb_set_t keys; + hb_map_keys (&glyph_map, &keys); + hb_vector_t pairs; + hb_codepoint_t key = HB_SET_VALUE_INVALID; + bool first = true; + while (hb_set_next (&keys, &key)) + { + if (!first) + pairs.push (','); + first = false; + hb_codepoint_t val = hb_map_get (&glyph_map, key); + char buf[64]; + int len = snprintf (buf, sizeof (buf), "%u:%u", key, val); + if (unlikely (len < 0 || (size_t) len >= sizeof (buf))) return false; + pairs.extend (hb_bytes_t (buf, len)); + } + if (pairs.length) + { + hb_vector_t opt; + opt.extend (hb_bytes_t ("--gid-map=", 10)); + opt.extend (pairs.as_array ()); + opt.push ('\0'); + if (opt.arrayZ) _append_arg (sb, opt.arrayZ); + } + return true; +} + +static bool +_format_axes_location_arg (const hb_hashmap_t &axes_location, + hb_vector_t &sb) +{ + if (axes_location.is_empty ()) + return true; + + hb_vector_t axis_tags; + for (auto tag : axes_location.keys ()) + axis_tags.push (tag); + axis_tags.qsort ([] (const hb_tag_t &a, const hb_tag_t &b) { return a < b ? -1 : a > b ? 1 : 0; }); + + hb_vector_t specs; + bool first = true; + for (hb_tag_t tag : axis_tags) + { + Triple triple = axes_location.get (tag); + if (!first) + specs.push (','); + first = false; + + hb_vector_t tag_buf; + _format_tag (tag, tag_buf); + + char buf[128]; + int len; + if (triple.minimum == triple.middle && triple.middle == triple.maximum) + { + len = snprintf (buf, sizeof (buf), "%.*s=%g", (int) tag_buf.length, tag_buf.arrayZ, (double) triple.middle); + } + else if (std::isnan (triple.minimum) && std::isnan (triple.middle) && std::isnan (triple.maximum)) + { + len = snprintf (buf, sizeof (buf), "%.*s=drop", (int) tag_buf.length, tag_buf.arrayZ); + } + else + { + len = snprintf (buf, sizeof (buf), "%.*s=%g:%g:%g", (int) tag_buf.length, tag_buf.arrayZ, + (double) triple.minimum, (double) triple.middle, (double) triple.maximum); + } + if (unlikely (len < 0 || (size_t) len >= sizeof (buf))) return false; + specs.extend (hb_bytes_t (buf, len)); + } + if (specs.length) + { + hb_vector_t opt; + opt.extend (hb_bytes_t ("--variations=", 13)); + opt.extend (specs.as_array ()); + opt.push ('\0'); + if (opt.arrayZ) _append_arg (sb, opt.arrayZ); + } + return true; +} + +/** + * hb_subset_input_to_string_or_fail: + * @input: a #hb_subset_input_t object. + * + * Produces a command line string representation of the given subset input + * suitable for use with the `hb-subset` command line tool. + * + * Return value: (transfer full): A new #hb_blob_t containing the command line + * string, or `NULL` if failed. Destroy with hb_blob_destroy(). + * + * XSince: EXPERIMENTAL + **/ +hb_blob_t * +hb_subset_input_to_string_or_fail (hb_subset_input_t *input) +{ + if (unlikely (!input || input->in_error ())) + return nullptr; + + hb_vector_t sb; + + struct flag_option_t { + hb_subset_flags_t flag; + char option[32]; + }; + static const flag_option_t flag_options[] = { + { HB_SUBSET_FLAGS_NO_HINTING, "no-hinting" }, + { HB_SUBSET_FLAGS_RETAIN_GIDS, "retain-gids" }, + { HB_SUBSET_FLAGS_DESUBROUTINIZE, "desubroutinize" }, + { HB_SUBSET_FLAGS_NAME_LEGACY, "name-legacy" }, + { HB_SUBSET_FLAGS_SET_OVERLAPS_FLAG, "set-overlaps-flag" }, + { HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED, "passthrough-tables" }, + { HB_SUBSET_FLAGS_NOTDEF_OUTLINE, "notdef-outline" }, + { HB_SUBSET_FLAGS_GLYPH_NAMES, "glyph-names" }, + { HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES, "no-prune-unicode-ranges" }, + { HB_SUBSET_FLAGS_NO_LAYOUT_CLOSURE, "no-layout-closure" }, + { HB_SUBSET_FLAGS_OPTIMIZE_IUP_DELTAS, "optimize" }, + { HB_SUBSET_FLAGS_NO_BIDI_CLOSURE, "no-bidi-closure" }, +#ifdef HB_EXPERIMENTAL_API + { HB_SUBSET_FLAGS_IFTB_REQUIREMENTS, "iftb-requirements" }, + { HB_SUBSET_FLAGS_RETAIN_NUM_GLYPHS, "retain-num-glyphs" }, +#endif + { HB_SUBSET_FLAGS_DOWNGRADE_CFF2, "downgrade-cff2" }, + }; + +#ifdef HB_EXPERIMENTAL_API + static_assert (sizeof (flag_options) / sizeof (flag_options[0]) == 15, + "Check all flags in hb_subset_flags_t are handled here."); +#else + static_assert (sizeof (flag_options) / sizeof (flag_options[0]) == 13, + "Check all flags in hb_subset_flags_t are handled here."); +#endif + + for (const auto &fo : flag_options) + { + if (input->flags & fo.flag) + { + char buf[36]; + snprintf (buf, sizeof (buf), "--%s", fo.option); + _append_arg (sb, buf); + } + } + + hb_subset_input_t *default_input = hb_subset_input_create_or_fail (); + if (unlikely (!default_input)) + return nullptr; + + // Serialize all sets if they are not equal to their default setting: +#define PROCESS_NUMBER_SET(field, opt_name, ...) \ + if (!_is_set_default (input->sets.field, default_input->sets.field)) \ + _format_number_set_arg (input->sets.field, opt_name, sb, ##__VA_ARGS__) + +#define PROCESS_TAG_SET(field, opt_name) \ + if (!_is_set_default (input->sets.field, default_input->sets.field)) \ + _format_tag_set_arg (input->sets.field, opt_name, sb) + + PROCESS_NUMBER_SET (unicodes, "unicodes", 16); + PROCESS_NUMBER_SET (glyphs, "gids"); + PROCESS_NUMBER_SET (name_ids, "name-IDs"); + PROCESS_NUMBER_SET (name_languages, "name-languages"); + PROCESS_TAG_SET (layout_features, "layout-features"); + PROCESS_TAG_SET (layout_scripts, "layout-scripts"); + PROCESS_TAG_SET (drop_tables, "drop-tables"); + PROCESS_TAG_SET (no_subset_tables, "passthrough-tables"); + +#undef PROCESS_NUMBER_SET +#undef PROCESS_TAG_SET + + hb_subset_input_destroy (default_input); + + static_assert (sizeof (input->sets) / sizeof (hb_set_t*) == 8, + "Check all sets in hb_subset_input_t::sets_t are handled here."); + + if (unlikely (!_format_glyph_map_arg (input->glyph_map, sb))) + return nullptr; + + if (unlikely (!_format_axes_location_arg (input->axes_location, sb))) + return nullptr; + + sb.push ('\0'); + if (unlikely (sb.in_error ())) + return nullptr; + + unsigned len = 0; + char *buf = sb.steal (&len); + if (unlikely (!buf)) + return nullptr; + + return hb_blob_create_or_fail (buf, len, HB_MEMORY_MODE_WRITABLE, buf, hb_free); +} +#endif + /** * hb_subset_preprocess: * @source: a #hb_face_t object. diff --git a/src/hb-subset-plan-member-list.hh b/src/hb-subset-plan-member-list.hh index 398fe81ec..d91edba9d 100644 --- a/src/hb-subset-plan-member-list.hh +++ b/src/hb-subset-plan-member-list.hh @@ -65,6 +65,7 @@ HB_SUBSET_PLAN_MEMBER (hb_set_t, _glyphset) HB_SUBSET_PLAN_MEMBER (hb_set_t, _glyphset_gsub) HB_SUBSET_PLAN_MEMBER (hb_set_t, _glyphset_mathed) HB_SUBSET_PLAN_MEMBER (hb_set_t, _glyphset_colred) +HB_SUBSET_PLAN_MEMBER (hb_set_t, _glyphset_cmaped) //active lookups we'd like to retain HB_SUBSET_PLAN_MEMBER (hb_map_t, gsub_lookups) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index b1325dd2e..02f891a14 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -451,6 +451,14 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, plan->_glyphset_gsub.add (0); // Not-def _cmap_closure (plan->source, &plan->unicodes, &plan->_glyphset_gsub); + plan->_glyphset_cmaped = plan->_glyphset_gsub; + + if (!drop_tables->has (HB_OT_TAG_MATH)) + { + _math_closure (plan, &plan->_glyphset_gsub); + _remove_invalid_gids (&plan->_glyphset_gsub, plan->source->get_num_glyphs ()); + } + plan->_glyphset_mathed = plan->_glyphset_gsub; #ifndef HB_NO_SUBSET_LAYOUT layout_populate_gids_to_retain(plan, drop_tables); @@ -458,14 +466,7 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, _remove_invalid_gids (&plan->_glyphset_gsub, plan->source->get_num_glyphs ()); - plan->_glyphset_mathed = plan->_glyphset_gsub; - if (!drop_tables->has (HB_OT_TAG_MATH)) - { - _math_closure (plan, &plan->_glyphset_mathed); - _remove_invalid_gids (&plan->_glyphset_mathed, plan->source->get_num_glyphs ()); - } - - hb_set_t cur_glyphset = plan->_glyphset_mathed; + hb_set_t cur_glyphset = plan->_glyphset_gsub; if (!drop_tables->has (HB_OT_TAG_COLR)) { _colr_closure (plan, &cur_glyphset); diff --git a/src/hb-subset-serialize.h b/src/hb-subset-serialize.h index 075d132ef..c906eaed5 100644 --- a/src/hb-subset-serialize.h +++ b/src/hb-subset-serialize.h @@ -27,11 +27,7 @@ #define HB_SUBSET_SERIALIZE_H #if !defined(HB_SUBSET_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR) -#if defined(__GNUC__) || defined(__clang__) #warning "Include instead." -#elif defined(_MSC_VER) -#pragma message("Include instead.") -#endif #endif #include "hb.h" diff --git a/src/hb-subset.h b/src/hb-subset.h index 2f108873f..c74ce5439 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -32,6 +32,7 @@ #include "hb-ot.h" #include "hb-subset-serialize.h" #include "hb-subset-depend.h" +#include "hb-subset-serialize.h" #undef HB_SUBSET_H_IN @@ -89,9 +90,12 @@ typedef struct hb_subset_plan_t hb_subset_plan_t; * HB_SUBSET_FLAGS_RETAIN_GIDS then the number of glyphs in the font won't * be reduced as a result of subsetting. If necessary empty glyphs will be * included at the end of the font to keep the number of glyphs unchanged. - * @HB_SUBSET_FLAGS_DOWNGRADE_CFF2: If set and instantiating a variable font, - * convert the output CFF2 table to CFF1. This enables compatibility with older - * renderers that don't support CFF2. Since: 13.0.0 + * @HB_SUBSET_FLAGS_DOWNGRADE_CFF2: If set and instantiating a variable font + * with all axes pinned, convert the output CFF2 table to CFF1. This enables + * compatibility with older renderers that don't support CFF2. Since: 13.0.0 + * @HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET: If set and subsetting a CID-keyed CFF + * font, the output CFF charset will use sequential identity CIDs (CID = new + * GID) rather than preserving the original CIDs. XSince: REPLACEME * * List of boolean properties that can be configured on the subset input. * @@ -116,6 +120,7 @@ typedef enum { /*< flags >*/ HB_SUBSET_FLAGS_RETAIN_NUM_GLYPHS = 0x00002000u, #endif HB_SUBSET_FLAGS_DOWNGRADE_CFF2 = 0x00004000u, + HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET = 0x00008000u, } hb_subset_flags_t; /** @@ -233,6 +238,9 @@ hb_subset_axis_range_to_string (hb_subset_input_t *input, unsigned size); #ifdef HB_EXPERIMENTAL_API +HB_EXTERN hb_blob_t * +hb_subset_input_to_string_or_fail (hb_subset_input_t *input); + HB_EXTERN hb_bool_t hb_subset_input_override_name_table (hb_subset_input_t *input, hb_ot_name_id_t name_id, diff --git a/src/hb-vector-buf.hh b/src/hb-vector-buf.hh index 543cbddd7..5b2321dec 100644 --- a/src/hb-vector-buf.hh +++ b/src/hb-vector-buf.hh @@ -155,10 +155,13 @@ struct hb_vector_buf_t : hb_vector_t bool append_base64 (const uint8_t *data, unsigned len) { - unsigned out_len = ((len + 2) / 3) * 4; + /* Output is 4 bytes per 3 input bytes; compute without overflowing. */ + unsigned ngroups = len / 3 + (len % 3 != 0); + unsigned out_len; unsigned old_len = length; unsigned new_len; - if (unlikely (hb_unsigned_add_overflows (old_len, out_len, &new_len) || + if (unlikely (hb_unsigned_mul_overflows (ngroups, 4, &out_len) || + hb_unsigned_add_overflows (old_len, out_len, &new_len) || !resize_dirty ((int) new_len))) return false; diff --git a/src/hb-vector-paint-pdf.cc b/src/hb-vector-paint-pdf.cc index 1acf72f9e..a9f365777 100644 --- a/src/hb-vector-paint-pdf.cc +++ b/src/hb-vector-paint-pdf.cc @@ -392,6 +392,58 @@ hb_pdf_paint_pop_transform (hb_paint_funcs_t *, paint->current_body ().append_str ("Q\n"); } +static void +hb_pdf_paint_fill_glyph (hb_paint_funcs_t *, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t, + hb_color_t c, + void *) +{ + auto *paint = (hb_vector_paint_t *) paint_data; + if (unlikely (!paint->ensure_initialized ())) + return; + + float r = hb_color_get_red (c) / 255.f; + float g = hb_color_get_green (c) / 255.f; + float b = hb_color_get_blue (c) / 255.f; + float a = hb_color_get_alpha (c) / 255.f; + + if (a < 1.f / 255.f) + return; + + auto &body = paint->current_body (); + + bool scoped = false; + /* Set alpha via ExtGState if needed, scoped so it does not leak + * into later paints. */ + if (a < 1.f - 1.f / 512.f) + { + auto *res = hb_pdf_get_resources (paint); + if (res) + { + unsigned gs_idx = res->add_extgstate_alpha (a); + body.append_str ("q\n"); + scoped = true; + body.append_str ("/GS"); + body.append_unsigned (gs_idx); + body.append_str (" gs\n"); + } + } + + body.append_num (r, 4); + body.append_c (' '); + body.append_num (g, 4); + body.append_c (' '); + body.append_num (b, 4); + body.append_str (" rg\n"); + hb_pdf_emit_glyph_path (paint, font, glyph, &body); + body.append_str ("f\n"); + if (scoped) + body.append_str ("Q\n"); +} + static void hb_pdf_paint_push_clip_glyph (hb_paint_funcs_t *, void *paint_data, @@ -546,8 +598,19 @@ hb_pdf_build_indexed_smask (hb_vector_buf_t *out, (void) width; (void) height; (void) trns; (void) trns_len; return false; #else + /* Guard the size arithmetic below against 32-bit overflow. width/height come + * from the attacker-controlled PNG IHDR; without this, (width + 1) * height or + * width * height can wrap and under-size buffers that are then indexed per + * pixel (raw + y * (width + 1), out->arrayZ[y * width + x]). */ + unsigned raw_len, mask_len; + if (!width || !height || + width == 0xFFFFFFFFu || + hb_unsigned_mul_overflows (width + 1, height, &raw_len) || + hb_unsigned_mul_overflows (width, height, &mask_len)) + return false; + /* Decompress IDAT (zlib). */ - unsigned raw_len = (width + 1) * height; /* 1 filter byte per row + width bytes */ + /* raw_len = (width + 1) * height: 1 filter byte per row + width bytes. */ uint8_t *raw = (uint8_t *) hb_malloc (raw_len); if (!raw) return false; HB_SCOPE_GUARD (hb_free (raw)); @@ -567,7 +630,7 @@ hb_pdf_build_indexed_smask (hb_vector_buf_t *out, return false; /* Un-filter and map to alpha. */ - if (!out->resize (width * height)) + if (!out->resize (mask_len)) return false; uint8_t *unfiltered = (uint8_t *) hb_malloc (width); @@ -680,11 +743,14 @@ hb_pdf_paint_image (hb_paint_funcs_t *, hb_vector_buf_t idat; unsigned pos = 8; - while (pos + 12 <= len) + /* Invariant: pos <= len (len >= 8 checked above). All bounds checks below + * are written to avoid 32-bit wrapping: a malicious chunk_len must not be + * able to wrap pos + 12 + chunk_len past the end of the buffer. */ + while (len - pos >= 12) { uint32_t chunk_len = hb_pdf_png_u32 (data + pos); uint32_t chunk_type = hb_pdf_png_u32 (data + pos + 4); - if (pos + 12 + chunk_len > len) + if (chunk_len > len - pos - 12) break; const uint8_t *chunk_data = data + pos + 8; @@ -1520,6 +1586,7 @@ static struct hb_pdf_paint_funcs_lazy_loader_t hb_paint_funcs_t *funcs = hb_paint_funcs_create (); hb_paint_funcs_set_push_transform_func (funcs, (hb_paint_push_transform_func_t) hb_pdf_paint_push_transform, nullptr, nullptr); hb_paint_funcs_set_pop_transform_func (funcs, (hb_paint_pop_transform_func_t) hb_pdf_paint_pop_transform, nullptr, nullptr); + hb_paint_funcs_set_fill_glyph_func (funcs, (hb_paint_fill_glyph_func_t) hb_pdf_paint_fill_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_glyph_func (funcs, (hb_paint_push_clip_glyph_func_t) hb_pdf_paint_push_clip_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_rectangle_func (funcs, (hb_paint_push_clip_rectangle_func_t) hb_pdf_paint_push_clip_rectangle, nullptr, nullptr); hb_paint_funcs_set_push_clip_path_start_func (funcs, (hb_paint_push_clip_path_start_func_t) hb_pdf_paint_push_clip_path_start, nullptr, nullptr); @@ -1598,11 +1665,11 @@ hb_vector_paint_render_pdf (hb_vector_paint_t *paint) out.append_str ("3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox ["); out.append_num (ex); out.append_c (' '); - out.append_num (-(ey + eh)); + out.append_num (ey); out.append_c (' '); out.append_num (ex + ew); out.append_c (' '); - out.append_num (-ey); + out.append_num (ey + eh); out.append_str ("]\n/Contents 4 0 R"); /* Resources. */ @@ -1660,7 +1727,7 @@ hb_vector_paint_render_pdf (hb_vector_paint_t *paint) bg_prefix.append_str (" rg\n"); bg_prefix.append_num (ex); bg_prefix.append_c (' '); - bg_prefix.append_num (-(ey + eh)); + bg_prefix.append_num (ey); bg_prefix.append_c (' '); bg_prefix.append_num (ew); bg_prefix.append_c (' '); diff --git a/src/hb-vector-paint-svg.cc b/src/hb-vector-paint-svg.cc index eca53e39a..7cca077bb 100644 --- a/src/hb-vector-paint-svg.cc +++ b/src/hb-vector-paint-svg.cc @@ -268,6 +268,7 @@ static void hb_vector_paint_push_transform (hb_paint_funcs_t *, void *, float, float, float, float, float, float, void *); static void hb_vector_paint_pop_transform (hb_paint_funcs_t *, void *, void *); +static void hb_vector_paint_fill_glyph (hb_paint_funcs_t *, void *, hb_codepoint_t, hb_font_t *, hb_bool_t, hb_color_t, void *); static void hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *, void *, hb_codepoint_t, hb_font_t *, void *); static void hb_vector_paint_push_clip_rectangle (hb_paint_funcs_t *, void *, float, float, float, float, void *); static hb_draw_funcs_t * hb_vector_paint_push_clip_path_start (hb_paint_funcs_t *, void *, void **, void *); @@ -308,6 +309,7 @@ static struct hb_vector_paint_funcs_lazy_loader_t hb_paint_funcs_t *funcs = hb_paint_funcs_create (); hb_paint_funcs_set_push_transform_func (funcs, (hb_paint_push_transform_func_t) hb_vector_paint_push_transform, nullptr, nullptr); hb_paint_funcs_set_pop_transform_func (funcs, (hb_paint_pop_transform_func_t) hb_vector_paint_pop_transform, nullptr, nullptr); + hb_paint_funcs_set_fill_glyph_func (funcs, (hb_paint_fill_glyph_func_t) hb_vector_paint_fill_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_glyph_func (funcs, (hb_paint_push_clip_glyph_func_t) hb_vector_paint_push_clip_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_rectangle_func (funcs, (hb_paint_push_clip_rectangle_func_t) hb_vector_paint_push_clip_rectangle, nullptr, nullptr); hb_paint_funcs_set_push_clip_path_start_func (funcs, (hb_paint_push_clip_path_start_func_t) hb_vector_paint_push_clip_path_start, nullptr, nullptr); @@ -413,6 +415,32 @@ hb_vector_paint_pop_transform (hb_paint_funcs_t *, paint->current_body ().append_str ("\n"); } +static void +hb_vector_paint_fill_glyph (hb_paint_funcs_t *, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t, + hb_color_t color, + void *) +{ + auto *paint = (hb_vector_paint_t *) paint_data; + if (unlikely (!paint->ensure_initialized ())) + return; + + paint->path.clear (); + hb_vector_path_sink_t sink = {&paint->path, paint->get_precision (), + paint->x_scale_factor, paint->y_scale_factor}; + hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink); + + auto &body = paint->current_body (); + body.append_str ("path.arrayZ, paint->path.length); + body.append_str ("\" fill=\""); + body.append_svg_color (color, true); + body.append_str ("\"/>\n"); +} + static void hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *, void *paint_data, diff --git a/src/hb.hh b/src/hb.hh index 24c862503..6e7105a2c 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -151,6 +151,7 @@ #pragma GCC diagnostic ignored "-Wrange-loop-analysis" // https://github.com/harfbuzz/harfbuzz/issues/2834 #pragma GCC diagnostic ignored "-Wstrict-aliasing" #pragma GCC diagnostic ignored "-Wtype-limits" +#pragma GCC diagnostic ignored "-Wunused-template" #pragma GCC diagnostic ignored "-Wc++11-compat" // only gcc raises it #endif @@ -280,7 +281,7 @@ #if defined(__GNUC__) && (__GNUC__ >= 4) || (__clang__) #define HB_UNUSED __attribute__((unused)) #elif defined(_MSC_VER) /* https://github.com/harfbuzz/harfbuzz/issues/635 */ -#define HB_UNUSED __pragma(warning(suppress: 4100 4101)) +#define HB_UNUSED __pragma(warning(suppress: 4100 4101 4189)) #else #define HB_UNUSED #endif diff --git a/src/meson.build b/src/meson.build index 491b75a44..299ecd60b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -396,7 +396,6 @@ hb_subset_sources = files( 'hb-subset-cff-common.hh', 'hb-subset-cff1.cc', 'hb-subset-cff2.cc', - 'hb-subset-cff2-to-cff1.cc', 'hb-subset-cff2-to-cff1.hh', 'hb-subset-input.cc', 'hb-subset-input.hh', @@ -649,6 +648,10 @@ else hb_so_version = '0' endif +if host_machine.system() == 'aix' + version = '0' +endif + if get_option('fuzzer_ldflags') != '' extra_hb_cpp_args += ['-DHB_CUSTOM_MALLOC'] hb_sources += hb_failing_alloc_sources @@ -713,7 +716,6 @@ if not get_option('subset').disabled() endif hb_raster_sources = files( - 'hb-raster.cc', 'hb-raster-image.cc', 'hb-raster-image.hh', 'hb-raster.hh', @@ -1114,6 +1116,16 @@ if fs.is_absolute(cmake_install_libdir) endif endif +cmake_install_bindir = get_option('bindir') + +if fs.is_absolute(cmake_install_bindir) + if meson.version().version_compare('>=1.3.0') + cmake_install_bindir = fs.relative_to(cmake_install_bindir, get_option('prefix')) + else + cmake_install_bindir = run_command(relative_to, cmake_install_bindir, get_option('prefix'), check: true).stdout().strip() + endif +endif + cmake_config.set('PACKAGE_INIT', ''' get_filename_component(PACKAGE_PREFIX_DIR "@0@" ABSOLUTE) @@ -1137,21 +1149,41 @@ endmacro() cmake_config.set('PACKAGE_CMAKE_INSTALL_INCLUDEDIR', '${PACKAGE_PREFIX_DIR}/@0@'.format(cmake_install_includedir)) cmake_config.set('PACKAGE_CMAKE_INSTALL_LIBDIR', '${PACKAGE_PREFIX_DIR}/@0@'.format(cmake_install_libdir)) +cmake_config.set('PACKAGE_CMAKE_INSTALL_BINDIR', '${PACKAGE_PREFIX_DIR}/@0@'.format(cmake_install_bindir)) cmake_config.set('PACKAGE_INCLUDE_INSTALL_DIR', '${PACKAGE_PREFIX_DIR}/@0@/@1@'.format(cmake_install_includedir, meson.project_name())) cmake_config.set('HARFBUZZ_VERSION', meson.project_version()) cmake_config.set('HB_HAVE_GOBJECT', have_gobject ? 'YES' : 'NO') cmake_config.set('HB_LIBRARY_TYPE', get_option('default_library') == 'static' ? 'STATIC' : 'SHARED') +cmake_config.set('HB_HAS_IMPORT_LIBRARY', 'NO') +cmake_config.set('HB_IMPLIB_PREFIX', '') +cmake_config.set('HB_IMPLIB_SUFFIX', '') if get_option('default_library') == 'static' + cmake_config.set('HB_LIB_DIR', '${PACKAGE_PREFIX_DIR}/@0@'.format(cmake_install_libdir)) cmake_config.set('HB_LIB_PREFIX', '${CMAKE_STATIC_LIBRARY_PREFIX}') cmake_config.set('HB_LIB_SUFFIX', '${CMAKE_STATIC_LIBRARY_SUFFIX}') elif host_machine.system() == 'darwin' + cmake_config.set('HB_LIB_DIR', '${PACKAGE_PREFIX_DIR}/@0@'.format(cmake_install_libdir)) cmake_config.set('HB_LIB_PREFIX', '${CMAKE_SHARED_LIBRARY_PREFIX}') cmake_config.set('HB_LIB_SUFFIX', '.@0@${CMAKE_SHARED_LIBRARY_SUFFIX}'.format(hb_so_version)) elif host_machine.system() == 'windows' - cmake_config.set('HB_LIB_PREFIX', '${CMAKE_IMPORT_LIBRARY_PREFIX}') - cmake_config.set('HB_LIB_SUFFIX', '${CMAKE_IMPORT_LIBRARY_SUFFIX}') + cmake_config.set('HB_HAS_IMPORT_LIBRARY', 'YES') + cmake_config.set('HB_LIB_DIR', '${PACKAGE_PREFIX_DIR}/@0@'.format(cmake_install_bindir)) + cmake_config.set('HB_LIB_PREFIX', '${CMAKE_SHARED_LIBRARY_PREFIX}') + if hb_so_version == '' + cmake_config.set('HB_LIB_SUFFIX', '${CMAKE_SHARED_LIBRARY_SUFFIX}') + else + cmake_config.set('HB_LIB_SUFFIX', '-@0@${CMAKE_SHARED_LIBRARY_SUFFIX}'.format(hb_so_version)) + endif + cmake_config.set('HB_IMPLIB_PREFIX', '${CMAKE_IMPORT_LIBRARY_PREFIX}') + cmake_config.set('HB_IMPLIB_SUFFIX', '${CMAKE_IMPORT_LIBRARY_SUFFIX}') +elif host_machine.system() == 'android' + # Meson does not version shared libraries on Android. + cmake_config.set('HB_LIB_DIR', '${PACKAGE_PREFIX_DIR}/@0@'.format(cmake_install_libdir)) + cmake_config.set('HB_LIB_PREFIX', '${CMAKE_SHARED_LIBRARY_PREFIX}') + cmake_config.set('HB_LIB_SUFFIX', '${CMAKE_SHARED_LIBRARY_SUFFIX}') else + cmake_config.set('HB_LIB_DIR', '${PACKAGE_PREFIX_DIR}/@0@'.format(cmake_install_libdir)) cmake_config.set('HB_LIB_PREFIX', '${CMAKE_SHARED_LIBRARY_PREFIX}') cmake_config.set('HB_LIB_SUFFIX', '${CMAKE_SHARED_LIBRARY_SUFFIX}.@0@'.format(version)) endif diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml index 736265fa7..31842c10c 100644 --- a/src/rust/Cargo.toml +++ b/src/rust/Cargo.toml @@ -4,9 +4,9 @@ edition = "2021" rust-version = "1.87.0" [dependencies] -harfrust = { version = "0.8.3", optional = true } +harfrust = { version = "0.12.0", features = ["experimental_font_api"], optional = true } # harfrust = { git = "https://github.com/harfbuzz/harfrust", optional = true } -read-fonts = "0.39.*" +read-fonts = "0.41.*" skrifa = { version = "0.*", optional = true } smallvec = "1.*" diff --git a/src/rust/font.rs b/src/rust/font.rs index 84bc79b57..247bcdf0c 100644 --- a/src/rust/font.rs +++ b/src/rust/font.rs @@ -701,6 +701,32 @@ impl ColorPainter for HbColorPainter<'_> { ) { unsafe { hb_paint_push_inverse_font_transform(self.paint_funcs, self.paint_data, self.font); + } + + if brush_transform.is_none() { + if let Brush::Solid { + palette_index: color_index, + alpha, + } = brush + { + let is_foreground = color_index == 0xFFFF; + let color = self.lookup_color(color_index, alpha); + unsafe { + hb_paint_fill_glyph( + self.paint_funcs, + self.paint_data, + glyph_id.to_u32() as hb_codepoint_t, + self.font, + is_foreground as hb_bool_t, + color, + ); + } + self.pop_transform(); + return; + } + } + + unsafe { hb_paint_push_clip_glyph( self.paint_funcs, self.paint_data, diff --git a/src/rust/meson.build b/src/rust/meson.build index ace3e4164..806930b55 100644 --- a/src/rust/meson.build +++ b/src/rust/meson.build @@ -55,6 +55,7 @@ harfbuzz_rust = custom_target( input: sources + ['Cargo.toml'], output: ['libharfbuzz_rust.a'], depends: [hb_rs], + build_always_stale: true, env: ['OUT_DIR=' + meson.current_build_dir(), 'RUSTFLAGS=' + rust_flags, ], diff --git a/src/rust/shape.rs b/src/rust/shape.rs index 26c47e373..781dcf1d4 100644 --- a/src/rust/shape.rs +++ b/src/rust/shape.rs @@ -5,16 +5,18 @@ use super::hb::*; use std::ffi::c_void; -use std::mem::{align_of, offset_of, size_of, transmute}; +use std::mem::{align_of, offset_of, size_of}; use std::ptr::null_mut; +use std::sync::Arc; use harfrust::{ - funcs::{AdvanceWidthBatch, BuiltinFontFuncs, FontFuncs}, - FontRef, GlyphExtents, GlyphFlags as HRGlyphFlags, GlyphInfo as HRGlyphInfo, - GlyphPosition as HRGlyphPosition, NormalizedCoord, ShapeOptions, Shaper, ShaperData, - ShaperInstance, Tag, + font::{ + AdvanceWidthBatch, BuiltinFontFuncs, Font, FontBlob, FontFuncs, FontInstance, + FontTableFunction, + }, + GlyphExtents, GlyphFlags as HRGlyphFlags, GlyphId, GlyphInfo as HRGlyphInfo, + GlyphPosition as HRGlyphPosition, NormalizedCoord, ShapeOptions, Tag, }; -use read_fonts::types::GlyphId; use smallvec::SmallVec; type HRFeatureVec = SmallVec<[harfrust::Feature; 4]>; @@ -51,36 +53,76 @@ const _: () = { assert!(offset_of!(hb_glyph_position_t, y_offset) == offset_of!(HRGlyphPosition, y_offset)); }; -pub struct HBHarfRustFaceData<'a> { - face_blob: *mut hb_blob_t, - font_ref: FontRef<'a>, - shaper_data: ShaperData, +pub struct HBHarfRustFaceData { + font: Font, } +struct HbFace(*mut hb_face_t); + +impl HbFace { + unsafe fn new(face: *mut hb_face_t) -> Self { + Self(face) + } + + fn reference_table(&self, tag: Tag) -> *mut hb_blob_t { + unsafe { hb_face_reference_table(self.0, u32::from_be_bytes(tag.to_be_bytes())) } + } +} + +unsafe impl Send for HbFace {} +unsafe impl Sync for HbFace {} + +struct HbBlob(*mut hb_blob_t); + +impl Drop for HbBlob { + fn drop(&mut self) { + unsafe { + hb_blob_destroy(self.0); + } + } +} + +impl AsRef<[u8]> for HbBlob { + fn as_ref(&self) -> &[u8] { + let mut length = 0; + let data = unsafe { hb_blob_get_data(self.0, &mut length) }; + if data.is_null() { + &[] + } else { + unsafe { std::slice::from_raw_parts(data.cast(), length as usize) } + } + } +} + +unsafe impl Send for HbBlob {} +unsafe impl Sync for HbBlob {} + #[unsafe(no_mangle)] pub unsafe extern "C" fn _hb_harfrust_shaper_face_data_create_rs( face: *mut hb_face_t, ) -> *mut c_void { let face_index = hb_face_get_index(face); - let face_blob = hb_face_reference_blob(face); - let blob_length = hb_blob_get_length(face_blob); - let blob_data: *const u8 = hb_blob_get_data(face_blob, null_mut()).cast(); - if blob_data.is_null() { - return null_mut(); - } - let face_data = std::slice::from_raw_parts(blob_data, blob_length as usize); + let hb_face = HbFace::new(face); + let table_fn = FontTableFunction::new(Arc::new(move |tag| { + let blob = hb_face.reference_table(tag); + if blob.is_null() { + return None; + } + if unsafe { hb_blob_get_length(blob) } == 0 { + unsafe { + hb_blob_destroy(blob); + } + return None; + } + Some(FontBlob::Shared(Arc::new(HbBlob(blob)))) + })); - let font_ref = match FontRef::from_index(face_data, face_index) { - Ok(f) => f, + let font = match Font::new(table_fn, face_index) { + Ok(font) => font, Err(_) => return null_mut(), }; - let shaper_data = ShaperData::new(&font_ref); - let hr_face_data = Box::new(HBHarfRustFaceData { - face_blob, - font_ref, - shaper_data, - }); + let hr_face_data = Box::new(HBHarfRustFaceData { font }); Box::into_raw(hr_face_data) as *mut c_void } @@ -88,15 +130,11 @@ pub unsafe extern "C" fn _hb_harfrust_shaper_face_data_create_rs( #[unsafe(no_mangle)] pub unsafe extern "C" fn _hb_harfrust_shaper_face_data_destroy_rs(data: *mut c_void) { let data = data as *mut HBHarfRustFaceData; - let hr_face_data = Box::from_raw(data); - let blob = hr_face_data.face_blob; - hb_blob_destroy(blob); + let _hr_face_data = Box::from_raw(data); } pub struct HBHarfRustFontData { - // Keep the instance alive because `shaper` borrows variation data from it. - _shaper_instance: Box, - shaper: Shaper<'static>, + instance: FontInstance, } struct HBHarfBuzzFontFuncs { @@ -173,7 +211,7 @@ impl FontFuncs for HBHarfBuzzFontFuncs { } } -fn font_to_shaper_instance(font: *mut hb_font_t, font_ref: &FontRef<'_>) -> ShaperInstance { +fn font_to_instance(font: *mut hb_font_t, font_ref: &Font) -> FontInstance { let mut num_coords: u32 = 0; let coords = unsafe { hb_font_get_var_coords_normalized(font, &mut num_coords) }; let coords = if coords.is_null() { @@ -182,7 +220,9 @@ fn font_to_shaper_instance(font: *mut hb_font_t, font_ref: &FontRef<'_>) -> Shap unsafe { std::slice::from_raw_parts(coords, num_coords as usize) } }; let coords = coords.iter().map(|&v| NormalizedCoord::from_bits(v as i16)); - ShaperInstance::from_coords(font_ref, coords) + FontInstance::builder(font_ref) + .normalized_coords(coords) + .build() } #[unsafe(no_mangle)] @@ -192,19 +232,10 @@ pub unsafe extern "C" fn _hb_harfrust_shaper_font_data_create_rs( ) -> *mut c_void { let face_data = face_data as *const HBHarfRustFaceData; - let font_ref = &(*face_data).font_ref; - let shaper_instance = Box::new(font_to_shaper_instance(font, font_ref)); - let shaper_instance_ref = &*(&*shaper_instance as *const _); - let shaper = (*face_data) - .shaper_data - .shaper(font_ref) - .instance(Some(shaper_instance_ref)) - .build(); + let instance = font_to_instance(font, &(*face_data).font); + let hr_font_data = HBHarfRustFontData { instance }; - let hr_font_data = Box::new(HBHarfRustFontData { - _shaper_instance: shaper_instance, - shaper: transmute::, harfrust::Shaper<'_>>(shaper), - }); + let hr_font_data = Box::new(hr_font_data); let hr_font_data_ptr = Box::into_raw(hr_font_data); hr_font_data_ptr as *mut c_void @@ -282,10 +313,13 @@ pub unsafe extern "C" fn _hb_harfrust_shape_plan_create_rs( }; let features = hb_feature_to_hr_feature(features, num_features); - let shaper = &(*font_data).shaper; - - let hr_shape_plan = - harfrust::ShapePlan::new(shaper, direction, script, language.as_ref(), &features); + let hr_shape_plan = harfrust::ShapePlan::new( + &(*font_data).instance, + direction, + script, + language.as_ref(), + &features, + ); let hr_shape_plan = Box::new(hr_shape_plan); Box::into_raw(hr_shape_plan) as *mut c_void } @@ -385,15 +419,13 @@ pub unsafe extern "C" fn _hb_harfrust_shape_rs( let mut y_scale = 0; hb_font_get_scale(font, &mut x_scale, &mut y_scale); let mut font_funcs = HBHarfBuzzFontFuncs { font }; - let glyphs = (*font_data).shaper.shape( - hr_buffer, - ShapeOptions::new() - .plan(shape_plan) - .scale_separate(Some((x_scale, y_scale))) - .point_size(ptem) - .features(&features) - .font_funcs(Some(&mut font_funcs)), - ); + let options = ShapeOptions::new() + .plan(shape_plan) + .scale_separate(Some((x_scale, y_scale))) + .point_size(ptem) + .features(&features) + .font_funcs(Some(&mut font_funcs)); + let glyphs = harfrust::shape(&(*font_data).instance, hr_buffer, options); hb_buffer_set_content_type( buffer, diff --git a/src/test-repacker.cc b/src/test-repacker.cc index fa8721016..50cbcd642 100644 --- a/src/test-repacker.cc +++ b/src/test-repacker.cc @@ -1939,7 +1939,7 @@ static void test_duplicate_leaf () populate_serializer_complex_2 (&a); graph_t graph (a.object_graph ()); - graph.duplicate (4, 1); + graph.duplicate (4, 1, false); graph.normalize(); e.start_serialize(); @@ -1979,7 +1979,7 @@ static void test_duplicate_interior () populate_serializer_complex_3 (&c); graph_t graph (c.object_graph ()); - graph.duplicate (3, 2); + graph.duplicate (3, 2, false); hb_always_assert(strncmp (graph.object (6).head, "jkl", 3) == 0); hb_always_assert(graph.object (6).real_links.length == 1); diff --git a/test/api/fonts/SourceHanSans-Regular.41,4C2E.identity.otf b/test/api/fonts/SourceHanSans-Regular.41,4C2E.identity.otf new file mode 100644 index 000000000..ddb4cc6de Binary files /dev/null and b/test/api/fonts/SourceHanSans-Regular.41,4C2E.identity.otf differ diff --git a/test/api/fonts/varc-6868.ttf b/test/api/fonts/varc-6868.ttf index 6041d6cc1..f9eb5ced0 100644 Binary files a/test/api/fonts/varc-6868.ttf and b/test/api/fonts/varc-6868.ttf differ diff --git a/test/api/fonts/varc-ac00-ac01.ttf b/test/api/fonts/varc-ac00-ac01.ttf index fb3a08780..a97cd8314 100644 Binary files a/test/api/fonts/varc-ac00-ac01.ttf and b/test/api/fonts/varc-ac00-ac01.ttf differ diff --git a/test/api/fonts/varc-ac01-conditional.ttf b/test/api/fonts/varc-ac01-conditional.ttf index 912a146e2..02dacf822 100644 Binary files a/test/api/fonts/varc-ac01-conditional.ttf and b/test/api/fonts/varc-ac01-conditional.ttf differ diff --git a/test/api/meson.build b/test/api/meson.build index c42f1376a..cc799e126 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -34,6 +34,7 @@ tests = [ 'test-ot-layout.c', 'test-ot-ligature-carets.c', 'test-ot-name.c', + 'test-ot-nullable-output.c', 'test-ot-math.c', 'test-ot-meta.c', 'test-ot-metrics.c', diff --git a/test/api/results-paint/bad-154 b/test/api/results-paint/bad-154 index 1dcf2489b..bd39666e4 100644 --- a/test/api/results-paint/bad-154 +++ b/test/api/results-paint/bad-154 @@ -3,11 +3,7 @@ start transform 1 0 0 1 0 0 push group push group start transform 1 0 0 1 0 0 - start clip glyph 159 - start transform 1 0 0 1 0 0 - solid 128 128 128 102 - end transform - end clip + fill glyph 159 solid 128 128 128 102 end transform pop group mode 3 pop group mode 3 diff --git a/test/api/results-paint/hand-10 b/test/api/results-paint/hand-10 index 2ba03ef53..06bfb136f 100644 --- a/test/api/results-paint/hand-10 +++ b/test/api/results-paint/hand-10 @@ -29,25 +29,13 @@ start transform 1 0 0 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 15 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 15 solid 145 103 77 255 end transform start transform 1 0 0 1 0 0 - start clip glyph 16 - start transform 1 0 0 1 0 0 - solid 30 136 229 255 - end transform - end clip + fill glyph 16 solid 30 136 229 255 end transform start transform 1 0 0 1 0 0 - start clip glyph 21 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 21 solid 145 103 77 255 end transform start transform 1 0 0 1 0 0 start clip glyph 16 @@ -62,11 +50,7 @@ start transform 1 0 0 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 18 - start transform 1 0 0 1 0 0 - solid 66 66 66 51 - end transform - end clip + fill glyph 18 solid 66 66 66 51 end transform start transform 1 0 0 1 0 0 start clip glyph 19 @@ -85,11 +69,7 @@ start transform 1 0 0 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 20 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 20 solid 145 103 77 255 end transform end clip end transform diff --git a/test/api/results-paint/hand-10.2 b/test/api/results-paint/hand-10.2 index 379a02b47..49a5a7c54 100644 --- a/test/api/results-paint/hand-10.2 +++ b/test/api/results-paint/hand-10.2 @@ -30,25 +30,13 @@ start transform 1 0 0.2 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 15 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 15 solid 145 103 77 255 end transform start transform 1 0 0 1 0 0 - start clip glyph 16 - start transform 1 0 0 1 0 0 - solid 30 136 229 255 - end transform - end clip + fill glyph 16 solid 30 136 229 255 end transform start transform 1 0 0 1 0 0 - start clip glyph 21 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 21 solid 145 103 77 255 end transform start transform 1 0 0 1 0 0 start clip glyph 16 @@ -63,11 +51,7 @@ start transform 1 0 0.2 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 18 - start transform 1 0 0 1 0 0 - solid 66 66 66 51 - end transform - end clip + fill glyph 18 solid 66 66 66 51 end transform start transform 1 0 0 1 0 0 start clip glyph 19 @@ -86,11 +70,7 @@ start transform 1 0 0.2 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 20 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 20 solid 145 103 77 255 end transform end clip end transform diff --git a/test/api/results-paint/rocher-1 b/test/api/results-paint/rocher-1 index bede5acbd..3f5925668 100644 --- a/test/api/results-paint/rocher-1 +++ b/test/api/results-paint/rocher-1 @@ -1,14 +1,6 @@ start transform 1 0 0.3 1 0 0 - start clip glyph 8 - solid 81 61 50 255 - end clip - start clip glyph 9 - solid 245 185 68 255 - end clip - start clip glyph 10 - solid 224 142 55 255 - end clip - start clip glyph 11 - solid 245 202 86 255 - end clip + fill glyph 8 solid 81 61 50 255 + fill glyph 9 solid 245 185 68 255 + fill glyph 10 solid 224 142 55 255 + fill glyph 11 solid 245 202 86 255 end transform diff --git a/test/api/results-paint/rocher-2 b/test/api/results-paint/rocher-2 index 4cb377293..8558dfd26 100644 --- a/test/api/results-paint/rocher-2 +++ b/test/api/results-paint/rocher-2 @@ -1,14 +1,6 @@ start transform 1 0 0.3 1 0 0 - start clip glyph 12 - solid 81 61 50 255 - end clip - start clip glyph 13 - solid 245 185 68 255 - end clip - start clip glyph 14 - solid 224 142 55 255 - end clip - start clip glyph 15 - solid 245 202 86 255 - end clip + fill glyph 12 solid 81 61 50 255 + fill glyph 13 solid 245 185 68 255 + fill glyph 14 solid 224 142 55 255 + fill glyph 15 solid 245 202 86 255 end transform diff --git a/test/api/results-paint/rocher-3 b/test/api/results-paint/rocher-3 index 326fdc4f9..08072ede7 100644 --- a/test/api/results-paint/rocher-3 +++ b/test/api/results-paint/rocher-3 @@ -1,12 +1,4 @@ -start clip glyph 16 - solid 81 61 50 255 -end clip -start clip glyph 17 - solid 245 185 68 255 -end clip -start clip glyph 18 - solid 224 142 55 255 -end clip -start clip glyph 19 - solid 245 202 86 255 -end clip +fill glyph 16 solid 81 61 50 255 +fill glyph 17 solid 245 185 68 255 +fill glyph 18 solid 224 142 55 255 +fill glyph 19 solid 245 202 86 255 diff --git a/test/api/results-paint/test-106 b/test/api/results-paint/test-106 index 60bf166ff..8fe63746d 100644 --- a/test/api/results-paint/test-106 +++ b/test/api/results-paint/test-106 @@ -1,20 +1,12 @@ start transform 1 0 0 1 0 0 push group start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 0 0 255 128 - end transform - end clip + fill glyph 3 solid 0 0 255 128 end transform push group start transform 1 0.268 0 1 0 -134 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 255 165 0 179 - end transform - end clip + fill glyph 3 solid 255 165 0 179 end transform end transform pop group mode 4 diff --git a/test/api/results-paint/test-116 b/test/api/results-paint/test-116 index 2b38f892e..8e9dca4ef 100644 --- a/test/api/results-paint/test-116 +++ b/test/api/results-paint/test-116 @@ -1,20 +1,12 @@ start transform 1 0 0 1 0 0 push group start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 0 0 255 128 - end transform - end clip + fill glyph 3 solid 0 0 255 128 end transform push group start transform 1 0 0 1 100 0 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 255 165 0 179 - end transform - end clip + fill glyph 3 solid 255 165 0 179 end transform end transform pop group mode 4 diff --git a/test/api/results-paint/test-123 b/test/api/results-paint/test-123 index 2afe0285a..667bf84e5 100644 --- a/test/api/results-paint/test-123 +++ b/test/api/results-paint/test-123 @@ -1,30 +1,18 @@ start transform 1 0 0 1 0 0 start clip rectangle 0 0 1e+03 1e+03 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 0 0 0 255 - end transform - end clip + fill glyph 3 solid 0 0 0 255 end transform push group start transform 0.5 0 0 0.5 166 334 start transform 1 0 0 1 0 0 - start clip glyph 2 - start transform 1 0 0 1 0 0 - solid 255 220 1 255 - end transform - end clip + fill glyph 2 solid 255 220 1 255 end transform end transform push group start transform 0.5 0 0 0.5 334 166 start transform 1 0 0 1 0 0 - start clip glyph 2 - start transform 1 0 0 1 0 0 - solid 104 199 232 255 - end transform - end clip + fill glyph 2 solid 104 199 232 255 end transform end transform pop group mode 3 diff --git a/test/api/results-paint/test-154 b/test/api/results-paint/test-154 index 750a0503c..c5644b26b 100644 --- a/test/api/results-paint/test-154 +++ b/test/api/results-paint/test-154 @@ -1,11 +1,7 @@ start transform 1 0 0 1 0 0 start clip rectangle 100 250 900 950 start transform 1 0 0 1 0 0 - start clip glyph 154 - start transform 1 0 0 1 0 0 - solid 0 0 0 255 - end transform - end clip + fill glyph 154 solid 0 0 0 255 end transform end clip end transform diff --git a/test/api/results-paint/test-165 b/test/api/results-paint/test-165 index dd59b78c5..0172bbad0 100644 --- a/test/api/results-paint/test-165 +++ b/test/api/results-paint/test-165 @@ -1,3 +1 @@ -start clip glyph 165 - solid 0 0 0 255 -end clip +fill glyph 165 solid 0 0 0 255 diff --git a/test/api/results-paint/test-175 b/test/api/results-paint/test-175 index 77ca1eead..d6f868eaf 100644 --- a/test/api/results-paint/test-175 +++ b/test/api/results-paint/test-175 @@ -1,3 +1 @@ -start clip glyph 175 - solid 0 0 0 255 -end clip +fill glyph 175 solid 0 0 0 255 diff --git a/test/api/results-paint/test-6 b/test/api/results-paint/test-6 index ad5897b56..1ac702954 100644 --- a/test/api/results-paint/test-6 +++ b/test/api/results-paint/test-6 @@ -1,3 +1 @@ -start clip glyph 6 - solid 0 0 0 255 -end clip +fill glyph 6 solid 0 0 0 255 diff --git a/test/api/results-paint/testvf-106 b/test/api/results-paint/testvf-106 index 60bf166ff..8fe63746d 100644 --- a/test/api/results-paint/testvf-106 +++ b/test/api/results-paint/testvf-106 @@ -1,20 +1,12 @@ start transform 1 0 0 1 0 0 push group start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 0 0 255 128 - end transform - end clip + fill glyph 3 solid 0 0 255 128 end transform push group start transform 1 0.268 0 1 0 -134 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 255 165 0 179 - end transform - end clip + fill glyph 3 solid 255 165 0 179 end transform end transform pop group mode 4 diff --git a/test/api/results-paint/testvf-116 b/test/api/results-paint/testvf-116 index 2b38f892e..8e9dca4ef 100644 --- a/test/api/results-paint/testvf-116 +++ b/test/api/results-paint/testvf-116 @@ -1,20 +1,12 @@ start transform 1 0 0 1 0 0 push group start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 0 0 255 128 - end transform - end clip + fill glyph 3 solid 0 0 255 128 end transform push group start transform 1 0 0 1 100 0 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 255 165 0 179 - end transform - end clip + fill glyph 3 solid 255 165 0 179 end transform end transform pop group mode 4 diff --git a/test/api/results-paint/testvf-123 b/test/api/results-paint/testvf-123 index 2afe0285a..667bf84e5 100644 --- a/test/api/results-paint/testvf-123 +++ b/test/api/results-paint/testvf-123 @@ -1,30 +1,18 @@ start transform 1 0 0 1 0 0 start clip rectangle 0 0 1e+03 1e+03 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 0 0 0 255 - end transform - end clip + fill glyph 3 solid 0 0 0 255 end transform push group start transform 0.5 0 0 0.5 166 334 start transform 1 0 0 1 0 0 - start clip glyph 2 - start transform 1 0 0 1 0 0 - solid 255 220 1 255 - end transform - end clip + fill glyph 2 solid 255 220 1 255 end transform end transform push group start transform 0.5 0 0 0.5 334 166 start transform 1 0 0 1 0 0 - start clip glyph 2 - start transform 1 0 0 1 0 0 - solid 104 199 232 255 - end transform - end clip + fill glyph 2 solid 104 199 232 255 end transform end transform pop group mode 3 diff --git a/test/api/results-paint/testvf-154 b/test/api/results-paint/testvf-154 index 750a0503c..c5644b26b 100644 --- a/test/api/results-paint/testvf-154 +++ b/test/api/results-paint/testvf-154 @@ -1,11 +1,7 @@ start transform 1 0 0 1 0 0 start clip rectangle 100 250 900 950 start transform 1 0 0 1 0 0 - start clip glyph 154 - start transform 1 0 0 1 0 0 - solid 0 0 0 255 - end transform - end clip + fill glyph 154 solid 0 0 0 255 end transform end clip end transform diff --git a/test/api/results-paint/testvf-165 b/test/api/results-paint/testvf-165 index dd59b78c5..0172bbad0 100644 --- a/test/api/results-paint/testvf-165 +++ b/test/api/results-paint/testvf-165 @@ -1,3 +1 @@ -start clip glyph 165 - solid 0 0 0 255 -end clip +fill glyph 165 solid 0 0 0 255 diff --git a/test/api/results-paint/testvf-175 b/test/api/results-paint/testvf-175 index 77ca1eead..d6f868eaf 100644 --- a/test/api/results-paint/testvf-175 +++ b/test/api/results-paint/testvf-175 @@ -1,3 +1 @@ -start clip glyph 175 - solid 0 0 0 255 -end clip +fill glyph 175 solid 0 0 0 255 diff --git a/test/api/results-paint/testvf-6 b/test/api/results-paint/testvf-6 index ad5897b56..1ac702954 100644 --- a/test/api/results-paint/testvf-6 +++ b/test/api/results-paint/testvf-6 @@ -1,3 +1 @@ -start clip glyph 6 - solid 0 0 0 255 -end clip +fill glyph 6 solid 0 0 0 255 diff --git a/test/api/test-collect-unicodes.c b/test/api/test-collect-unicodes.c index ee1e938cc..a4aea6286 100644 --- a/test/api/test-collect-unicodes.c +++ b/test/api/test-collect-unicodes.c @@ -49,6 +49,64 @@ test_collect_unicodes_format4 (void) hb_face_destroy (face); } +static void +test_collect_unicodes_format4_with_range_offsets_and_deltas (void) +{ + const char cmap_data[44] = { + 0, 0, 0, 1, /* cmap header */ + 0, 0, 0, 3, 0, 0, 0, 12, /* encoding records */ + /* cmap 4 */ + 0, 4, /* format */ + 0, 44, /* length */ + 0, 0, /* lang */ + 0, 2, /* segcountx2 */ + 0, 0, /* search range */ + 0, 0, /* entry selector */ + 0, 0, /* range shift */ + 0, 73, /* end code [0] */ + 0, 0, /* pad */ + 0, 70, /* start code [0] */ + 0, 5, /* id delta [0] */ + 0, 2, /* id range offset [0] */ + 0, 8, /* glyph id u70 */ + 0, 5, /* glyph id u71 */ + 0, 0, /* glyph id u72 */ + 0, 12, /* glyph id u73 */ + }; + + hb_blob_t* cmap = hb_blob_create(cmap_data, 44, HB_MEMORY_MODE_READONLY, 0, 0); + hb_face_t* face = hb_face_builder_create(); + hb_face_builder_add_table(face, HB_TAG('c', 'm', 'a', 'p'), cmap); + hb_blob_destroy(cmap); + + hb_set_t *codepoints = hb_set_create(); + hb_map_t *mapping = hb_map_create(); + hb_codepoint_t cp; + + hb_face_collect_unicodes (face, codepoints); + + cp = HB_SET_VALUE_INVALID; + g_assert_true (hb_set_next (codepoints, &cp)); + g_assert_cmpuint (70, ==, cp); + g_assert_true (hb_set_next (codepoints, &cp)); + g_assert_cmpuint (71, ==, cp); + g_assert_true (hb_set_next (codepoints, &cp)); + g_assert_cmpuint (73, ==, cp); + g_assert_false (hb_set_next (codepoints, &cp)); + + hb_set_clear(codepoints); + hb_face_collect_nominal_glyph_mapping(face, mapping, codepoints); + + g_assert_cmpuint (hb_map_get(mapping, 70), ==, 8 + 5); + g_assert_cmpuint (hb_map_get(mapping, 71), ==, 5 + 5); + g_assert_false (hb_map_has(mapping, 72)); + g_assert_cmpuint (hb_map_get(mapping, 73), ==, 12 + 5); + + hb_map_destroy(mapping); + hb_set_destroy (codepoints); + hb_face_destroy (face); +} + static void test_collect_unicodes_format12_notdef (void) { @@ -135,6 +193,7 @@ main (int argc, char **argv) hb_test_add (test_collect_unicodes_format4); hb_test_add (test_collect_unicodes_format12); hb_test_add (test_collect_unicodes_format12_notdef); + hb_test_add (test_collect_unicodes_format4_with_range_offsets_and_deltas); return hb_test_run(); } diff --git a/test/api/test-get-table-tags.c b/test/api/test-get-table-tags.c index 192943708..960b1c53a 100644 --- a/test/api/test-get-table-tags.c +++ b/test/api/test-get-table-tags.c @@ -27,6 +27,7 @@ #include "hb-test.h" #include +#include #ifdef HAVE_FREETYPE #include #endif @@ -128,6 +129,63 @@ test_get_table_tags_ft (void) FT_Done_FreeType (ft_library); hb_blob_destroy (blob); } + +static unsigned long +_ft_stream_read (FT_Stream stream, + unsigned long offset, + unsigned char *buffer, + unsigned long count) +{ + hb_blob_t *blob = (hb_blob_t *) stream->descriptor.pointer; + unsigned int length; + const char *data = hb_blob_get_data (blob, &length); + if (offset > length) + return 0; + if (count == 0) /* Seek. */ + return 0; + if (offset + count > length) + count = length - offset; + memcpy (buffer, data + offset, count); + return count; +} + +static void +_ft_stream_close (FT_Stream stream HB_UNUSED) {} + +static void +test_get_table_tags_ft_stream (void) +{ + /* Exercise the streaming-face path, which (unlike an in-memory face) uses + * hb-ft's own _hb_ft_get_table_tags callback. */ + hb_face_t *source = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf"); + hb_blob_t *blob = hb_face_reference_blob (source); + hb_face_destroy (source); + + FT_Library ft_library; + g_assert_cmpint (0, ==, FT_Init_FreeType (&ft_library)); + + FT_StreamRec stream = {0}; + stream.size = hb_blob_get_length (blob); + stream.descriptor.pointer = blob; + stream.read = _ft_stream_read; + stream.close = _ft_stream_close; + + FT_Open_Args args = {0}; + args.flags = FT_OPEN_STREAM; + args.stream = &stream; + + FT_Face ft_face; + g_assert_cmpint (0, ==, FT_Open_Face (ft_library, &args, 0, &ft_face)); + + hb_face_t *face = hb_ft_face_create (ft_face, NULL); + + _test_get_table_tags (face); + + hb_face_destroy (face); + FT_Done_Face (ft_face); + FT_Done_FreeType (ft_library); + hb_blob_destroy (blob); +} #endif #ifdef HAVE_CORETEXT @@ -167,6 +225,7 @@ main (int argc, char **argv) hb_test_add (test_get_table_tags_builder); #ifdef HAVE_FREETYPE hb_test_add (test_get_table_tags_ft); + hb_test_add (test_get_table_tags_ft_stream); #endif #ifdef HAVE_CORETEXT hb_test_add (test_get_table_tags_ct); diff --git a/test/api/test-gpu.cc b/test/api/test-gpu.cc index fd4a47ade..42ec372c2 100644 --- a/test/api/test-gpu.cc +++ b/test/api/test-gpu.cc @@ -519,6 +519,46 @@ test_paint_recycle_blob (void) } +static void +test_paint_clip_path_depth_overflow (void) +{ + /* push_clip_path_end must honor the same clip-depth cap as + * push_clip_glyph and push_clip_path_start. Interleaving clip + * pushes drives clip_depth past HB_GPU_PAINT_MAX_CLIP_DEPTH before + * the path is closed; without a bound check push_clip_path_end + * wrote past the fixed-size clip_stack (heap-buffer-overflow). */ + hb_gpu_paint_t *p = hb_gpu_paint_create_or_fail (); + g_assert_nonnull (p); + hb_gpu_paint_set_scale (p, 1000, 1000); + + hb_paint_funcs_t *pf = hb_gpu_paint_get_funcs (p); + hb_font_t *font = hb_font_get_empty (); + + void *draw_data = nullptr; + hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, p, &draw_data); + g_assert_nonnull (df); + + hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; + hb_draw_move_to (df, draw_data, &st, 0.f, 0.f); + hb_draw_line_to (df, draw_data, &st, 100.f, 0.f); + hb_draw_line_to (df, draw_data, &st, 100.f, 100.f); + hb_draw_close_path (df, draw_data, &st); + + /* Push more clips than the stack holds before closing the path. */ + for (unsigned i = 0; i < 4; i++) + hb_paint_push_clip_glyph (pf, p, i, font); + + hb_paint_push_clip_path_end (pf, p); + + /* Overflowing the clip stack marks the paint unsupported rather + * than writing past clip_stack, so encode returns NULL. */ + hb_blob_t *blob = hb_gpu_paint_encode (p, nullptr); + g_assert_null (blob); + + hb_gpu_paint_destroy (p); +} + + static void test_shapes (void) { @@ -633,6 +673,7 @@ main (int argc, char **argv) hb_test_add (test_paint_auto_clear_on_encode); hb_test_add (test_paint_reset); hb_test_add (test_paint_recycle_blob); + hb_test_add (test_paint_clip_path_depth_overflow); return hb_test_run (); } diff --git a/test/api/test-ot-face.c b/test/api/test-ot-face.c index 31779af46..37c2be127 100644 --- a/test/api/test-ot-face.c +++ b/test/api/test-ot-face.c @@ -215,6 +215,30 @@ test_ot_var_axis_on_zero_named_instance (void) hb_face_destroy (face); } +#ifndef HB_NO_VERTICAL +static void +test_ot_font_v_origin_cache_invalidated_by_scale (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/Mplus1p-Regular.660E.ttf"); + hb_font_t *font = hb_font_create (face); + hb_codepoint_t glyph; + hb_position_t x, y1, y2; + + g_assert_true (hb_font_get_nominal_glyph (font, 0x660E, &glyph)); + + hb_font_set_scale (font, 1000, 1000); + g_assert_true (hb_font_get_glyph_v_origin (font, glyph, &x, &y1)); + + hb_font_set_scale (font, 1000, 2000); + g_assert_true (hb_font_get_glyph_v_origin (font, glyph, &x, &y2)); + + g_assert_cmpint (y2, ==, y1 * 2); + + hb_font_destroy (font); + hb_face_destroy (face); +} +#endif + int main (int argc, char **argv) { @@ -222,6 +246,9 @@ main (int argc, char **argv) hb_test_add (test_ot_face_empty); hb_test_add (test_ot_var_axis_on_zero_named_instance); +#ifndef HB_NO_VERTICAL + hb_test_add (test_ot_font_v_origin_cache_invalidated_by_scale); +#endif return hb_test_run(); } diff --git a/test/api/test-ot-layout.c b/test/api/test-ot-layout.c index c3fe0ce74..27522c780 100644 --- a/test/api/test-ot-layout.c +++ b/test/api/test-ot-layout.c @@ -27,8 +27,49 @@ #include #include +#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT) && defined(HAVE_MMAP) +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#endif + #define STATIC_ARRAY_SIZE 255 +#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT) && defined(HAVE_MMAP) +static void +test_ot_layout_gdef_unsupported_version (void) +{ + const char gdef[] = {0x87, 0x00, 0x00, 0x06, 0x30}; + long pagesize = sysconf (_SC_PAGESIZE); + char *mapping; + char *table; + hb_blob_t *blob; + hb_face_t *face; + + g_assert_cmpint (pagesize, >, 0); + mapping = mmap (NULL, 2 * pagesize, PROT_NONE, + MAP_PRIVATE | MAP_ANON, -1, 0); + g_assert_true (mapping != MAP_FAILED); + g_assert_cmpint (mprotect (mapping, pagesize, PROT_READ | PROT_WRITE), ==, 0); + + table = mapping + pagesize - sizeof (gdef); + memcpy (table, gdef, sizeof (gdef)); + g_assert_cmpint (mprotect (mapping, pagesize, PROT_READ), ==, 0); + + face = hb_face_builder_create (); + blob = hb_blob_create (table, sizeof (gdef), HB_MEMORY_MODE_READONLY, + NULL, NULL); + g_assert_true (hb_face_builder_add_table (face, HB_OT_TAG_GDEF, blob)); + hb_blob_destroy (blob); + + g_assert_false (hb_ot_layout_has_glyph_classes (face)); + + hb_face_destroy (face); + g_assert_cmpint (munmap (mapping, 2 * pagesize), ==, 0); +} +#endif + static void test_ot_layout_table_get_script_tags (void) { @@ -219,6 +260,9 @@ int main (int argc, char **argv) { hb_test_init (&argc, &argv); +#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT) && defined(HAVE_MMAP) + hb_test_add (test_ot_layout_gdef_unsupported_version); +#endif hb_test_add (test_ot_layout_table_get_script_tags); hb_test_add (test_ot_layout_table_find_script); hb_test_add (test_ot_layout_script_get_language_tags); diff --git a/test/api/test-ot-nullable-output.c b/test/api/test-ot-nullable-output.c new file mode 100644 index 000000000..fe2605db4 --- /dev/null +++ b/test/api/test-ot-nullable-output.c @@ -0,0 +1,171 @@ +/* + * Copyright © 2026 Behdad Esfahbod + * + * 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. + */ + +#include "hb-test.h" + +#include +#include + +/* Regression test for GHSA-v5mv-8hhw-vff8: the "list getter" APIs document + * their output array as nullable ("may be NULL"; pass NULL to just query the + * count). Passing a NULL output array together with a non-NULL count on a + * populated table used to write through the NULL pointer and crash. Each case + * below calls the getter with a non-NULL count and a NULL output array on a + * font whose table is populated, and checks it returns the total without + * crashing. */ + +static void +test_nullable_output_cpal_colors (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/cpal-v0.ttf"); + unsigned int count = 100; + g_assert_cmpuint (hb_ot_color_palette_get_colors (face, 0, 0, &count, NULL), ==, 2); + hb_face_destroy (face); +} + +static void +test_nullable_output_colr_layers (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/cpal-v1.ttf"); + unsigned int count = 100; + g_assert_cmpuint (hb_ot_color_glyph_get_layers (face, 2, 0, &count, NULL), ==, 2); + hb_face_destroy (face); +} + +static void +test_nullable_output_meta_entries (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/meta.ttf"); + unsigned int count = 100; + unsigned int total = hb_ot_meta_get_entry_tags (face, 0, &count, NULL); + g_assert_cmpuint (total, >, 0); + hb_face_destroy (face); +} + +#ifndef HB_NO_AAT +static void +test_nullable_output_aat_feature_types (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/aat-feat.ttf"); + unsigned int count = 100; + g_assert_cmpuint (hb_aat_layout_get_feature_types (face, 0, &count, NULL), ==, 11); + hb_face_destroy (face); +} + +static void +test_nullable_output_aat_selector_infos (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/aat-feat.ttf"); + unsigned int count = 100; + g_assert_cmpuint (hb_aat_layout_feature_type_get_selector_infos ( + face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE, + 0, &count, NULL, NULL), ==, 4); + hb_face_destroy (face); +} +#endif + +static void +test_nullable_output_cv_characters (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/cv01.otf"); + unsigned int feature_index; + if (hb_ot_layout_language_find_feature (face, HB_OT_TAG_GSUB, 0, + HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX, + HB_TAG ('c','v','0','1'), &feature_index)) + { + unsigned int count = 100; + g_assert_cmpuint (hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, + feature_index, 0, + &count, NULL), ==, 2); + } + hb_face_destroy (face); +} + +static void +test_nullable_output_gsub_alternates (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansPro-Regular.otf"); + unsigned int count = 100; + g_assert_cmpuint (hb_ot_layout_lookup_get_glyph_alternates (face, 1, 1091, 0, + &count, NULL), ==, 7); + hb_face_destroy (face); +} + +static void +test_nullable_output_table_tags (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/cpal-v0.ttf"); + unsigned int count = 100; + unsigned int total = hb_face_get_table_tags (face, 0, &count, NULL); + g_assert_cmpuint (total, >, 0); + hb_face_destroy (face); +} + +static void +test_nullable_output_var_axis_infos (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype.abc.otf"); + unsigned int count = 100; + unsigned int total = hb_ot_var_get_axis_infos (face, 0, &count, NULL); + g_assert_cmpuint (total, >, 0); + hb_face_destroy (face); +} + +static void +test_nullable_output_math_kernings (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/MathTestFontFull.otf"); + hb_font_t *font = hb_font_create (face); + hb_codepoint_t glyph; + if (hb_font_get_glyph_from_name (font, "I", -1, &glyph)) + { + unsigned int count = 100; + g_assert_cmpuint (hb_ot_math_get_glyph_kernings (font, glyph, + HB_OT_MATH_KERN_TOP_RIGHT, + 0, &count, NULL), ==, 10); + } + hb_font_destroy (font); + hb_face_destroy (face); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + + hb_test_add (test_nullable_output_cpal_colors); + hb_test_add (test_nullable_output_colr_layers); + hb_test_add (test_nullable_output_meta_entries); +#ifndef HB_NO_AAT + hb_test_add (test_nullable_output_aat_feature_types); + hb_test_add (test_nullable_output_aat_selector_infos); +#endif + hb_test_add (test_nullable_output_cv_characters); + hb_test_add (test_nullable_output_gsub_alternates); + hb_test_add (test_nullable_output_table_tags); + hb_test_add (test_nullable_output_var_axis_infos); + hb_test_add (test_nullable_output_math_kernings); + + return hb_test_run (); +} diff --git a/test/api/test-ot-tag.c b/test/api/test-ot-tag.c index 60a9c0c0f..e01c169ca 100644 --- a/test/api/test-ot-tag.c +++ b/test/api/test-ot-tag.c @@ -291,6 +291,9 @@ test_ot_tags_to_script_and_language (void) test_tags_to_script_and_language ("dev2", "MAR", "Deva", "mr-x-hbsc-64657632"); test_tags_to_script_and_language ("dev3", "MAR", "Deva", "mr"); test_tags_to_script_and_language ("qaa", "QTZ0", "Qaaa", "x-hbot-51545a30-hbsc-71616120"); + /* Default language tag maps to a NULL language; the script-suffix path + * must not dereference it. */ + test_tags_to_script_and_language ("DFLT", "dflt", "", NULL); } static void diff --git a/test/api/test-paint.c b/test/api/test-paint.c index f12ca426d..fb829c809 100644 --- a/test/api/test-paint.c +++ b/test/api/test-paint.c @@ -111,6 +111,24 @@ pop_transform (hb_paint_funcs_t *funcs HB_UNUSED, print (data, "end transform"); } +static void +fill_glyph (hb_paint_funcs_t *funcs HB_UNUSED, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font HB_UNUSED, + hb_bool_t use_foreground HB_UNUSED, + hb_color_t color, + void *user_data HB_UNUSED) +{ + paint_data_t *data = paint_data; + + print (data, "fill glyph %u solid %d %d %d %d", glyph, + hb_color_get_red (color), + hb_color_get_green (color), + hb_color_get_blue (color), + hb_color_get_alpha (color)); +} + static hb_bool_t paint_color_glyph (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data, @@ -341,6 +359,7 @@ get_test_paint_funcs (void) hb_paint_funcs_set_push_transform_func (funcs, push_transform, NULL, NULL); hb_paint_funcs_set_pop_transform_func (funcs, pop_transform, NULL, NULL); + hb_paint_funcs_set_fill_glyph_func (funcs, fill_glyph, NULL, NULL); hb_paint_funcs_set_color_glyph_func (funcs, paint_color_glyph, NULL, NULL); hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph, NULL, NULL); hb_paint_funcs_set_push_clip_rectangle_func (funcs, push_clip_rectangle, NULL, NULL); @@ -828,6 +847,70 @@ test_push_clip_path_round_trip (void) hb_draw_funcs_destroy (sink); } +/* Test the default implementation of fill_glyph does the + * push_clip_glyph + color + pop_clip sequence. */ +static void +test_fill_glyph_nil_decomposes (void) +{ + hb_paint_funcs_t *funcs = hb_paint_funcs_create (); + hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph, NULL, NULL); + hb_paint_funcs_set_color_func (funcs, paint_color, NULL, NULL); + hb_paint_funcs_set_pop_clip_func (funcs, pop_clip, NULL, NULL); + hb_paint_funcs_make_immutable (funcs); + + paint_data_t data; + data.string = g_string_new (""); + data.level = 0; + + hb_paint_fill_glyph (funcs, &data, 42, hb_font_get_empty (), + FALSE, HB_COLOR (1, 2, 3, 4)); + + g_assert_true (data.level == 0); + g_assert_cmpstr (data.string->str, ==, + "start clip glyph 42\n" + " solid 3 2 1 4\n" + "end clip\n"); + + g_string_free (data.string, TRUE); + hb_paint_funcs_destroy (funcs); +} + +static void *color_glyph_user_data_seen; + +static hb_bool_t +color_glyph_record_user_data (hb_paint_funcs_t *funcs HB_UNUSED, + void *paint_data HB_UNUSED, + hb_codepoint_t glyph HB_UNUSED, + hb_font_t *font HB_UNUSED, + void *user_data) +{ + color_glyph_user_data_seen = user_data; + return TRUE; +} + +/* Each callback must be handed the user_data it was registered with, + * not another callback's. */ +static void +test_color_glyph_user_data (void) +{ + char color_glyph_ctx = 0; + char push_clip_glyph_ctx = 0; + + hb_paint_funcs_t *funcs = hb_paint_funcs_create (); + hb_paint_funcs_set_color_glyph_func (funcs, color_glyph_record_user_data, + &color_glyph_ctx, NULL); + hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph, + &push_clip_glyph_ctx, NULL); + hb_paint_funcs_make_immutable (funcs); + + color_glyph_user_data_seen = NULL; + hb_paint_color_glyph (funcs, NULL, 42, hb_font_get_empty ()); + + g_assert_true (color_glyph_user_data_seen == &color_glyph_ctx); + + hb_paint_funcs_destroy (funcs); +} + int main (int argc, char **argv) @@ -840,6 +923,8 @@ main (int argc, char **argv) * below doesn't prevent them from running. */ hb_test_add (test_push_clip_path_nil_returns_null); hb_test_add (test_push_clip_path_round_trip); + hb_test_add (test_fill_glyph_nil_decomposes); + hb_test_add (test_color_glyph_user_data); for (unsigned int i = 0; i < G_N_ELEMENTS (paint_tests); i++) { diff --git a/test/api/test-raster.cc b/test/api/test-raster.cc index 144e84f05..f82f91583 100644 --- a/test/api/test-raster.cc +++ b/test/api/test-raster.cc @@ -225,6 +225,67 @@ test_set_glyph_extents_with_transform (void) hb_raster_draw_destroy (rdr); } +/* ── Test 6: image paint under an overflowing transform ──────────── */ + +/* Nested scales, each representable, whose product overflows to infinity. + * The inverse transform then carries NaN into the image sampler's texel + * coordinates. Exercised for the float-to-int conversion, so this needs a + * sanitizer build to catch a regression. */ +static void +test_image_nonfinite_transform (void) +{ + hb_raster_paint_t *paint = hb_raster_paint_create_or_fail (); + g_assert_nonnull (paint); + + hb_raster_extents_t ext = {0, 0, 32, 32, 0}; + hb_raster_paint_set_extents (paint, &ext); + + hb_paint_funcs_t *funcs = hb_raster_paint_get_funcs (paint); + + hb_paint_push_transform (funcs, paint, 1e30f, 0.f, 0.f, 1e30f, 0.f, 0.f); + hb_paint_push_transform (funcs, paint, 1e30f, 0.f, 0.f, 1e30f, 0.f, 0.f); + + const unsigned w = 4, h = 4; + char pixels[w * h * 4]; + memset (pixels, 0, sizeof (pixels)); + hb_blob_t *blob = hb_blob_create (pixels, sizeof (pixels), + HB_MEMORY_MODE_READONLY, nullptr, nullptr); + + hb_glyph_extents_t gext = {0, 32, 32, -32}; + hb_paint_image (funcs, paint, blob, w, h, + HB_PAINT_IMAGE_FORMAT_BGRA, 0.f, &gext); + + hb_paint_pop_transform (funcs, paint); + hb_paint_pop_transform (funcs, paint); + + hb_blob_destroy (blob); + hb_raster_paint_destroy (paint); +} + +/* ── Test 7: glyph extents that overflow the int grid ────────────── */ + +/* Glyph extents are int32, so a transform that scales them up puts the + * corner coordinates far outside the int range before they are floored + * back to the integer pixel grid. Exercised for the conversion itself, + * so this needs a sanitizer build to catch a regression. */ +static void +test_set_glyph_extents_overflow (void) +{ + hb_glyph_extents_t gext = {-2000000000, 2000000000, 2000000000, -2000000000}; + + hb_raster_draw_t *rdr = hb_raster_draw_create_or_fail (); + g_assert_nonnull (rdr); + hb_raster_draw_set_transform (rdr, 1000.f, 0.f, 0.f, 1000.f, 0.f, 0.f); + hb_raster_draw_set_glyph_extents (rdr, &gext); + hb_raster_draw_destroy (rdr); + + hb_raster_paint_t *paint = hb_raster_paint_create_or_fail (); + g_assert_nonnull (paint); + hb_raster_paint_set_transform (paint, 1000.f, 0.f, 0.f, 1000.f, 0.f, 0.f); + hb_raster_paint_set_glyph_extents (paint, &gext); + hb_raster_paint_destroy (paint); +} + /* ── main ────────────────────────────────────────────────────────── */ int @@ -237,6 +298,8 @@ main (int argc, char **argv) hb_test_add (test_subpixel_edge); hb_test_add (test_transform); hb_test_add (test_set_glyph_extents_with_transform); + hb_test_add (test_image_nonfinite_transform); + hb_test_add (test_set_glyph_extents_overflow); return hb_test_run (); } diff --git a/test/api/test-subset-cff1.c b/test/api/test-subset-cff1.c index f6a79a9c8..88c79bbb9 100644 --- a/test/api/test-subset-cff1.c +++ b/test/api/test-subset-cff1.c @@ -336,6 +336,54 @@ test_subset_cff1_j_retaingids (void) hb_face_destroy (face_41_4c2e); } +static void +test_subset_cff1_identity_charset (void) +{ + /* The flag has no effect on a name-keyed font, so this is the same output + * as test_subset_cff1(). */ + hb_face_t *face_abc = hb_test_open_font_file ("fonts/SourceSansPro-Regular.abc.otf"); + hb_face_t *face_ac = hb_test_open_font_file ("fonts/SourceSansPro-Regular.ac.otf"); + + hb_set_t *codepoints = hb_set_create (); + hb_subset_input_t *input; + hb_face_t *face_abc_subset; + hb_set_add (codepoints, 'a'); + hb_set_add (codepoints, 'c'); + input = hb_subset_test_create_input (codepoints); + hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET); + face_abc_subset = hb_subset_test_create_subset (face_abc, input); + hb_set_destroy (codepoints); + + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('C','F','F',' ')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_ac); +} + +static void +test_subset_cff1_j_identity_charset (void) +{ + hb_face_t *face_41_3041_4c2e = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,3041,4C2E.otf"); + hb_face_t *face_41_4c2e = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,4C2E.identity.otf"); + + hb_set_t *codepoints = hb_set_create (); + hb_subset_input_t *input; + hb_face_t *face_41_3041_4c2e_subset; + hb_set_add (codepoints, 0x41); + hb_set_add (codepoints, 0x4C2E); + input = hb_subset_test_create_input (codepoints); + hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET); + face_41_3041_4c2e_subset = hb_subset_test_create_subset (face_41_3041_4c2e, input); + hb_set_destroy (codepoints); + + hb_subset_test_check (face_41_4c2e, face_41_3041_4c2e_subset, HB_TAG ('C','F','F',' ')); + + hb_face_destroy (face_41_3041_4c2e_subset); + hb_face_destroy (face_41_3041_4c2e); + hb_face_destroy (face_41_4c2e); +} + #ifdef HB_EXPERIMENTAL_API static void test_subset_cff1_iftb_requirements (void) @@ -383,6 +431,8 @@ main (int argc, char **argv) hb_test_add (test_subset_cff1_dotsection); hb_test_add (test_subset_cff1_retaingids); hb_test_add (test_subset_cff1_j_retaingids); + hb_test_add (test_subset_cff1_identity_charset); + hb_test_add (test_subset_cff1_j_identity_charset); #ifdef HB_EXPERIMENTAL_API hb_test_add (test_subset_cff1_iftb_requirements); diff --git a/test/api/test-subset.c b/test/api/test-subset.c index ad78260d0..3e87328f2 100644 --- a/test/api/test-subset.c +++ b/test/api/test-subset.c @@ -338,7 +338,7 @@ test_subset_cff2_get_charstring_data_no_cff (void) hb_blob_t* cs0 = hb_subset_cff2_get_charstring_data (face, 0); g_assert_true (hb_blob_get_length (cs0) == 0); - + hb_face_destroy (builder); hb_blob_destroy (face_blob); hb_face_destroy (face); @@ -403,6 +403,202 @@ test_subset_cff2_get_charstring_data_lifetime (void) #endif +#ifdef HB_EXPERIMENTAL_API +static void +test_subset_input_to_string (void) +{ + /* Test NULL input */ + g_assert_null (hb_subset_input_to_string_or_fail (NULL)); + + /* Test default input -> empty string */ + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_blob_t *blob = hb_subset_input_to_string_or_fail (input); + g_assert_nonnull (blob); + unsigned len = 0; + const char *data = hb_blob_get_data (blob, &len); + g_assert_cmpint (len, ==, 1); + g_assert_cmpstr (data, ==, ""); + hb_blob_destroy (blob); + hb_subset_input_destroy (input); + } + + /* Test unicodes ranges */ + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_set_t *unicodes = hb_subset_input_unicode_set (input); + hb_set_add (unicodes, 0x41); + hb_set_add (unicodes, 0x42); + hb_set_add (unicodes, 0x43); + hb_set_add (unicodes, 0x45); + hb_set_add (unicodes, 0x61); + hb_set_add (unicodes, 0x62); + hb_set_add (unicodes, 0x63); + + hb_blob_t *blob = hb_subset_input_to_string_or_fail (input); + g_assert_nonnull (blob); + unsigned len = 0; + const char *data = hb_blob_get_data (blob, &len); + g_assert_cmpstr (data, ==, "--unicodes=41-43,45,61-63"); + hb_blob_destroy (blob); + hb_subset_input_destroy (input); + } + + /* Test gids ranges and flags */ + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_set_t *gids = hb_subset_input_glyph_set (input); + hb_set_add (gids, 1); + hb_set_add (gids, 2); + hb_set_add (gids, 3); + hb_set_add (gids, 5); + hb_set_add (gids, 10); + hb_set_add (gids, 11); + hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_NO_HINTING | HB_SUBSET_FLAGS_RETAIN_GIDS); + + hb_blob_t *blob = hb_subset_input_to_string_or_fail (input); + g_assert_nonnull (blob); + unsigned len = 0; + const char *data = hb_blob_get_data (blob, &len); + g_assert_cmpstr (data, ==, "--no-hinting --retain-gids --gids=1-3,5,10-11"); + hb_blob_destroy (blob); + hb_subset_input_destroy (input); + } + + /* Test keep everything */ + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_subset_input_keep_everything (input); + + hb_blob_t *blob = hb_subset_input_to_string_or_fail (input); + g_assert_nonnull (blob); + unsigned len = 0; + const char *data = hb_blob_get_data (blob, &len); + const char *expected = "--name-legacy --passthrough-tables --notdef-outline --glyph-names --no-prune-unicode-ranges --unicodes=* --gids=* --name-IDs=* --name-languages=* --layout-features=* --drop-tables-=*"; + g_assert_cmpstr (data, ==, expected); + g_assert_cmpint (len - 1, ==, strlen (expected)); + hb_blob_destroy (blob); + hb_subset_input_destroy (input); + } + + /* Test inverted sets with exclusions */ + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_set_t *unicodes = hb_subset_input_set (input, HB_SUBSET_SETS_UNICODE); + hb_set_invert (unicodes); + hb_set_del (unicodes, 0x20); + hb_set_del (unicodes, 0x41); + hb_set_del (unicodes, 0x42); + hb_set_del (unicodes, 0x43); + + hb_set_t *gids = hb_subset_input_set (input, HB_SUBSET_SETS_GLYPH_INDEX); + hb_set_invert (gids); + hb_set_del (gids, 5); + hb_set_del (gids, 6); + hb_set_del (gids, 7); + + hb_set_t *features = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + hb_set_clear (features); + hb_set_invert (features); + hb_set_del (features, HB_TAG ('k', 'e', 'r', 'n')); + + hb_blob_t *blob = hb_subset_input_to_string_or_fail (input); + g_assert_nonnull (blob); + unsigned len = 0; + const char *data = hb_blob_get_data (blob, &len); + const char *expected = "--unicodes=* --unicodes-=20,41-43 --gids=* --gids-=5-7 --layout-features=* --layout-features-=kern"; + g_assert_cmpstr (data, ==, expected); + hb_blob_destroy (blob); + hb_subset_input_destroy (input); + } + + /* Test empty non-default sets */ + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_set_clear (hb_subset_input_set (input, HB_SUBSET_SETS_NAME_ID)); + hb_set_clear (hb_subset_input_set (input, HB_SUBSET_SETS_NAME_LANG_ID)); + + hb_blob_t *blob = hb_subset_input_to_string_or_fail (input); + g_assert_nonnull (blob); + unsigned len = 0; + const char *data = hb_blob_get_data (blob, &len); + const char *expected = "--name-IDs-=* --name-languages-=*"; + g_assert_cmpstr (data, ==, expected); + hb_blob_destroy (blob); + hb_subset_input_destroy (input); + } + + /* Test non-default non-inverted tag sets */ + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + + hb_set_t *features = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + hb_set_clear (features); + hb_set_add (features, HB_TAG ('l', 'i', 'g', 'a')); + hb_set_add (features, HB_TAG ('k', 'e', 'r', 'n')); + + hb_set_t *scripts = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_SCRIPT_TAG); + hb_set_clear (scripts); + hb_set_add (scripts, HB_TAG ('l', 'a', 't', 'n')); + + hb_set_t *drop_tables = hb_subset_input_set (input, HB_SUBSET_SETS_DROP_TABLE_TAG); + hb_set_clear (drop_tables); + hb_set_add (drop_tables, HB_TAG ('G', 'S', 'U', 'B')); + + hb_blob_t *blob = hb_subset_input_to_string_or_fail (input); + g_assert_nonnull (blob); + unsigned len = 0; + const char *data = hb_blob_get_data (blob, &len); + const char *expected = "--layout-features=kern,liga --layout-scripts=latn --drop-tables=GSUB"; + g_assert_cmpstr (data, ==, expected); + hb_blob_destroy (blob); + hb_subset_input_destroy (input); + } + + /* Test tag sanitization with unsafe ASCII characters */ + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + + hb_set_t *features = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + hb_set_clear (features); + /* Tag with space, newline, and single-quote: 'a \n'' */ + hb_set_add (features, HB_TAG ('a', ' ', '\n', '\'')); + + hb_blob_t *blob = hb_subset_input_to_string_or_fail (input); + g_assert_nonnull (blob); + unsigned len = 0; + const char *data = hb_blob_get_data (blob, &len); + const char *expected = "--layout-features=a___"; + g_assert_cmpstr (data, ==, expected); + hb_blob_destroy (blob); + hb_subset_input_destroy (input); + } + + /* Test trimming trailing whitespace from tags */ + { + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + + hb_set_t *drop_tables = hb_subset_input_set (input, HB_SUBSET_SETS_DROP_TABLE_TAG); + hb_set_clear (drop_tables); + hb_set_add (drop_tables, HB_TAG ('c', 'v', 't', ' ')); + + hb_set_t *features = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG); + hb_set_clear (features); + hb_set_add (features, HB_TAG (' ', ' ', ' ', ' ')); + hb_set_add (features, HB_TAG ('f', 'o', 'o', ' ')); + + hb_blob_t *blob = hb_subset_input_to_string_or_fail (input); + g_assert_nonnull (blob); + unsigned len = 0; + const char *data = hb_blob_get_data (blob, &len); + const char *expected = "--layout-features=,foo --drop-tables=cvt"; + g_assert_cmpstr (data, ==, expected); + hb_blob_destroy (blob); + hb_subset_input_destroy (input); + } +} +#endif + int main (int argc, char **argv) { @@ -417,6 +613,7 @@ main (int argc, char **argv) hb_test_add (test_subset_create_for_tables_face); #ifdef HB_EXPERIMENTAL_API + hb_test_add (test_subset_input_to_string); hb_test_add (test_subset_cff2_get_charstring_data); hb_test_add (test_subset_cff2_get_all_charstrings_data); hb_test_add (test_subset_cff2_get_charstring_data_no_cff); @@ -426,3 +623,4 @@ main (int argc, char **argv) return hb_test_run(); } + diff --git a/test/fuzzing/fonts/037322204d9bc87b6b0b0f2342c97caa9c5fd479 b/test/fuzzing/fonts/037322204d9bc87b6b0b0f2342c97caa9c5fd479 new file mode 100644 index 000000000..1a2ca4cf5 Binary files /dev/null and b/test/fuzzing/fonts/037322204d9bc87b6b0b0f2342c97caa9c5fd479 differ diff --git a/test/fuzzing/fonts/cbdt-png-indexed-trns-smask-dimension-oob.ttf b/test/fuzzing/fonts/cbdt-png-indexed-trns-smask-dimension-oob.ttf new file mode 100644 index 000000000..5227c3e7e Binary files /dev/null and b/test/fuzzing/fonts/cbdt-png-indexed-trns-smask-dimension-oob.ttf differ diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-4621471331450880 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-4621471331450880 new file mode 100644 index 000000000..9b8f17f6d Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-4621471331450880 differ diff --git a/test/fuzzing/fonts/sbix-png-plte-chunklen-oob.ttf b/test/fuzzing/fonts/sbix-png-plte-chunklen-oob.ttf new file mode 100644 index 000000000..b941b6884 Binary files /dev/null and b/test/fuzzing/fonts/sbix-png-plte-chunklen-oob.ttf differ diff --git a/test/shape/data/in-house/fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf b/test/shape/data/in-house/fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf new file mode 100644 index 000000000..41825c743 Binary files /dev/null and b/test/shape/data/in-house/fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf differ diff --git a/test/shape/data/in-house/meson.build b/test/shape/data/in-house/meson.build index 12a313a83..1253b08e5 100644 --- a/test/shape/data/in-house/meson.build +++ b/test/shape/data/in-house/meson.build @@ -22,6 +22,7 @@ in_house_tests = [ 'emoji-clusters.tests', 'fallback-positioning.tests', 'glyph-props-no-gdef.tests', + 'hangul-calt.tests', 'hangul-jamo.tests', 'harfbust.tests', 'hebrew-diacritics.tests', diff --git a/test/shape/data/in-house/tests/hangul-calt.tests b/test/shape/data/in-house/tests/hangul-calt.tests new file mode 100644 index 000000000..0c1eba6c4 --- /dev/null +++ b/test/shape/data/in-house/tests/hangul-calt.tests @@ -0,0 +1,5 @@ +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;;U+AC00,U+003D,U+003E;[ga=0+600|eq_gt.calt=1+600] +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;;U+AC00,U+B098;[ga_na.calt=0+600] +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;;U+1100,U+1100;[jamoL=0+600|jamoL=1+600] +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;;U+B098,U+B098;[na_na.liga=0+600] +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;--features=calt=0;U+AC00,U+003D,U+003E;[ga=0+600|equal=1+600|greater=2+600] diff --git a/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.41,42,43.wght=200-400-800.ttf b/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.41,42,43.wght=200-400-800.ttf new file mode 100644 index 000000000..0561b7734 Binary files /dev/null and b/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.41,42,43.wght=200-400-800.ttf differ diff --git a/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.41,42,43.wght=300-600.ttf b/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.41,42,43.wght=300-600.ttf new file mode 100644 index 000000000..5bf6d58b9 Binary files /dev/null and b/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.41,42,43.wght=300-600.ttf differ diff --git a/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.all.wght=200-400-800.ttf b/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.all.wght=200-400-800.ttf new file mode 100644 index 000000000..97c16721d Binary files /dev/null and b/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.all.wght=200-400-800.ttf differ diff --git a/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.all.wght=300-600.ttf b/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.all.wght=300-600.ttf new file mode 100644 index 000000000..35af082a6 Binary files /dev/null and b/test/subset/data/expected/hvar_partial_instance_implicit_map/ImplicitHVAR.default.all.wght=300-600.ttf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.CNTR=drop.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.CNTR=drop.otf new file mode 100644 index 000000000..13f87196c Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.CNTR=drop.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.wght=300-500-700,CNTR=25-75.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.wght=300-500-700,CNTR=25-75.otf new file mode 100644 index 000000000..d59b75d52 Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.wght=300-500-700,CNTR=25-75.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.wght=300-600.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.wght=300-600.otf new file mode 100644 index 000000000..f1af6023e Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.wght=300-600.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.wght=500,CNTR=0-100.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.wght=500,CNTR=0-100.otf new file mode 100644 index 000000000..d11a3cef6 Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.41,42,43.wght=500,CNTR=0-100.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.CNTR=drop.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.CNTR=drop.otf new file mode 100644 index 000000000..389f12758 Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.CNTR=drop.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.wght=300-500-700,CNTR=25-75.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.wght=300-500-700,CNTR=25-75.otf new file mode 100644 index 000000000..9d5412577 Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.wght=300-500-700,CNTR=25-75.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.wght=300-600.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.wght=300-600.otf new file mode 100644 index 000000000..c7e9e2cbd Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.wght=300-600.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.wght=500,CNTR=0-100.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.wght=500,CNTR=0-100.otf new file mode 100644 index 000000000..a68d19590 Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype.default.all.wght=500,CNTR=0-100.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.CNTR=drop.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.CNTR=drop.otf new file mode 100644 index 000000000..4db7879bc Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.CNTR=drop.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.wght=300-500-700,CNTR=25-75.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.wght=300-500-700,CNTR=25-75.otf new file mode 100644 index 000000000..b7b353ae1 Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.wght=300-500-700,CNTR=25-75.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.wght=300-600.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.wght=300-600.otf new file mode 100644 index 000000000..4e7f4d1b9 Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.wght=300-600.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.wght=500,CNTR=0-100.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.wght=500,CNTR=0-100.otf new file mode 100644 index 000000000..8bf3f51ba Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.41,42,43.wght=500,CNTR=0-100.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.CNTR=drop.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.CNTR=drop.otf new file mode 100644 index 000000000..4db7879bc Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.CNTR=drop.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.wght=300-500-700,CNTR=25-75.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.wght=300-500-700,CNTR=25-75.otf new file mode 100644 index 000000000..b7b353ae1 Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.wght=300-500-700,CNTR=25-75.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.wght=300-600.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.wght=300-600.otf new file mode 100644 index 000000000..4e7f4d1b9 Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.wght=300-600.otf differ diff --git a/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.wght=500,CNTR=0-100.otf b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.wght=500,CNTR=0-100.otf new file mode 100644 index 000000000..8bf3f51ba Binary files /dev/null and b/test/subset/data/expected/instantiate_cff2_partial/AdobeVFPrototype_vsindex.default.all.wght=500,CNTR=0-100.otf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.default.21D4.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.default.21D4.ttf new file mode 100644 index 000000000..a9f37ff42 Binary files /dev/null and b/test/subset/data/expected/math/STIXTwoMath-Regular.default.21D4.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.default.2f,7c,305.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.default.2f,7c,305.ttf index e662f4cfe..80d2ffb30 100644 Binary files a/test/subset/data/expected/math/STIXTwoMath-Regular.default.2f,7c,305.ttf and b/test/subset/data/expected/math/STIXTwoMath-Regular.default.2f,7c,305.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.default.all.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.default.all.ttf index 08ec8e4f7..cb493838c 100644 Binary files a/test/subset/data/expected/math/STIXTwoMath-Regular.default.all.ttf and b/test/subset/data/expected/math/STIXTwoMath-Regular.default.all.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.21D4.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.21D4.ttf new file mode 100644 index 000000000..8e3a8cc07 Binary files /dev/null and b/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.21D4.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.2f,7c,305.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.2f,7c,305.ttf index b757c5c86..f8184b38b 100644 Binary files a/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.2f,7c,305.ttf and b/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.2f,7c,305.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.all.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.all.ttf index 58c72774b..cec887140 100644 Binary files a/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.all.ttf and b/test/subset/data/expected/math/STIXTwoMath-Regular.glyph-names.all.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.21D4.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.21D4.ttf new file mode 100644 index 000000000..3a2167413 Binary files /dev/null and b/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.21D4.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.2f,7c,305.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.2f,7c,305.ttf index a93fdbb29..e8c01ff68 100644 Binary files a/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.2f,7c,305.ttf and b/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.2f,7c,305.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.all.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.all.ttf index c589e1d46..285d711c1 100644 Binary files a/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.all.ttf and b/test/subset/data/expected/math/STIXTwoMath-Regular.notdef-outline.all.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.21D4.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.21D4.ttf new file mode 100644 index 000000000..df494264d Binary files /dev/null and b/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.21D4.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.2f,7c,305.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.2f,7c,305.ttf index 77a863619..1769e121e 100644 Binary files a/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.2f,7c,305.ttf and b/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.2f,7c,305.ttf differ diff --git a/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.all.ttf b/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.all.ttf index c77123e91..d39aebc4c 100644 Binary files a/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.all.ttf and b/test/subset/data/expected/math/STIXTwoMath-Regular.retain-gids.all.ttf differ diff --git a/test/subset/data/expected/retain-num-glyphs/NotoSansJP-VF.subset.retain-num-glyphs.all.otf b/test/subset/data/expected/retain-num-glyphs/NotoSansJP-VF.subset.retain-num-glyphs.all.otf index 8105e7907..43e8bcc60 100644 Binary files a/test/subset/data/expected/retain-num-glyphs/NotoSansJP-VF.subset.retain-num-glyphs.all.otf and b/test/subset/data/expected/retain-num-glyphs/NotoSansJP-VF.subset.retain-num-glyphs.all.otf differ diff --git a/test/subset/data/fonts/AdobeVFPrototype_vsindex.otf b/test/subset/data/fonts/AdobeVFPrototype_vsindex.otf new file mode 100644 index 000000000..3697b46c1 Binary files /dev/null and b/test/subset/data/fonts/AdobeVFPrototype_vsindex.otf differ diff --git a/test/subset/data/fonts/ImplicitHVAR.ttf b/test/subset/data/fonts/ImplicitHVAR.ttf new file mode 100644 index 000000000..2f4d74eeb Binary files /dev/null and b/test/subset/data/fonts/ImplicitHVAR.ttf differ diff --git a/test/subset/data/fonts/bad-gsub.otf b/test/subset/data/fonts/bad-gsub.otf new file mode 100644 index 000000000..27ed30b54 Binary files /dev/null and b/test/subset/data/fonts/bad-gsub.otf differ diff --git a/test/subset/data/repack_tests/duplicate_before_mutation.tests b/test/subset/data/repack_tests/duplicate_before_mutation.tests new file mode 100644 index 000000000..79e019c86 --- /dev/null +++ b/test/subset/data/repack_tests/duplicate_before_mutation.tests @@ -0,0 +1,31 @@ +bad-gsub.otf +U+0061 +U+0062 +U+0063 +U+0064 +U+0065 +U+0066 +U+0067 +U+0068 +U+0069 +U+006A +U+006B +U+006C +U+006D +U+006E +U+006F +U+0070 +U+0071 +U+0072 +U+0073 +U+0074 +U+0075 +U+0076 +U+0077 +U+0078 +U+0079 +U+007A +U+007B +U+007C +U+007D + diff --git a/test/subset/data/tests/hvar_partial_instance_implicit_map.tests b/test/subset/data/tests/hvar_partial_instance_implicit_map.tests new file mode 100644 index 000000000..4dc40f039 --- /dev/null +++ b/test/subset/data/tests/hvar_partial_instance_implicit_map.tests @@ -0,0 +1,13 @@ +FONTS: +ImplicitHVAR.ttf + +PROFILES: +default.txt + +SUBSETS: +* +ABC + +INSTANCES: +wght=300:600 +wght=200:400:800 diff --git a/test/subset/data/tests/instantiate_cff2_partial.tests b/test/subset/data/tests/instantiate_cff2_partial.tests new file mode 100644 index 000000000..6acfde791 --- /dev/null +++ b/test/subset/data/tests/instantiate_cff2_partial.tests @@ -0,0 +1,19 @@ +FONTS: +AdobeVFPrototype.otf +AdobeVFPrototype_vsindex.otf + +PROFILES: +default.txt + +SUBSETS: +* +ABC + +INSTANCES: +wght=300:600 +wght=500,CNTR=0:100 +wght=300:500:700,CNTR=25:75 +CNTR=drop + +OPTIONS: +no_fonttools diff --git a/test/subset/data/tests/math.tests b/test/subset/data/tests/math.tests index 91a2405d1..3582e265a 100644 --- a/test/subset/data/tests/math.tests +++ b/test/subset/data/tests/math.tests @@ -9,4 +9,5 @@ notdef-outline.txt SUBSETS: U+2f,U+7c,U+305 +U+21D4 * diff --git a/test/subset/meson.build b/test/subset/meson.build index 870601830..1c8298cdc 100644 --- a/test/subset/meson.build +++ b/test/subset/meson.build @@ -62,6 +62,7 @@ tests = [ 'instantiate_colrv1', 'instantiate_glyf', 'instantiate_cff2', + 'instantiate_cff2_partial', 'downgrade_cff2', 'instantiate_cff2_tsb', 'full_instance', @@ -75,6 +76,7 @@ tests = [ 'instantiate_cff2_update_metrics', 'layout.empty_ligature_offset', 'glyf_partial_instancing', + 'hvar_partial_instance_implicit_map', 'mvar_partial_instance', 'update_def_wght', 'feature_variations_partial_instance', @@ -103,6 +105,7 @@ repack_tests = [ 'isolation', 'advanced_prioritization', 'space_splitting', + 'duplicate_before_mutation', ] run_test = find_program('run-tests.py') diff --git a/test/vector/data/expected/basic/colrv0-large-scale.pdf b/test/vector/data/expected/basic/colrv0-large-scale.pdf new file mode 100644 index 000000000..54074f06a --- /dev/null +++ b/test/vector/data/expected/basic/colrv0-large-scale.pdf @@ -0,0 +1,159 @@ +%PDF-1.4 +%ÀÁÂÃ +1 0 obj +<< /Type /Catalog /Pages 2 0 R >> +endobj +2 0 obj +<< /Type /Pages /Kids [3 0 R] /Count 1 >> +endobj +3 0 obj +<< /Type /Page /Parent 2 0 R /MediaBox [-16 -8208 65552 57360] +/Contents 4 0 R >> +endobj +4 0 obj +<< /Length 4518 >> +stream +1 1 1 rg +-16 -8208 65568 65568 re f +q +1 0 0 1 0 0 cm +0.8667 0.1804 0.2667 rg +55936 47744 m +62336 41344 65536 33621.33 65536 24576 c +65536 15530.67 62336 7808 55936 1408 c +49536 -4992 41813.33 -8192 32768 -8192 c +23722.67 -8192 16000 -4992 9600 1408 c +3200 7808 0 15530.67 0 24576 c +0 33621.33 3200 41344 9600 47744 c +16000 54144 23722.67 57344 32768 57344 c +41813.33 57344 49536 54144 55936 47744 c +h +f +1 1 1 rg +25472 35200 m +26410.67 35200 26880 34645.33 26880 33536 c +26880 32426.67 26410.67 31872 25472 31872 c +20992 31872 l +22101.33 29312 23637.33 27050.67 25600 25088 c +25941.33 24746.67 26112 24320 26112 23808 c +26112 23381.33 25984 22997.33 25728 22656 c +25386.67 22314.67 25002.67 22144 24576 22144 c +24064 22144 23594.67 22357.33 23168 22784 c +22144 24234.67 21162.67 26112 20224 28416 c +20650.67 25344 20864 22869.33 20864 20992 c +20864 3456 l +20864 2517.33 20266.67 2048 19072 2048 c +17962.67 2048 17408 2517.33 17408 3456 c +17408 19712 l +17408 21504 17664 24064 18176 27392 c +16554.67 22101.33 14592 17877.33 12288 14720 c +11861.33 14208 11349.33 13952 10752 13952 c +10410.67 13952 10112 14037.33 9856 14208 c +9344 14634.67 9088 15104 9088 15616 c +9088 16042.67 9216 16469.33 9472 16896 c +12800 20992 15232 25984 16768 31872 c +11520 31872 l +10581.33 31872 10112 32426.67 10112 33536 c +10112 34645.33 10581.33 35200 11520 35200 c +17408 35200 l +17408 41600 l +15786.67 41258.67 14250.67 41002.67 12800 40832 c +12800 40746.67 12714.67 40704 12544 40704 c +11605.33 40704 11050.67 41216 10880 42240 c +10880 42496 l +10880 43434.67 11306.67 43989.33 12160 44160 c +16853.33 44842.67 20693.33 45952 23680 47488 c +24021.33 47658.67 24405.33 47744 24832 47744 c +25429.33 47744 25941.33 47445.33 26368 46848 c +26624 46506.67 26752 46165.33 26752 45824 c +26752 45226.67 26410.67 44757.33 25728 44416 c +24533.33 43818.67 22912 43178.67 20864 42496 c +20864 35200 l +25472 35200 l +h +33792 36224 m +33792 37162.67 34432 37632 35712 37632 c +36906.67 37632 37504 37120 37504 36096 c +37504 19328 l +42197.33 25642.67 45738.67 33706.67 48128 43520 c +48298.67 44458.67 48853.33 44928 49792 44928 c +49962.67 44928 50133.33 44885.33 50304 44800 c +51413.33 44629.33 51968 44074.67 51968 43136 c +51968 42880 51925.33 42709.33 51840 42624 c +48597.33 30677.33 43818.67 21120 37504 13952 c +37504 9088 l +37504 7978.67 38016 7338.67 39040 7168 c +39893.33 7082.67 41045.33 7040 42496 7040 c +43776 7040 44906.67 7168 45888 7424 c +46869.33 7680 47488 8234.67 47744 9088 c +48085.33 10282.67 48298.67 11946.67 48384 14080 c +48384 15104 48981.33 15616 50176 15616 c +50304 15616 l +51413.33 15530.67 51968 14933.33 51968 13824 c +51968 13696 l +51797.33 10794.67 51456 8533.33 50944 6912 c +50346.67 5290.67 49066.67 4266.67 47104 3840 c +45994.67 3669.33 44458.67 3541.33 42496 3456 c +40618.67 3456 38997.33 3541.33 37632 3712 c +35072 4053.33 33792 5418.67 33792 7808 c +33792 11264 l +31317.33 8960 28672 6954.67 25856 5248 c +25429.33 4992 25002.67 4864 24576 4864 c +23893.33 4864 23424 5162.67 23168 5760 c +22912 6016 22784 6357.33 22784 6784 c +22784 7552 23125.33 8106.67 23808 8448 c +27306.67 10410.67 30634.67 13013.33 33792 16256 c +33792 36224 l +h +29696 30592 m +29781.33 30592 29866.67 30592 29952 30592 c +30976 30421.33 31488 29866.67 31488 28928 c +31488 28672 31488 28501.33 31488 28416 c +30976 23466.67 29952 19200 28416 15616 c +27989.33 14848 27392 14464 26624 14464 c +26368 14464 26112 14506.67 25856 14592 c +25258.67 14933.33 24960 15402.67 24960 16000 c +24960 16341.33 25045.33 16682.67 25216 17024 c +26666.67 20352 27648 24405.33 28160 29184 c +28245.33 30122.67 28757.33 30592 29696 30592 c +h +42624 41984 m +43221.33 41472 43520 40917.33 43520 40320 c +43520 39978.67 43434.67 39680 43264 39424 c +42837.33 38826.67 42282.67 38528 41600 38528 c +41088 38528 40661.33 38698.67 40320 39040 c +37845.33 41002.67 35157.33 42709.33 32256 44160 c +31658.67 44501.33 31360 44970.67 31360 45568 c +31360 45909.33 31445.33 46208 31616 46464 c +32042.67 47146.67 32640 47488 33408 47488 c +33664 47488 34005.33 47402.67 34432 47232 c +37674.67 45696 40405.33 43946.67 42624 41984 c +h +50816 29952 m +51498.67 29952 52053.33 29568 52480 28800 c +53930.67 25642.67 55082.67 22058.67 55936 18048 c +56021.33 17706.67 56064 17450.67 56064 17280 c +56064 16512 55637.33 15957.33 54784 15616 c +54442.67 15616 54229.33 15616 54144 15616 c +53290.67 15616 52736 16085.33 52480 17024 c +51456 21205.33 50346.67 24661.33 49152 27392 c +48981.33 27648 48896 27946.67 48896 28288 c +48896 28970.67 49237.33 29482.67 49920 29824 c +50176 29909.33 50474.67 29952 50816 29952 c +h +f +Q +endstream +endobj +xref +0 5 +0000000000 65535 f +0000000015 00000 n +0000000064 00000 n +0000000121 00000 n +0000000218 00000 n +trailer +<< /Size 5 /Root 1 0 R >> +startxref +4787 +%%EOF diff --git a/test/vector/data/expected/basic/colrv0-large-scale.svg b/test/vector/data/expected/basic/colrv0-large-scale.svg new file mode 100644 index 000000000..bd76c65d3 --- /dev/null +++ b/test/vector/data/expected/basic/colrv0-large-scale.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/vector/data/expected/basic/glyf-quadratics.pdf b/test/vector/data/expected/basic/glyf-quadratics.pdf new file mode 100644 index 000000000..d13a2c5c9 --- /dev/null +++ b/test/vector/data/expected/basic/glyf-quadratics.pdf @@ -0,0 +1,116 @@ +%PDF-1.4 +%ÀÁÂÃ +1 0 obj +<< /Type /Catalog /Pages 2 0 R >> +endobj +2 0 obj +<< /Type /Pages /Kids [3 0 R] /Count 1 >> +endobj +3 0 obj +<< /Type /Page /Parent 2 0 R /MediaBox [-16 -60816 106736 16016] /Contents 4 0 R >> +endobj +4 0 obj +<< /Length 2625 >> +stream +1 1 1 rg +-16 -60816 106752 76832 re f +0 0 0 rg +25856 0 m +25514.67 682.67 25237.33 1898.67 25024 3648 c +22272 789.33 18986.67 -640 15168 -640 c +11754.67 -640 8954.67 325.33 6768 2256 c +4581.33 4186.67 3488 6634.67 3488 9600 c +3488 13205.33 4858.67 16005.33 7600 18000 c +10341.33 19994.67 14197.33 20992 19168 20992 c +24928 20992 l +24928 23712 l +24928 25781.33 24309.33 27429.33 23072 28656 c +21834.67 29882.67 20010.67 30496 17600 30496 c +15488 30496 13717.33 29962.67 12288 28896 c +10858.67 27829.33 10144 26538.67 10144 25024 c +4192 25024 l +4192 26752 4805.33 28421.33 6032 30032 c +7258.67 31642.67 8922.67 32917.33 11024 33856 c +13125.33 34794.67 15434.67 35264 17952 35264 c +21941.33 35264 25066.67 34266.67 27328 32272 c +29589.33 30277.33 30762.67 27530.67 30848 24032 c +30848 8096 l +30848 4917.33 31253.33 2389.33 32064 512 c +32064 0 l +25856 0 l +h +16032 4512 m +17888 4512 19648 4992 21312 5952 c +22976 6912 24181.33 8160 24928 9696 c +24928 16800 l +20288 16800 l +13034.67 16800 9408 14677.33 9408 10432 c +9408 8576 10026.67 7125.33 11264 6080 c +12501.33 5034.67 14090.67 4512 16032 4512 c +h +f +0 0 0 rg +69440 16928 m +69440 11637.33 68224 7386.67 65792 4176 c +63360 965.33 60096 -640 56000 -640 c +51626.67 -640 48245.33 906.67 45856 4000 c +45568 0 l +40128 0 l +40128 49152 l +46048 49152 l +46048 30816 l +48437.33 33781.33 51733.33 35264 55936 35264 c +60138.66 35264 63440 33674.67 65840 30496 c +68240 27317.33 69440 22965.33 69440 17440 c +69440 16928 l +h +63520 17600 m +63520 21632 62741.34 24746.67 61184 26944 c +59626.66 29141.33 57386.66 30240 54464 30240 c +50560 30240 47754.67 28426.67 46048 24800 c +46048 9824 l +47861.33 6197.33 50688 4384 54528 4384 c +57365.34 4384 59573.34 5482.67 61152 7680 c +62730.66 9877.33 63520 13184 63520 17600 c +h +f +0 0 0 rg +90784 4192 m +92896 4192 94741.34 4832 96320 6112 c +97898.66 7392 98773.34 8992 98944 10912 c +104544 10912 l +104437.34 8928 103754.66 7040 102496 5248 c +101237.34 3456 99557.34 2026.67 97456 960 c +95354.66 -106.67 93130.66 -640 90784 -640 c +86069.34 -640 82320 933.33 79536 4080 c +76752 7226.67 75360 11530.67 75360 16992 c +75360 17984 l +75360 21354.67 75978.66 24352 77216 26976 c +78453.34 29600 80229.34 31637.33 82544 33088 c +84858.66 34538.67 87594.66 35264 90752 35264 c +94634.66 35264 97861.34 34101.33 100432 31776 c +103002.66 29450.67 104373.34 26432 104544 22720 c +98944 22720 l +98773.34 24960 97925.34 26800 96400 28240 c +94874.66 29680 92992 30400 90752 30400 c +87744 30400 85413.34 29317.33 83760 27152 c +82106.66 24986.67 81280 21856 81280 17760 c +81280 16640 l +81280 12650.67 82101.34 9578.67 83744 7424 c +85386.66 5269.33 87733.34 4192 90784 4192 c +h +f +endstream +endobj +xref +0 5 +0000000000 65535 f +0000000015 00000 n +0000000064 00000 n +0000000121 00000 n +0000000220 00000 n +trailer +<< /Size 5 /Root 1 0 R >> +startxref +2896 +%%EOF diff --git a/test/vector/data/expected/basic/handwriting-cff-colr-1.svg b/test/vector/data/expected/basic/handwriting-cff-colr-1.svg index ae4d35ddd..8534b1234 100644 --- a/test/vector/data/expected/basic/handwriting-cff-colr-1.svg +++ b/test/vector/data/expected/basic/handwriting-cff-colr-1.svg @@ -7,30 +7,18 @@ - + - - - - - - - - - - - - + + - - @@ -46,49 +34,29 @@ + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + @@ -97,11 +65,7 @@ - - - - - + diff --git a/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg b/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg index 61792c743..789b5a247 100644 --- a/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg +++ b/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg @@ -7,30 +7,18 @@ - + - - - - - - - - - - - - + + - - @@ -46,49 +34,29 @@ + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + @@ -97,11 +65,7 @@ - - - - - + diff --git a/test/vector/data/tests/basic.tests b/test/vector/data/tests/basic.tests index ba33a715c..0c7c6eec9 100644 --- a/test/vector/data/tests/basic.tests +++ b/test/vector/data/tests/basic.tests @@ -13,3 +13,6 @@ ../../../fuzzing/fonts/noto_handwriting-glyf_colr_1.ttf;;U+270D;../expected/basic/handwriting-glyf-colr-1.svg ../../../fuzzing/fonts/noto_handwriting-cff_colr_1.otf;;U+270D;../expected/basic/handwriting-cff-colr-1.svg ../../../fuzzing/fonts/noto_handwriting-cff2_colr_1.otf;;U+270D;../expected/basic/handwriting-cff-colr-1.svg +../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=65536;U+0061,U+0062,U+0063;../expected/basic/glyf-quadratics.pdf +../../../api/fonts/TwemojiMozilla.subset.default.32,3299.ttf;--font-size=65536;U+3299;../expected/basic/colrv0-large-scale.svg +../../../api/fonts/TwemojiMozilla.subset.default.32,3299.ttf;--font-size=65536;U+3299;../expected/basic/colrv0-large-scale.pdf diff --git a/test/vector/run-tests.py b/test/vector/run-tests.py index 8436900d9..95823c757 100755 --- a/test/vector/run-tests.py +++ b/test/vector/run-tests.py @@ -199,7 +199,8 @@ try: print("# " + str(e)) continue - with tempfile.NamedTemporaryFile(prefix="hb-vector-test-", suffix=".svg", delete=False) as tmp: + suffix = os.path.splitext(expected_file)[1] + with tempfile.NamedTemporaryFile(prefix="hb-vector-test-", suffix=suffix, delete=False) as tmp: output_path = tmp.name try: @@ -220,9 +221,9 @@ try: print("# hb-vector did not create output file") continue - with open(expected_path, encoding="utf-8") as fp: + with open(expected_path, encoding="utf-8", errors="surrogateescape") as fp: expected = fp.read() - with open(output_path, encoding="utf-8") as fp: + with open(output_path, encoding="utf-8", errors="surrogateescape") as fp: actual = fp.read() if actual == expected: diff --git a/util/gpu/demo-renderer-d3d11.cc b/util/gpu/demo-renderer-d3d11.cc index c29ec6255..def5dd696 100644 --- a/util/gpu/demo-renderer-d3d11.cc +++ b/util/gpu/demo-renderer-d3d11.cc @@ -167,6 +167,8 @@ struct demo_renderer_d3d11_t : demo_renderer_t backend.alloc = [](void *ctx_, const char *data, unsigned len_bytes) -> unsigned { auto *self = (demo_renderer_d3d11_t *) ctx_; unsigned len_texels = len_bytes / 8; + if (self->atlas.cursor + len_texels > self->atlas.capacity) + die ("Ran out of atlas memory"); unsigned offset = self->atlas.cursor; self->atlas.cursor += len_texels; const int16_t *src = (const int16_t *) data; diff --git a/util/hb-ft-raster.cc b/util/hb-ft-raster.cc index d1d877f39..1c55375cc 100644 --- a/util/hb-ft-raster.cc +++ b/util/hb-ft-raster.cc @@ -332,5 +332,6 @@ int main (int argc, char **argv) { using main_t = main_font_text_t, font_options_t, shape_text_options_t>; - return batch_main (argc, argv); + argv_t args (argc, argv); + return batch_main (args.argc, args.argv); } diff --git a/util/hb-gpu.cc b/util/hb-gpu.cc index d73666844..2645e2d4d 100644 --- a/util/hb-gpu.cc +++ b/util/hb-gpu.cc @@ -183,6 +183,7 @@ struct gpu_main_t : base_t int main (int argc, char **argv) { + argv_t args (argc, argv); gpu_main_t driver; - return driver (argc, argv); + return driver (args.argc, args.argv); } diff --git a/util/hb-info.cc b/util/hb-info.cc index 197ce3b58..d5a8292ba 100644 --- a/util/hb-info.cc +++ b/util/hb-info.cc @@ -143,7 +143,7 @@ struct info_t : GOptionEntry entries[] = { {"quiet", 'q', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->verbose, "Generate machine-readable output", nullptr}, - {G_OPTION_REMAINING, 0, G_OPTION_FLAG_IN_MAIN, + {G_OPTION_REMAINING, 0, G_OPTION_FLAG_IN_MAIN | G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, (gpointer) &collect_rest, nullptr, "[FONT-FILE]"}, {nullptr} }; @@ -1437,5 +1437,6 @@ retry: int main (int argc, char **argv) { - return batch_main (argc, argv); + argv_t args (argc, argv); + return batch_main (args.argc, args.argv); } diff --git a/util/hb-raster.cc b/util/hb-raster.cc index 7d70594a9..31a0e8cc0 100644 --- a/util/hb-raster.cc +++ b/util/hb-raster.cc @@ -38,5 +38,6 @@ int main (int argc, char **argv) { using main_t = main_font_text_t, font_options_t, shape_text_options_t>; - return batch_main (argc, argv); + argv_t args (argc, argv); + return batch_main (args.argc, args.argv); } diff --git a/util/hb-shape.cc b/util/hb-shape.cc index 9eec5636a..4c7032b0a 100644 --- a/util/hb-shape.cc +++ b/util/hb-shape.cc @@ -39,5 +39,6 @@ int main (int argc, char **argv) { using main_t = main_font_text_t, font_options_t, shape_text_options_t>; - return batch_main (argc, argv); + argv_t args (argc, argv); + return batch_main (args.argc, args.argv); } diff --git a/util/hb-subset.cc b/util/hb-subset.cc index 8c6058de5..f2f41fdf4 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -981,6 +981,7 @@ subset_main_t::add_options () {"retain-gids", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "If set don't renumber glyph ids in the subset.", nullptr}, {"desubroutinize", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "Remove CFF/CFF2 use of subroutines", nullptr}, {"downgrade-cff2", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "Convert instantiated variable fonts from CFF2 to CFF1", nullptr}, + {"cff-identity-charset", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "Emit identity CFF charset (CID = new GID) for CID-keyed CFF", nullptr}, {"name-legacy", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "Keep legacy (non-Unicode) 'name' table entries", nullptr}, {"set-overlaps-flag", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "Set the overlaps flag on each glyph.", nullptr}, {"notdef-outline", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &set_flag, "Keep the outline of \'.notdef\' glyph", nullptr}, @@ -1023,7 +1024,7 @@ subset_main_t::add_options () GOptionEntry entries[] = { - {G_OPTION_REMAINING, 0, G_OPTION_FLAG_IN_MAIN, + {G_OPTION_REMAINING, 0, G_OPTION_FLAG_IN_MAIN | G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, (gpointer) &collect_rest, nullptr, "[FONT-FILE] [TEXT]"}, {nullptr} }; @@ -1034,5 +1035,6 @@ subset_main_t::add_options () int main (int argc, char **argv) { - return batch_main (argc, argv); + argv_t args (argc, argv); + return batch_main (args.argc, args.argv); } diff --git a/util/hb-vector.cc b/util/hb-vector.cc index a042ebc92..89e3650a8 100644 --- a/util/hb-vector.cc +++ b/util/hb-vector.cc @@ -36,5 +36,6 @@ int main (int argc, char **argv) { using main_t = main_font_text_t, font_options_t, shape_text_options_t>; - return batch_main (argc, argv); + argv_t args (argc, argv); + return batch_main (args.argc, args.argv); } diff --git a/util/hb-view.cc b/util/hb-view.cc index 604976e1e..83d823221 100644 --- a/util/hb-view.cc +++ b/util/hb-view.cc @@ -39,5 +39,6 @@ int main (int argc, char **argv) { using main_t = main_font_text_t, font_options_t, shape_text_options_t>; - return batch_main (argc, argv); + argv_t args (argc, argv); + return batch_main (args.argc, args.argv); } diff --git a/util/main-font-text.hh b/util/main-font-text.hh index 01219dc2f..d32a71f50 100644 --- a/util/main-font-text.hh +++ b/util/main-font-text.hh @@ -70,7 +70,7 @@ struct main_font_text_t : GOptionEntry entries[] = { - {G_OPTION_REMAINING, 0, G_OPTION_FLAG_IN_MAIN, + {G_OPTION_REMAINING, 0, G_OPTION_FLAG_IN_MAIN | G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, (gpointer) &collect_rest, nullptr, "[FONT-FILE] [TEXT]"}, {nullptr} }; diff --git a/util/meson.build b/util/meson.build index 5bb21d334..8b188a259 100644 --- a/util/meson.build +++ b/util/meson.build @@ -28,7 +28,7 @@ hb_subset_cli_sources = [ # If found, invoke it on our four binaries to build man pages # If not found, just skip this step -if not get_option('docs').disabled() +if not get_option('docs').disabled() and not meson.is_cross_build() help2man = find_program('help2man', required: false) else help2man = disabler() diff --git a/util/options.hh b/util/options.hh index dd335fde7..83cef2563 100644 --- a/util/options.hh +++ b/util/options.hh @@ -56,7 +56,6 @@ #include #include - enum return_value_t { RETURN_VALUE_SUCCESS = 0, @@ -68,6 +67,33 @@ enum return_value_t static inline void fail (hb_bool_t suggest_help, const char *format, ...) G_GNUC_NORETURN G_GNUC_PRINTF (2, 3); +struct argv_t +{ + argv_t (int argc_, char **argv_) + : argc (argc_), argv (argv_) + { +#ifdef G_OS_WIN32 + argv_utf8 = g_win32_get_command_line (); + argc = (int) g_strv_length (argv_utf8); + argv = argv_utf8; +#endif + } + + ~argv_t () + { +#ifdef G_OS_WIN32 + g_strfreev (argv_utf8); +#endif + } + + int argc; + char **argv; + +#ifdef G_OS_WIN32 + gchar **argv_utf8 = nullptr; +#endif +}; + static inline void fail (hb_bool_t suggest_help, const char *format, ...) { @@ -266,7 +292,21 @@ option_parser_t::parse (int *argc, char ***argv, bool ignore_error) set_full_description (); GError *parse_error = nullptr; - if (!g_option_context_parse (context, argc, argv, &parse_error)) + bool parse_ok; +#ifdef G_OS_WIN32 + /* g_option_context_parse() on Windows converts argv from the ACP via + * g_locale_to_utf8(), but argv is already in UTF-8. + * Use g_option_context_parse_strv() to skip the locale conversion. */ + gchar **win32_argv = g_new (gchar *, *argc + 1); + for (int i = 0; i < *argc; i++) + win32_argv[i] = g_strdup ((*argv)[i]); + win32_argv[*argc] = nullptr; + parse_ok = g_option_context_parse_strv (context, &win32_argv, &parse_error); + g_strfreev (win32_argv); +#else + parse_ok = g_option_context_parse (context, argc, argv, &parse_error); +#endif + if (!parse_ok) { if (parse_error) {