-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement simple example using swash to render to png #54
Conversation
4ea250c
to
4cc54f5
Compare
We lost this in the switch to fontique. I can submit a small patch to fix it.
Probably not unless we’re just doing it for effect. Might be nice to add an option at some point.
Black on white without gamma correction is going to look “dirty”. Something simple like
These are the parameters for controlling interpolation in variable fonts. You should be able to feed the slice directly into |
Ah. Yes, it seems important!
Perhaps using these functions? https://observablehq.com/@toja/color-blending-with-gamma-correction. If I'm understanding correctly the correct process is:
I see. Does this also need to be plugged in with skrifa? |
See #56 for a patch that might get emoji working with this example |
We can do full sRGB if you'd like but I think just applying the power function to the alpha component will give us reasonably good results for the example.
It does. We use the |
The trouble I was having with apply I have implemented an attempt at sRGB <-> Linear RGB conversion. Not sure if I've done it correctly (it's interesting that you suggest applying the curve to the alpha channel as the solution I've ended up with applies it to everything but the alpha channel!) as the result isn't obviously better (but it's good enough that it looks plausibly correct to me). I've left both functions in the code for the time being if you want to inspect them. Naive: Gamma corrected:
Ah, gotcha. I'll have a look at plugging this in tomorrow. |
Assuming this is using system-ui on macOS, setting the normalized coordinates should also get you the requested bold on the first four characters since San Francisco is a variable font. |
Ah, that would be good. Bold was working with Helvetica, but it generally looked pretty bad with Helvetica so I switched it out. And I'd like to leave it on |
Pretty sure my gamma correction function is wrong as the serif font looks much better with the naive blending. |
Yeah, this is exceptionally tricky to get right. I’ll play with it later this evening. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that once the other (tiny-skia) lands, this will move to a crate as well?
Yes. Hoping to land the tiny-skia one (#55) first. Will update this one once we've settled on a design there. |
Hmm... the EDIT: I've update this PR to use |
@dfrg Hmm.. I've added this, but I still don't seem to get bold text. |
Was just working on this :) Found a bug in swash's avar table. Update to swash 0.1.16 should fix it. |
Overall, this is looking pretty good to me now. I'm happy to punt on the gamma issue, get the tiny-skia version landed and then merge this one after making the crate extraction changes. |
This example uses `skrifa` and `tiny-skia` rather than `swash` and `image` as in #54. ## Output ![tiny_skia_render](https://github.com/linebender/parley/assets/1007307/74cbf3b6-380c-4dff-91e4-976612982fac) ## Notes - This has the same issue as #54 around emoji rendering not working / being implemented - There is an issue with the centers of closed letter forms incorrectly being filled - The code for this is IMO much nicer than the swash version (at the cost of the heavier tiny-skia dependency) - This example does not have hinting enabled
examples/swash_render/src/main.rs
Outdated
} | ||
} | ||
} | ||
Content::SubpixelMask => unimplemented!(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dfrg What are the semantics of the SubpixelMask
? (/ how would one apply that to an RGBA image?). I reckon it would be good to demonstrate that even if we don't actually enable subpixel mode in the example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an rgba image with an alpha component per color channel (the alpha in the mask is ignored). This document (https://github.com/servo/webrender/blob/main/webrender/doc/text-rendering.md#subpixel-text-blending) has a good explanation of the math.
I've rebased this on top of latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a couple suggestions and some confusion about the code duplication.
This is basically working. But it could definitely do with some actual review and cleanup before merging.
Output
Notes
Emoji rendering is not workingConverting from aparley::Font
to aswash::FontRef
is very awkward, specifically when the font file is a collection. The ParleyFont
stores the index of the font within the collection, but Swash'sFontRef
expect the byte offset of the font within the collection. I could not find this exposed anywhere in parley/fontique/skrifa/read-fonts so I'm currently doing pointer arithmetic to get it.I'm currently writing to a file calledoutput.png
in the users current working directory. Possibly we could do better than that (some kind of gitignored "data" directory in the parley repo?)I've added an impl ofBrush
forpeniko::Color
, but possibly we ought to just blanket impl for all types implementing the requisite super traits?I'm not using theNormalizedCoords
as they always seemed to be empty in my example (what are they for?)