Clean up the `text` module inside `canvas` a bit

This commit is contained in:
Patrick Walton 2020-03-30 21:32:30 -07:00
parent e864536b31
commit 6d6b5191bb
3 changed files with 28 additions and 31 deletions

View File

@ -26,24 +26,40 @@ use pathfinder_geometry::rect::RectF;
use pathfinder_geometry::transform2d::Transform2F; use pathfinder_geometry::transform2d::Transform2F;
use pathfinder_renderer::paint::{Paint, PaintId}; use pathfinder_renderer::paint::{Paint, PaintId};
use pathfinder_renderer::scene::{ClipPath, ClipPathId, DrawPath, RenderTarget, Scene}; use pathfinder_renderer::scene::{ClipPath, ClipPathId, DrawPath, RenderTarget, Scene};
use skribo::FontCollection;
use std::borrow::Cow; use std::borrow::Cow;
use std::default::Default; use std::default::Default;
use std::f32::consts::PI; use std::f32::consts::PI;
use std::fmt::{Debug, Error as FmtError, Formatter}; use std::fmt::{Debug, Error as FmtError, Formatter};
use std::mem; use std::mem;
use std::sync::Arc; use std::sync::Arc;
use text::FontCollection;
pub use text::CanvasFontContext;
#[cfg(feature = "pf-text")] #[cfg(feature = "pf-text")]
pub use text::TextMetrics; pub use text::TextMetrics;
pub use text::CanvasFontContext;
const HAIRLINE_STROKE_WIDTH: f32 = 0.0333; const HAIRLINE_STROKE_WIDTH: f32 = 0.0333;
const DEFAULT_FONT_SIZE: f32 = 10.0; const DEFAULT_FONT_SIZE: f32 = 10.0;
#[cfg_attr(not(feature = "pf-text"), path = "text_no_text.rs")] #[cfg(feature = "pf-text")]
mod 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)] #[cfg(test)]
mod tests; mod tests;

View File

@ -8,21 +8,21 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use pathfinder_geometry::vector::Vector2F; use crate::{CanvasRenderingContext2D, TextAlign};
use pathfinder_geometry::transform2d::Transform2F;
use pathfinder_renderer::paint::PaintId;
use std::sync::Arc;
use std::iter;
use font_kit::family_name::FamilyName; use font_kit::family_name::FamilyName;
use font_kit::handle::Handle; use font_kit::handle::Handle;
use font_kit::hinting::HintingOptions; use font_kit::hinting::HintingOptions;
use font_kit::loaders::default::Font;
use font_kit::properties::Properties; use font_kit::properties::Properties;
use font_kit::source::{Source, SystemSource}; use font_kit::source::{Source, SystemSource};
use font_kit::sources::mem::MemSource; 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}; use pathfinder_text::{SceneExt, TextRenderMode};
pub use font_kit::loaders::default::Font; use skribo::{FontCollection, FontFamily, Layout, TextStyle};
pub use crate::{CanvasRenderingContext2D, TextAlign}; use std::iter;
use std::sync::Arc;
impl CanvasRenderingContext2D { impl CanvasRenderingContext2D {
pub fn fill_text(&mut self, string: &str, position: Vector2F) { pub fn fill_text(&mut self, string: &str, position: Vector2F) {
@ -133,6 +133,7 @@ pub struct TextMetrics {
pub width: f32, pub width: f32,
} }
#[cfg(feature = "pf-text")]
#[derive(Clone)] #[derive(Clone)]
pub struct CanvasFontContext { pub struct CanvasFontContext {
#[allow(dead_code)] #[allow(dead_code)]

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;