We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
How can I render a whole line of text into a colored bitmap?
I made some attempts, but encountered the following problems:
My render function is as follows
fn render_text(text: &str, font: &Font, font_size: f32) -> anyhow::Result<Canvas> { let mut chars = vec![]; for char in text.chars() { let glyph_id = match font.glyph_for_char(char) { Some(s) => s, None => Err(format!("No such char `{char}` in font `{}`", font.family_name()))?, }; let size = font.raster_bounds( glyph_id, font_size, Transform2F::from_translation(Vector2F::new(0.0, font_size)), HintingOptions::None, RasterizationOptions::SubpixelAa, )?; chars.push((glyph_id, size)); } let mut x = 0.0; let mut canvas = Canvas::new(Vector2I::new(font_size as i32), Format::A8); for (glyph_id, rect) in chars { font.rasterize_glyph( &mut canvas, glyph_id, font_size, Transform2F::from_translation(Vector2F::new(x, font_size)), HintingOptions::None, RasterizationOptions::SubpixelAa, )?; x += rect.size().x() as f32; } Ok(canvas) }
The text was updated successfully, but these errors were encountered:
https://github.com/servo/servo/blob/309c4f9b51a4a0c951da1b96a91fdef040b52e82/components/canvas/raqote_backend.rs#L521-L560 is the routine we use in servo.
Sorry, something went wrong.
No branches or pull requests
How can I render a whole line of text into a colored bitmap?
I made some attempts, but encountered the following problems:
My render function is as follows
The text was updated successfully, but these errors were encountered: