From f0480854a9cd76f443848dbfa14256089b56abfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 19 May 2020 20:30:46 +0200 Subject: [PATCH] Move built-in fonts to `iced_graphics` --- glow/Cargo.toml | 2 +- glow/src/backend.rs | 5 +++-- glow/src/text.rs | 14 ++------------ graphics/Cargo.toml | 2 ++ .../text/icons.ttf => graphics/fonts/Icons.ttf | Bin {wgpu => graphics}/fonts/Lato-Regular.ttf | Bin {wgpu => graphics}/fonts/OFL.txt | 0 graphics/src/font.rs | 12 ++++++++++++ wgpu/Cargo.toml | 2 +- wgpu/src/backend.rs | 5 +++-- wgpu/src/text.rs | 13 ++----------- wgpu/src/text/icons.ttf | Bin 4912 -> 0 bytes 12 files changed, 26 insertions(+), 29 deletions(-) rename glow/src/text/icons.ttf => graphics/fonts/Icons.ttf (100%) rename {wgpu => graphics}/fonts/Lato-Regular.ttf (100%) rename {wgpu => graphics}/fonts/OFL.txt (100%) delete mode 100644 wgpu/src/text/icons.ttf diff --git a/glow/Cargo.toml b/glow/Cargo.toml index 158e2bf0..72ed8758 100644 --- a/glow/Cargo.toml +++ b/glow/Cargo.toml @@ -23,7 +23,7 @@ path = "../native" [dependencies.iced_graphics] version = "0.1" path = "../graphics" -features = ["font-source"] +features = ["font-source", "font-fallback", "font-icons"] [dependencies.surfman] path = "../../surfman/surfman" diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 7293eba1..94683e56 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -3,6 +3,7 @@ use crate::text; use crate::triangle; use crate::{Quad, Settings, Transformation, Viewport}; use iced_graphics::backend; +use iced_graphics::font; use iced_graphics::Primitive; use iced_native::mouse; use iced_native::{Background, Font, Point, Rectangle, Size, Vector}; @@ -404,8 +405,8 @@ impl iced_graphics::Backend for Backend { } impl backend::Text for Backend { - const ICON_FONT: Font = text::BUILTIN_ICONS; - const CHECKMARK_ICON: char = text::CHECKMARK_ICON; + const ICON_FONT: Font = font::ICONS; + const CHECKMARK_ICON: char = font::CHECKMARK_ICON; fn measure( &self, diff --git a/glow/src/text.rs b/glow/src/text.rs index be88ceaf..952fd2cd 100644 --- a/glow/src/text.rs +++ b/glow/src/text.rs @@ -2,16 +2,6 @@ use crate::Transformation; use iced_graphics::font; use std::{cell::RefCell, collections::HashMap}; -pub const BUILTIN_ICONS: iced_native::Font = iced_native::Font::External { - name: "iced_glow icons", - bytes: include_bytes!("text/icons.ttf"), -}; - -pub const CHECKMARK_ICON: char = '\u{F00C}'; - -const FALLBACK_FONT: &[u8] = - include_bytes!("../../wgpu/fonts/Lato-Regular.ttf"); - #[derive(Debug)] pub struct Pipeline { draw_brush: RefCell>, @@ -29,7 +19,7 @@ impl Pipeline { default_font.map(|slice| slice.to_vec()).unwrap_or_else(|| { font_source .load(&[font::Family::SansSerif, font::Family::Serif]) - .unwrap_or_else(|_| FALLBACK_FONT.to_vec()) + .unwrap_or_else(|_| font::FALLBACK.to_vec()) }); let load_glyph_brush = |font: Vec| { @@ -48,7 +38,7 @@ impl Pipeline { .unwrap_or_else(|_: glow_glyph::rusttype::Error| { log::warn!("System font failed to load. Falling back to embedded font..."); - load_glyph_brush(FALLBACK_FONT.to_vec()).expect("Load fallback font") + load_glyph_brush(font::FALLBACK.to_vec()).expect("Load fallback font") }); let draw_brush = diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index c937763c..61f1f6d4 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -7,6 +7,8 @@ edition = "2018" [features] canvas = ["lyon"] font-source = ["font-kit"] +font-fallback = [] +font-icons = [] [dependencies] bytemuck = "1.2" diff --git a/glow/src/text/icons.ttf b/graphics/fonts/Icons.ttf similarity index 100% rename from glow/src/text/icons.ttf rename to graphics/fonts/Icons.ttf diff --git a/wgpu/fonts/Lato-Regular.ttf b/graphics/fonts/Lato-Regular.ttf similarity index 100% rename from wgpu/fonts/Lato-Regular.ttf rename to graphics/fonts/Lato-Regular.ttf diff --git a/wgpu/fonts/OFL.txt b/graphics/fonts/OFL.txt similarity index 100% rename from wgpu/fonts/OFL.txt rename to graphics/fonts/OFL.txt diff --git a/graphics/src/font.rs b/graphics/src/font.rs index 3890beba..a490e609 100644 --- a/graphics/src/font.rs +++ b/graphics/src/font.rs @@ -8,3 +8,15 @@ pub use source::Source; pub use font_kit::{ error::SelectionError as LoadError, family_name::FamilyName as Family, }; + +#[cfg(feature = "font-fallback")] +pub const FALLBACK: &[u8] = include_bytes!("../fonts/Lato-Regular.ttf"); + +#[cfg(feature = "font-icons")] +pub const ICONS: iced_native::Font = iced_native::Font::External { + name: "iced_wgpu icons", + bytes: include_bytes!("../fonts/Icons.ttf"), +}; + +#[cfg(feature = "font-icons")] +pub const CHECKMARK_ICON: char = '\u{F00C}'; diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index b59c7fa3..35ea9c31 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -32,7 +32,7 @@ path = "../native" [dependencies.iced_graphics] version = "0.1" path = "../graphics" -features = ["font-source"] +features = ["font-source", "font-fallback", "font-icons"] [dependencies.image] version = "0.23" diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index ba1a57a5..073a79e2 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -3,6 +3,7 @@ use crate::text; use crate::triangle; use crate::{Quad, Settings, Target, Transformation}; use iced_graphics::backend; +use iced_graphics::font; use iced_graphics::Primitive; use iced_native::mouse; use iced_native::{Background, Font, Point, Rectangle, Size, Vector}; @@ -456,8 +457,8 @@ impl iced_graphics::Backend for Backend { } impl backend::Text for Backend { - const ICON_FONT: Font = text::BUILTIN_ICONS; - const CHECKMARK_ICON: char = text::CHECKMARK_ICON; + const ICON_FONT: Font = font::ICONS; + const CHECKMARK_ICON: char = font::CHECKMARK_ICON; fn measure( &self, diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index ae9b6b22..c1782fe5 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -2,15 +2,6 @@ use crate::Transformation; use iced_graphics::font; use std::{cell::RefCell, collections::HashMap}; -pub const BUILTIN_ICONS: iced_native::Font = iced_native::Font::External { - name: "iced_wgpu icons", - bytes: include_bytes!("text/icons.ttf"), -}; - -pub const CHECKMARK_ICON: char = '\u{F00C}'; - -const FALLBACK_FONT: &[u8] = include_bytes!("../fonts/Lato-Regular.ttf"); - #[derive(Debug)] pub struct Pipeline { draw_brush: RefCell>, @@ -32,7 +23,7 @@ impl Pipeline { default_font.map(|slice| slice.to_vec()).unwrap_or_else(|| { font_source .load(&[font::Family::SansSerif, font::Family::Serif]) - .unwrap_or_else(|_| FALLBACK_FONT.to_vec()) + .unwrap_or_else(|_| font::FALLBACK.to_vec()) }); let load_glyph_brush = |font: Vec| { @@ -51,7 +42,7 @@ impl Pipeline { .unwrap_or_else(|_: wgpu_glyph::rusttype::Error| { log::warn!("System font failed to load. Falling back to embedded font..."); - load_glyph_brush(FALLBACK_FONT.to_vec()).expect("Load fallback font") + load_glyph_brush(font::FALLBACK.to_vec()).expect("Load fallback font") }); let draw_brush = brush_builder diff --git a/wgpu/src/text/icons.ttf b/wgpu/src/text/icons.ttf deleted file mode 100644 index 1c832f86576e51451b729a7fe513616dea38d21a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4912 zcmZQzWME+6XJ}wxW+-qE4s}xKR;^-SVEDtpz!2getZ(F|6WGkaz!<>5zz~+4n^^GC z*MKz`!8D zz`!oRz`($fo>Q52>C-+A1_ox3`htwq#1ygD0*@IOm^&C47|b#8 zFsNkYmQ=7`U|?WiV15G9pOc@Q$Y25HzhPitV9QOcC}3F4J&%Eb`3uPYyu{qpGjrt? z85meZ7#Nt&7UUO~6x1-XFfg!z^y?H9r4~GO)ZW9uAhd#kfuRlTcP<7420I2O7dM{} z2ELrck~{_}1{RPV3=Cj-WHw_?W_lt62ULcUfd#CRk%5DOk%0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