add CanvasRenderingContext2D::fill_layout – a method to draw layouts directly, without using skribo

This commit is contained in:
Sebastian Köln 2019-06-24 16:12:05 +03:00
parent 0012f09eeb
commit 2a129b7bbd
1 changed files with 13 additions and 3 deletions

View File

@ -102,6 +102,16 @@ impl CanvasRenderingContext2D {
TextMetrics { width: self.layout_text(string).width() } TextMetrics { width: self.layout_text(string).width() }
} }
pub fn fill_layout(&mut self, layout: &Layout, transform: Transform2DF) {
let paint_id = self.scene.push_paint(&self.current_state.fill_paint);
drop(self.scene.push_layout(&layout,
&TextStyle { size: self.current_state.font_size },
&transform.post_mul(&self.current_state.transform),
TextRenderMode::Fill,
HintingOptions::None,
paint_id));
}
fn fill_or_stroke_text(&mut self, fn fill_or_stroke_text(&mut self,
string: &str, string: &str,
mut position: Vector2F, mut position: Vector2F,
@ -127,7 +137,7 @@ impl CanvasRenderingContext2D {
paint_id)); paint_id));
} }
fn layout_text(&self, string: &str) -> Layout { pub fn layout_text(&self, string: &str) -> Layout {
skribo::layout(&TextStyle { size: self.current_state.font_size }, skribo::layout(&TextStyle { size: self.current_state.font_size },
&self.current_state.font_collection, &self.current_state.font_collection,
string) string)