-
-
Notifications
You must be signed in to change notification settings - Fork 934
web: Render device fonts using offscreen canvas #22254
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
base: master
Are you sure you want to change the base?
Conversation
Values such as scale, ascent, descent, leading belong to the same category of font metrics, and conceptually it makes sense to represent them as one object, as they cannot be separated.
GlyphRef can both reference a &Glyph directly or a Ref<Glyph>, which is required to abstract away glyphs generated dynamically and cached. This is useful for e.g. rendering text on web using canvas.
This patch adds support for bitmap glyphs in addition to shape-based glyphs. Bitmap glyphs are useful for supporting device text rendered by the OS.
External font renderer provides/renders glyphs on demand, when core requests them. The logic of rendering glyphs can be external to core and is abstracted away so that frontends can provide their font renderers for device text.
CanvasFontRenderer is an implementation of a font renderer that can render glyphs using an offscreen canvas. This allows Ruffle to support device text properly on web.
Using this config option the user can select how device fonts should be rendered.
When DeviceFontRenderer::Canvas is set, no fonts will be set up, and instead CanvasFontRenderer will be used to render all device fonts.
| fn to_font_str(italic: bool, bold: bool, size: f64, font_family: &str) -> String { | ||
| let italic = if italic { "italic " } else { "" }; | ||
| let bold = if bold { "bold " } else { "" }; | ||
| format!("{italic}{bold}{size}px {font_family}") |
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 might missing quotes around the family?
|
Is it possible to switch to using the current text rendering if for the browser in use |
|
I think we can fall back to a regular canvas then. |
Implement device fonts support on web using canvas font renderer. Device fonts are rendered on canvas and then used as a bitmap in Ruffle.
This PR is divided roughly into 2 parts:
This solves the current issue of missing device fonts on web—Ruffle currently uses the default, embedded Noto Sans font and allows providing custom fonts as device fonts. When the "canvas" font renderer is enabled, glyphs are rendered on an offscreen canvas by the device, and stored in a bitmap.
This is currently experimental, as some things may not work properly or are missing, such as:
This is being put behind a setting
deviceFontRendererwith valuecanvas(instead of the defaultembedded).TODO: