Merge pull request #6913 from beganovich/jira-651

Support for different fonts
This commit is contained in:
David Bomba 2021-10-28 05:19:07 +11:00 committed by GitHub
commit 25c3f7bf08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 86 additions and 10 deletions

View File

@ -264,4 +264,17 @@ 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
{
return $font
? ['name' => str_replace('_', ' ', $font), 'url' => sprintf('https://fonts.googleapis.com/css2?family=%s&display=swap', str_replace('_', '+', $font))]
: ['name' => 'Arial', 'url' => ''];
}
}

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($this->settings->primary_font)['name'], 'label' => ''];
$data['$font_url'] = ['value' => Helpers::resolveFont($this->settings->primary_font)['url'], 'label' => ''];
$data['$invoiceninja.whitelabel'] = ['value' => 'https://raw.githubusercontent.com/invoiceninja/invoiceninja/v5-develop/public/images/new_logo.png', 'label' => ''];

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: $primary_color;
--secondary-color: $secondary_color;
@ -8,7 +10,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "$font_size";
zoom: 80%;
}

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: $primary_color;
--secondary-color: $secondary_color;
@ -8,7 +10,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "$font_size";
zoom: 80%;
}

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: $primary_color;
--secondary-color: $secondary_color;
@ -8,7 +10,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "$font_size";
zoom: 80%;
}

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: $primary_color;
--secondary-color: $secondary_color;
@ -8,7 +10,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "$font_size";
zoom: 80%;
}

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: $primary_color;
--secondary-color: $secondary_color;
@ -8,7 +10,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "$font_size";
zoom: 80%;
}

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: $primary_color;
--secondary-color: $secondary_color;
@ -8,7 +10,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "$font_size";
zoom: 80%;
}

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: #298aab;
--secondary-color: #7081e0;
@ -7,7 +9,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "7px";
zoom: 80%;
}

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: $primary_color;
--secondary-color: $secondary_color;
@ -8,7 +10,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "$font_size";
zoom: 80%;
}

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: $primary_color;
--secondary-color: $secondary_color;
@ -8,7 +10,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "$font_size";
zoom: 80%;
}

View File

@ -1,4 +1,6 @@
<style id="style">
@import url($font_url);
:root {
--primary-color: $primary_color;
--secondary-color: $secondary_color;
@ -7,7 +9,7 @@
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
font-family: $font_name, Helvetica, sans-serif;
font-size: "$font_size";
zoom: 80%;
margin: 0;

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']);
}
}