Skip to content

Commit

Permalink
fontconfig: Add more stretch conversions, note provenance (#210)
Browse files Browse the repository at this point in the history
This adds more of the defined stretch constants that Fontconfig has and
notes the provenance of the constants as having come from Fontconfig
documentation.
  • Loading branch information
waywardmonkeys authored Dec 8, 2024
1 parent b5f16e9 commit 4fc2a6d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion fontique/src/backend/fontconfig/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,33 @@ use std::io::Read;
use std::path::PathBuf;

impl Stretch {
fn from_fc(width: i32) -> Self {
/// Creates a new stretch attribute with the given value from Fontconfig.
///
/// The values are determined based on the [fonts.conf documentation].
///
/// [fonts.conf documentation]: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
pub fn from_fc(width: i32) -> Self {
match width {
50 => Self::ULTRA_CONDENSED,
63 => Self::EXTRA_CONDENSED,
75 => Self::CONDENSED,
87 => Self::SEMI_CONDENSED,
100 => Self::NORMAL,
113 => Self::SEMI_EXPANDED,
125 => Self::EXPANDED,
150 => Self::EXTRA_EXPANDED,
200 => Self::ULTRA_EXPANDED,
_ => Self::from_ratio(width as f32 / 100.0),
}
}
}

impl Style {
/// Creates a new style attribute with the given value from Fontconfig.
///
/// The values are determined based on the [fonts.conf documentation].
///
/// [fonts.conf documentation]: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
fn from_fc(slant: i32) -> Self {
match slant {
100 => Self::Italic,
Expand All @@ -28,6 +44,11 @@ impl Style {
}

impl Weight {
/// Creates a new weight attribute with the given value from Fontconfig.
///
/// The values are determined based on the [fonts.conf documentation].
///
/// [fonts.conf documentation]: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
fn from_fc(weight: i32) -> Self {
const MAP: &[(i32, i32)] = &[
(0, 0),
Expand Down

0 comments on commit 4fc2a6d

Please sign in to comment.