Skip to content

Commit

Permalink
Remove use of cfg_aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
tronical committed Mar 6, 2023
1 parent 590de07 commit 3ff2e61
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 38 deletions.
5 changes: 1 addition & 4 deletions internal/renderers/femtovg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ license = "GPL-3.0-only OR LicenseRef-Slint-commercial"
description = "FemtoVG based renderer for Slint"
repository = "https://github.com/slint-ui/slint"
homepage = "https://slint-ui.com"
build = "build.rs"
rust-version.workspace = true

[lib]
Expand All @@ -28,6 +27,7 @@ i-slint-common = { version = "=1.0.0", path = "../../../internal/common" }
const-field-offset = { version = "0.1", path = "../../../helper_crates/const-field-offset" }
vtable = { version = "0.1.6", path = "../../../helper_crates/vtable" }

cfg-if = "1"
derive_more = "0.99.5"
lyon_path = "1.0"
once_cell = "1.5"
Expand Down Expand Up @@ -61,6 +61,3 @@ wasm-bindgen = { version = "0.2" }
[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32")))'.dependencies]
libc = { version = "0.2" }
yeslogic-fontconfig-sys = { version = "3.2", optional = true }

[build-dependencies]
cfg_aliases = "0.1.0"
19 changes: 0 additions & 19 deletions internal/renderers/femtovg/build.rs

This file was deleted.

81 changes: 66 additions & 15 deletions internal/renderers/femtovg/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ use super::{PhysicalLength, PhysicalPoint, PhysicalSize};
pub const DEFAULT_FONT_SIZE: LogicalLength = LogicalLength::new(12.);
pub const DEFAULT_FONT_WEIGHT: i32 = 400; // CSS normal

#[cfg(use_fontconfig)]
#[cfg(all(
not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_arch = "wasm32"
)),
feature = "fontconfig"
))]
mod fontconfig;

/// This function can be used to register a custom TrueType font with Slint,
Expand Down Expand Up @@ -174,15 +182,31 @@ pub struct FontCache {
pub(crate) text_context: TextContext,
pub(crate) available_fonts: fontdb::Database,
available_families: HashSet<SharedString>,
#[cfg(use_fontconfig)]
#[cfg(all(
not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_arch = "wasm32"
)),
feature = "fontconfig"
))]
fontconfig_fallback_families: Vec<SharedString>,
}

impl Default for FontCache {
fn default() -> Self {
let mut font_db = fontdb::Database::new();

#[cfg(use_fontconfig)]
#[cfg(all(
not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_arch = "wasm32"
)),
feature = "fontconfig"
))]
let mut fontconfig_fallback_families;

#[cfg(not(feature = "diskfonts"))]
Expand All @@ -194,16 +218,27 @@ impl Default for FontCache {
#[cfg(feature = "diskfonts")]
{
font_db.load_system_fonts();
#[cfg(not(use_fontconfig))]
let default_sans_serif_family = "Arial";
#[cfg(use_fontconfig)]
let default_sans_serif_family = {
fontconfig_fallback_families = fontconfig::find_families("sans-serif")
.into_iter()
.map(|s| s.into())
.collect::<Vec<SharedString>>();
fontconfig_fallback_families.remove(0)
};
cfg_if::cfg_if! {
if #[cfg(all(
not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_arch = "wasm32"
)),
feature = "fontconfig"
))] {
let default_sans_serif_family = {
fontconfig_fallback_families = fontconfig::find_families("sans-serif")
.into_iter()
.map(|s| s.into())
.collect::<Vec<SharedString>>();
fontconfig_fallback_families.remove(0)
};
} else {
let default_sans_serif_family = "Arial";
}
}
font_db.set_sans_serif_family(default_sans_serif_family);
}
let available_families = font_db
Expand All @@ -220,7 +255,15 @@ impl Default for FontCache {
text_context: Default::default(),
available_fonts: font_db,
available_families,
#[cfg(use_fontconfig)]
#[cfg(all(
not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_arch = "wasm32"
)),
feature = "fontconfig"
))]
fontconfig_fallback_families,
}
}
Expand Down Expand Up @@ -479,7 +522,15 @@ impl FontCache {
fallback_fonts
}

#[cfg(use_fontconfig)]
#[cfg(all(
not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_arch = "wasm32"
)),
feature = "fontconfig"
))]
fn font_fallbacks_for_request(
&self,
_family: Option<&SharedString>,
Expand Down

0 comments on commit 3ff2e61

Please sign in to comment.