Repository navigation
Conversation
|
The resvg PR has been open for nearly a year, so I wouldn't hold my breath |
We aren't. We're just switching anyway. |
93e5ec1 to
84b2bd8
Compare
|
Looks like there's finally movement in linebender/resvg#922 |
|
linebender/resvg#922 has now been merged Edit: The 0.48 release includes this change |
Finally coming in googlefonts/fontations#2105 |
53a3e84 to
bd7670d
Compare
There was a problem hiding this comment.
I've finished the migration and gotten this PR in a working state. Still a number of things to do though, and I've left some comments.
Note that fontations is currently undergoing an API change (pointed out to me in googlefonts/fontations#2156 (comment)): googlefonts/fontations#1852 (comment). A number of things are moving from skrifa into read-fonts, and this work should be finished in a few weeks time. This PR will probably change a fair bit then once that work is done, so probably best to hold off on a review until then. (I will start to get the code working using this new API, which is under a feature flag, on another branch.)
A bunch of tests are failing. Most are svg tests, due to glyph ids changing. A more important change though is that skrifa doesn't always return None when outlining empty glyphs (e.g. spaces). So we have a bunch of <symbol><path d="M 0 0"/></symbol> showing up now. (I'd imagine this change is wrong, though.)
There are also some render tests and one pdf test failing, which I need to look into.
| } | ||
| } | ||
|
|
||
| struct ColrBuilder<'a>(&'a mut String); |
There was a problem hiding this comment.
Everything from this point onward was taken from resvg (with minor modifications): linebender/resvg#922. Need to properly attribute it.
There was a problem hiding this comment.
I've changed it up slightly to make use of some new stuff in read-fonts, but is otherwise the same "structure" as the code from resvg.
| // TODO: Normalizing the stops into the 0..1 range moves the circles onto the | ||
| // first and last stop, which can make `r0` (and in theory `r1`) negative. | ||
| // SVG cannot express that, so the color line should be cut where the radius | ||
| // reaches zero, with an interpolated stop inserted at the cut and the | ||
| // remaining stops reparameterized into the 0..1 range. | ||
| self.svg.start_element("radialGradient"); | ||
| self.svg.write_attribute("id", &gradient_id); | ||
| self.svg.write_attribute("cx", &gradient.x1); | ||
| self.svg.write_attribute("cy", &gradient.y1); | ||
| self.svg.write_attribute("r", &gradient.r1); | ||
| self.svg.write_attribute("fr", &gradient.r0); | ||
| self.svg.write_attribute("fx", &gradient.x0); | ||
| self.svg.write_attribute("fy", &gradient.y0); | ||
| self.svg.write_attribute("cx", &c1.x); | ||
| self.svg.write_attribute("cy", &c1.y); | ||
| self.svg.write_attribute("r", &r1); | ||
| self.svg.write_attribute("fr", &r0); | ||
| self.svg.write_attribute("fx", &c0.x); | ||
| self.svg.write_attribute("fy", &c0.y); | ||
| self.svg.write_attribute("gradientUnits", &"userSpaceOnUse"); | ||
| self.write_spread_method_attribute(gradient.extend); | ||
| self.write_spread_method_attribute(extend); | ||
| self.write_transform_attribute("gradientTransform", gradient_transform); |
There was a problem hiding this comment.
gpt-6 astra flagged this on review with the following comment. I have no idea about this part of the code (I took it from resvg after all).
Skrifa can supply negative radii when normalizing valid COLR color stops. I reproduced
r0 = -256, which this code writes asfr="-256". Usvg clamps that to zero without adjusting the stops, changing the gradient’s colors and geometry. The color line needs truncation and reparameterization before SVG serialization.
There was a problem hiding this comment.
I believe the code was originally written by @LaurenzV, so perhaps he can make sense of it?
6850b1b to
d1e9977
Compare
rustybuzz and ttf-parser to harfrust and fontationsrustybuzz and ttf-parser to harfrust and read-fonts`
rustybuzz and ttf-parser to harfrust and read-fonts`rustybuzz and ttf-parser to harfrust and read-fonts
ecabea6 to
52070c6
Compare
|
What is it that's actually blocking this? |
It was blocked by this from @mkorje's earlier comment:
But this has been resolved since. |
laurmaedje
left a comment
There was a problem hiding this comment.
Looks pretty good!
A few things aside from the in-code comments:
-
The
text-colr-svg-glyphs-different-sizetest regressed. Seems to be something with COLRv1 painting. -
So we have a bunch of
<symbol><path d="M 0 0"/></symbol>showing up now.Maybe let's just filter these out?
-
We may also want to wait for resvg to be ported
That has happened since. We'd first need to bump it in krilla though. Currently, we have many versions of the fontations crates in the tree. I suspect that could be streamlined with some changes in upstream crates (mostly krilla and hayro, but resvg also seems to still be on 0.12 of harfrust...). Since the dependency tree is already a mess, we don't necessarily have to block the PR on this, but we could, depending on preference.
-
Glyph bounds now also respect color glyphs. With top and bottom edge
"bounds", Noto Color Emoji 😀 goes from 0pt to 11.69pt tall. Yay! This fixes #8074. We should add a test that covers this.
Also, here are some behavior changes Claude found, which are fine, but good to know about:
-
The width class 0 or above 9 now map to
UltraCondensed/UltraExpandedinstead ofNormal. -
The oblique bit is no longer gated on OS/2 version >= 4.
-
Fonts without an OS/2 table now take bold/italic from the
headtable'smacStylefield. Courier Bold is now correctly 700 instead of 400, and Courier Oblique becomes Italic. -
Fonts with a units-per-em outside 16-16384 now load (with 1000) instead of being rejected.
-
Glyph bounds now use the metadata from the glyphs' header instead of outlining it when possible (can be wrong or lead to small changes).
-
Empty glyphs now return
Some(zero)instead ofNone, soTextItem::bboxincludes the origins of spaces. -
Text widths change for Apple fonts that have a trak table because we set the point size. That seems like a good thing.
| .unwrap_or_default() | ||
| let extents = |gid, | ||
| f: fn( | ||
| read_fonts::model::metrics::GlyphExtents<read_fonts::types::F48Dot16>, |
There was a problem hiding this comment.
The formatting is a bit much here. Perhaps we can have a use? You seem to avoid them for read_fonts in some cases (any particular reason like name clashes?), but it could also be a function-local use.
There was a problem hiding this comment.
Sure, rustfmt is being a bit weird here aha. There's no particular reason, other than I think before the uses weren't entirely consistent, so I just opted to avoid them.
There was a problem hiding this comment.
I realise that I am now too using it inconsistently anyway, even within this file!
| let mut coverage = Coverage::default(); | ||
| if let Some(cmap) = ttf.tables().cmap { | ||
| for subtable in cmap.subtables { | ||
| if subtable.is_unicode() { | ||
| let mut subtable_coverage = | ||
| CoverageBuilder::with_capacity(coverage.0.len()); | ||
| subtable.codepoints(|c| { | ||
| // We expect codepoints in CMAP subtables to be already sorted | ||
| subtable_coverage.add_codepoint(c); | ||
| }); | ||
| coverage = coverage.union(&subtable_coverage.build()); | ||
| } | ||
| } | ||
| } | ||
| let coverage = | ||
| Coverage::from_vec(font.charmap().unicodes().map(|(c, _)| c).collect()); |
There was a problem hiding this comment.
#8676 very carefully optimized this to use the cmap table structure to reduce sorting overhead, by building coverage per subtable and then unioning. It would be very unfortunate to lose this optimization.
There was a problem hiding this comment.
Originally, I decided to just use font.charmap() for convenience. Then I found out that .charmap() is really only selecting a single subtable, and this is what the shaper actually uses (rustybuzz did this before, and harfrust does it too), so walking all the subtables to collect coverage is actually slightly incorrect.
So unioning isn't needed anymore. We can still reduce the sorting overhead though which I did in a commit, but with a fallback in case codepoints aren't sorted (I think this can come up, see https://docs.rs/read-fonts/latest/read_fonts/model/charmap/struct.Charmap.html, due to tables like DMAP for example).
| // TODO: Normalizing the stops into the 0..1 range moves the circles onto the | ||
| // first and last stop, which can make `r0` (and in theory `r1`) negative. | ||
| // SVG cannot express that, so the color line should be cut where the radius | ||
| // reaches zero, with an interpolated stop inserted at the cut and the | ||
| // remaining stops reparameterized into the 0..1 range. | ||
| self.svg.start_element("radialGradient"); | ||
| self.svg.write_attribute("id", &gradient_id); | ||
| self.svg.write_attribute("cx", &gradient.x1); | ||
| self.svg.write_attribute("cy", &gradient.y1); | ||
| self.svg.write_attribute("r", &gradient.r1); | ||
| self.svg.write_attribute("fr", &gradient.r0); | ||
| self.svg.write_attribute("fx", &gradient.x0); | ||
| self.svg.write_attribute("fy", &gradient.y0); | ||
| self.svg.write_attribute("cx", &c1.x); | ||
| self.svg.write_attribute("cy", &c1.y); | ||
| self.svg.write_attribute("r", &r1); | ||
| self.svg.write_attribute("fr", &r0); | ||
| self.svg.write_attribute("fx", &c0.x); | ||
| self.svg.write_attribute("fy", &c0.y); | ||
| self.svg.write_attribute("gradientUnits", &"userSpaceOnUse"); | ||
| self.write_spread_method_attribute(gradient.extend); | ||
| self.write_spread_method_attribute(extend); | ||
| self.write_transform_attribute("gradientTransform", gradient_transform); |
There was a problem hiding this comment.
I believe the code was originally written by @LaurenzV, so perhaps he can make sense of it?
I've done that.
I will add this soon.
And I will look into this. |
An attempt at doing this migration. Other PRs: typst/pixglyph#4.
The first (and only, atm) commit does the smallest change possible needed to replace
rustybuzzwithharfrust. The second commit will try to replace as much ofttf-parserwithread-fontsand/orskrifa(tbd).Note that we won't be able to get rid of
ttf-parsercompletely just yet, sinceread-fontslacks support for the MATH table (see googlefonts/fontations#1269).We may also want to wait for
resvgto be ported (see linebender/resvg#922).Performance/binary size analysis needs to be done.
Similar in spirit to these changes, we might want to investigate migrating to
fontiquefromfontdb(see the discussion in https://xi.zulipchat.com/#narrow/channel/465085-resvg/topic/Moving.20resvg.20to.20fontations.2Fharfrust/with/572344735).