From f515f128948c1e69267c5e53722ca1634f24b6c2 Mon Sep 17 00:00:00 2001 From: WhiteHades <44260523+WhiteHades@users.noreply.github.com> Date: Wed, 15 Jul 2026 15:40:42 +0600 Subject: [PATCH 1/3] fix: render registered kana outlines --- changelog.d/registered-kana-outlines.md | 1 + src/primitives/canvas/font_ttf.zig | 10 +- src/primitives/canvas/font_ttf_tests.zig | 16 +++ .../NotoSansJP-kana-boundary.ttf | Bin 0 -> 6912 bytes .../testdata/noto-kana-boundary/OFL.txt | 93 ++++++++++++++++++ .../testdata/noto-kana-boundary/README.md | 16 +++ 6 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 changelog.d/registered-kana-outlines.md create mode 100644 src/primitives/canvas/testdata/noto-kana-boundary/NotoSansJP-kana-boundary.ttf create mode 100644 src/primitives/canvas/testdata/noto-kana-boundary/OFL.txt create mode 100644 src/primitives/canvas/testdata/noto-kana-boundary/README.md diff --git a/changelog.d/registered-kana-outlines.md b/changelog.d/registered-kana-outlines.md new file mode 100644 index 000000000..6fc074bdd --- /dev/null +++ b/changelog.d/registered-kana-outlines.md @@ -0,0 +1 @@ +fix: **Registered kana outlines**: TrueType glyphs with up to 138 points now render instead of falling back to blocks. diff --git a/src/primitives/canvas/font_ttf.zig b/src/primitives/canvas/font_ttf.zig index de7f88ee8..5d63710cb 100644 --- a/src/primitives/canvas/font_ttf.zig +++ b/src/primitives/canvas/font_ttf.zig @@ -9,10 +9,10 @@ //! shaping, no CFF. The deterministic estimator (`text_metrics.zig`) //! derives its advance table from this face's `cmap`/`hmtx`, so layout //! measures with exactly the advances these outlines are inked at. -//! All parsing is bounds-checked against fixed budgets sized from -//! the bundled face's `maxp` (96 points / 16 contours per simple glyph, -//! composites well under both), and any glyph beyond the budget fails -//! with a recoverable error so callers can fall back to block glyphs. +//! All parsing is bounds-checked against fixed budgets sized from the +//! bundled and registered-face fixtures (138 points / 24 contours per +//! simple glyph), and any glyph beyond the budget fails with a recoverable +//! error so callers can fall back to block glyphs. //! //! The bundled face is embedded at comptime and its table directory is //! validated at comptime: a corrupt bundle is a compile error, and the @@ -32,7 +32,7 @@ pub const Error = error{ FontGlyphTooComplex, } || @import("vector.zig").Error; -pub const max_glyph_points: usize = 128; +pub const max_glyph_points: usize = 138; pub const max_glyph_contours: usize = 24; pub const max_composite_depth: usize = 4; pub const max_composite_components: usize = 8; diff --git a/src/primitives/canvas/font_ttf_tests.zig b/src/primitives/canvas/font_ttf_tests.zig index b1f23d1ca..d4b9217e6 100644 --- a/src/primitives/canvas/font_ttf_tests.zig +++ b/src/primitives/canvas/font_ttf_tests.zig @@ -11,6 +11,7 @@ const drawing = @import("drawing.zig"); const PointF = geometry.PointF; const Affine = drawing.Affine; +const kana_boundary_bytes = @embedFile("testdata/noto-kana-boundary/NotoSansJP-kana-boundary.ttf"); const grid_size: usize = 24; @@ -203,6 +204,21 @@ test "mono outlines rasterize within the vector budgets" { } } +test "registered kana outlines render at the parser boundary" { + const face = try font_ttf.Face.parse(kana_boundary_bytes); + var mapped: usize = 0; + var codepoint: u21 = 0; + while (codepoint <= 0xFFFF) : (codepoint += 1) { + const glyph = face.glyphIndex(codepoint); + if (glyph == 0) continue; + var builder = vector.PathBuilder(256){}; + try face.glyphOutline(glyph, Affine.identity(), &builder); + try std.testing.expect(builder.slice().len > 0); + mapped += 1; + } + try std.testing.expectEqual(@as(usize, 5), mapped); +} + test "corrupt font bytes fail to parse without crashing" { try std.testing.expectError(error.FontParseFailed, font_ttf.Face.parse(&.{})); try std.testing.expectError(error.FontParseFailed, font_ttf.Face.parse(font_ttf.geist_regular_bytes[0..64])); diff --git a/src/primitives/canvas/testdata/noto-kana-boundary/NotoSansJP-kana-boundary.ttf b/src/primitives/canvas/testdata/noto-kana-boundary/NotoSansJP-kana-boundary.ttf new file mode 100644 index 0000000000000000000000000000000000000000..45952edee2fd7945f37b3ed37f5d15b0cba49945 GIT binary patch literal 6912 zcmcgwX>45Abv|#IHw(!b&Tv+)Lvj`lhaAq%Wyq1Zi<^exj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+I>zo|4!3R0(N*+cz{4xedG-k2 zr(kOeQr>5Nec{yRcNS;S+Xg9K7*#rj9^K2r9H^-inv;JGp@$1!#VHzUG2hv6Z6zJYrkv(fZvm^1siou$~9O;syP zF)|thfX?f$e(SBj`iDPy<+V3&(D(QLY(cfdE3*y8@%$N|RcM*SoR7i-@ArS}yYBA^ zWe+BANirvxQ;dx&_YKFJ@BPKQXyM(*=x99j!v76Cyl)u!UDYDD@DAmD#%sp2+l76e zK@q!{`x&nh^fN|N>S!7u4|9+Cz$-b3%vHdio&$5dt5wgw zb7AS)x6yOp>)m>^dEd*Fdoc^a`;QvY_SD&~Uw4jQI!jneYOM;r4& z(Rv>9UWZ=xf-^R*{l^etKj;!jK+d)xOCzg+y+r>E#>=FPj7=9Puyl22gL+nXRxVJ_ zT5)Tg0vC!~MG9;b_qGs|`CPy!1DP7hNA2|Wa*KqPO0prJzd+Ld9|J#0%FrXQ^)z~% zB(E=>JBw#;eR*YjXM1z&W7um)wC}sio*O>2Va6$~^--KFq;IKZ0c8Q63dkA!tyJGm zyiq%hn@=!Y{>M7)OD5_^)VULdfQmxk9uxwY5iX#pTDVjyZs0_8U{6+CC0O(!&x$zt znDDml|Ab8YKSiGi|Md8pa9j6(juMvz^-N{PS44?VNvzvMS?uLs%_nVM;-!_HJu+X~ z*^A>`b+>P9OMn+T*kbEAL#h&5JD>O1c0GxgSJ(CgE{iIwL=ti0B=I{euAXpvarVfP j11uT@r$;abC)H{a{{3bppI!IUzgWcCRkO~6v`hG3(a~gF literal 0 HcmV?d00001 diff --git a/src/primitives/canvas/testdata/noto-kana-boundary/OFL.txt b/src/primitives/canvas/testdata/noto-kana-boundary/OFL.txt new file mode 100644 index 000000000..89b1c616c --- /dev/null +++ b/src/primitives/canvas/testdata/noto-kana-boundary/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source' + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font Software, +subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/primitives/canvas/testdata/noto-kana-boundary/README.md b/src/primitives/canvas/testdata/noto-kana-boundary/README.md new file mode 100644 index 000000000..55f3afff7 --- /dev/null +++ b/src/primitives/canvas/testdata/noto-kana-boundary/README.md @@ -0,0 +1,16 @@ +# Noto Sans JP kana boundary fixture + +`NotoSansJP-kana-boundary.ttf` is a Modified Version of Noto Sans JP 2.004-H2 containing five kana glyphs that exercise Native SDK's registered-font outline bound. The complete SIL Open Font License is in `OFL.txt`. + +- Source commit: `google/fonts@295d98a7a0c17c68f1341eaeea354e7960ea70d3` +- Source file SHA-256: `c2f3b4d463500a2ddcd3849cded1fceeb9fd6d1c32e6cbecd568453ba50fc68f` +- Static Regular SHA-256: `946280470c7f8dff9c7256a10c6fb06544c75e83553e906a1a0ad946211de7ed` +- Fixture SHA-256: `411ba21d889de26b1a93b37a996734d37f71e63f4c37c7d3092a1c52df64e204` +- Generator: FontTools 4.63.0 + +```sh +curl -fsSL 'https://raw.githubusercontent.com/google/fonts/295d98a7a0c17c68f1341eaeea354e7960ea70d3/ofl/notosansjp/NotoSansJP%5Bwght%5D.ttf' -o NotoSansJP-wght.ttf +export SOURCE_DATE_EPOCH=1784100876 +fonttools varLib.instancer NotoSansJP-wght.ttf wght=400 --update-name-table --output=NotoSansJP-Regular-400.ttf +pyftsubset NotoSansJP-Regular-400.ttf '--unicodes=U+3070,U+3071,U+307C,U+307D,U+3091' --output-file=NotoSansJP-kana-boundary.ttf '--name-IDs=*' --name-legacy '--name-languages=*' +``` From 3c8996571b65df4759291c4ed9beced4a3a3a9b9 Mon Sep 17 00:00:00 2001 From: WhiteHades <44260523+WhiteHades@users.noreply.github.com> Date: Wed, 15 Jul 2026 16:14:13 +0600 Subject: [PATCH 2/3] fix: render common japanese outlines --- changelog.d/registered-japanese-outlines.md | 1 + changelog.d/registered-kana-outlines.md | 1 - src/primitives/canvas/font_ttf.zig | 6 ++--- src/primitives/canvas/font_ttf_tests.zig | 22 +++++++++++------- src/primitives/canvas/reference.zig | 3 ++- .../NotoSansJP-japanese-boundary.ttf} | Bin 6912 -> 7652 bytes .../OFL.txt | 0 .../testdata/noto-japanese-boundary/README.md | 18 ++++++++++++++ .../testdata/noto-kana-boundary/README.md | 16 ------------- 9 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 changelog.d/registered-japanese-outlines.md delete mode 100644 changelog.d/registered-kana-outlines.md rename src/primitives/canvas/testdata/{noto-kana-boundary/NotoSansJP-kana-boundary.ttf => noto-japanese-boundary/NotoSansJP-japanese-boundary.ttf} (73%) rename src/primitives/canvas/testdata/{noto-kana-boundary => noto-japanese-boundary}/OFL.txt (100%) create mode 100644 src/primitives/canvas/testdata/noto-japanese-boundary/README.md delete mode 100644 src/primitives/canvas/testdata/noto-kana-boundary/README.md diff --git a/changelog.d/registered-japanese-outlines.md b/changelog.d/registered-japanese-outlines.md new file mode 100644 index 000000000..3e5d42e10 --- /dev/null +++ b/changelog.d/registered-japanese-outlines.md @@ -0,0 +1 @@ +fix: **Registered Japanese outlines**: Larger registered-font glyphs such as `鬱` now render instead of falling back to blocks. diff --git a/changelog.d/registered-kana-outlines.md b/changelog.d/registered-kana-outlines.md deleted file mode 100644 index 6fc074bdd..000000000 --- a/changelog.d/registered-kana-outlines.md +++ /dev/null @@ -1 +0,0 @@ -fix: **Registered kana outlines**: TrueType glyphs with up to 138 points now render instead of falling back to blocks. diff --git a/src/primitives/canvas/font_ttf.zig b/src/primitives/canvas/font_ttf.zig index 5d63710cb..ee911b12c 100644 --- a/src/primitives/canvas/font_ttf.zig +++ b/src/primitives/canvas/font_ttf.zig @@ -10,7 +10,7 @@ //! derives its advance table from this face's `cmap`/`hmtx`, so layout //! measures with exactly the advances these outlines are inked at. //! All parsing is bounds-checked against fixed budgets sized from the -//! bundled and registered-face fixtures (138 points / 24 contours per +//! bundled and registered-face fixtures (237 points / 26 contours per //! simple glyph), and any glyph beyond the budget fails with a recoverable //! error so callers can fall back to block glyphs. //! @@ -32,8 +32,8 @@ pub const Error = error{ FontGlyphTooComplex, } || @import("vector.zig").Error; -pub const max_glyph_points: usize = 138; -pub const max_glyph_contours: usize = 24; +pub const max_glyph_points: usize = 237; +pub const max_glyph_contours: usize = 26; pub const max_composite_depth: usize = 4; pub const max_composite_components: usize = 8; diff --git a/src/primitives/canvas/font_ttf_tests.zig b/src/primitives/canvas/font_ttf_tests.zig index d4b9217e6..b502908da 100644 --- a/src/primitives/canvas/font_ttf_tests.zig +++ b/src/primitives/canvas/font_ttf_tests.zig @@ -11,7 +11,7 @@ const drawing = @import("drawing.zig"); const PointF = geometry.PointF; const Affine = drawing.Affine; -const kana_boundary_bytes = @embedFile("testdata/noto-kana-boundary/NotoSansJP-kana-boundary.ttf"); +const japanese_boundary_bytes = @embedFile("testdata/noto-japanese-boundary/NotoSansJP-japanese-boundary.ttf"); const grid_size: usize = 24; @@ -204,19 +204,23 @@ test "mono outlines rasterize within the vector budgets" { } } -test "registered kana outlines render at the parser boundary" { - const face = try font_ttf.Face.parse(kana_boundary_bytes); - var mapped: usize = 0; - var codepoint: u21 = 0; - while (codepoint <= 0xFFFF) : (codepoint += 1) { +test "registered Japanese outlines render at the parser boundary" { + const face = try font_ttf.Face.parse(japanese_boundary_bytes); + const expected = [_]u21{ 'ば', 'ぱ', 'ぼ', 'ぽ', 'ゑ', '鬱' }; + for (expected) |codepoint| { const glyph = face.glyphIndex(codepoint); - if (glyph == 0) continue; + try std.testing.expect(glyph != 0); var builder = vector.PathBuilder(256){}; try face.glyphOutline(glyph, Affine.identity(), &builder); try std.testing.expect(builder.slice().len > 0); - mapped += 1; } - try std.testing.expectEqual(@as(usize, 5), mapped); + + var mapped: usize = 0; + var codepoint: u21 = 0; + while (codepoint <= 0xFFFF) : (codepoint += 1) { + if (face.glyphIndex(codepoint) != 0) mapped += 1; + } + try std.testing.expectEqual(expected.len, mapped); } test "corrupt font bytes fail to parse without crashing" { diff --git a/src/primitives/canvas/reference.zig b/src/primitives/canvas/reference.zig index 862b9eda4..deb81fb2d 100644 --- a/src/primitives/canvas/reference.zig +++ b/src/primitives/canvas/reference.zig @@ -45,7 +45,8 @@ const vector = @import("vector.zig"); const font_ttf = @import("font_ttf.zig"); /// Element budget for one glyph outline: the bundled face's densest -/// glyphs stay well under this (maxp: 96 points per simple glyph). +/// glyphs stay well under this, and the registered Japanese boundary +/// fixture emits 243 elements. const reference_glyph_path_capacity: usize = 256; const referenceBlurKernel = reference_blur.referenceBlurKernel; diff --git a/src/primitives/canvas/testdata/noto-kana-boundary/NotoSansJP-kana-boundary.ttf b/src/primitives/canvas/testdata/noto-japanese-boundary/NotoSansJP-japanese-boundary.ttf similarity index 73% rename from src/primitives/canvas/testdata/noto-kana-boundary/NotoSansJP-kana-boundary.ttf rename to src/primitives/canvas/testdata/noto-japanese-boundary/NotoSansJP-japanese-boundary.ttf index 45952edee2fd7945f37b3ed37f5d15b0cba49945..752c45b65da18d26c51090c6f20375f9ba0b5dcb 100644 GI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c6i8d96%AP1^q<2RZXz~B+Ah$xLc}k)pLY|#i(Q=qW0goZQP9pUW Dq#|l~ diff --git a/src/primitives/canvas/testdata/noto-kana-boundary/OFL.txt b/src/primitives/canvas/testdata/noto-japanese-boundary/OFL.txt similarity index 100% rename from src/primitives/canvas/testdata/noto-kana-boundary/OFL.txt rename to src/primitives/canvas/testdata/noto-japanese-boundary/OFL.txt diff --git a/src/primitives/canvas/testdata/noto-japanese-boundary/README.md b/src/primitives/canvas/testdata/noto-japanese-boundary/README.md new file mode 100644 index 000000000..9c178d8e0 --- /dev/null +++ b/src/primitives/canvas/testdata/noto-japanese-boundary/README.md @@ -0,0 +1,18 @@ +# Noto Sans JP Japanese outline boundary fixture + +`NotoSansJP-japanese-boundary.ttf` is a Modified Version of Noto Sans JP 2.004-H2 containing five kana glyphs and the common-use kanji `鬱`. The fixture exercises Native SDK's registered-font bounds up to 237 points and 26 contours. The complete SIL Open Font License is in `OFL.txt`. + +- Source commit: `google/fonts@295d98a7a0c17c68f1341eaeea354e7960ea70d3` +- Source file SHA-256: `c2f3b4d463500a2ddcd3849cded1fceeb9fd6d1c32e6cbecd568453ba50fc68f` +- Static Regular SHA-256: `946280470c7f8dff9c7256a10c6fb06544c75e83553e906a1a0ad946211de7ed` +- Fixture SHA-256: `8a0c8b2e78eab29b4e26615a93695df8cc5eaae08ef981e517dc207069d9f308` +- Generator: FontTools 4.63.0 + +```sh +workdir=$(mktemp -d) +trap 'rm -rf "$workdir"' EXIT +curl -fsSL 'https://raw.githubusercontent.com/google/fonts/295d98a7a0c17c68f1341eaeea354e7960ea70d3/ofl/notosansjp/NotoSansJP%5Bwght%5D.ttf' -o "$workdir/NotoSansJP-wght.ttf" +export SOURCE_DATE_EPOCH=1784100876 +fonttools varLib.instancer "$workdir/NotoSansJP-wght.ttf" wght=400 --update-name-table --output="$workdir/NotoSansJP-Regular-400.ttf" +pyftsubset "$workdir/NotoSansJP-Regular-400.ttf" '--unicodes=U+3070,U+3071,U+307C,U+307D,U+3091,U+9B31' --output-file=NotoSansJP-japanese-boundary.ttf '--name-IDs=*' --name-legacy '--name-languages=*' +``` diff --git a/src/primitives/canvas/testdata/noto-kana-boundary/README.md b/src/primitives/canvas/testdata/noto-kana-boundary/README.md deleted file mode 100644 index 55f3afff7..000000000 --- a/src/primitives/canvas/testdata/noto-kana-boundary/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Noto Sans JP kana boundary fixture - -`NotoSansJP-kana-boundary.ttf` is a Modified Version of Noto Sans JP 2.004-H2 containing five kana glyphs that exercise Native SDK's registered-font outline bound. The complete SIL Open Font License is in `OFL.txt`. - -- Source commit: `google/fonts@295d98a7a0c17c68f1341eaeea354e7960ea70d3` -- Source file SHA-256: `c2f3b4d463500a2ddcd3849cded1fceeb9fd6d1c32e6cbecd568453ba50fc68f` -- Static Regular SHA-256: `946280470c7f8dff9c7256a10c6fb06544c75e83553e906a1a0ad946211de7ed` -- Fixture SHA-256: `411ba21d889de26b1a93b37a996734d37f71e63f4c37c7d3092a1c52df64e204` -- Generator: FontTools 4.63.0 - -```sh -curl -fsSL 'https://raw.githubusercontent.com/google/fonts/295d98a7a0c17c68f1341eaeea354e7960ea70d3/ofl/notosansjp/NotoSansJP%5Bwght%5D.ttf' -o NotoSansJP-wght.ttf -export SOURCE_DATE_EPOCH=1784100876 -fonttools varLib.instancer NotoSansJP-wght.ttf wght=400 --update-name-table --output=NotoSansJP-Regular-400.ttf -pyftsubset NotoSansJP-Regular-400.ttf '--unicodes=U+3070,U+3071,U+307C,U+307D,U+3091' --output-file=NotoSansJP-kana-boundary.ttf '--name-IDs=*' --name-legacy '--name-languages=*' -``` From d6eb4de1b000993d91a3dc374816dfb3de6de83c Mon Sep 17 00:00:00 2001 From: WhiteHades <44260523+WhiteHades@users.noreply.github.com> Date: Wed, 15 Jul 2026 18:30:05 +0600 Subject: [PATCH 3/3] fix: cover registered glyph path bounds --- src/primitives/canvas/font_ttf.zig | 3 +++ src/primitives/canvas/font_ttf_tests.zig | 6 +++++- src/primitives/canvas/reference.zig | 7 ++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/primitives/canvas/font_ttf.zig b/src/primitives/canvas/font_ttf.zig index ee911b12c..056f486f8 100644 --- a/src/primitives/canvas/font_ttf.zig +++ b/src/primitives/canvas/font_ttf.zig @@ -34,6 +34,9 @@ pub const Error = error{ pub const max_glyph_points: usize = 237; pub const max_glyph_contours: usize = 26; +/// A simple glyph emits at most one segment per point plus one move and +/// one close for each contour. +pub const max_simple_glyph_path_elements: usize = max_glyph_points + 2 * max_glyph_contours; pub const max_composite_depth: usize = 4; pub const max_composite_components: usize = 8; diff --git a/src/primitives/canvas/font_ttf_tests.zig b/src/primitives/canvas/font_ttf_tests.zig index b502908da..6070852a2 100644 --- a/src/primitives/canvas/font_ttf_tests.zig +++ b/src/primitives/canvas/font_ttf_tests.zig @@ -207,13 +207,17 @@ test "mono outlines rasterize within the vector budgets" { test "registered Japanese outlines render at the parser boundary" { const face = try font_ttf.Face.parse(japanese_boundary_bytes); const expected = [_]u21{ 'ば', 'ぱ', 'ぼ', 'ぽ', 'ゑ', '鬱' }; + var max_emitted: usize = 0; for (expected) |codepoint| { const glyph = face.glyphIndex(codepoint); try std.testing.expect(glyph != 0); - var builder = vector.PathBuilder(256){}; + var builder = vector.PathBuilder(font_ttf.max_simple_glyph_path_elements){}; try face.glyphOutline(glyph, Affine.identity(), &builder); try std.testing.expect(builder.slice().len > 0); + max_emitted = @max(max_emitted, builder.slice().len); } + try std.testing.expectEqual(@as(usize, 243), max_emitted); + try std.testing.expectEqual(@as(usize, 289), font_ttf.max_simple_glyph_path_elements); var mapped: usize = 0; var codepoint: u21 = 0; diff --git a/src/primitives/canvas/reference.zig b/src/primitives/canvas/reference.zig index deb81fb2d..3330d1ce2 100644 --- a/src/primitives/canvas/reference.zig +++ b/src/primitives/canvas/reference.zig @@ -44,10 +44,8 @@ const render_fingerprints = @import("render_fingerprints.zig"); const vector = @import("vector.zig"); const font_ttf = @import("font_ttf.zig"); -/// Element budget for one glyph outline: the bundled face's densest -/// glyphs stay well under this, and the registered Japanese boundary -/// fixture emits 243 elements. -const reference_glyph_path_capacity: usize = 256; +/// Element budget for every simple glyph accepted by the bounded parser. +const reference_glyph_path_capacity: usize = font_ttf.max_simple_glyph_path_elements; const referenceBlurKernel = reference_blur.referenceBlurKernel; const referenceBlurSampleWithKernel = reference_blur.referenceBlurSampleWithKernel; @@ -1075,7 +1073,6 @@ fn referenceScaleRect(rect: geometry.RectF, scale: f32) geometry.RectF { return geometry.RectF.init(rect.x * scale, rect.y * scale, rect.width * scale, rect.height * scale); } - fn referencePixelCenter(x: usize, y: usize) geometry.PointF { return geometry.PointF.init(@as(f32, @floatFromInt(x)) + 0.5, @as(f32, @floatFromInt(y)) + 0.5); }