WIP: Render glyphs using canvas#1
Draft
juancampa wants to merge 35 commits into
Draft
Conversation
…rper strokes Clippy pass Default to middle stroke to not break normal paths Add `round_to_pixel_center` Fix `Stroke` preview Fix indent lines Fix side/topbottom panels Fix window Fix separator Add rendering test Increase size of top bar and adjust a couple of margins Undo no-op change. Fix typo. Make crate-pub for now
This was causing gaze to show the text cursor when hovering the invisible text agent input box
The TitleBar was updated upstream but the issue is still there. I'll have to push a PR later. Changed here: emilk@8dc2ba2?w=1
Uses an OffscreenCanvas to render glyphs instead of the `ab_glyph`
rasterizer. It works but glyphs look unaligned, I think it's because we
don't use the canvas to _measure_ the glyphs and the metrics determined by
`ab_glyph` don't match the metrics used by the canvas (canvas bounding
boxes tend to be smaller, probably because grid alignment?)
Benefits:
- We can use OS native fonts that look nicer (i.e. `system-ui`, `SF
Mono`). We can't embed these due to licensing issues.
- Text shold look sharper since the OS rasterizer should use hints
and/or better align outlines to the pixel grid
- Smaller wasm files.
Future work:
- Use `OffscreenCanvasRenderingContext2D.measureText` to measure text.
Consider implementing the `ab_glyph::Font` trait in a struct that
uses wasm_bindgen calls behind the scenes.
- Test with system fonts
Limitations:
- Generally speaking, the texture atlas approach of rendering text is
limited by the fact that there's only one version of each glyph (one
bitmap), but looking at how the browser renders text, each instance
of e.g. the glyph "a", can rasterize to a slightly different bitmap,
when they land on different non-integer coordinates. Egui does align
each glyph to the pixel boundary in `text_layout.rs`
|
d045d8b to
8411e70
Compare
bd72681 to
f07ec28
Compare
73461b7 to
38199c8
Compare
a0b5855 to
3b6a09b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uses an OffscreenCanvas to render glyphs instead of the
ab_glyphrasterizer.Benefits:
system-ui,SF Mono). We can't embed these due to licensing issues.Future work:
OffscreenCanvasRenderingContext2D.measureTextto measure text. Consider implementing theab_glyph::Fonttrait in a struct that uses wasm_bindgen calls behind the scenes.Limitations:
text_layout.rsStatus of this PR:
It works but glyphs look unaligned, I think it's because we don't use the canvas to measure the glyphs and the metrics determined by
ab_glyphdon't match the metrics used by the canvas (canvas bounding boxes tend to be smaller, probably because grid alignment?)