mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 13:14:30 -04:00
Merge pull request #6913 from beganovich/jira-651
Support for different fonts
This commit is contained in:
commit
25c3f7bf08
@ -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' => ''];
|
||||
}
|
||||
}
|
||||
|
@ -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' => ''];
|
||||
|
||||
|
@ -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%;
|
||||
}
|
||||
|
@ -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%;
|
||||
}
|
||||
|
@ -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%;
|
||||
}
|
||||
|
@ -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%;
|
||||
}
|
||||
|
@ -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%;
|
||||
}
|
||||
|
@ -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%;
|
||||
}
|
||||
|
@ -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%;
|
||||
}
|
||||
|
@ -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%;
|
||||
}
|
||||
|
@ -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%;
|
||||
}
|
||||
|
@ -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;
|
||||
|
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