Skip to content

Commit d403072

Browse files
authored
Merge pull request #341 from harfbuzz/gen-tag-table.py
Switch more table generation to HarfBuzz
2 parents ac61d48 + 59f66ec commit d403072

14 files changed

+1644
-3406
lines changed

harfrust/src/hb/ot_shaper_use_table.rs

Lines changed: 269 additions & 266 deletions
Large diffs are not rendered by default.

harfrust/src/hb/ot_shaper_vowel_constraints.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// WARNING: this file was generated by scripts/gen-vowel-constraints.py
1+
/* == Start of generated functions == */
2+
// WARNING: this file was generated by ../../harfbuzz/src/gen-vowel-constraints.py --rust
23

34
#![allow(clippy::single_match)]
45

@@ -458,3 +459,4 @@ pub fn preprocess_text_vowel_constraints(buffer: &mut hb_buffer_t) {
458459
}
459460
buffer.sync();
460461
}
462+
/* == End of generated functions == */

harfrust/src/hb/tag.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,34 @@ fn lang_cmp(s1: &str, s2: &str) -> core::cmp::Ordering {
139139
s1[..ea].cmp(&s2[..eb])
140140
}
141141

142+
pub(super) fn subtag_matches(language: &str, subtag: &str) -> bool {
143+
for (i, _) in language.match_indices(subtag) {
144+
if let Some(c) = language.as_bytes().get(i + subtag.len()) {
145+
if !c.is_ascii_alphanumeric() {
146+
return true;
147+
}
148+
} else {
149+
return true;
150+
}
151+
}
152+
153+
false
154+
}
155+
156+
pub(super) fn lang_matches(language: &str, spec: &str) -> bool {
157+
if language.starts_with(spec) {
158+
return language.len() == spec.len() || language.as_bytes().get(spec.len()) == Some(&b'-');
159+
}
160+
161+
false
162+
}
163+
164+
pub(super) fn strncmp(s1: &str, s2: &str, n: usize) -> bool {
165+
let n1 = core::cmp::min(n, s1.len());
166+
let n2 = core::cmp::min(n, s2.len());
167+
s1[..n1] == s2[..n2]
168+
}
169+
142170
fn tags_from_language(language: &Language, tags: &mut ThreeTags) {
143171
let language = language.as_str();
144172

harfrust/src/hb/tag_table.rs

Lines changed: 99 additions & 125 deletions
Large diffs are not rendered by default.

harfrust/src/hb/ucd_table.rs

Lines changed: 1150 additions & 1147 deletions
Large diffs are not rendered by default.

scripts/README.md

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,30 @@
44
repo. The Unicode/OT table generators shared with HarfBuzz live in `~/harfbuzz/src`
55
and should be run from there.
66

7+
For regenerating the Rust-side shared Unicode/OT tables, use the wrapper
8+
makefile in this directory. It assumes HarfBuzz lives in `~/harfbuzz` by
9+
default and can be overridden with `HARFBUZZ_DIR=...`.
10+
711
Local generators in this repo:
812

913
```sh
1014
bash bump-version.sh 0.6.0
1115

12-
python3 ./gen-vowel-constraints.py > ../harfrust/src/hb/ot_shaper_vowel_constraints.rs
13-
rustfmt ../harfrust/src/hb/ot_shaper_vowel_constraints.rs
16+
python3 ./gen-shaping-tests.py
1417

15-
python3 ./gen-tag-table.py > ../harfrust/src/hb/tag_table.rs
16-
rustfmt ../harfrust/src/hb/tag_table.rs
18+
python3 ./gen-shaping-tests.py /path/to/harfbuzz
1719
```
1820

21+
`gen-shaping-tests.py` assumes HarfBuzz is in `~/harfbuzz` by default. If
22+
`~/harfbuzz/builddir/util/hb-shape` is missing but `~/harfbuzz/builddir`
23+
exists, it will run `ninja -C ~/harfbuzz/builddir` first.
24+
1925
HarfBuzz-owned generators used by `harfrust`:
2026

2127
```sh
22-
PYTHONPATH=/Users/behdad/packtab \
23-
python3 ~/harfbuzz/src/gen-ucd-table.py --rust \
24-
~/harfbuzz/src/ucd.nounihan.grouped.xml \
25-
~/harfbuzz/src/hb-script-list.h \
26-
> ../harfrust/src/hb/ucd_table.rs
27-
28-
PYTHONPATH=/Users/behdad/packtab \
29-
python3 ~/harfbuzz/src/gen-use-table.py --rust \
30-
~/harfbuzz/src/IndicSyllabicCategory.txt \
31-
~/harfbuzz/src/IndicPositionalCategory.txt \
32-
~/harfbuzz/src/ArabicShaping.txt \
33-
~/harfbuzz/src/DerivedCoreProperties.txt \
34-
~/harfbuzz/src/UnicodeData.txt \
35-
~/harfbuzz/src/Blocks.txt \
36-
~/harfbuzz/src/Scripts.txt \
37-
./ms-use/IndicSyllabicCategory-Additional.txt \
38-
./ms-use/IndicPositionalCategory-Additional.txt \
39-
> ../harfrust/src/hb/ot_shaper_use_table.rs
40-
41-
PYTHONPATH=/Users/behdad/packtab \
42-
python3 ~/harfbuzz/src/gen-arabic-table.py --rust \
43-
~/harfbuzz/src/ArabicShaping.txt \
44-
~/harfbuzz/src/UnicodeData.txt \
45-
~/harfbuzz/src/Blocks.txt \
46-
> ../harfrust/src/hb/ot_shaper_arabic_table.rs
47-
48-
PYTHONPATH=/Users/behdad/packtab \
49-
python3 ~/harfbuzz/src/gen-indic-table.py --rust \
50-
~/harfbuzz/src/IndicSyllabicCategory.txt \
51-
~/harfbuzz/src/IndicPositionalCategory.txt \
52-
~/harfbuzz/src/Blocks.txt \
53-
> ../harfrust/src/hb/ot_shaper_indic_table.rs
54-
55-
PYTHONPATH=/Users/behdad/packtab \
56-
python3 ~/harfbuzz/src/gen-emoji-table.py --rust \
57-
~/harfbuzz/src/emoji-data.txt \
58-
~/harfbuzz/src/emoji-test.txt \
59-
> ../harfrust/src/hb/unicode_emoji_table.rs
28+
make -f update-unicode-tables.mk
29+
30+
make -f update-unicode-tables.mk hb-refresh
31+
32+
make -f update-unicode-tables.mk HARFBUZZ_DIR=/path/to/harfbuzz
6033
```

scripts/gen-shaping-tests.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,21 @@
3636
]
3737

3838

39-
def check_hb_build(hb_shape_exe):
40-
if not hb_shape_exe.exists():
41-
print("Build harfbuzz first using:")
42-
print(" meson builddir")
43-
print(" ninja -Cbuilddir")
44-
exit(1)
39+
def check_hb_build(hb_dir, hb_shape_exe):
40+
if hb_shape_exe.exists():
41+
return
42+
43+
build_dir = hb_dir / "builddir"
44+
if build_dir.exists():
45+
subprocess.run(["ninja", "-C", str(build_dir)], check=True)
46+
if hb_shape_exe.exists():
47+
return
48+
49+
print("Build harfbuzz first using:")
50+
print(f" cd {hb_dir}")
51+
print(" meson setup builddir")
52+
print(" ninja -C builddir")
53+
exit(1)
4554

4655

4756
def update_font_path(tests_name, fontfile):
@@ -233,18 +242,18 @@ def convert_test_files(root_dir, hb_shape_exe, tests_dir, tests_name, files, cus
233242

234243

235244
def main():
236-
if len(sys.argv) != 2:
237-
print("Usage: gen-shaping-tests.py /path/to/harfbuzz-src")
245+
if len(sys.argv) > 2:
246+
print("Usage: gen-shaping-tests.py [/path/to/harfbuzz-src]")
238247
exit(1)
239248

240-
hb_dir = Path(sys.argv[1])
249+
hb_dir = Path(sys.argv[1]).expanduser() if len(sys.argv) == 2 else Path("~/harfbuzz").expanduser()
241250
assert hb_dir.exists()
242251

243252
rb_root = pathlib.Path(__file__).parent.parent
244253

245254
# Check that harfbuzz was built.
246255
hb_shape_exe = hb_dir.joinpath("builddir/util/hb-shape")
247-
check_hb_build(hb_shape_exe)
256+
check_hb_build(hb_dir, hb_shape_exe)
248257

249258
def to_hb_absolute(name):
250259
return hb_dir / f"test/shape/data/{name}/tests"

0 commit comments

Comments
 (0)