Skip to content
Merged
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
13 changes: 9 additions & 4 deletions jspdf.plugin.from_html.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2014 Diego Casorran, https://github.com/diegocr
* 2014 Daniel Husar, https://github.com/danielhusar
* 2014 Wolfgang Gassler, https://github.com/woolfg
* 2014 Steven Spungin, https://github.com/flamenco
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -811,13 +812,13 @@
out,
paragraphspacing_after,
paragraphspacing_before,
priorblockstype,
priorblockstyle,
styles,
fontSize;
fragments = PurgeWhiteSpace(this.paragraph.text);
styles = this.paragraph.style;
blockstyle = this.paragraph.blockstyle;
priorblockstype = this.paragraph.blockstyle || {};
priorblockstyle = this.paragraph.priorblockstyle || {};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been priorblockstype AKA priorblockstyle. Yes?

Even with this change, code is not working. This method is sometimes called with phantom empty paragraphs that reset the state. Workaround is to use this.priorMarginBottom instead. That may not be best solution however.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, dunno.. i'm not familiar enough with that code, so i'll just assume you're correct, it indeed seems so :)

this.paragraph = {
text : [],
style : [],
Expand All @@ -832,8 +833,11 @@
maxLineHeight = void 0;
defaultFontSize = 12;
fontToUnitRatio = defaultFontSize / this.pdf.internal.scaleFactor;
paragraphspacing_before = (Math.max((blockstyle["margin-top"] || 0) - (priorblockstype["margin-bottom"] || 0), 0) + (blockstyle["padding-top"] || 0)) * fontToUnitRatio;
this.priorMarginBottom = this.priorMarginBottom || 0;
paragraphspacing_before = (Math.max((blockstyle["margin-top"] || 0) - this.priorMarginBottom, 0) + (blockstyle["padding-top"] || 0)) * fontToUnitRatio;
paragraphspacing_after = ((blockstyle["margin-bottom"] || 0) + (blockstyle["padding-bottom"] || 0)) * fontToUnitRatio;
this.priorMarginBottom = blockstyle["margin-bottom"] || 0;

out = this.pdf.internal.write;
i = void 0;
l = void 0;
Expand Down Expand Up @@ -863,8 +867,9 @@
indentMove = wantedIndent - currentIndent;
currentIndent = wantedIndent;
}
var indentMore = (Math.max(blockstyle["margin-left"] || 0, 0)) * fontToUnitRatio;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hack. It seems that margin-left is considered in the line margin logic, but not scaled. (Putting a giant value in will have an effect on the original code.)

//move the cursor
out(indentMove, (-1 * defaultFontSize * maxLineHeight).toFixed(2), "Td");
out(indentMove + indentMore, (-1 * defaultFontSize * maxLineHeight).toFixed(2), "Td");
i = 0;
l = line.length;
while (i !== l) {
Expand Down