mirror of
https://github.com/penpot/penpot.git
synced 2025-05-21 01:06:11 +02:00
✨ Add label to wasm renderer
This commit is contained in:
parent
0325d43e96
commit
8c310e6e5c
2 changed files with 23 additions and 1 deletions
|
@ -23,6 +23,9 @@ use options::RenderOptions;
|
||||||
pub use blend::BlendMode;
|
pub use blend::BlendMode;
|
||||||
pub use images::*;
|
pub use images::*;
|
||||||
|
|
||||||
|
const DEFAULT_FONT_BYTES: &[u8] =
|
||||||
|
include_bytes!("../../frontend/resources/fonts/RobotoMono-Regular.ttf");
|
||||||
|
|
||||||
pub(crate) struct RenderState {
|
pub(crate) struct RenderState {
|
||||||
gpu_state: GpuState,
|
gpu_state: GpuState,
|
||||||
options: RenderOptions,
|
options: RenderOptions,
|
||||||
|
@ -58,7 +61,7 @@ impl RenderState {
|
||||||
|
|
||||||
let mut font_provider = skia::textlayout::TypefaceFontProvider::new();
|
let mut font_provider = skia::textlayout::TypefaceFontProvider::new();
|
||||||
let default_font = skia::FontMgr::default()
|
let default_font = skia::FontMgr::default()
|
||||||
.new_from_data(include_bytes!("fonts/RobotoMono-Regular.ttf"), None)
|
.new_from_data(DEFAULT_FONT_BYTES, None)
|
||||||
.expect("Failed to load font");
|
.expect("Failed to load font");
|
||||||
font_provider.register_typeface(default_font, "robotomono-regular");
|
font_provider.register_typeface(default_font, "robotomono-regular");
|
||||||
|
|
||||||
|
@ -289,6 +292,8 @@ impl RenderState {
|
||||||
self.render_debug();
|
self.render_debug();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug::render_wasm_label(self);
|
||||||
|
|
||||||
self.flush();
|
self.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,23 @@ fn render_debug_view(render_state: &mut RenderState) {
|
||||||
.draw_rect(scaled_rect, &paint);
|
.draw_rect(scaled_rect, &paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn render_wasm_label(render_state: &mut RenderState) {
|
||||||
|
let canvas = render_state.final_surface.canvas();
|
||||||
|
|
||||||
|
let skia::ISize { width, height } = canvas.base_layer_size();
|
||||||
|
let p = skia::Point::new(width as f32 - 100.0, height as f32 - 25.0);
|
||||||
|
let mut paint = skia::Paint::default();
|
||||||
|
paint.set_color(skia::Color::from_argb(100, 0, 0, 0));
|
||||||
|
|
||||||
|
let font_provider = &render_state.font_provider;
|
||||||
|
let typeface = font_provider
|
||||||
|
.match_family_style("robotomono-regular", skia::FontStyle::default())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let font = skia::Font::new(typeface, 10.0);
|
||||||
|
canvas.draw_str("WASM RENDERER", p, &font, &paint);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render_debug_element(render_state: &mut RenderState, element: &Shape, intersected: bool) {
|
pub fn render_debug_element(render_state: &mut RenderState, element: &Shape, intersected: bool) {
|
||||||
let mut paint = skia::Paint::default();
|
let mut paint = skia::Paint::default();
|
||||||
paint.set_style(skia::PaintStyle::Stroke);
|
paint.set_style(skia::PaintStyle::Stroke);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue