From 6d6b5191bbba1ad0d37718806bd9660b8d96fb34 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 30 Mar 2020 21:32:30 -0700 Subject: [PATCH] Clean up the `text` module inside `canvas` a bit --- canvas/src/lib.rs | 22 +++++++++++++++++++--- canvas/src/text.rs | 17 +++++++++-------- canvas/src/text_no_text.rs | 20 -------------------- 3 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 canvas/src/text_no_text.rs diff --git a/canvas/src/lib.rs b/canvas/src/lib.rs index f75946f0..9bda7bf4 100644 --- a/canvas/src/lib.rs +++ b/canvas/src/lib.rs @@ -26,24 +26,40 @@ use pathfinder_geometry::rect::RectF; use pathfinder_geometry::transform2d::Transform2F; use pathfinder_renderer::paint::{Paint, PaintId}; use pathfinder_renderer::scene::{ClipPath, ClipPathId, DrawPath, RenderTarget, Scene}; +use skribo::FontCollection; use std::borrow::Cow; use std::default::Default; use std::f32::consts::PI; use std::fmt::{Debug, Error as FmtError, Formatter}; use std::mem; use std::sync::Arc; -use text::FontCollection; + +pub use text::CanvasFontContext; #[cfg(feature = "pf-text")] pub use text::TextMetrics; -pub use text::CanvasFontContext; const HAIRLINE_STROKE_WIDTH: f32 = 0.0333; const DEFAULT_FONT_SIZE: f32 = 10.0; -#[cfg_attr(not(feature = "pf-text"), path = "text_no_text.rs")] +#[cfg(feature = "pf-text")] mod text; +// For users who don't want text capability, include a tiny convenience stub. +#[cfg(not(feature = "pf-text"))] +mod text { + #[derive(Clone)] + pub struct CanvasFontContext; + + impl CanvasFontContext { + pub fn from_system_source() -> Self { + CanvasFontContext + } + } + + pub struct FontCollection; +} + #[cfg(test)] mod tests; diff --git a/canvas/src/text.rs b/canvas/src/text.rs index b11f3eb9..7e65eaf9 100644 --- a/canvas/src/text.rs +++ b/canvas/src/text.rs @@ -8,21 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use pathfinder_geometry::vector::Vector2F; -use pathfinder_geometry::transform2d::Transform2F; -use pathfinder_renderer::paint::PaintId; -use std::sync::Arc; -use std::iter; +use crate::{CanvasRenderingContext2D, TextAlign}; use font_kit::family_name::FamilyName; use font_kit::handle::Handle; use font_kit::hinting::HintingOptions; +use font_kit::loaders::default::Font; use font_kit::properties::Properties; use font_kit::source::{Source, SystemSource}; use font_kit::sources::mem::MemSource; -pub use skribo::{FontCollection, FontFamily, Layout, TextStyle}; +use pathfinder_geometry::transform2d::Transform2F; +use pathfinder_geometry::vector::Vector2F; +use pathfinder_renderer::paint::PaintId; use pathfinder_text::{SceneExt, TextRenderMode}; -pub use font_kit::loaders::default::Font; -pub use crate::{CanvasRenderingContext2D, TextAlign}; +use skribo::{FontCollection, FontFamily, Layout, TextStyle}; +use std::iter; +use std::sync::Arc; impl CanvasRenderingContext2D { pub fn fill_text(&mut self, string: &str, position: Vector2F) { @@ -133,6 +133,7 @@ pub struct TextMetrics { pub width: f32, } +#[cfg(feature = "pf-text")] #[derive(Clone)] pub struct CanvasFontContext { #[allow(dead_code)] diff --git a/canvas/src/text_no_text.rs b/canvas/src/text_no_text.rs deleted file mode 100644 index 45c25a76..00000000 --- a/canvas/src/text_no_text.rs +++ /dev/null @@ -1,20 +0,0 @@ -// pathfinder/canvas/src/text_no_text.rs -// -// Copyright © 2019 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[derive(Clone)] -pub struct CanvasFontContext; - -impl CanvasFontContext { - pub fn from_system_source() -> Self { - CanvasFontContext - } -} - -pub struct FontCollection;