Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bold font in azure static web apps #439

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/pdf/swissqrbill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export class SwissQRBill {
private separate: boolean = false;
private outlines: boolean = true;
private language: Language = "DE";
private font: string = "Helvetica";

private font: PDFKit.Mixins.PDFFontSource = "Helvetica";
private fontBold: PDFKit.Mixins.PDFFontSource = "Helvetica-Bold";

private _x: number = 0;
private _y: number = 0;

Expand All @@ -76,6 +77,7 @@ export class SwissQRBill {
this.language = options?.language !== undefined ? options.language : this.language;
this.outlines = options?.outlines !== undefined ? options.outlines : this.outlines;
this.font = options?.fontName !== undefined ? options.fontName : this.font;
this.fontBold = options?.fontNameBold !== undefined ? options.fontNameBold : `${this.font}-Bold`;

if(options?.scissors !== undefined){
this.scissors = options.scissors;
Expand Down Expand Up @@ -237,14 +239,14 @@ export class SwissQRBill {

// Receipt
doc.fontSize(11);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].receipt, this.x(5), this.y(5), {
align: "left",
width: mm2pt(52)
});

doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].account, this.x(5), this.y(12), {
lineGap: 1,
width: mm2pt(52)
Expand All @@ -265,7 +267,7 @@ export class SwissQRBill {
if(this.data.reference !== undefined){

doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].reference, {
lineGap: 1,
width: mm2pt(52)
Expand All @@ -287,7 +289,7 @@ export class SwissQRBill {
if(this.data.debtor !== undefined){

doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].payableBy, {
lineGap: 1,
width: mm2pt(52)
Expand All @@ -303,7 +305,7 @@ export class SwissQRBill {
} else {

doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].payableByName, {
lineGap: 1,
width: mm2pt(52)
Expand All @@ -316,7 +318,7 @@ export class SwissQRBill {

// Amount
doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].currency, this.x(5), this.y(68), {
lineGap: 1,
width: mm2pt(15)
Expand Down Expand Up @@ -346,7 +348,7 @@ export class SwissQRBill {
}

doc.fontSize(6);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].acceptancePoint, this.x(5), this.y(82), {
align: "right",
height: mm2pt(18),
Expand All @@ -356,7 +358,7 @@ export class SwissQRBill {

// Payment part middle container
doc.fontSize(11);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].paymentPart, this.x(67), this.y(5), {
align: "left",
lineGap: 1,
Expand All @@ -369,7 +371,7 @@ export class SwissQRBill {

// Amount
doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].currency, this.x(67), this.y(68), {
lineGap: 1,
width: mm2pt(15)
Expand Down Expand Up @@ -401,7 +403,7 @@ export class SwissQRBill {
const [scheme, data] = this.data.av1.split(/(\/.+)/);

doc.fontSize(7);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(scheme, this.x(67), this.y(90), {
continued: true,
height: mm2pt(3),
Expand All @@ -421,7 +423,7 @@ export class SwissQRBill {
const [scheme, data] = this.data.av2.split(/(\/.+)/);

doc.fontSize(7);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(scheme, this.x(67), this.y(93), {
continued: true,
height: mm2pt(3),
Expand All @@ -438,7 +440,7 @@ export class SwissQRBill {

// Payment part right column
doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].account, this.x(118), this.y(5), {
lineGap: 1,
width: mm2pt(87)
Expand All @@ -457,7 +459,7 @@ export class SwissQRBill {
if(this.data.reference !== undefined){

doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].reference, {
lineGap: 1,
width: mm2pt(87)
Expand All @@ -479,7 +481,7 @@ export class SwissQRBill {
if(this.data.message !== undefined || this.data.additionalInformation !== undefined){

doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].additionalInformation, {
lineGap: 1,
width: mm2pt(87)
Expand Down Expand Up @@ -531,7 +533,7 @@ export class SwissQRBill {
if(this.data.debtor !== undefined){

doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].payableBy, {
lineGap: 1,
width: mm2pt(87)
Expand All @@ -547,7 +549,7 @@ export class SwissQRBill {
} else {

doc.fontSize(8);
doc.font(`${this.font}-Bold`);
doc.font(this.fontBold);
doc.text(translations[this.language].payableByName, {
lineGap: 1,
width: mm2pt(87)
Expand Down
17 changes: 16 additions & 1 deletion src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,22 @@ interface QRBillOptions {
* const qrBill = new SwissQRBill(data, { fontName: "Liberation-Sans" });
* ```
*/
fontName?: "Arial" | "Frutiger" | "Helvetica" | "Liberation Sans";
fontName?: "Arial" | "Frutiger" | "Helvetica" | "Liberation Sans" | PDFKit.Mixins.PDFFontSource;

/**
* Bold font used for the QR-Bill.
* Fonts other than Helvetica must be registered in the PDFKit document. {@link http://pdfkit.org/docs/text.html#fonts}
* @defaultValue 'Helvetica'
* @example
* ```ts
* // Register the font
* pdf.registerFont("Liberation-Sans", "path/to/LiberationSans-Regular.ttf");
* pdf.registerFont("Liberation-Sans-Bold", "path/to/LiberationSans-Bold.ttf");
*
* const qrBill = new SwissQRBill(data, { fontNameBold: "Liberation-Sans-Bold" });
* ```
*/
fontNameBold?: "Arial-Bold" | "Frutiger-Bold" | "Helvetica-Bold" | "Liberation Sans-Bold" | PDFKit.Mixins.PDFFontSource;

/**
* The language with which the bill is rendered.
Expand Down
1,951 changes: 1,951 additions & 0 deletions tests/__snapshots__/integration/options.test.snap

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion tests/integration/options.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";

import { minimalRequired } from "swissqrbill:tests:data/valid-data.js";
import { creditorWithZipString, minimalRequired } from "swissqrbill:tests:data/valid-data.js";
import { pdf } from "swissqrbill:tests:utils/pdf.js";
import { svg } from "swissqrbill:tests:utils/svg.js";

Expand Down Expand Up @@ -51,4 +51,11 @@ describe("options", async () => {
expect(svgSnapshot).toMatchSnapshot();
});

test("font bold", async () => {
const name = "font-bold";
const pdfSnapshot = await pdf(creditorWithZipString, `options/${name}.pdf`, { fontName: "Helvetica", fontNameBold: "Helvetica-Bold" });
const svgSnapshot = await svg(creditorWithZipString, `options/${name}.svg`, { fontName: "Helvetica", fontNameBold: "Helvetica-Bold" });
expect(pdfSnapshot).toMatchSnapshot();
expect(svgSnapshot).toMatchSnapshot();
});
});
Loading