From ea2ed93b0e8727d14127b5d0939c2c4ee0305f08 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 6 Oct 2025 17:18:15 +0200 Subject: [PATCH] parley: Upgrade to parley and fontique 0.6 --- Cargo.toml | 2 +- internal/backends/qt/qt_window.rs | 9 +++------ internal/core/Cargo.toml | 2 +- internal/core/textlayout/sharedparley.rs | 18 +++++++++--------- internal/renderers/femtovg/font_cache.rs | 2 +- internal/renderers/femtovg/itemrenderer.rs | 4 ++-- internal/renderers/skia/font_cache.rs | 2 +- internal/renderers/skia/itemrenderer.rs | 2 +- 8 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 44ef3cb2797..2ead2bc0cf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -173,7 +173,7 @@ wgpu-26 = { package = "wgpu", version = "26", default-features = false } wgpu-27 = { package = "wgpu", version = "27", default-features = false } input = { version = "0.9.0", default-features = false } tr = { version = "0.1", default-features = false } -fontique = { version = "0.5.0" } +fontique = { version = "0.6.0" } [profile.release] lto = true diff --git a/internal/backends/qt/qt_window.rs b/internal/backends/qt/qt_window.rs index 550757a6841..c7a90990adc 100644 --- a/internal/backends/qt/qt_window.rs +++ b/internal/backends/qt/qt_window.rs @@ -1065,7 +1065,7 @@ impl GlyphRenderer for QtItemRenderer<'_> { fn draw_glyph_run( &mut self, - font: &sharedparley::parley::Font, + font: &sharedparley::parley::FontData, font_size: f32, brush: Self::PlatformBrush, y_offset: sharedparley::PhysicalLength, @@ -1080,10 +1080,7 @@ impl GlyphRenderer for QtItemRenderer<'_> { let (glyph_indices, positions): (Vec, Vec) = glyphs_it .into_iter() .map(|g| { - ( - g.id as u32, - qttypes::QPointF { x: g.x as f64, y: g.y as f64 + y_offset.get() as f64 }, - ) + (g.id, qttypes::QPointF { x: g.x as f64, y: g.y as f64 + y_offset.get() as f64 }) }) .unzip(); @@ -1180,7 +1177,7 @@ impl Default for FontCache { } impl FontCache { - pub fn font(&mut self, font: &parley::Font) -> Option { + pub fn font(&mut self, font: &parley::FontData) -> Option { self.fonts .entry((font.data.id(), font.index)) .or_insert_with(move || { diff --git a/internal/core/Cargo.toml b/internal/core/Cargo.toml index a74774bdf35..7b043e5698e 100644 --- a/internal/core/Cargo.toml +++ b/internal/core/Cargo.toml @@ -105,7 +105,7 @@ unicode-script = { version = "0.5.7", optional = true } integer-sqrt = { version = "0.1.5" } bytemuck = { workspace = true, optional = true, features = ["derive"] } sys-locale = { version = "0.3.2", optional = true } -parley = { version = "0.5.0", optional = true } +parley = { version = "0.6.0", optional = true } image = { workspace = true, optional = true, default-features = false } clru = { workspace = true, optional = true } diff --git a/internal/core/textlayout/sharedparley.rs b/internal/core/textlayout/sharedparley.rs index 5ddccccbc7a..b899b46a7b1 100644 --- a/internal/core/textlayout/sharedparley.rs +++ b/internal/core/textlayout/sharedparley.rs @@ -52,7 +52,7 @@ pub trait GlyphRenderer: crate::item_rendering::ItemRenderer { /// given y offset. fn draw_glyph_run( &mut self, - font: &parley::Font, + font: &parley::FontData, font_size: f32, brush: Self::PlatformBrush, y_offset: PhysicalLength, @@ -238,7 +238,7 @@ fn layout(text: &str, scale_factor: ScaleFactor, options: LayoutOptions) -> Layo max_physical_width.map(|width| width.get()), match options.horizontal_align { TextHorizontalAlignment::Left => parley::Alignment::Left, - TextHorizontalAlignment::Center => parley::Alignment::Middle, + TextHorizontalAlignment::Center => parley::Alignment::Center, TextHorizontalAlignment::Right => parley::Alignment::Right, }, parley::AlignmentOptions::default(), @@ -315,7 +315,7 @@ impl Layout { default_stroke_brush: Option<::PlatformBrush>, draw_glyphs: &mut dyn FnMut( &mut R, - &parley::Font, + &parley::FontData, f32, ::PlatformBrush, &mut dyn Iterator, @@ -547,8 +547,8 @@ pub fn draw_text_input( item_renderer.fill_rectangle( PhysicalRect::new( PhysicalPoint::from_lengths( - PhysicalLength::new(rect.min_x() as _), - PhysicalLength::new(rect.min_y() as _) + layout.y_offset, + PhysicalLength::new(rect.x0 as _), + PhysicalLength::new(rect.y0 as _) + layout.y_offset, ), PhysicalSize::new(rect.width() as _, rect.height() as _), ), @@ -577,8 +577,8 @@ pub fn draw_text_input( item_renderer.fill_rectangle( PhysicalRect::new( PhysicalPoint::from_lengths( - PhysicalLength::new(rect.min_x() as _), - PhysicalLength::new(rect.min_y() as _) + layout.y_offset, + PhysicalLength::new(rect.x0 as _), + PhysicalLength::new(rect.y0 as _) + layout.y_offset, ), PhysicalSize::new(rect.width() as _, rect.height() as _), ), @@ -691,8 +691,8 @@ pub fn text_input_cursor_rect_for_byte_offset( let rect = cursor.geometry(&layout.inner, (text_input.text_cursor_width()).get()); PhysicalRect::new( PhysicalPoint::from_lengths( - PhysicalLength::new(rect.min_x() as _), - PhysicalLength::new(rect.min_y() as _) + layout.y_offset, + PhysicalLength::new(rect.x0 as _), + PhysicalLength::new(rect.y0 as _) + layout.y_offset, ), PhysicalSize::new(rect.width() as _, rect.height() as _), ) / scale_factor diff --git a/internal/renderers/femtovg/font_cache.rs b/internal/renderers/femtovg/font_cache.rs index 3596c8b40b7..ee6b078d77a 100644 --- a/internal/renderers/femtovg/font_cache.rs +++ b/internal/renderers/femtovg/font_cache.rs @@ -25,7 +25,7 @@ impl Default for FontCache { } impl FontCache { - pub fn font(&mut self, font: &parley::Font) -> femtovg::FontId { + pub fn font(&mut self, font: &parley::FontData) -> femtovg::FontId { let text_context = self.text_context.clone(); *self.fonts.entry((font.data.id(), font.index)).or_insert_with(move || { diff --git a/internal/renderers/femtovg/itemrenderer.rs b/internal/renderers/femtovg/itemrenderer.rs index 1c50cbf180a..e64a418134f 100644 --- a/internal/renderers/femtovg/itemrenderer.rs +++ b/internal/renderers/femtovg/itemrenderer.rs @@ -960,7 +960,7 @@ impl<'a, R: femtovg::Renderer + TextureImporter> GlyphRenderer for GLItemRendere fn draw_glyph_run( &mut self, - font: &parley::Font, + font: &parley::FontData, font_size: f32, mut brush: Self::PlatformBrush, y_offset: sharedparley::PhysicalLength, @@ -971,7 +971,7 @@ impl<'a, R: femtovg::Renderer + TextureImporter> GlyphRenderer for GLItemRendere let glyphs_it = glyphs_it.map(|glyph| femtovg::PositionedGlyph { x: glyph.x, y: glyph.y + y_offset.get(), - glyph_id: glyph.id, + glyph_id: glyph.id as u16, }); let mut canvas = self.canvas.borrow_mut(); diff --git a/internal/renderers/skia/font_cache.rs b/internal/renderers/skia/font_cache.rs index c6f6ab2948c..407811115ed 100644 --- a/internal/renderers/skia/font_cache.rs +++ b/internal/renderers/skia/font_cache.rs @@ -17,7 +17,7 @@ impl Default for FontCache { } impl FontCache { - pub fn font(&mut self, font: &parley::Font) -> Option { + pub fn font(&mut self, font: &parley::FontData) -> Option { self.fonts .entry((font.data.id(), font.index)) .or_insert_with(|| { diff --git a/internal/renderers/skia/itemrenderer.rs b/internal/renderers/skia/itemrenderer.rs index 69715e68d20..dc552b89d9a 100644 --- a/internal/renderers/skia/itemrenderer.rs +++ b/internal/renderers/skia/itemrenderer.rs @@ -959,7 +959,7 @@ impl GlyphRenderer for SkiaItemRenderer<'_> { fn draw_glyph_run( &mut self, - font: &sharedparley::parley::Font, + font: &sharedparley::parley::FontData, font_size: f32, brush: Self::PlatformBrush, y_offset: sharedparley::PhysicalLength,