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

Update fromHTML for Unicode text support #1

Open
wants to merge 1 commit into
base: master
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
105 changes: 75 additions & 30 deletions dist/jspdf.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
/** @license
*
* jsPDF - PDF Document creation from JavaScript
* Version 2.1.1 Built on 2019-10-11T08:56:17.234Z
* CommitID 0dd01f177e
* Version 1.5.3 Built on 2020-06-19T10:01:49.186Z
* CommitID 2c5e6c7cb0
*
* Copyright (c) 2010-2018 James Hall <james@parall.ax>, https://github.com/MrRio/jsPDF
* 2015-2018 yWorks GmbH, http://www.yworks.com
Expand Down Expand Up @@ -37,6 +37,8 @@
*/

function _typeof(obj) {
"@babel/helpers - typeof";

if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
Expand Down Expand Up @@ -1420,6 +1422,10 @@
*/

var Matrix = function Matrix(sx, shy, shx, sy, tx, ty) {
if (!(this instanceof Matrix)) {
return new Matrix(sx, shy, shx, sy, tx, ty);
}

var _matrix = [];
/**
* @name sx
Expand Down Expand Up @@ -1827,8 +1833,13 @@
*/


API.ShadingPattern = function (type, coords, colors, gState, matrix) {
advancedApiModeTrap("ShadingPattern"); // see putPattern() for information how they are realized
API.ShadingPattern = function ShadingPattern(type, coords, colors, gState, matrix) {
advancedApiModeTrap("ShadingPattern");

if (!(this instanceof ShadingPattern)) {
return new ShadingPattern(type, coords, colors, gState, matrix);
} // see putPattern() for information how they are realized


this.type = type === "axial" ? 2 : 3;
this.coords = coords;
Expand All @@ -1851,8 +1862,13 @@
*/


API.TilingPattern = function (boundingBox, xStep, yStep, gState, matrix) {
API.TilingPattern = function TilingPattern(boundingBox, xStep, yStep, gState, matrix) {
advancedApiModeTrap("TilingPattern");

if (!(this instanceof TilingPattern)) {
return new TilingPattern(boundingBox, xStep, yStep, gState, matrix);
}

this.boundingBox = boundingBox;
this.xStep = xStep;
this.yStep = yStep;
Expand Down Expand Up @@ -3480,7 +3496,7 @@
*
* @memberof jsPDF#
* @name setPage
* @param {number} page Switch the active page to the page number specified.
* @param {number} page Switch the active page to the page number specified (indexed starting at 1).
* @example
* doc = jsPDF()
* doc.addPage()
Expand Down Expand Up @@ -5500,7 +5516,10 @@
*/


API.GState = function (parameters) {
API.GState = function GState(parameters) {
if (!(this instanceof GState)) {
return new GState(parameters);
}
/**
* @name GState#opacity
* @type {any}
Expand All @@ -5510,6 +5529,8 @@
* @name GState#stroke-opacity
* @type {any}
*/


var supported = "opacity,stroke-opacity".split(",");

for (var p in parameters) {
Expand Down Expand Up @@ -5935,8 +5956,7 @@
* @instance
* @param {string} filename The filename including extension.
* @param {Object} options An Object with additional options, possible options: 'returnPromise'.
* @returns {jsPDF} jsPDF-instance
*/
* @returns {jsPDF} jsPDF-instance */


API.save = function (filename, options) {
Expand Down Expand Up @@ -6146,7 +6166,7 @@
* @memberof jsPDF#
*/

jsPDF.version = '2.1.1';
jsPDF.version = '1.5.3';

if (typeof define === "function" && define.amd) {
define(function () {
Expand Down Expand Up @@ -8994,9 +9014,6 @@
globalObj["AcroForm"] = {
Appearance: AcroFormAppearance
};
} else {
// eslint-disable-next-line no-console
console.warn("AcroForm-Classes are not populated into global-namespace, because the class-Names exist already. This avoids conflicts with the already used framework.");
}

jsPDFAPI.AcroFormChoiceField = AcroFormChoiceField;
Expand Down Expand Up @@ -11125,7 +11142,7 @@
* @param {Integer} [y] top-position for top-left corner of table
* @param {Object[]} [data] An array of objects containing key-value pairs corresponding to a row of data.
* @param {String[]} [headers] Omit or null to auto-generate headers at a performance cost
* @param {Object} [config.printHeaders] True to print column headers at the top of every page
* @param {Object} [config.printHeaders] True to print column headers at the top of every page
* @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value
* @param {Object} [config.margins] margin values for left, top, bottom, and width
* @param {Object} [config.fontSize] Integer fontSize to use (optional)
Expand Down Expand Up @@ -11289,10 +11306,16 @@
var padding = this.internal.__cell__.padding;
var fontSize = this.internal.__cell__.table_font_size;
var scaleFactor = this.internal.scaleFactor;
return Object.keys(model).map(function (value) {
return _typeof(value) === "object" ? value.text : value;
}).map(function (value) {
return this.splitTextToSize(value, columnWidths[value] - padding - padding);
return Object.keys(model).map(function (key) {
return [key, model[key]];
}).map(function (item) {
var key = item[0];
var value = item[1];
return _typeof(value) === "object" ? [key, value.text] : [key, value];
}).map(function (item) {
var key = item[0];
var value = item[1];
return this.splitTextToSize(value, columnWidths[key] - padding - padding);
}, this).map(function (value) {
return this.getLineHeightFactor() * value.length * fontSize / scaleFactor + padding + padding;
}, this).reduce(function (pv, cv) {
Expand Down Expand Up @@ -13828,7 +13851,8 @@
x: 0,
y: 0,
html2canvas: {},
jsPDF: {}
jsPDF: {},
backgroundColor: "transparent"
}
};
/* ----- FROM / TO ----- */
Expand Down Expand Up @@ -13925,7 +13949,7 @@
right: 0,
top: 0,
margin: "auto",
backgroundColor: "white"
backgroundColor: this.opt.backgroundColor
}; // Set the overlay to hidden (could be changed in the future to provide a print preview).

var source = cloneNode(this.prop.src, this.opt.html2canvas.javascriptEnabled);
Expand Down Expand Up @@ -14972,13 +14996,13 @@
*
Color Allowed Interpretation
Type Bit Depths
0 1,2,4,8,16 Each pixel is a grayscale sample.
2 8,16 Each pixel is an R,G,B triple.
3 1,2,4,8 Each pixel is a palette index;
0 1,2,4,8,16 Each pixel is a grayscale sample.
2 8,16 Each pixel is an R,G,B triple.
3 1,2,4,8 Each pixel is a palette index;
a PLTE chunk must appear.
4 8,16 Each pixel is a grayscale sample,
4 8,16 Each pixel is a grayscale sample,
followed by an alpha sample.
6 8,16 Each pixel is an R,G,B triple,
6 8,16 Each pixel is an R,G,B triple,
followed by an alpha sample.
*/

Expand Down Expand Up @@ -15823,6 +15847,8 @@
} else {
if (doKerning && _typeof(kerning[char_code]) === "object" && !isNaN(parseInt(kerning[char_code][prior_char_code], 10))) {
kerningValue = kerning[char_code][prior_char_code] / kerningFractionOf;
} else {
kerningValue = 0;
}

output.push((widths[char_code] || default_char_width) / widthsFractionOf + kerningValue);
Expand Down Expand Up @@ -17747,6 +17773,8 @@
* 2014 Wolfgang Gassler, https://github.com/woolfg
* 2014 Steven Spungin, https://github.com/flamenco
*
* Copyright (c) 2020 BMD Software, https://github.com/BMDSoftware
*
* @license
*
* ====================================================================
Expand Down Expand Up @@ -17913,7 +17941,13 @@
prop = prop.replace(/-\D/g, function (match) {
return match.charAt(1).toUpperCase();
});
return compCSS[prop];
var val = compCSS[prop];

if (val.startsWith('"') && val.endsWith('"')) {
val = val.slice(1, val.length - 1);
}

return val;
};
}(element);

Expand Down Expand Up @@ -18578,9 +18612,21 @@

if (style["word-spacing"] !== undefined && style["word-spacing"] > 0) {
this.pdf.internal.write(style["word-spacing"].toFixed(2), "Tw");
} // pdfEscape is enough for text document properties,
// but not for Unicode text that we want to render.
// So if the font is Identity-H, we use `pdfEscape16` to convert the text
// to hexadecimal glyph codes.


var pdfStream;

if (font.encoding === 'Identity-H') {
pdfStream = "<" + this.pdf.pdfEscape16(text, font) + "> Tj";
} else {
pdfStream = "(" + this.pdf.internal.pdfEscape(text) + ") Tj";
}

this.pdf.internal.write("/" + font.id, (defaultFontSize * style["font-size"]).toFixed(2), "Tf", "(" + this.pdf.internal.pdfEscape(text) + ") Tj"); //set the word spacing back to neutral => 0
this.pdf.internal.write("/" + font.id, (defaultFontSize * style["font-size"]).toFixed(2), "Tf", pdfStream); //set the word spacing back to neutral => 0

if (style["word-spacing"] !== undefined) {
this.pdf.internal.write(0, "Tw");
Expand Down Expand Up @@ -18700,11 +18746,10 @@
wantedIndent = this.pdf.internal.getCoordinateString(line[0][1]["margin-left"]);
indentMove = wantedIndent - currentIndent;
currentIndent = wantedIndent;
}
} //move the cursor

var indentMore = Math.max(blockstyle["margin-left"] || 0, 0) * fontToUnitRatio; //move the cursor

out(indentMove + indentMore, (-1 * defaultFontSize * maxLineHeight).toFixed(2), "Td");
out(indentMove, (-1 * defaultFontSize * maxLineHeight).toFixed(2), "Td");
i = 0;
l = line.length;

Expand Down
Loading