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

Prepare 2.5.2 #3769

Merged
merged 2 commits into from
Sep 17, 2024
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ yarn add jspdf
Alternatively, load it from a CDN:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.2/jspdf.umd.min.js"></script>
```

Or always get latest version via [unpkg](https://unpkg.com/browse/jspdf/)
Expand Down Expand Up @@ -178,7 +178,7 @@ Alternatively, you can load the prebundled polyfill file. This is not recommende
loading polyfills multiple times. Might still be nifty for small applications or quick POCs.

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/polyfills.umd.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.2/polyfills.umd.js"></script>
```

## Use of Unicode Characters / UTF-8:
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jspdf",
"version": "2.5.1",
"version": "2.5.2",
"homepage": "https://github.com/mrrio/jspdf",
"description": "PDF Document creation from JavaScript",
"main": [
Expand Down
50 changes: 40 additions & 10 deletions dist/jspdf.es.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @license
*
* jsPDF - PDF Document creation from JavaScript
* Version 2.5.1 Built on 2022-01-28T15:37:57.791Z
* Version 2.5.2 Built on 2024-09-17T13:29:57.859Z
* CommitID 00000000
*
* Copyright (c) 2010-2021 James Hall <[email protected]>, https://github.com/MrRio/jsPDF
Expand Down Expand Up @@ -4554,19 +4554,21 @@ function jsPDF(options) {
}, options.flags);
var wordSpacingPerLine = [];

var findWidth = function findWidth(v) {
return scope.getStringUnitWidth(v, {
font: activeFont,
charSpace: charSpace,
fontSize: activeFontSize,
doKerning: false
}) * activeFontSize / scaleFactor;
};

if (Object.prototype.toString.call(text) === "[object Array]") {
da = transformTextToSpecialArray(text);
var newY;

if (align !== "left") {
lineWidths = da.map(function (v) {
return scope.getStringUnitWidth(v, {
font: activeFont,
charSpace: charSpace,
fontSize: activeFontSize,
doKerning: false
}) * activeFontSize / scaleFactor;
});
lineWidths = da.map(findWidth);
} //The first line uses the "main" Td setting,
//and the subsequent lines are offset by the
//previous line's x coordinate.
Expand Down Expand Up @@ -4620,6 +4622,34 @@ function jsPDF(options) {
for (var h = 0; h < len; h++) {
text.push(da[h]);
}
} else if (align === "justify" && activeFont.encoding === "Identity-H") {
// when using unicode fonts, wordSpacePerLine does not apply
text = [];
len = da.length;
maxWidth = maxWidth !== 0 ? maxWidth : pageWidth;
var backToStartX = 0;

for (var l = 0; l < len; l++) {
newY = l === 0 ? getVerticalCoordinate(y) : -leading;
newX = l === 0 ? getHorizontalCoordinate(x) : backToStartX;

if (l < len - 1) {
var spacing = scale((maxWidth - lineWidths[l]) / (da[l].split(" ").length - 1));
var words = da[l].split(" ");
text.push([words[0] + " ", newX, newY]);
backToStartX = 0; // distance to reset back to the left

for (var _i = 1; _i < words.length; _i++) {
var shiftAmount = (findWidth(words[_i - 1] + " " + words[_i]) - findWidth(words[_i])) * scaleFactor + spacing;
if (_i == words.length - 1) text.push([words[_i], shiftAmount, 0]);else text.push([words[_i] + " ", shiftAmount, 0]);
backToStartX -= shiftAmount;
}
} else {
text.push([da[l], newX, newY]);
}
}

text.push(["", backToStartX, 0]);
} else if (align === "justify") {
text = [];
len = da.length;
Expand Down Expand Up @@ -6649,7 +6679,7 @@ jsPDF.API = {
* @memberof jsPDF#
*/

jsPDF.version = "2.5.1";
jsPDF.version = "2.5.2";

var jsPDFAPI = jsPDF.API;
var scaleFactor = 1;
Expand Down
2 changes: 1 addition & 1 deletion dist/jspdf.es.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/jspdf.es.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jspdf.es.min.js.map

Large diffs are not rendered by default.

62 changes: 46 additions & 16 deletions dist/jspdf.node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @license
*
* jsPDF - PDF Document creation from JavaScript
* Version 2.5.1 Built on 2022-01-28T15:37:57.791Z
* Version 2.5.2 Built on 2024-09-17T13:29:57.860Z
* CommitID 00000000
*
* Copyright (c) 2010-2021 James Hall <[email protected]>, https://github.com/MrRio/jsPDF
Expand Down Expand Up @@ -4617,23 +4617,23 @@ function jsPDF(options) {
flags = Object.assign({ autoencode: true, noBOM: true }, options.flags);

var wordSpacingPerLine = [];

var findWidth = function(v) {
return (
(scope.getStringUnitWidth(v, {
font: activeFont,
charSpace: charSpace,
fontSize: activeFontSize,
doKerning: false
}) *
activeFontSize) /
scaleFactor
);
};
if (Object.prototype.toString.call(text) === "[object Array]") {
da = transformTextToSpecialArray(text);
var newY;
if (align !== "left") {
lineWidths = da.map(function(v) {
return (
(scope.getStringUnitWidth(v, {
font: activeFont,
charSpace: charSpace,
fontSize: activeFontSize,
doKerning: false
}) *
activeFontSize) /
scaleFactor
);
});
lineWidths = da.map(findWidth);
}
//The first line uses the "main" Td setting,
//and the subsequent lines are offset by the
Expand Down Expand Up @@ -4680,11 +4680,41 @@ function jsPDF(options) {
for (var h = 0; h < len; h++) {
text.push(da[h]);
}
} else if (align === "justify" && activeFont.encoding === "Identity-H") {
// when using unicode fonts, wordSpacePerLine does not apply
text = [];
len = da.length;
maxWidth = maxWidth !== 0 ? maxWidth : pageWidth;
let backToStartX = 0;
for (var l = 0; l < len; l++) {
newY = l === 0 ? getVerticalCoordinate(y) : -leading;
newX = l === 0 ? getHorizontalCoordinate(x) : backToStartX;
if (l < len - 1) {
let spacing = scale(
(maxWidth - lineWidths[l]) / (da[l].split(" ").length - 1)
);
let words = da[l].split(" ");
text.push([words[0] + " ", newX, newY]);
backToStartX = 0; // distance to reset back to the left
for (let i = 1; i < words.length; i++) {
let shiftAmount =
(findWidth(words[i - 1] + " " + words[i]) -
findWidth(words[i])) *
scaleFactor +
spacing;
if (i == words.length - 1) text.push([words[i], shiftAmount, 0]);
else text.push([words[i] + " ", shiftAmount, 0]);
backToStartX -= shiftAmount;
}
} else {
text.push([da[l], newX, newY]);
}
}
text.push(["", backToStartX, 0]);
} else if (align === "justify") {
text = [];
len = da.length;
maxWidth = maxWidth !== 0 ? maxWidth : pageWidth;

for (var l = 0; l < len; l++) {
newY = l === 0 ? getVerticalCoordinate(y) : -leading;
newX = l === 0 ? getHorizontalCoordinate(x) : 0;
Expand Down Expand Up @@ -6861,7 +6891,7 @@ jsPDF.API = {
* @type {string}
* @memberof jsPDF#
*/
jsPDF.version = "2.5.1";
jsPDF.version = "2.5.2";

/* global jsPDF */

Expand Down
2 changes: 1 addition & 1 deletion dist/jspdf.node.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/jspdf.node.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jspdf.node.min.js.map

Large diffs are not rendered by default.

Loading
Loading