Skip to content

Commit

Permalink
Merge branch 'master' into features/node-section
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 committed Nov 23, 2024
2 parents 8acc262 + 64f1b97 commit 05e7ccc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fixed speed in Node.js if is fetching URL for image or font redirected
- Fixed aspect ratio for image with exif orientation tag
- Fixed font size calculation for watermark if is page orientation is changed

## 0.3.0-beta.12 - 2024-11-03

Expand Down Expand Up @@ -50,7 +51,7 @@
- Allow the document language to be specified
- Fixed cover image size inside table
- Fixed "Cannot read properties of undefined (reading 'bottomMost')" if table contains too few rows
- Fixed invalid source-maps in builded js file
- Fixed invalid source-maps in built js file

## 0.3.0-beta.6 - 2023-11-09

Expand All @@ -76,7 +77,7 @@
## 0.3.0-beta.2 - 2022-04-01

- Attachments embedding
- Support passing headers to request for loading font files and images via URL adresses
- Support passing headers to request for loading font files and images via URL addresses

## 0.3.0-beta.1 - 2022-01-01

Expand Down
54 changes: 29 additions & 25 deletions src/LayoutBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,36 +284,40 @@ class LayoutBuilder {
return;
}

watermark.font = watermark.font || defaultStyle.font || 'Roboto';
watermark.fontSize = watermark.fontSize || 'auto';
watermark.color = watermark.color || 'black';
watermark.opacity = isNumber(watermark.opacity) ? watermark.opacity : 0.6;
watermark.bold = watermark.bold || false;
watermark.italics = watermark.italics || false;
watermark.angle = isValue(watermark.angle) ? watermark.angle : null;

if (watermark.angle === null) {
watermark.angle = Math.atan2(this.pageSize.height, this.pageSize.width) * -180 / Math.PI;
let pages = this.writer.context().pages;
for (let i = 0, l = pages.length; i < l; i++) {
pages[i].watermark = getWatermarkObject({ ...watermark }, pages[i].pageSize, pdfDocument, defaultStyle);
}

if (watermark.fontSize === 'auto') {
watermark.fontSize = getWatermarkFontSize(this.pageSize, watermark, pdfDocument);
}
function getWatermarkObject(watermark, pageSize, pdfDocument, defaultStyle) {
watermark.font = watermark.font || defaultStyle.font || 'Roboto';
watermark.fontSize = watermark.fontSize || 'auto';
watermark.color = watermark.color || 'black';
watermark.opacity = isNumber(watermark.opacity) ? watermark.opacity : 0.6;
watermark.bold = watermark.bold || false;
watermark.italics = watermark.italics || false;
watermark.angle = isValue(watermark.angle) ? watermark.angle : null;

if (watermark.angle === null) {
watermark.angle = Math.atan2(pageSize.height, pageSize.width) * -180 / Math.PI;
}

let watermarkObject = {
text: watermark.text,
font: pdfDocument.provideFont(watermark.font, watermark.bold, watermark.italics),
fontSize: watermark.fontSize,
color: watermark.color,
opacity: watermark.opacity,
angle: watermark.angle
};
if (watermark.fontSize === 'auto') {
watermark.fontSize = getWatermarkFontSize(pageSize, watermark, pdfDocument);
}

watermarkObject._size = getWatermarkSize(watermark, pdfDocument);
let watermarkObject = {
text: watermark.text,
font: pdfDocument.provideFont(watermark.font, watermark.bold, watermark.italics),
fontSize: watermark.fontSize,
color: watermark.color,
opacity: watermark.opacity,
angle: watermark.angle
};

let pages = this.writer.context().pages;
for (let i = 0, l = pages.length; i < l; i++) {
pages[i].watermark = watermarkObject;
watermarkObject._size = getWatermarkSize(watermark, pdfDocument);

return watermarkObject;
}

function getWatermarkSize(watermark, pdfDocument) {
Expand Down

0 comments on commit 05e7ccc

Please sign in to comment.