From 1318d0e461064eb38a7dbef89b835185b73b89a9 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 11 Nov 2019 14:55:44 -0800 Subject: [PATCH] Added ios support. --- Cargo.toml | 6 +++--- src/loaders/mod.rs | 11 +++++++---- src/source.rs | 26 +++++++++++++++----------- src/sources/mod.rs | 9 +++++++-- src/test.rs | 20 ++++++++++---------- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6199d82..925f6a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,15 +46,15 @@ dwrote = { version = "0.9", default-features = false } version = "0.3" features = ["minwindef", "winbase"] -[target.'cfg(target_os = "macos")'.dependencies] +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] core-foundation = "0.6" core-graphics = "^0.17.1" core-text = "13.2" -[target.'cfg(not(any(target_family = "windows", target_os = "macos")))'.dependencies] +[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))'.dependencies] freetype = "^0.4.1" -[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_arch = "wasm32")))'.dependencies] +[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32")))'.dependencies] servo-fontconfig = "0.4" [target.'cfg(not(any(target_arch = "wasm32", target_family = "windows", target_os = "android")))'.dependencies] diff --git a/src/loaders/mod.rs b/src/loaders/mod.rs index 504a08d..b455546 100644 --- a/src/loaders/mod.rs +++ b/src/loaders/mod.rs @@ -10,26 +10,29 @@ //! The different system services that can load and rasterize fonts. -#[cfg(all(target_os = "macos", not(feature = "loader-freetype-default")))] +#[cfg(all( + any(target_os = "macos", target_os = "ios"), + not(feature = "loader-freetype-default") +))] pub use crate::loaders::core_text as default; #[cfg(all(target_family = "windows", not(feature = "loader-freetype-default")))] pub use crate::loaders::directwrite as default; #[cfg(any( - not(any(target_os = "macos", target_family = "windows")), + not(any(target_os = "macos", target_os = "ios", target_family = "windows")), feature = "loader-freetype-default" ))] pub use crate::loaders::freetype as default; -#[cfg(all(target_os = "macos"))] +#[cfg(any(target_os = "macos", target_os = "ios"))] pub mod core_text; #[cfg(all(target_family = "windows"))] pub mod directwrite; #[cfg(any( - not(any(target_os = "macos", target_family = "windows")), + not(any(target_os = "macos", target_os = "ios", target_family = "windows")), feature = "loader-freetype" ))] pub mod freetype; diff --git a/src/source.rs b/src/source.rs index 27f3c6a..dae9ded 100644 --- a/src/source.rs +++ b/src/source.rs @@ -19,7 +19,10 @@ use crate::handle::Handle; use crate::matching; use crate::properties::Properties; -#[cfg(all(target_os = "macos", not(feature = "source-fontconfig-default")))] +#[cfg(all( + any(target_os = "macos", target_os = "ios"), + not(feature = "loader-freetype-default") +))] pub use crate::sources::core_text::CoreTextSource as SystemSource; #[cfg(all(target_family = "windows", not(feature = "source-fontconfig-default")))] pub use crate::sources::directwrite::DirectWriteSource as SystemSource; @@ -27,6 +30,7 @@ pub use crate::sources::directwrite::DirectWriteSource as SystemSource; not(any( target_os = "android", target_os = "macos", + target_os = "ios", target_family = "windows", target_arch = "wasm32" )), @@ -37,28 +41,28 @@ pub use crate::sources::fontconfig::FontconfigSource as SystemSource; pub use crate::sources::fs::FsSource as SystemSource; // FIXME(pcwalton): These could expand to multiple fonts, and they could be language-specific. -#[cfg(any(target_family = "windows", target_os = "macos"))] +#[cfg(any(target_family = "windows", target_os = "macos", target_os = "ios"))] const DEFAULT_FONT_FAMILY_SERIF: &'static str = "Times New Roman"; -#[cfg(any(target_family = "windows", target_os = "macos"))] +#[cfg(any(target_family = "windows", target_os = "macos", target_os = "ios"))] const DEFAULT_FONT_FAMILY_SANS_SERIF: &'static str = "Arial"; -#[cfg(any(target_family = "windows", target_os = "macos"))] +#[cfg(any(target_family = "windows", target_os = "macos", target_os = "ios"))] const DEFAULT_FONT_FAMILY_MONOSPACE: &'static str = "Courier New"; -#[cfg(any(target_family = "windows", target_os = "macos"))] +#[cfg(any(target_family = "windows", target_os = "macos", target_os = "ios"))] const DEFAULT_FONT_FAMILY_CURSIVE: &'static str = "Comic Sans MS"; #[cfg(target_family = "windows")] const DEFAULT_FONT_FAMILY_FANTASY: &'static str = "Impact"; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] const DEFAULT_FONT_FAMILY_FANTASY: &'static str = "Papyrus"; -#[cfg(not(any(target_family = "windows", target_os = "macos")))] +#[cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))] const DEFAULT_FONT_FAMILY_SERIF: &'static str = "serif"; -#[cfg(not(any(target_family = "windows", target_os = "macos")))] +#[cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))] const DEFAULT_FONT_FAMILY_SANS_SERIF: &'static str = "sans-serif"; -#[cfg(not(any(target_family = "windows", target_os = "macos")))] +#[cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))] const DEFAULT_FONT_FAMILY_MONOSPACE: &'static str = "monospace"; -#[cfg(not(any(target_family = "windows", target_os = "macos")))] +#[cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))] const DEFAULT_FONT_FAMILY_CURSIVE: &'static str = "cursive"; -#[cfg(not(any(target_family = "windows", target_os = "macos")))] +#[cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))] const DEFAULT_FONT_FAMILY_FANTASY: &'static str = "fantasy"; /// A database of installed fonts that can be queried. diff --git a/src/sources/mod.rs b/src/sources/mod.rs index 7431596..a6fb97b 100644 --- a/src/sources/mod.rs +++ b/src/sources/mod.rs @@ -14,14 +14,19 @@ //! installed on the system. The remaining databases (`fs`, `mem`, and `multi`) allow `font-kit` to //! query fonts not installed on the system. -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] pub mod core_text; #[cfg(target_family = "windows")] pub mod directwrite; #[cfg(any( - not(any(target_os = "macos", target_family = "windows", target_arch = "wasm32")), + not(any( + target_os = "macos", + target_os = "ios", + target_family = "windows", + target_arch = "wasm32" + )), feature = "source-fontconfig" ))] pub mod fontconfig; diff --git a/src/test.rs b/src/test.rs index ce9ca72..3f86143 100644 --- a/src/test.rs +++ b/src/test.rs @@ -161,7 +161,7 @@ pub fn get_glyph_outline() { assert_close!(events.next()); } -#[cfg(not(any(target_family = "windows", target_os = "macos")))] +#[cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))] #[test] pub fn get_glyph_outline() { let mut path_builder = Path::builder(); @@ -196,7 +196,7 @@ pub fn get_glyph_outline() { // Right now, only FreeType can do hinting. #[cfg(all( - not(any(target_os = "macos", target_family = "windows")), + not(any(target_os = "macos", target_os = "ios", target_family = "windows")), feature = "loader-freetype-default" ))] #[test] @@ -228,7 +228,7 @@ pub fn get_vertically_hinted_glyph_outline() { assert_close!(events.next()); } -#[cfg(not(any(target_os = "macos", target_family = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_family = "windows")))] #[test] pub fn get_vertically_hinted_glyph_outline() { let mut path_builder = Path::builder(); @@ -263,7 +263,7 @@ pub fn get_vertically_hinted_glyph_outline() { // Right now, only FreeType can do hinting. #[cfg(all( - not(any(target_os = "macos", target_family = "windows")), + not(any(target_os = "macos", target_os = "ios", target_family = "windows")), feature = "loader-freetype-default" ))] #[test] @@ -298,7 +298,7 @@ pub fn get_fully_hinted_glyph_outline() { assert_close!(events.next()); } -#[cfg(not(any(target_os = "macos", target_family = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_family = "windows")))] #[test] pub fn get_fully_hinted_glyph_outline() { let mut path_builder = Path::builder(); @@ -345,7 +345,7 @@ pub fn get_empty_glyph_outline() { assert_eq!(events.next(), None); } -#[cfg(any(target_family = "windows", target_os = "macos"))] +#[cfg(any(target_family = "windows", target_os = "macos", target_os = "ios"))] #[test] pub fn get_glyph_typographic_bounds() { let font = SystemSource::new() @@ -363,7 +363,7 @@ pub fn get_glyph_typographic_bounds() { ); } -#[cfg(not(any(target_family = "windows", target_os = "macos")))] +#[cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))] #[test] pub fn get_glyph_typographic_bounds() { let font = SystemSource::new() @@ -407,7 +407,7 @@ pub fn get_glyph_advance_and_origin() { assert_eq!(font.origin(glyph), Ok(Point2D::zero())); } -#[cfg(not(any(target_family = "windows", target_os = "macos")))] +#[cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))] #[test] pub fn get_glyph_advance_and_origin() { let font = SystemSource::new() @@ -439,7 +439,7 @@ pub fn get_font_metrics() { assert_eq!(metrics.x_height, 1062.0); } -#[cfg(not(any(target_family = "windows", target_os = "macos")))] +#[cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios")))] #[test] pub fn get_font_metrics() { let font = SystemSource::new() @@ -564,7 +564,7 @@ pub fn rasterize_glyph_bilevel() { } #[cfg(any( - not(any(target_os = "macos", target_family = "windows")), + not(any(target_os = "macos", target_os = "ios", target_family = "windows")), feature = "loader-freetype-default" ))] #[test]