diff --git a/CHANGELOG.md b/CHANGELOG.md index b8616ccdc..d828c49e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Updated Roboto font (version 3.005) - Fixed calculating auto page height +- Fixed TrueType Collection loading from URL ## 0.3.0-beta.2 - 2022-04-01 diff --git a/src/Printer.js b/src/Printer.js index b511a0896..5ea8493ae 100644 --- a/src/Printer.js +++ b/src/Printer.js @@ -126,24 +126,48 @@ class PdfPrinter { for (let font in this.fontDescriptors) { if (this.fontDescriptors.hasOwnProperty(font)) { if (this.fontDescriptors[font].normal) { - let url = getExtendedUrl(this.fontDescriptors[font].normal); - this.urlResolver.resolve(url.url, url.headers); - this.fontDescriptors[font].normal = url.url; + if (Array.isArray(this.fontDescriptors[font].normal)) { // TrueType Collection + let url = getExtendedUrl(this.fontDescriptors[font].normal[0]); + this.urlResolver.resolve(url.url, url.headers); + this.fontDescriptors[font].normal[0] = url.url; + } else { + let url = getExtendedUrl(this.fontDescriptors[font].normal); + this.urlResolver.resolve(url.url, url.headers); + this.fontDescriptors[font].normal = url.url; + } } if (this.fontDescriptors[font].bold) { - let url = getExtendedUrl(this.fontDescriptors[font].bold); - this.urlResolver.resolve(url.url, url.headers); - this.fontDescriptors[font].bold = url.url; + if (Array.isArray(this.fontDescriptors[font].bold)) { // TrueType Collection + let url = getExtendedUrl(this.fontDescriptors[font].bold[0]); + this.urlResolver.resolve(url.url, url.headers); + this.fontDescriptors[font].bold[0] = url.url; + } else { + let url = getExtendedUrl(this.fontDescriptors[font].bold); + this.urlResolver.resolve(url.url, url.headers); + this.fontDescriptors[font].bold = url.url; + } } if (this.fontDescriptors[font].italics) { - let url = getExtendedUrl(this.fontDescriptors[font].italics); - this.urlResolver.resolve(url.url, url.headers); - this.fontDescriptors[font].italics = url.url; + if (Array.isArray(this.fontDescriptors[font].italics)) { // TrueType Collection + let url = getExtendedUrl(this.fontDescriptors[font].italics[0]); + this.urlResolver.resolve(url.url, url.headers); + this.fontDescriptors[font].italics[0] = url.url; + } else { + let url = getExtendedUrl(this.fontDescriptors[font].italics); + this.urlResolver.resolve(url.url, url.headers); + this.fontDescriptors[font].italics = url.url; + } } if (this.fontDescriptors[font].bolditalics) { - let url = getExtendedUrl(this.fontDescriptors[font].bolditalics); - this.urlResolver.resolve(url.url, url.headers); - this.fontDescriptors[font].bolditalics = url.url; + if (Array.isArray(this.fontDescriptors[font].bolditalics)) { // TrueType Collection + let url = getExtendedUrl(this.fontDescriptors[font].bolditalics[0]); + this.urlResolver.resolve(url.url, url.headers); + this.fontDescriptors[font].bolditalics[0] = url.url; + } else { + let url = getExtendedUrl(this.fontDescriptors[font].bolditalics); + this.urlResolver.resolve(url.url, url.headers); + this.fontDescriptors[font].bolditalics = url.url; + } } } }