Skip to content

Commit 4fc2a6d

Browse files
fontconfig: Add more stretch conversions, note provenance (#210)
This adds more of the defined stretch constants that Fontconfig has and notes the provenance of the constants as having come from Fontconfig documentation.
1 parent b5f16e9 commit 4fc2a6d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

fontique/src/backend/fontconfig/cache.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,33 @@ use std::io::Read;
77
use std::path::PathBuf;
88

99
impl Stretch {
10-
fn from_fc(width: i32) -> Self {
10+
/// Creates a new stretch attribute with the given value from Fontconfig.
11+
///
12+
/// The values are determined based on the [fonts.conf documentation].
13+
///
14+
/// [fonts.conf documentation]: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
15+
pub fn from_fc(width: i32) -> Self {
1116
match width {
17+
50 => Self::ULTRA_CONDENSED,
1218
63 => Self::EXTRA_CONDENSED,
19+
75 => Self::CONDENSED,
1320
87 => Self::SEMI_CONDENSED,
21+
100 => Self::NORMAL,
1422
113 => Self::SEMI_EXPANDED,
23+
125 => Self::EXPANDED,
24+
150 => Self::EXTRA_EXPANDED,
25+
200 => Self::ULTRA_EXPANDED,
1526
_ => Self::from_ratio(width as f32 / 100.0),
1627
}
1728
}
1829
}
1930

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

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

0 commit comments

Comments
 (0)