From db96ecae94a7c06d04528e8d4461ebca86d2d249 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 30 Mar 2019 16:58:45 +0100 Subject: =?UTF-8?q?Move=20some=20types=20into=20better=20places=20?= =?UTF-8?q?=F0=9F=A7=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/font.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/font.rs') diff --git a/src/font.rs b/src/font.rs index 294c2b7e..37346a3e 100644 --- a/src/font.rs +++ b/src/font.rs @@ -1,6 +1,4 @@ -//! Font loading, utility and subsetting. - -#![macro_use] +//! Font loading and transforming. use std::collections::HashMap; use std::path::{Path, PathBuf}; @@ -9,7 +7,7 @@ use byteorder::{BE, ReadBytesExt, WriteBytesExt}; use opentype::{Error as OpentypeError, OpenTypeReader, Outlines, TableRecord, Tag}; use opentype::tables::{Header, Name, CharMap, MaximumProfile, HorizontalMetrics, Post, OS2}; use opentype::global::{MacStyleFlags, NameEntry}; -use crate::doc::{Size, FontFamily}; +use crate::engine::Size; /// An font wrapper which allows to subset a font. @@ -54,8 +52,8 @@ impl Font { /// Create a new font from a font program. pub fn new(program: Vec) -> FontResult { // Create opentype reader to parse font tables - let mut readable = Cursor::new(&program); - let mut reader = OpenTypeReader::new(&mut readable); + let cursor = Cursor::new(&program); + let mut reader = OpenTypeReader::new(cursor); // Read the relevant tables // (all of these are required by the OpenType specification) @@ -586,8 +584,6 @@ impl TakeInvalid for Option { } } -/////////////////////////////////////////////////////////////////////////////// - /// A type that provides fonts matching given criteria. pub trait FontProvider { /// Returns a font matching the configuration @@ -599,8 +595,18 @@ pub trait FontProvider { /// /// Automatically implemented for all types that are [`Read`] and [`Seek`]. pub trait FontSource: Read + Seek {} + impl FontSource for T where T: Read + Seek {} +/// A family of fonts (either generic or named). +#[derive(Debug, Clone, Eq, PartialEq)] +pub enum FontFamily { + SansSerif, + Serif, + Monospace, + Named(String), +} + /// Criteria to filter fonts. #[derive(Debug, Clone, PartialEq)] pub struct FontConfig { @@ -694,8 +700,8 @@ impl FileFontDescriptor<'_> { #[macro_export] macro_rules! file_font { ($family:expr, [$($generic:ident),*], $path:expr, $bold:expr, $italic:expr) => {{ - let mut families = vec![$crate::doc::FontFamily::Named($family.to_string())]; - families.extend([$($crate::doc::FontFamily::$generic),*].iter().cloned()); + let mut families = vec![$crate::font::FontFamily::Named($family.to_string())]; + families.extend([$($crate::font::FontFamily::$generic),*].iter().cloned()); $crate::font::FileFontDescriptor { path: std::path::Path::new($path), families, -- cgit v1.2.3