Resolving fonts

This commit is contained in:
Benjamin Beganović 2021-10-27 14:51:43 +02:00
parent 369acc27be
commit dda391bb3a
3 changed files with 68 additions and 0 deletions

View File

@ -264,4 +264,29 @@ class Helpers
return $value;
}
/**
* Resolve the font from the supported fonts array.
*
* @param string $font
* @return array
*/
public static function resolveFont(string $font = 'Arial'): array
{
$fonts = [
'Arial' => '',
'Inter' => 'https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap',
'Roboto' => 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap',
'Irish Grover' => 'https://fonts.googleapis.com/css2?family=Irish+Grover&display=swap',
];
if (array_key_exists($font, $fonts)) {
return [
'name' => $font,
'url' => $fonts[$font],
];
}
return ['name' => 'Arial', 'url' => $fonts['Arial']];
}
}

View File

@ -445,6 +445,8 @@ class HtmlEngine
$data['_rate3'] = ['value' => '', 'label' => ctrans('texts.tax')];
$data['$font_size'] = ['value' => $this->settings->font_size . 'px', 'label' => ''];
$data['$font_name'] = ['value' => Helpers::resolveFont()['name'], 'label' => ''];
$data['$font_url'] = ['value' => Helpers::resolveFont()['url'], 'label' => ''];
$data['$invoiceninja.whitelabel'] = ['value' => 'https://raw.githubusercontent.com/invoiceninja/invoiceninja/v5-develop/public/images/new_logo.png', 'label' => ''];

View File

@ -0,0 +1,41 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Unit;
use App\Utils\Helpers;
use PHPUnit\Framework\TestCase;
class HelpersTest extends TestCase
{
public function testFontsReturnFormat(): void
{
$font = Helpers::resolveFont();
$this->assertArrayHasKey('name', $font);
$this->assertArrayHasKey('url', $font);
}
public function testResolvingFont(): void
{
$font = Helpers::resolveFont('Inter');
$this->assertEquals('Inter', $font['name']);
}
public function testDefaultFontIsArial(): void
{
$font = Helpers::resolveFont();
$this->assertEquals('Arial', $font['name']);
}
}