Merge branch 'main' into HVF

This commit is contained in:
Behdad Esfahbod committed 2025-06-11 16:33:15 -06:00
commit 12475fc9df
35 files changed
+492 -451

No files matched your search

-22
View File
@@ -1,22 +0,0 @@
#!/usr/bin/env bash
set -e
set -o pipefail
if [[ -z $GITHUB_TOKEN ]]; then
echo "No GITHUB_TOKEN secret found, artifact publishing skipped"
exit
fi
if ! hash ghr 2> /dev/null; then
_GHR_VER=v0.14.0
_GHR=ghr_${_GHR_VER}_linux_amd64
curl -sfL https://github.com/tcnksm/ghr/releases/download/$_GHR_VER/$_GHR.tar.gz |
tar xz -C . --strip-components=1 $_GHR/ghr
fi
./ghr -replace \
-u $CIRCLE_PROJECT_USERNAME \
-r $CIRCLE_PROJECT_REPONAME \
$CIRCLE_TAG \
$1
+3 -3
View File
@@ -81,7 +81,7 @@ ninja==1.11.1.4 \
# via -r requirements.in
# The following packages are considered to be unsafe in a requirements file:
setuptools==80.8.0 \
--hash=sha256:49f7af965996f26d43c8ae34539c8d99c5042fbff34302ea151eaa9c207cd257 \
--hash=sha256:95a60484590d24103af13b686121328cc2736bee85de8936383111e421b9edc0
setuptools==80.9.0 \
--hash=sha256:062d34222ad13e0cc312a4c02d73f059e86a4acbfbdea8f8f76b28c99f306922 \
--hash=sha256:f36b47402ecde768dbfafc46e8e4207b4360c654f1f3bb84475f0a28628fb19c
# via -r requirements.in
-231
View File
@@ -1,231 +0,0 @@
version: 2.1
executors:
win32-executor:
docker:
- image: ubuntu:24.04
win64-executor:
docker:
- image: ubuntu:24.04
dist-executor:
docker:
- image: cimg/base:2023.10
jobs:
macos-aat-fonts:
macos:
xcode: "15.3.0"
steps:
- checkout
- run: HOMEBREW_NO_AUTO_UPDATE=1 brew install pkg-config ragel freetype glib cairo python3 icu4c graphite2 gobject-introspection ninja
- run: pip3 install meson --upgrade
- run: brew link --force icu4c
- run: PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig" meson setup build -Dcoretext=enabled -Dgraphite=enabled -Dauto_features=enabled -Dchafa=disabled -Ddocs=disabled
- run: meson compile -Cbuild
- run: meson test -Cbuild --print-errorlogs
- store_artifacts:
path: build/meson-logs/
dist:
executor: dist-executor
steps:
- checkout
- run: sudo apt update && DEBIAN_FRONTEND=noninteractive sudo apt install -y git ninja-build binutils gcc g++ pkg-config ragel gtk-doc-tools gobject-introspection libfreetype6-dev libglib2.0-dev libgirepository1.0-dev libcairo2-dev libicu-dev libgraphite2-dev python3 python3-pip
- run: pip3 install fonttools meson --upgrade
- run: meson setup build
- run: meson dist --no-tests -Cbuild
- persist_to_workspace:
root: .
paths: [build/meson-dist/harfbuzz-*.tar.xz]
publish-dist:
executor: dist-executor
steps:
- checkout
- attach_workspace:
at: .
- run: |
.ci/publish_release_artifact.sh build/meson-dist/harfbuzz-$CIRCLE_TAG.tar.xz
fedora-valgrind:
docker:
- image: fedora:36
steps:
- checkout
- run: dnf install -y pkg-config ragel valgrind gcc gcc-c++ meson git glib2-devel freetype-devel cairo-devel libicu-devel gobject-introspection-devel graphite2-devel redhat-rpm-config python python-pip || true
- run: meson setup build --buildtype=debugoptimized
- run: meson compile -Cbuild -j9
- run: RUN_VALGRIND=1 meson test -Cbuild -t 10 --no-suite=slow --wrap='valgrind --leak-check=full --error-exitcode=1' --print-errorlogs --num-processes=$(($(nproc)/2 + 1))
asan-ubsan:
docker:
- image: ubuntu
steps:
- checkout
- run: apt update || true
- run: DEBIAN_FRONTEND=noninteractive apt install -y python3 python3-pip python3-venv ninja-build clang lld git binutils pkg-config ragel libfreetype6-dev libglib2.0-dev libcairo2-dev libicu-dev libgraphite2-dev
- run: |
export ASAN_OPTIONS=log_path=stderr:halt_on_error=1:abort_on_error=1
export UBSAN_OPTIONS=log_path=stderr:halt_on_error=1:abort_on_error=1:print_stacktrace=1
python3 -m venv venv
source venv/bin/activate
pip3 install meson==0.60.0
CC=clang CXX=clang++ meson setup build --default-library=static -Db_sanitize=address,undefined --buildtype=debugoptimized --wrap-mode=nodownload -Dexperimental_api=true
meson compile -Cbuild -j9
meson test -Cbuild -t 10 --print-errorlogs | asan_symbolize | c++filt
tsan:
docker:
- image: ubuntu:24.04
steps:
- checkout
- run: apt update || true
- run: DEBIAN_FRONTEND=noninteractive apt install -y python3 python3-pip python3-venv ninja-build clang lld git binutils pkg-config ragel libfreetype6-dev libglib2.0-dev libcairo2-dev libicu-dev libgraphite2-dev
- run: |
export TSAN_OPTIONS=log_path=stderr:halt_on_error=1:abort_on_error=1
python3 -m venv venv
source venv/bin/activate
pip3 install meson==0.60.0
CC=clang CXX=clang++ meson setup build --default-library=static -Db_sanitize=thread --buildtype=debugoptimized --wrap-mode=nodownload -Dexperimental_api=true
meson compile -Cbuild -j9
meson test -Cbuild -t 10 --print-errorlogs | asan_symbolize | c++filt
msan:
docker:
- image: ubuntu:24.04
steps:
- checkout
- run: apt update || true
- run: DEBIAN_FRONTEND=noninteractive apt install -y python3 python3-pip python3-venv ninja-build clang lld git binutils pkg-config ragel libfreetype6-dev libglib2.0-dev libcairo2-dev libicu-dev libgraphite2-dev
- run: |
export MSAN_OPTIONS=log_path=stderr:halt_on_error=1:abort_on_error=1:print_stacktrace=1
python3 -m venv venv
source venv/bin/activate
pip3 install meson==0.60.0
# msan, needs --force-fallback-for=glib,freetype2 also which doesn't work yet but runs fuzzer cases at least
CC=clang CXX=clang++ meson setup build --default-library=static -Db_sanitize=memory --buildtype=debugoptimized --wrap-mode=nodownload -Dauto_features=disabled -Dtests=enabled -Dexperimental_api=true
meson compile -Cbuild -j9
meson test -Cbuild -t 10 --print-errorlogs | asan_symbolize | c++filt
clang-cxx2a:
docker:
- image: ubuntu
steps:
- checkout
- run: apt update || true
- run: DEBIAN_FRONTEND=noninteractive apt install -y clang lld git binutils
- run: clang -c src/harfbuzz-subset.cc -DHB_NO_MT -Werror -std=c++2a
crossbuild-win32:
executor: win32-executor
steps:
- checkout
- run: dpkg --add-architecture i386
- run: apt update
- run: DEBIAN_FRONTEND=noninteractive apt install -y ninja-build python3 python3-pip python3-venv git g++-mingw-w64-i686 zip wine wine32
- run: |
export LANG=en_US.UTF-8
python3 -m venv venv
source venv/bin/activate
pip3 install meson==1.6.0
bash .ci/build-win.sh 32
meson devenv -Cbuild-win32 meson test -t 10 --print-errorlogs --suite=harfbuzz
- store_artifacts:
path: harfbuzz-win32.zip
- persist_to_workspace:
root: .
paths: [harfbuzz-win32.zip]
publish-win32:
executor: win32-executor
steps:
- checkout
- attach_workspace:
at: .
- run: apt update
- run: DEBIAN_FRONTEND=noninteractive apt install -y curl
- run: |
mv harfbuzz-win32{,-$CIRCLE_TAG}.zip
.ci/publish_release_artifact.sh harfbuzz-win32-$CIRCLE_TAG.zip
crossbuild-win64:
executor: win64-executor
steps:
- checkout
- run: dpkg --add-architecture i386
- run: apt update
- run: DEBIAN_FRONTEND=noninteractive apt install -y ninja-build python3 python3-pip python3-venv git g++-mingw-w64-x86-64 zip wine wine64 wine32:i386
- run: |
export LANG=en_US.UTF-8
python3 -m venv venv
source venv/bin/activate
pip3 install meson==1.6.0
bash .ci/build-win.sh 64
meson devenv -Cbuild-win64 meson test -t 10 --print-errorlogs --suite=harfbuzz
- store_artifacts:
path: harfbuzz-win64.zip
- persist_to_workspace:
root: .
paths: [harfbuzz-win64.zip]
publish-win64:
executor: win64-executor
steps:
- checkout
- attach_workspace:
at: .
- run: apt update
- run: DEBIAN_FRONTEND=noninteractive apt install -y curl
- run: |
mv harfbuzz-win64{,-$CIRCLE_TAG}.zip
.ci/publish_release_artifact.sh harfbuzz-win64-$CIRCLE_TAG.zip
workflows:
version: 2
build:
jobs:
- macos-aat-fonts
- dist:
filters: # must have filter or won't work as a dependency
tags:
only: /.*/
- publish-dist:
requires:
- dist
filters:
tags:
only: /^\d+\.\d+\.\d+$/
branches:
ignore: /.*/
- fedora-valgrind
- asan-ubsan
- tsan
- msan
- clang-cxx2a
- crossbuild-win32:
filters: # must have filter or won't work as a dependency
tags:
only: /.*/
- crossbuild-win64:
filters: # must have filter or won't work as a dependency
tags:
only: /.*/
- publish-win32:
requires:
- crossbuild-win32
filters:
tags:
only: /^\d+\.\d+\.\d+$/
branches:
ignore: /.*/
- publish-win64:
requires:
- crossbuild-win64
filters:
tags:
only: /^\d+\.\d+\.\d+$/
branches:
ignore: /.*/
File renamed without changes.
+45
View File
@@ -0,0 +1,45 @@
name: c++ versions
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-24.04
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- name: g++ c++11
CXX: g++
CXX_STANDARD: c++11
PACKAGES: g++
- name: g++ c++2a
CXX: g++
CXX_STANDARD: c++2a
PACKAGES: g++
- name: clang c++11
CXX: clang++
CXX_STANDARD: c++11
PACKAGES: clang
- name: clang c++2a
CXX: clang++
CXX_STANDARD: c++2a
PACKAGES: clang
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt install -y ${{ matrix.PACKAGES }}
- name: Build
run: ${{ matrix.CXX }} -c src/harfbuzz-subset.cc -DHB_NO_MT -Werror -std=${{ matrix.CXX_STANDARD }}
+1 -1
View File
@@ -1,4 +1,4 @@
name: configs-ci
name: configs
on:
push:
+81
View File
@@ -0,0 +1,81 @@
name: crossbuild
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-24.04
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- name: win32
ARCH: 32
PACKAGES: g++-mingw-w64-i686 wine wine32
- name: win64
ARCH: 64
PACKAGES: g++-mingw-w64-x86-64 wine wine64 wine32:i386
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Ccache
uses: hendrikmuhs/ccache-action@63069e3931dedbf3b63792097479563182fe70d1 # v1.2.18
- name: Install Dependencies
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt install -y \
zip \
${{ matrix.PACKAGES }}
- name: Setup Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: '3.12'
- name: Install Python Dependencies
run: pip3 install -r .ci/requirements.txt --require-hashes
- name: Build
run: bash .ci/build-win.sh ${{ matrix.ARCH }}
- name: Test
run: meson devenv -Cbuild-win${{ matrix.ARCH }} meson test -t 10 --print-errorlogs --suite=harfbuzz
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: harfbuzz-win${{ matrix.ARCH }}
path: harfbuzz-win${{ matrix.ARCH }}.zip
if-no-files-found: error
release:
name: Create and populate release
needs: build
runs-on: ubuntu-24.04
if: contains(github.ref, 'refs/tags/')
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Rename artifacts
run: |
ls -R
for file in harfbuzz-win*.zip; do
mv -v "$file" "${file%.zip}-${{ github.ref_name }}.zip"
done
- name: Check for release
id: create_release
run: |
if ! gh release view ${{ github.ref_name }}; then
git show -s --format=%B ${{ github.ref_name }} | tail -n +4 | gh release create ${{ github.ref_name }} -t ${{ github.ref_name }} -F -
fi
- name: Populate release
run: |
gh release upload ${{ github.ref_name }} harfbuzz-win*-${{ github.ref_name }}.zip --clobber
@@ -1,4 +1,4 @@
name: linux-ci
name: linux
on:
push:
@@ -56,6 +56,10 @@ jobs:
run: meson compile -Cbuild
- name: Test
run: meson test --print-errorlogs -Cbuild
- name: Dist
run: |
git reset --hard HEAD # ragel may have modified the source tree
meson dist --no-tests -Cbuild
- name: Generate Documentations
run: ninja -Cbuild harfbuzz-doc
- name: Deploy Documentations
@@ -64,3 +68,37 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
REVISION: ${{ github.sha }}
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: harfbuzz
path: build/meson-dist/harfbuzz-*.tar.xz
if-no-files-found: error
release:
name: Create and populate release
needs: build
runs-on: ubuntu-24.04
if: contains(github.ref, 'refs/tags/')
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: harfbuzz
- name: Extract artifacts
run: |
ls -R
unzip harfbuzz.zip
ls -R
- name: Check for release
id: create_release
run: |
if ! gh release view ${{ github.ref_name }}; then
git show -s --format=%B ${{ github.ref_name }} | tail -n +4 | gh release create ${{ github.ref_name }} -t ${{ github.ref_name }} -F -
fi
- name: Populate release
run: |
gh release upload ${{ github.ref_name }} harfbuzz-${{ github.ref_name }}.tar.xz --clobber
@@ -1,4 +1,4 @@
name: macos-ci
name: macos
on:
push:
@@ -16,13 +16,12 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-2019, windows-latest]
include:
- name: msvc-2019-x86
os: windows-2019
- name: msvc-2025-x86
os: windows-2025
ARCH: x86
- name: msvc-2019-amd64
os: windows-latest
- name: msvc-2025-amd64
os: windows-2025
ARCH: amd64
name: ${{ matrix.name }}
File renamed without changes.
+70
View File
@@ -0,0 +1,70 @@
name: sanitizers
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-24.04
name: ${{ matrix.name }}
env:
CC: clang
CXX: clang++
ASAN_OPTIONS: log_path=stderr:halt_on_error=1:abort_on_error=1
UBSAN_OPTIONS: log_path=stderr:halt_on_error=1:abort_on_error=1:print_stacktrace=1
TSAN_OPTIONS: log_path=stderr:halt_on_error=1:abort_on_error=1
MSAN_OPTIONS: log_path=stderr:halt_on_error=1:abort_on_error=1:print_stacktrace=1
strategy:
fail-fast: false
matrix:
include:
- name: asan-ubsan
SANITIZE: address,undefined
- name: tsan
SANITIZE: thread
- name: msan
SANITIZE: memory
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Ccache
uses: hendrikmuhs/ccache-action@63069e3931dedbf3b63792097479563182fe70d1 # v1.2.18
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt install -y \
clang \
lld \
binutils \
pkg-config \
libfreetype6-dev \
libglib2.0-dev \
libcairo2-dev \
libicu-dev \
libgraphite2-dev
- name: Setup Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: '3.12'
- name: Install Python Dependencies
run: pip3 install -r .ci/requirements.txt --require-hashes
- name: Setup Meson
run: |
ccache --version
meson setup build \
--default-library=static \
--buildtype=debugoptimized \
--wrap-mode=nodownload \
-Db_sanitize=${{ matrix.SANITIZE }} \
-Dexperimental_api=true
- name: Build
run: meson compile -Cbuild
- name: Test
run: meson test -Cbuild -t 10 --print-errorlogs | asan_symbolize | c++filt
+2 -2
View File
@@ -34,7 +34,7 @@ jobs:
persist-credentials: false
- name: "Run analysis"
uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
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@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
uses: github/codeql-action/upload-sarif@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
with:
sarif_file: results.sarif
+44
View File
@@ -0,0 +1,44 @@
name: valgrind
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Ccache
uses: hendrikmuhs/ccache-action@63069e3931dedbf3b63792097479563182fe70d1 # v1.2.18
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt install -y \
valgrind \
binutils \
pkg-config \
libfreetype6-dev \
libglib2.0-dev \
libcairo2-dev \
libicu-dev \
libgraphite2-dev
- name: Setup Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: '3.12'
- name: Install Python Dependencies
run: pip3 install -r .ci/requirements.txt --require-hashes
- name: Setup Meson
run: meson setup build --buildtype=debugoptimized
- name: Build
run: meson compile -Cbuild
- name: Test
run: meson test -Cbuild -t 10 --no-suite=slow --wrap='valgrind --leak-check=full --error-exitcode=1' --print-errorlogs
+5 -4
View File
@@ -1,7 +1,6 @@
[![Linux CI Status](https://github.com/harfbuzz/harfbuzz/actions/workflows/linux-ci.yml/badge.svg)](https://github.com/harfbuzz/harfbuzz/actions/workflows/linux-ci.yml)
[![macoOS CI Status](https://github.com/harfbuzz/harfbuzz/actions/workflows/macos-ci.yml/badge.svg)](https://github.com/harfbuzz/harfbuzz/actions/workflows/macos-ci.yml)
[![Windows CI Status](https://github.com/harfbuzz/harfbuzz/actions/workflows/msvc-ci.yml/badge.svg)](https://github.com/harfbuzz/harfbuzz/actions/workflows/msvc-ci.yml)
[![CircleCI Build Status](https://circleci.com/gh/harfbuzz/harfbuzz/tree/main.svg?style=svg)](https://circleci.com/gh/harfbuzz/harfbuzz/tree/main)
[![Linux CI Status](https://github.com/harfbuzz/harfbuzz/actions/workflows/linux.yml/badge.svg)](https://github.com/harfbuzz/harfbuzz/actions/workflows/linux.yml)
[![macoOS CI Status](https://github.com/harfbuzz/harfbuzz/actions/workflows/macos.yml/badge.svg)](https://github.com/harfbuzz/harfbuzz/actions/workflows/macos.yml)
[![Windows CI Status](https://github.com/harfbuzz/harfbuzz/actions/workflows/msvc.yml/badge.svg)](https://github.com/harfbuzz/harfbuzz/actions/workflows/msvc.yml)
[![OSS-Fuzz Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/harfbuzz.svg)](https://oss-fuzz-build-logs.storage.googleapis.com/index.html#harfbuzz)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/15166/badge.svg)](https://scan.coverity.com/projects/harfbuzz)
[![Packaging status](https://repology.org/badge/tiny-repos/harfbuzz.svg)](https://repology.org/project/harfbuzz/versions)
@@ -79,6 +78,7 @@ Internationalization and Unicode Conference over the years:
More presentations and papers are available on [behdad][11]'s website.
In particular, the following _studies_ are relevant to HarfBuzz development:
- 2025 - [Introducing HarfRust][22]
- 2025 – [Subsetting][21]
- 2025 – [Caching][12]
- 2025 – [`hb-decycler`][13]
@@ -135,3 +135,4 @@ transliterated using the Latin script. It also means "talkative" or
[19]: https://prezi.com/view/THNPJGFVDUCWoM20syev/
[20]: https://behdad.org/doc/harfbuzz10years-slides.pdf
[21]: https://docs.google.com/document/d/1_vZrt97OorJ0jA1YzJ29LRcGr3YGrNJANdOABjVZGEs/preview
[22]: https://docs.google.com/document/d/1aH_waagdEM5UhslQxCeFEb82ECBhPlZjy5_MwLNLBYo/preview
+6 -6
View File
@@ -206,10 +206,10 @@ if get_option('fontations').enabled()
fontations_dep_found = true
endif
harfruzz_dep_found = false
if get_option('harfruzz').enabled()
harfrust_dep_found = false
if get_option('harfrust').enabled()
add_languages(['rust'], native: false, required : true)
harfruzz_dep_found = true
harfrust_dep_found = true
endif
conf = configuration_data()
@@ -257,8 +257,8 @@ if fontations_dep_found
conf.set('HAVE_FONTATIONS', 1)
endif
if harfruzz_dep_found
conf.set('HAVE_HARFRUZZ', 1)
if harfrust_dep_found
conf.set('HAVE_HARFRUST', 1)
endif
if wasm_dep.found()
@@ -492,7 +492,7 @@ build_summary = {
{'CoreText': conf.get('HAVE_CORETEXT', 0) == 1,
'DirectWrite': conf.get('HAVE_DIRECTWRITE', 0) == 1,
'GDI/Uniscribe': (conf.get('HAVE_GDI', 0) == 1) and (conf.get('HAVE_UNISCRIBE', 0) == 1),
'HarfRuzz': conf.get('HAVE_HARFRUZZ', 0) == 1,
'HarfRust': conf.get('HAVE_HARFRUST', 0) == 1,
},
'Other features':
{'Documentation': conf.get('HAVE_GTK_DOC', 0) == 1,
+2 -2
View File
@@ -23,8 +23,8 @@ option('directwrite', type: 'feature', value: 'disabled',
description: 'Enable DirectWrite shaper and font backend on Windows')
option('coretext', type: 'feature', value: 'disabled',
description: 'Enable CoreText shaper and font backend on Apple platforms')
option('harfruzz', type: 'feature', value: 'disabled',
description: 'Enable HarfRuzz shaper backend')
option('harfrust', type: 'feature', value: 'disabled',
description: 'Enable HarfRust shaper backend')
option('wasm', type: 'feature', value: 'disabled',
description: 'Enable WebAssembly shaper backend (experimental)')
+2 -1
View File
@@ -42,7 +42,8 @@ IGNORED_SYMBOLS += [
"_ZN3std3sys3pal4unix4args3imp15ARGV_INIT_ARRAY.*", # 'std::sys::pal::unix::args::imp::ARGV_INIT_ARRAY::.*'
"_ZN3std3sys4args4unix3imp15ARGV_INIT_ARRAY.*", # std::sys::args::unix::imp::ARGV_INIT_ARRAY::.*
"_ZN17compiler_builtins.*", # 'compiler_builtins::.*'
'_hb_harfruzz_.*_rs',
".*__rustc.*", # '.*__rustc.*' # Eg. _RNvCsgSLETaxrkfn_7___rustc17___rust_probestack
'_hb_harfrust_.*_rs',
]
IGNORED_SYMBOLS = "|".join(IGNORED_SYMBOLS)
+1
View File
@@ -193,6 +193,7 @@ elif language.name == "rust":
print("pub(crate) mod ucd {")
print()
print("#![allow(unused_parens)]")
print("#![allow(clippy::unnecessary_cast)]")
print()
print("use crate::hb::algs::{HB_CODEPOINT_ENCODE3, HB_CODEPOINT_ENCODE3_11_7_14};")
print("use crate::hb::common::script;")
+2 -1
View File
@@ -206,8 +206,9 @@ create_cg_font (hb_blob_t *blob, unsigned int index)
if (unlikely (named_instance_index != 0))
{
// https://github.com/harfbuzz/harfbuzz/issues/5300
// https://github.com/harfbuzz/harfbuzz/issues/5354
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || \
(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || \
(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) || \
(defined(__TV_OS_VERSION_MIN_REQUIRED) && __TV_OS_VERSION_MIN_REQUIRED >= 110000) || \
(defined(__WATCH_OS_VERSION_MIN_REQUIRED) && __WATCH_OS_VERSION_MIN_REQUIRED >= 40000) || \
(defined(__MACCATALYST_VERSION_MIN_REQUIRED) && __MACCATALYST_VERSION_MIN_REQUIRED >= 130100) || \
+4
View File
@@ -1104,6 +1104,10 @@ _hb_ft_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data
FT_ULong length = 0;
FT_Error error;
/* In new FreeType, a tag value of 1 loads the SFNT table directory. Reject it. */
if (tag == 1)
return nullptr;
/* Note: FreeType like HarfBuzz uses the NONE tag for fetching the entire blob */
error = FT_Load_Sfnt_Table (ft_face, tag, 0, nullptr, &length);
+29 -25
View File
@@ -24,7 +24,7 @@
#include "hb.hh"
#ifdef HAVE_HARFRUZZ
#ifdef HAVE_HARFRUST
#include "hb-shaper-impl.hh"
@@ -34,21 +34,21 @@
*/
extern "C" void *
_hb_harfruzz_shaper_face_data_create_rs (hb_face_t *face);
_hb_harfrust_shaper_face_data_create_rs (hb_face_t *face);
hb_harfruzz_face_data_t *
_hb_harfruzz_shaper_face_data_create (hb_face_t *face)
hb_harfrust_face_data_t *
_hb_harfrust_shaper_face_data_create (hb_face_t *face)
{
return (hb_harfruzz_face_data_t *) _hb_harfruzz_shaper_face_data_create_rs (face);
return (hb_harfrust_face_data_t *) _hb_harfrust_shaper_face_data_create_rs (face);
}
extern "C" void
_hb_harfruzz_shaper_face_data_destroy_rs (void *data);
_hb_harfrust_shaper_face_data_destroy_rs (void *data);
void
_hb_harfruzz_shaper_face_data_destroy (hb_harfruzz_face_data_t *data)
_hb_harfrust_shaper_face_data_destroy (hb_harfrust_face_data_t *data)
{
_hb_harfruzz_shaper_face_data_destroy_rs (data);
_hb_harfrust_shaper_face_data_destroy_rs (data);
}
@@ -57,22 +57,22 @@ _hb_harfruzz_shaper_face_data_destroy (hb_harfruzz_face_data_t *data)
*/
extern "C" void *
_hb_harfruzz_shaper_font_data_create_rs (hb_font_t *font, const void *face_data);
_hb_harfrust_shaper_font_data_create_rs (hb_font_t *font, const void *face_data);
hb_harfruzz_font_data_t *
_hb_harfruzz_shaper_font_data_create (hb_font_t *font)
hb_harfrust_font_data_t *
_hb_harfrust_shaper_font_data_create (hb_font_t *font)
{
const hb_harfruzz_face_data_t *face_data = font->face->data.harfruzz;
return (hb_harfruzz_font_data_t *) _hb_harfruzz_shaper_font_data_create_rs (font, face_data);
const hb_harfrust_face_data_t *face_data = font->face->data.harfrust;
return (hb_harfrust_font_data_t *) _hb_harfrust_shaper_font_data_create_rs (font, face_data);
}
extern "C" void
_hb_harfruzz_shaper_font_data_destroy_rs (void *data);
_hb_harfrust_shaper_font_data_destroy_rs (void *data);
void
_hb_harfruzz_shaper_font_data_destroy (hb_harfruzz_font_data_t *data)
_hb_harfrust_shaper_font_data_destroy (hb_harfrust_font_data_t *data)
{
_hb_harfruzz_shaper_font_data_destroy_rs (data);
_hb_harfrust_shaper_font_data_destroy_rs (data);
}
/*
@@ -80,13 +80,14 @@ _hb_harfruzz_shaper_font_data_destroy (hb_harfruzz_font_data_t *data)
*/
extern "C" void *
_hb_harfruzz_shape_plan_create_rs (const void *font_data,
_hb_harfrust_shape_plan_create_rs (const void *font_data,
const void *face_data,
hb_script_t script,
hb_language_t language,
hb_direction_t direction);
extern "C" void
_hb_harfruzz_shape_plan_destroy_rs (void *data);
_hb_harfrust_shape_plan_destroy_rs (void *data);
/*
@@ -94,7 +95,8 @@ _hb_harfruzz_shape_plan_destroy_rs (void *data);
*/
extern "C" hb_bool_t
_hb_harfruzz_shape_rs (const void *face_data,
_hb_harfrust_shape_rs (const void *font_data,
const void *face_data,
const void *rs_shape_plan,
hb_font_t *font,
hb_buffer_t *buffer,
@@ -104,13 +106,14 @@ _hb_harfruzz_shape_rs (const void *face_data,
static hb_user_data_key_t hr_shape_plan_key = {0};
hb_bool_t
_hb_harfruzz_shape (hb_shape_plan_t *shape_plan,
_hb_harfrust_shape (hb_shape_plan_t *shape_plan,
hb_font_t *font,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features)
{
const hb_harfruzz_font_data_t *font_data = font->data.harfruzz;
const hb_harfrust_font_data_t *font_data = font->data.harfrust;
const hb_harfrust_face_data_t *face_data = font->face->data.harfrust;
void *hr_shape_plan = nullptr;
@@ -121,7 +124,7 @@ _hb_harfruzz_shape (hb_shape_plan_t *shape_plan,
&hr_shape_plan_key);
if (unlikely (!hr_shape_plan))
{
hr_shape_plan = _hb_harfruzz_shape_plan_create_rs (font_data,
hr_shape_plan = _hb_harfrust_shape_plan_create_rs (font_data, face_data,
shape_plan->key.props.script,
shape_plan->key.props.language,
shape_plan->key.props.direction);
@@ -129,16 +132,17 @@ _hb_harfruzz_shape (hb_shape_plan_t *shape_plan,
!hb_shape_plan_set_user_data (shape_plan,
&hr_shape_plan_key,
hr_shape_plan,
_hb_harfruzz_shape_plan_destroy_rs,
_hb_harfrust_shape_plan_destroy_rs,
false))
{
_hb_harfruzz_shape_plan_destroy_rs (hr_shape_plan);
_hb_harfrust_shape_plan_destroy_rs (hr_shape_plan);
goto retry;
}
}
}
return _hb_harfruzz_shape_rs (font_data,
return _hb_harfrust_shape_rs (font_data,
face_data,
hr_shape_plan,
font,
buffer,
+5 -1
View File
@@ -73,7 +73,11 @@ struct hb_paint_funcs_t
float xx, float yx,
float xy, float yy,
float dx, float dy)
{ func.push_transform (this, paint_data,
{
// Handle -0.f to avoid -0.f == 0.f in the transform matrix.
if (dx == -0.f) dx = 0.f;
if (dy == -0.f) dy = 0.f;
func.push_transform (this, paint_data,
xx, yx, xy, yy, dx, dy,
!user_data ? nullptr : user_data->push_transform); }
void pop_transform (void *paint_data)
+5 -3
View File
@@ -471,9 +471,11 @@ struct hb_sanitize_context_t :
}
else
{
if (edit_count && !writable) {
start = hb_blob_get_data_writable (blob, nullptr);
end = start + blob->length;
if (edit_count && !writable)
{
unsigned length;
start = hb_blob_get_data_writable (blob, &length);
end = start + length;
if (start)
{
+2 -2
View File
@@ -57,8 +57,8 @@ HB_SHAPER_IMPLEMENT (directwrite)
HB_SHAPER_IMPLEMENT (coretext)
#endif
#ifdef HAVE_HARFRUZZ
HB_SHAPER_IMPLEMENT (harfruzz)
#ifdef HAVE_HARFRUST
HB_SHAPER_IMPLEMENT (harfrust)
#endif
#ifndef HB_NO_FALLBACK_SHAPE
+3 -1
View File
@@ -231,7 +231,9 @@ normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan)
(double) normalized_default,
(double) normalized_max));
if (normalized_default != 0)
if (normalized_default == -0.f)
normalized_default = 0.f; // Normalize -0 to 0
if (normalized_default != 0.f)
plan->pinned_at_default = false;
plan->normalized_coords[old_axis_idx] = roundf (normalized_default * 16384.f);
+6 -6
View File
@@ -340,8 +340,8 @@ hb_ft_headers = files('hb-ft.h')
hb_fontations_sources = files()
hb_fontations_headers = files('hb-fontations.h')
hb_harfruzz_sources = files('hb-harfruzz.cc')
hb_harfruzz_headers = files()
hb_harfrust_sources = files('hb-harfrust.cc')
hb_harfrust_headers = files()
hb_glib_sources = files('hb-glib.cc')
hb_glib_headers = files('hb-glib.h')
@@ -536,7 +536,7 @@ if conf.get('HAVE_CORETEXT', 0) == 1
harfbuzz_deps += coretext_deps
endif
if conf.get('HAVE_FONTATIONS', 0) == 1 or conf.get('HAVE_HARFRUZZ', 0) == 1
if conf.get('HAVE_FONTATIONS', 0) == 1 or conf.get('HAVE_HARFRUST', 0) == 1
subdir('rust')
harfbuzz_deps += [harfbuzz_rust_dep]
endif
@@ -546,9 +546,9 @@ if conf.get('HAVE_FONTATIONS', 0) == 1
hb_headers += hb_fontations_headers
endif
if conf.get('HAVE_HARFRUZZ', 0) == 1
hb_sources += hb_harfruzz_sources
hb_headers += hb_harfruzz_headers
if conf.get('HAVE_HARFRUST', 0) == 1
hb_sources += hb_harfrust_sources
hb_headers += hb_harfrust_headers
endif
have_icu = conf.get('HAVE_ICU', 0) == 1
+13 -30
View File
@@ -10,9 +10,9 @@ checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
[[package]]
name = "bytemuck"
version = "1.23.0"
version = "1.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9134a6ef01ce4b366b50689c94f82c14bc72bc5d0386829828a2e2752ef7958c"
checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422"
dependencies = [
"bytemuck_derive",
]
@@ -50,22 +50,20 @@ dependencies = [
name = "harfbuzz_rust"
version = "0.0.0"
dependencies = [
"harfruzz",
"harfrust",
"skrifa",
]
[[package]]
name = "harfruzz"
name = "harfrust"
version = "0.1.0"
source = "git+https://github.com/harfbuzz/harfruzz#966d38a4b7b2f23b77a0ce4c356542e9395102e8"
source = "git+https://github.com/harfbuzz/harfrust#2c3a8da47c8d67c88f63669ec44d8cb4f9771c62"
dependencies = [
"bitflags",
"bytemuck",
"core_maths",
"log",
"read-fonts",
"smallvec",
"ttf-parser",
]
[[package]]
@@ -74,12 +72,6 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]]
name = "log"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "proc-macro2"
version = "1.0.95"
@@ -100,9 +92,9 @@ dependencies = [
[[package]]
name = "read-fonts"
version = "0.29.1"
version = "0.29.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e85935612710191461ec9df47b4b5880dd6359d4fad3b2f2ed696215f6f3146"
checksum = "04ca636dac446b5664bd16c069c00a9621806895b8bb02c2dc68542b23b8f25d"
dependencies = [
"bytemuck",
"core_maths",
@@ -111,9 +103,9 @@ dependencies = [
[[package]]
name = "skrifa"
version = "0.31.1"
version = "0.31.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9c3bb8cab5196b98d70c866ce1ea81ab516104d5b396f84ae80f8766b5d5b4e"
checksum = "dbeb4ca4399663735553a09dd17ce7e49a0a0203f03b706b39628c4d913a8607"
dependencies = [
"bytemuck",
"read-fonts",
@@ -121,30 +113,21 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.15.0"
version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9"
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
[[package]]
name = "syn"
version = "2.0.101"
version = "2.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
checksum = "f6397daf94fa90f058bd0fd88429dd9e5738999cca8d701813c80723add80462"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "ttf-parser"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
dependencies = [
"core_maths",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
+2 -2
View File
@@ -4,7 +4,7 @@ edition = "2021"
[dependencies]
skrifa = { version = "0.*", optional = true }
harfruzz = { git = "https://github.com/harfbuzz/harfruzz", optional = true }
harfrust = { git = "https://github.com/harfbuzz/harfrust", optional = true }
[lib]
name = "harfbuzz_rust"
@@ -13,7 +13,7 @@ crate-type = ["staticlib"]
[features]
font = ["dep:skrifa"]
shape = ["dep:harfruzz"]
shape = ["dep:harfrust"]
[profile.release]
strip = true
+1 -1
View File
@@ -25,7 +25,7 @@ features = []
if conf.get('HAVE_FONTATIONS', 0) == 1
features += ['font']
endif
if conf.get('HAVE_HARFRUZZ', 0) == 1
if conf.get('HAVE_HARFRUST', 0) == 1
features += ['shape']
endif
if features.length() > 0
+107 -91
View File
@@ -6,16 +6,16 @@ use std::ffi::c_void;
use std::ptr::null_mut;
use std::str::FromStr;
use harfruzz::{F2Dot14, Face, FontRef, ShaperFont, Tag};
use harfrust::{FontRef, NormalizedCoord, ShaperData, ShaperInstance, Tag};
pub struct HBHarfRuzzFaceData<'a> {
pub struct HBHarfRustFaceData<'a> {
face_blob: *mut hb_blob_t,
font_ref: FontRef<'a>,
shaper_font: ShaperFont,
shaper_data: ShaperData,
}
#[no_mangle]
pub unsafe extern "C" fn _hb_harfruzz_shaper_face_data_create_rs(
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);
@@ -31,31 +31,30 @@ pub unsafe extern "C" fn _hb_harfruzz_shaper_face_data_create_rs(
Ok(f) => f,
Err(_) => return null_mut(),
};
let shaper_font = ShaperFont::new(&font_ref);
let shaper_data = ShaperData::new(&font_ref);
let hr_face_data = Box::new(HBHarfRuzzFaceData {
let hr_face_data = Box::new(HBHarfRustFaceData {
face_blob,
font_ref,
shaper_font,
shaper_data,
});
Box::into_raw(hr_face_data) as *mut c_void
}
#[no_mangle]
pub unsafe extern "C" fn _hb_harfruzz_shaper_face_data_destroy_rs(data: *mut c_void) {
let data = data as *mut HBHarfRuzzFaceData;
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);
}
pub struct HBHarfRuzzFontData<'a> {
coords: Vec<F2Dot14>,
face: Option<Face<'a>>,
pub struct HBHarfRustFontData {
shaper_instance: ShaperInstance,
}
fn font_coords_to_f2dot14(font: *mut hb_font_t) -> Vec<F2Dot14> {
fn font_to_shaper_instance(font: *mut hb_font_t, font_ref: &FontRef<'_>) -> ShaperInstance {
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() {
@@ -63,119 +62,120 @@ fn font_coords_to_f2dot14(font: *mut hb_font_t) -> Vec<F2Dot14> {
} else {
unsafe { std::slice::from_raw_parts(coords, num_coords as usize) }
};
coords
.iter()
.map(|&v| F2Dot14::from_bits(v as i16))
.collect::<Vec<_>>()
let coords = coords.iter().map(|&v| NormalizedCoord::from_bits(v as i16));
ShaperInstance::from_coords(font_ref, coords)
}
#[no_mangle]
pub unsafe extern "C" fn _hb_harfruzz_shaper_font_data_create_rs(
pub unsafe extern "C" fn _hb_harfrust_shaper_font_data_create_rs(
font: *mut hb_font_t,
face_data: *const c_void,
) -> *mut c_void {
let face_data = face_data as *const HBHarfRuzzFaceData;
let face_data = face_data as *const HBHarfRustFaceData;
let coords = font_coords_to_f2dot14(font);
let font_ref = &(*face_data).font_ref;
let shaper_instance = font_to_shaper_instance(font, font_ref);
let hr_font_data = Box::new(HBHarfRuzzFontData { coords, face: None });
let hr_font_data = Box::new(HBHarfRustFontData { shaper_instance });
let hr_font_data_ptr = Box::into_raw(hr_font_data);
(*hr_font_data_ptr).face = Some(
(*face_data)
.shaper_font
.shaper(&(*face_data).font_ref, &(*hr_font_data_ptr).coords),
);
hr_font_data_ptr as *mut c_void
}
#[no_mangle]
pub unsafe extern "C" fn _hb_harfruzz_shaper_font_data_destroy_rs(data: *mut c_void) {
let data = data as *mut HBHarfRuzzFontData;
pub unsafe extern "C" fn _hb_harfrust_shaper_font_data_destroy_rs(data: *mut c_void) {
let data = data as *mut HBHarfRustFontData;
let _hr_font_data = Box::from_raw(data);
}
fn hb_language_to_hr_language(language: hb_language_t) -> Option<harfruzz::Language> {
fn hb_language_to_hr_language(language: hb_language_t) -> Option<harfrust::Language> {
let language_str = unsafe { hb_language_to_string(language) };
if language_str.is_null() {
return None;
}
let language_str = unsafe { std::ffi::CStr::from_ptr(language_str) };
let language_str = language_str.to_str().unwrap_or_default();
Some(harfruzz::Language::from_str(language_str).unwrap())
Some(harfrust::Language::from_str(language_str).unwrap())
}
#[no_mangle]
pub unsafe extern "C" fn _hb_harfruzz_shape_plan_create_rs(
pub unsafe extern "C" fn _hb_harfrust_shape_plan_create_rs(
font_data: *const c_void,
face_data: *const c_void,
script: hb_script_t,
language: hb_language_t,
direction: hb_direction_t,
) -> *mut c_void {
let font_data = font_data as *const HBHarfRuzzFontData;
let font_data = font_data as *const HBHarfRustFontData;
let face_data = face_data as *const HBHarfRustFaceData;
let script = harfruzz::Script::from_iso15924_tag(Tag::from_u32(script));
let font_ref = &(*face_data).font_ref;
let script = harfrust::Script::from_iso15924_tag(Tag::from_u32(script));
let language = hb_language_to_hr_language(language);
let direction = match direction {
hb_direction_t_HB_DIRECTION_LTR => harfruzz::Direction::LeftToRight,
hb_direction_t_HB_DIRECTION_RTL => harfruzz::Direction::RightToLeft,
hb_direction_t_HB_DIRECTION_TTB => harfruzz::Direction::TopToBottom,
hb_direction_t_HB_DIRECTION_BTT => harfruzz::Direction::BottomToTop,
_ => harfruzz::Direction::Invalid,
hb_direction_t_HB_DIRECTION_LTR => harfrust::Direction::LeftToRight,
hb_direction_t_HB_DIRECTION_RTL => harfrust::Direction::RightToLeft,
hb_direction_t_HB_DIRECTION_TTB => harfrust::Direction::TopToBottom,
hb_direction_t_HB_DIRECTION_BTT => harfrust::Direction::BottomToTop,
_ => harfrust::Direction::Invalid,
};
let hr_shape_plan = harfruzz::ShapePlan::new(
(*font_data).face.as_ref().unwrap(),
direction,
script,
language.as_ref(),
&[],
);
let shaper = (*face_data)
.shaper_data
.shaper(font_ref)
.instance(Some(&(*font_data).shaper_instance))
.build();
let hr_shape_plan =
harfrust::ShapePlan::new(&shaper, direction, script, language.as_ref(), &[]);
let hr_shape_plan = Box::new(hr_shape_plan);
Box::into_raw(hr_shape_plan) as *mut c_void
}
#[no_mangle]
pub unsafe extern "C" fn _hb_harfruzz_shape_plan_destroy_rs(data: *mut c_void) {
let data = data as *mut harfruzz::ShapePlan;
pub unsafe extern "C" fn _hb_harfrust_shape_plan_destroy_rs(data: *mut c_void) {
let data = data as *mut harfrust::ShapePlan;
let _hr_shape_plan = Box::from_raw(data);
}
#[no_mangle]
pub unsafe extern "C" fn _hb_harfruzz_shape_rs(
pub unsafe extern "C" fn _hb_harfrust_shape_rs(
font_data: *const c_void,
face_data: *const c_void,
shape_plan: *const c_void,
font: *mut hb_font_t,
buffer: *mut hb_buffer_t,
features: *const hb_feature_t,
num_features: u32,
) -> hb_bool_t {
let font_data = font_data as *const HBHarfRuzzFontData;
let font_data = font_data as *const HBHarfRustFontData;
let face_data = face_data as *const HBHarfRustFaceData;
let mut hr_buffer = harfruzz::UnicodeBuffer::new();
let font_ref = &(*face_data).font_ref;
let mut hr_buffer = harfrust::UnicodeBuffer::new();
// Set buffer properties
let cluster_level = hb_buffer_get_cluster_level(buffer);
let cluster_level = match cluster_level {
hb_buffer_cluster_level_t_HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES => {
harfruzz::BufferClusterLevel::MonotoneGraphemes
harfrust::BufferClusterLevel::MonotoneGraphemes
}
hb_buffer_cluster_level_t_HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS => {
harfruzz::BufferClusterLevel::MonotoneCharacters
harfrust::BufferClusterLevel::MonotoneCharacters
}
hb_buffer_cluster_level_t_HB_BUFFER_CLUSTER_LEVEL_CHARACTERS => {
harfruzz::BufferClusterLevel::Characters
harfrust::BufferClusterLevel::Characters
}
/* TODO: Enable when added to HarfRuzz
hb_buffer_cluster_level_t_HB_BUFFER_CLUSTER_LEVEL_GRAPHEMES => {
harfruzz::BufferClusterLevel::Graphemes
harfrust::BufferClusterLevel::Graphemes
}
*/
_ => harfruzz::BufferClusterLevel::default(),
_ => harfrust::BufferClusterLevel::default(),
};
hr_buffer.set_cluster_level(cluster_level);
let flags = hb_buffer_get_flags(buffer);
hr_buffer.set_flags(harfruzz::BufferFlags::from_bits_truncate(flags));
hr_buffer.set_flags(harfrust::BufferFlags::from_bits_truncate(flags));
let not_found_variation_selector_glyph =
hb_buffer_get_not_found_variation_selector_glyph(buffer);
if not_found_variation_selector_glyph != u32::MAX {
@@ -186,16 +186,16 @@ pub unsafe extern "C" fn _hb_harfruzz_shape_rs(
let script = hb_buffer_get_script(buffer);
let language = hb_buffer_get_language(buffer);
let direction = hb_buffer_get_direction(buffer);
// Convert to HarfRuzz types
let script = harfruzz::Script::from_iso15924_tag(Tag::from_u32(script))
.unwrap_or(harfruzz::script::UNKNOWN);
// Convert to HarfRust types
let script = harfrust::Script::from_iso15924_tag(Tag::from_u32(script))
.unwrap_or(harfrust::script::UNKNOWN);
let language = hb_language_to_hr_language(language);
let direction = match direction {
hb_direction_t_HB_DIRECTION_LTR => harfruzz::Direction::LeftToRight,
hb_direction_t_HB_DIRECTION_RTL => harfruzz::Direction::RightToLeft,
hb_direction_t_HB_DIRECTION_TTB => harfruzz::Direction::TopToBottom,
hb_direction_t_HB_DIRECTION_BTT => harfruzz::Direction::BottomToTop,
_ => harfruzz::Direction::Invalid,
hb_direction_t_HB_DIRECTION_LTR => harfrust::Direction::LeftToRight,
hb_direction_t_HB_DIRECTION_RTL => harfrust::Direction::RightToLeft,
hb_direction_t_HB_DIRECTION_TTB => harfrust::Direction::TopToBottom,
hb_direction_t_HB_DIRECTION_BTT => harfrust::Direction::BottomToTop,
_ => harfrust::Direction::Invalid,
};
// Set properties on the buffer
hr_buffer.set_script(script);
@@ -215,33 +215,42 @@ pub unsafe extern "C" fn _hb_harfruzz_shape_rs(
hr_buffer.add(char::from_u32_unchecked(unicode), cluster);
}
let face = &(*font_data).face.as_ref().unwrap();
let ptem = hb_font_get_ptem(font);
let ptem = if ptem > 0.0 { Some(ptem) } else { None };
let shaper = (*face_data)
.shaper_data
.shaper(font_ref)
.instance(Some(&(*font_data).shaper_instance))
.point_size(ptem)
.build();
let features = if features.is_null() {
Vec::new()
} else {
let features = std::slice::from_raw_parts(features, num_features as usize);
features
.iter()
.map(|f| {
let tag = f.tag;
let value = f.value;
let start = f.start;
let end = f.end;
harfrust::Feature {
tag: Tag::from_u32(tag),
value,
start,
end,
}
})
.collect::<Vec<_>>()
};
let glyphs = if shape_plan.is_null() {
let features = if features.is_null() {
Vec::new()
} else {
let features = std::slice::from_raw_parts(features, num_features as usize);
features
.iter()
.map(|f| {
let tag = f.tag;
let value = f.value;
let start = f.start;
let end = f.end;
harfruzz::Feature {
tag: Tag::from_u32(tag),
value,
start,
end,
}
})
.collect::<Vec<_>>()
};
harfruzz::shape(face, &features, hr_buffer)
shaper.shape(hr_buffer, &features)
} else {
let shape_plan = shape_plan as *const harfruzz::ShapePlan;
harfruzz::shape_with_plan(face, shape_plan.as_ref().unwrap(), hr_buffer)
let shape_plan = shape_plan as *const harfrust::ShapePlan;
shaper.shape_with_plan(shape_plan.as_ref().unwrap(), hr_buffer, &features)
};
let count = glyphs.len();
@@ -260,7 +269,7 @@ pub unsafe extern "C" fn _hb_harfruzz_shape_rs(
let mut x_scale: i32 = 0;
let mut y_scale: i32 = 0;
hb_font_get_scale(font, &mut x_scale, &mut y_scale);
let upem = face.units_per_em();
let upem = shaper.units_per_em();
let x_scale = x_scale as f32 / upem as f32;
let y_scale = y_scale as f32 / upem as f32;
@@ -274,9 +283,16 @@ pub unsafe extern "C" fn _hb_harfruzz_shape_rs(
let pos = &mut *positions.add(i);
info.codepoint = hr_info.glyph_id;
info.cluster = hr_info.cluster;
info.mask = 0;
if hr_info.unsafe_to_break() {
info.mask |= hb_glyph_flags_t_HB_GLYPH_FLAG_UNSAFE_TO_BREAK;
}
if hr_info.unsafe_to_concat() {
info.mask |= hb_glyph_flags_t_HB_GLYPH_FLAG_UNSAFE_TO_CONCAT;
}
if hr_info.safe_to_insert_tatweel() {
info.mask |= hb_glyph_flags_t_HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL;
}
pos.x_advance = (hr_pos.x_advance as f32 * x_scale).round() as hb_position_t;
pos.y_advance = (hr_pos.y_advance as f32 * y_scale).round() as hb_position_t;
pos.x_offset = (hr_pos.x_offset as f32 * x_scale).round() as hb_position_t;
+1 -1
View File
@@ -8,7 +8,7 @@ start transform 1 0 0 1 0 0
end clip
end transform
push group
start transform 1 0.268 0 1 -0 -134
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
+1 -1
View File
@@ -8,7 +8,7 @@ start transform 1 0 0 1 0 0
end clip
end transform
push group
start transform 1 0.268 0 1 -0 -134
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
+4 -3
View File
@@ -30,7 +30,7 @@ def open_shape_batch_process():
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=sys.stdout,
stderr=subprocess.PIPE,
env=env,
)
return [process]
@@ -47,6 +47,7 @@ def shape_cmd(command, shape_process, verbose=False):
if shape_process[0].poll() is not None:
shape_process[0].stdin.close()
shape_process[0].stdout.close()
shape_process[0].stderr.close()
shape_process[0] = open_shape_batch_process()[0]
if verbose:
@@ -281,8 +282,8 @@ for filename in args:
if glyphs_expected != "*":
extra_options.append("--verify")
if shaper == "ot":
extra_options.append("--unsafe-to-concat")
extra_options.append("--unsafe-to-concat")
extra_options.append("--safe-to-insert-tatweel")
if verbose:
print(
+1 -4
View File
@@ -70,10 +70,7 @@ struct shape_consumer_t : shape_options_t
{
failed = true;
output.error (error);
if (hb_buffer_get_content_type (buffer) == HB_BUFFER_CONTENT_TYPE_GLYPHS)
break;
else
return true;
return true;
}
}