From 33c68d38b9effbbf792100463e63a2bef67786e6 Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Tue, 4 Feb 2020 21:13:04 -0800 Subject: [PATCH] support undercurl --- src/renderer/caching_shaper.rs | 2 +- src/renderer/mod.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/renderer/caching_shaper.rs b/src/renderer/caching_shaper.rs index a8c25a7..58f5f8c 100644 --- a/src/renderer/caching_shaper.rs +++ b/src/renderer/caching_shaper.rs @@ -29,7 +29,7 @@ const SYSTEM_EMOJI_FONT: &str = "Noto Color Emoji"; #[folder = "assets/fonts/"] struct Asset; -const DEFAULT_FONT_SIZE: f32 = 14.0; +const DEFAULT_FONT_SIZE: f32 = 24.0; #[derive(new, Clone, Hash, PartialEq, Eq, Debug)] struct ShapeKey { diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 6c80b76..db3fda0 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use skulpin::CoordinateSystemHelper; -use skulpin::skia_safe::{Canvas, Paint, Surface, Budgeted, Rect, colors}; +use skulpin::skia_safe::{Canvas, Paint, Surface, Budgeted, Rect, colors, dash_path_effect}; use skulpin::skia_safe::gpu::SurfaceOrigin; use log::trace; @@ -77,7 +77,16 @@ impl Renderer { if style.underline || style.undercurl { let line_position = self.shaper.underline_position(); + let stroke_width = self.shaper.base_size / 10.0; self.paint.set_color(style.special(&default_style.colors).to_color()); + self.paint.set_stroke_width(stroke_width); + + if style.undercurl { + self.paint.set_path_effect(dash_path_effect::new(&[stroke_width * 2.0, stroke_width * 2.0], 0.0)); + } else { + self.paint.set_path_effect(None); + } + canvas.draw_line((x, y - line_position + self.font_height), (x + width, y - line_position + self.font_height), &self.paint); }