From 024481ac7bf6b966d333326351997ee30d4c557c Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:53:46 +0100 Subject: [PATCH] Remove the `glyph` module entirely - this code was unused --- examples/scenes/src/simple_text.rs | 6 +- vello/src/glyph.rs | 154 ----------------------------- vello/src/lib.rs | 4 +- 3 files changed, 3 insertions(+), 161 deletions(-) delete mode 100644 vello/src/glyph.rs diff --git a/examples/scenes/src/simple_text.rs b/examples/scenes/src/simple_text.rs index 8f2356965..be5b931e6 100644 --- a/examples/scenes/src/simple_text.rs +++ b/examples/scenes/src/simple_text.rs @@ -3,12 +3,10 @@ use std::sync::Arc; -use vello::glyph::Glyph; use vello::kurbo::Affine; use vello::peniko::{Blob, Brush, BrushRef, Color, Font, StyleRef}; -use vello::skrifa::raw::FontRef; -use vello::skrifa::MetadataProvider; -use vello::Scene; +use vello::skrifa::{raw::FontRef, MetadataProvider}; +use vello::{Glyph, Scene}; // This is very much a hack to get things working. // On Windows, can set this to "c:\\Windows\\Fonts\\seguiemj.ttf" to get color emoji diff --git a/vello/src/glyph.rs b/vello/src/glyph.rs deleted file mode 100644 index 8d8a3627f..000000000 --- a/vello/src/glyph.rs +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2022 the Vello Authors -// SPDX-License-Identifier: Apache-2.0 OR MIT - -//! Support for glyph rendering. - -use crate::scene::Scene; -use peniko::kurbo::Affine; -use peniko::{Brush, Color, Fill, Style}; -use skrifa::instance::{NormalizedCoord, Size}; -use skrifa::outline::OutlinePen; -use skrifa::raw::FontRef; -use skrifa::setting::Setting; -use skrifa::{GlyphId, OutlineGlyphCollection}; -use vello_encoding::Encoding; - -use peniko::kurbo::Shape; -pub use skrifa; -use skrifa::outline::DrawSettings; -use skrifa::MetadataProvider; -pub use vello_encoding::Glyph; - -/// General context for creating scene fragments for glyph outlines. -#[derive(Default)] -pub struct GlyphContext { - coords: Vec, -} - -impl GlyphContext { - /// Creates a new context. - pub fn new() -> Self { - Self::default() - } - - /// Creates a new provider for generating scene fragments for glyphs from - /// the specified font and settings. - pub fn new_provider<'a, V>( - &'a mut self, - font: &FontRef<'a>, - ppem: f32, - _hint: bool, - variations: V, - ) -> GlyphProvider<'a> - where - V: IntoIterator, - V::Item: Into>, - { - let outlines = font.outline_glyphs(); - let size = Size::new(ppem); - let axes = font.axes(); - let axis_count = axes.len(); - self.coords.clear(); - self.coords.resize(axis_count, Default::default()); - axes.location_to_slice(variations, &mut self.coords); - if self.coords.iter().all(|x| *x == NormalizedCoord::default()) { - self.coords.clear(); - } - GlyphProvider { - outlines, - size, - coords: &self.coords, - } - } -} - -/// Generator for scene fragments containing glyph outlines for a specific -/// font. -pub struct GlyphProvider<'a> { - outlines: OutlineGlyphCollection<'a>, - size: Size, - coords: &'a [NormalizedCoord], -} - -impl<'a> GlyphProvider<'a> { - /// Returns a scene fragment containing the commands to render the - /// specified glyph. - pub fn get(&mut self, gid: u16, brush: Option<&Brush>) -> Option { - let mut scene = Scene::new(); - let mut path = BezPathPen::default(); - let outline = self.outlines.get(GlyphId::new(gid))?; - let draw_settings = DrawSettings::unhinted(self.size, self.coords); - outline.draw(draw_settings, &mut path).ok()?; - scene.fill( - Fill::NonZero, - Affine::IDENTITY, - brush.unwrap_or(&Brush::Solid(Color::rgb8(255, 255, 255))), - None, - &path.0, - ); - Some(scene) - } - - pub fn encode_glyph(&mut self, gid: u16, style: &Style, encoding: &mut Encoding) -> Option<()> { - let fill = match style { - Style::Fill(fill) => *fill, - Style::Stroke(_) => Fill::NonZero, - }; - encoding.encode_fill_style(fill); - let mut path = encoding.encode_path(true); - let outline = self.outlines.get(GlyphId::new(gid))?; - let draw_settings = DrawSettings::unhinted(self.size, self.coords); - match style { - Style::Fill(_) => { - outline.draw(draw_settings, &mut path).ok()?; - } - Style::Stroke(stroke) => { - const STROKE_TOLERANCE: f64 = 0.01; - let mut pen = BezPathPen::default(); - outline.draw(draw_settings, &mut pen).ok()?; - let stroked = peniko::kurbo::stroke( - pen.0.path_elements(STROKE_TOLERANCE), - stroke, - &Default::default(), - STROKE_TOLERANCE, - ); - path.shape(&stroked); - } - } - if path.finish(false) != 0 { - Some(()) - } else { - None - } - } -} - -#[derive(Default)] -struct BezPathPen(peniko::kurbo::BezPath); - -impl OutlinePen for BezPathPen { - fn move_to(&mut self, x: f32, y: f32) { - self.0.move_to((x as f64, y as f64)); - } - - fn line_to(&mut self, x: f32, y: f32) { - self.0.line_to((x as f64, y as f64)); - } - - fn quad_to(&mut self, cx0: f32, cy0: f32, x: f32, y: f32) { - self.0 - .quad_to((cx0 as f64, cy0 as f64), (x as f64, y as f64)); - } - - fn curve_to(&mut self, cx0: f32, cy0: f32, cx1: f32, cy1: f32, x: f32, y: f32) { - self.0.curve_to( - (cx0 as f64, cy0 as f64), - (cx1 as f64, cy1 as f64), - (x as f64, y as f64), - ); - } - - fn close(&mut self) { - self.0.close_path(); - } -} diff --git a/vello/src/lib.rs b/vello/src/lib.rs index d8e7f1164..fc6dbd729 100644 --- a/vello/src/lib.rs +++ b/vello/src/lib.rs @@ -97,10 +97,8 @@ pub use peniko; /// 2D geometry, with a focus on curves. pub use peniko::kurbo; -#[doc(hidden)] pub use skrifa; - -pub mod glyph; +pub use vello_encoding::Glyph; #[cfg(feature = "wgpu")] pub use wgpu;