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 zcmd^CU2I!P6+UyX?W9Q>nA@MRd1*udB^${dM2*d*~2nmo@z{9eFH`wx>@wMBu zDJ$(OH}#zFob%1hnKNhR-jX1qFug-2)pHjvrsbDM-iGDh_$|DC;qb()J@*A7k%xY% zwC2|TarC#pg8qH{>ZNN<8T#G*08!6V@XKm_X|45*cOB@HME&(8ccTt_1Ui1yyR>?v z`kN1a+Dl|IzrI{?%hA6@{sjFd^yAAg^h}u-q2GgkV0o>1z310JWd0dV?`o~&5=Msp zcQm0j_j;Xv(EnZN|Aa2r-L=XuzOye*6c{Elep#<=H0z%ih%d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