mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Resolving fonts
This commit is contained in:
parent
369acc27be
commit
dda391bb3a
@ -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']];
|
||||
}
|
||||
}
|
||||
|
@ -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' => ''];
|
||||
|
||||
|
41
tests/Unit/HelpersTest.php
Normal file
41
tests/Unit/HelpersTest.php
Normal 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']);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user