Skip to content

Commit

Permalink
convert font weight to number values fix #369
Browse files Browse the repository at this point in the history
+ update MANUAL with complete list of allowed font properties
  • Loading branch information
vincent-peugnet committed Dec 7, 2023
1 parent af0097e commit d9674c9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
30 changes: 30 additions & 0 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,36 @@ For example:
The `fonts.css` file will be automatically re-generated each time you upload or rename files in this folder using the web interface. If you add or modify files by any other way, you can manually trigger the generation. Under the *File > Magic folder* menu, select: *Regenerate @fontface CSS file*


##### Authorized properties

Here is the full list of font properties you can use in W.

- **style**
- `italique`
- `oblique`
- **weight**
- `thin` conveted to `100`
- `extra-light` conveted to `200`
- `light` conveted to `300`
- `medium` conveted to `500`
- `semi-bold` conveted to `600`
- `bold`
- `extra-bold` conveted to `800`
- `black` conveted to `900`
- **stretch**
- `ultra-condensed`
- `extra-condensed`
- `condensed`
- `semi-condensed`
- `semi-expanded`
- `expanded`
- `extra-expanded`
- `ultra-expanded`


CSS properties for weight only use `normal` and `bold` as absolute values. otherwise, you have to specify it with a number value. **W** will convert text defined weight to numbered values for other common weights.


#### CSS folder

This contain two files:
Expand Down
26 changes: 18 additions & 8 deletions app/class/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class Font
"ultra-expanded" => self::STRETCH,
];

public const WEIGHT_EQUIV = [
'thin' => 100,
'extra-light' => 200,
'light' => 300,
'medium' => 500,
'semi-bold' => 600,
'extra-bold' => 800,
'black' => 900,
];

/**
* Feed it with media sharing same basename. Only font formats may differ.
*
Expand All @@ -70,6 +80,9 @@ public function __construct(array $medias)
$options = array_unique(array_flip($options));

foreach ($options as $param => $value) {
if ($param === self::WEIGHT) {
$value = self::WEIGHT_EQUIV[$value] ?? $value;
}
$this->$param = $value;
};
}
Expand Down Expand Up @@ -105,17 +118,14 @@ public function fontface(): string
return $src;
}, $this->medias());
$css .= implode(",\n", $srcs) . ";";
if (!is_null($this->style())) {
$style = $this->style();
$css .= "\n font-style: $style;";
if (!is_null($this->style)) {
$css .= "\n font-style: $this->style;";
}
if (!is_null($this->weight())) {
$weight = $this->weight();
$css .= "\n font-weight: $weight;";
$css .= "\n font-weight: $this->weight;";
}
if (!is_null($this->stretch())) {
$stretch = $this->stretch();
$css .= "\n font-stretch: $stretch;";
if (!is_null($this->stretch)) {
$css .= "\n font-stretch: $this->stretch;";
}
return "$css\n}\n\n";
}
Expand Down

0 comments on commit d9674c9

Please sign in to comment.