diff --git a/src/demo/index.php b/src/demo/index.php index 121f3d9e..37640ded 100644 --- a/src/demo/index.php +++ b/src/demo/index.php @@ -64,6 +64,9 @@ function gtag() { + + + diff --git a/src/demo/js/script.js b/src/demo/js/script.js index 60d55663..056d414b 100644 --- a/src/demo/js/script.js +++ b/src/demo/js/script.js @@ -2,6 +2,7 @@ let preview = { // default values defaults: { font: "monospace", + weight: "400", color: "36BCF7", background: "00000000", size: "20", diff --git a/src/models/GoogleFontConverter.php b/src/models/GoogleFontConverter.php index 4b8c5813..affea3b2 100644 --- a/src/models/GoogleFontConverter.php +++ b/src/models/GoogleFontConverter.php @@ -12,12 +12,12 @@ class GoogleFontConverter * @param string $text Text to display in font * @return string|false The CSS for displaying the font */ - public static function fetchFontCSS($font, $text) + public static function fetchFontCSS($font, $weight, $text) { $url = "https://fonts.googleapis.com/css2?" . http_build_query([ - "family" => $font, + "family" => $font . ":wght@" . $weight, "text" => $text, "display" => "fallback", ]); diff --git a/src/models/RendererModel.php b/src/models/RendererModel.php index d71e9605..0681ac57 100644 --- a/src/models/RendererModel.php +++ b/src/models/RendererModel.php @@ -13,6 +13,9 @@ class RendererModel /** @var string $font Font family */ public $font; + /** @var string $font Font weight */ + public $weight; + /** @var string $color Font color */ public $color; @@ -52,6 +55,7 @@ class RendererModel /** @var array $DEFAULTS */ private $DEFAULTS = [ "font" => "monospace", + "weight" => "400", "color" => "#36BCF7", "background" => "#00000000", "size" => "20", @@ -75,6 +79,7 @@ public function __construct($template, $params) $this->template = $template; $this->lines = $this->checkLines($params["lines"] ?? ""); $this->font = $this->checkFont($params["font"] ?? $this->DEFAULTS["font"]); + $this->weight = $this->checkNumberPositive($params["weight"] ?? $this->DEFAULTS["weight"], "Font weight"); $this->color = $this->checkColor($params["color"] ?? $this->DEFAULTS["color"], "color"); $this->background = $this->checkColor($params["background"] ?? $this->DEFAULTS["background"], "background"); $this->size = $this->checkNumberPositive($params["size"] ?? $this->DEFAULTS["size"], "Font size"); @@ -85,7 +90,7 @@ public function __construct($template, $params) $this->multiline = $this->checkBoolean($params["multiline"] ?? $this->DEFAULTS["multiline"]); $this->duration = $this->checkNumberPositive($params["duration"] ?? $this->DEFAULTS["duration"], "duration"); $this->pause = $this->checkNumberNonNegative($params["pause"] ?? $this->DEFAULTS["pause"], "pause"); - $this->fontCSS = $this->fetchFontCSS($this->font, $params["lines"]); + $this->fontCSS = $this->fetchFontCSS($this->font, $this->weight, $params["lines"]); } /** @@ -185,12 +190,12 @@ private function checkBoolean($bool) * @param string $text Text to display in font * @return string The CSS for displaying the font */ - private function fetchFontCSS($font, $text) + private function fetchFontCSS($font, $weight, $text) { // skip checking if left as default if ($font != $this->DEFAULTS["font"]) { // fetch and convert from Google Fonts - $from_google_fonts = GoogleFontConverter::fetchFontCSS($font, $text); + $from_google_fonts = GoogleFontConverter::fetchFontCSS($font, $weight, $text); if ($from_google_fonts) { // return the CSS for displaying the font return "\n";