From d9674c924525faf3c656445a46374ccda1db0370 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Thu, 7 Dec 2023 12:22:26 +0100 Subject: [PATCH] convert font weight to number values fix #369 + update MANUAL with complete list of allowed font properties --- MANUAL.md | 30 ++++++++++++++++++++++++++++++ app/class/Font.php | 26 ++++++++++++++++++-------- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/MANUAL.md b/MANUAL.md index acbfa0a7..aed808b0 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -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: diff --git a/app/class/Font.php b/app/class/Font.php index e95ce6c1..676db941 100644 --- a/app/class/Font.php +++ b/app/class/Font.php @@ -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. * @@ -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; }; } @@ -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"; }