Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/58/feature gate font kit #370

Merged
merged 2 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `"system_font"` feature gates reading system fonts. [#370]

[#370]: https://github.com/hecrj/iced/pull/370

## [0.1.1] - 2020-04-15
### Added
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"]

[features]
default = ["wgpu"]
default = ["wgpu", "default_system_font"]
# Enables the `iced_wgpu` renderer
wgpu = ["iced_wgpu"]
# Enables the `Image` widget
Expand All @@ -21,10 +21,14 @@ image = ["iced_wgpu/image"]
svg = ["iced_wgpu/svg"]
# Enables the `Canvas` widget
canvas = ["iced_wgpu/canvas"]
# Enables using system fonts.
default_system_font = ["iced_wgpu/default_system_font"]
# Enables the `iced_glow` renderer. Overrides `iced_wgpu`
glow = ["iced_glow", "iced_glutin"]
# Enables the `Canvas` widget for `iced_glow`
glow_canvas = ["iced_glow/canvas"]
# Enables using system fonts for `iced_glow`.
glow_default_system_font = ["iced_glow/default_system_font"]
# Enables a debug view in native platforms (press F12)
debug = ["iced_winit/debug"]
# Enables `tokio` as the `executor::Default` on native platforms
Expand Down
3 changes: 2 additions & 1 deletion glow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/hecrj/iced"

[features]
canvas = ["iced_graphics/canvas"]
default_system_font = ["iced_graphics/font-source"]
# Not supported yet!
image = []
svg = []
Expand All @@ -29,7 +30,7 @@ path = "../native"
[dependencies.iced_graphics]
version = "0.1"
path = "../graphics"
features = ["font-source", "font-fallback", "font-icons", "opengl"]
features = ["font-fallback", "font-icons", "opengl"]

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
Expand Down
17 changes: 11 additions & 6 deletions glow/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ pub struct Pipeline {

impl Pipeline {
pub fn new(gl: &glow::Context, default_font: Option<&[u8]>) -> Self {
let default_font = default_font.map(|slice| slice.to_vec());

// TODO: Font customization
let font_source = font::Source::new();
#[cfg(feature = "default_system_font")]
let default_font = {
default_font.or_else(|| {
font::Source::new()
.load(&[font::Family::SansSerif, font::Family::Serif])
.ok()
})
};

let default_font =
default_font.map(|slice| slice.to_vec()).unwrap_or_else(|| {
font_source
.load(&[font::Family::SansSerif, font::Family::Serif])
.unwrap_or_else(|_| font::FALLBACK.to_vec())
});
default_font.unwrap_or_else(|| font::FALLBACK.to_vec());

let font = ab_glyph::FontArc::try_from_vec(default_font)
.unwrap_or_else(|_| {
Expand Down
3 changes: 2 additions & 1 deletion wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository = "https://github.com/hecrj/iced"
[features]
svg = ["resvg"]
canvas = ["iced_graphics/canvas"]
default_system_font = ["iced_graphics/font-source"]

[dependencies]
wgpu = "0.5"
Expand All @@ -32,7 +33,7 @@ path = "../native"
[dependencies.iced_graphics]
version = "0.1"
path = "../graphics"
features = ["font-source", "font-fallback", "font-icons"]
features = ["font-fallback", "font-icons"]

[dependencies.image]
version = "0.23"
Expand Down
17 changes: 11 additions & 6 deletions wgpu/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ impl Pipeline {
format: wgpu::TextureFormat,
default_font: Option<&[u8]>,
) -> Self {
let default_font = default_font.map(|slice| slice.to_vec());

// TODO: Font customization
let font_source = font::Source::new();
#[cfg(feature = "default_system_font")]
let default_font = {
default_font.or_else(|| {
font::Source::new()
.load(&[font::Family::SansSerif, font::Family::Serif])
.ok()
})
};

let default_font =
default_font.map(|slice| slice.to_vec()).unwrap_or_else(|| {
font_source
.load(&[font::Family::SansSerif, font::Family::Serif])
.unwrap_or_else(|_| font::FALLBACK.to_vec())
});
default_font.unwrap_or_else(|| font::FALLBACK.to_vec());

let font = ab_glyph::FontArc::try_from_vec(default_font)
.unwrap_or_else(|_| {
Expand Down