Skip to content

Commit 4952bd2

Browse files
committed
New dist files with updated basic example
1 parent 9ca4a6d commit 4952bd2

File tree

4 files changed

+160
-25
lines changed

4 files changed

+160
-25
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jspdf",
3-
"version": "1.0.119",
3+
"version": "1.0.131",
44
"homepage": "https://github.com/mrrio/jspdf",
55
"description": "PDF Document creation from JavaScript",
66
"main": "dist/jspdf.min.js",

dist/jspdf.debug.js

Lines changed: 132 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @preserve
22
* jsPDF - PDF Document creation from JavaScript
3-
* Version 1.0.119-git Built on 2014-04-29T03:48
4-
* CommitID 119a246e55
3+
* Version 1.0.131-git Built on 2014-05-11T20:51
4+
* CommitID 9ca4a6ded0
55
*
66
* Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
77
* 2010 Aaron Spike, https://github.com/acspike
@@ -1693,7 +1693,7 @@ var jsPDF = (function(global) {
16931693
* pdfdoc.mymethod() // <- !!!!!!
16941694
*/
16951695
jsPDF.API = {events:[]};
1696-
jsPDF.version = "1.0.119-debug 2014-04-29T03:48:diegocr";
1696+
jsPDF.version = "1.0.131-debug 2014-05-11T20:51:diegocr";
16971697

16981698
if (typeof define === 'function') {
16991699
define(function() {
@@ -2831,6 +2831,7 @@ var jsPDF = (function(global) {
28312831
* Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
28322832
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
28332833
* 2014 Diego Casorran, https://github.com/diegocr
2834+
* 2014 Daniel Husar, https://github.com/danielhusar
28342835
*
28352836
* Permission is hereby granted, free of charge, to any person obtaining
28362837
* a copy of this software and associated documentation files (the
@@ -2854,7 +2855,11 @@ var jsPDF = (function(global) {
28542855
*/
28552856

28562857
(function(jsPDFAPI) {
2857-
var DrillForContent, FontNameDB, FontStyleMap, FontWeightMap, GetCSS, PurgeWhiteSpace, Renderer, ResolveFont, ResolveUnitedNumber, UnitedNumberMap, elementHandledElsewhere, images, loadImgs, process, tableToJson;
2858+
var clone,DrillForContent, FontNameDB, FontStyleMap, FontWeightMap, GetCSS, PurgeWhiteSpace, Renderer, ResolveFont, ResolveUnitedNumber, UnitedNumberMap, elementHandledElsewhere, images, loadImgs, process, tableToJson;
2859+
clone = (function(){
2860+
return function (obj) { Clone.prototype=obj; return new Clone() };
2861+
function Clone(){}
2862+
}());
28582863
PurgeWhiteSpace = function(array) {
28592864
var fragment, i, l, lTrimmed, r, rTrimmed, trailingSpace;
28602865
i = 0;
@@ -2913,6 +2918,16 @@ var jsPDF = (function(global) {
29132918
return name;
29142919
};
29152920
ResolveUnitedNumber = function(css_line_height_string) {
2921+
2922+
//IE8 issues
2923+
css_line_height_string = css_line_height_string === "auto" ? "0px" : css_line_height_string;
2924+
if (css_line_height_string.indexOf("em") > -1 && !isNaN(Number(css_line_height_string.replace("em", "")))) {
2925+
css_line_height_string = Number(css_line_height_string.replace("em", "")) * 18.719 + "px";
2926+
}
2927+
if (css_line_height_string.indexOf("pt") > -1 && !isNaN(Number(css_line_height_string.replace("pt", "")))) {
2928+
css_line_height_string = Number(css_line_height_string.replace("pt", "")) * 1.333 + "px";
2929+
}
2930+
29162931
var normal, undef, value;
29172932
undef = void 0;
29182933
normal = 16.00;
@@ -2968,6 +2983,7 @@ var jsPDF = (function(global) {
29682983
tmp = void 0;
29692984
css["font-family"] = ResolveFont(computedCSSElement("font-family")) || "times";
29702985
css["font-style"] = FontStyleMap[computedCSSElement("font-style")] || "normal";
2986+
css["text-align"] = TextAlignMap[computedCSSElement("text-align")] || "left";
29712987
tmp = FontWeightMap[computedCSSElement("font-weight")] || "normal";
29722988
if (tmp === "bold") {
29732989
if (css["font-style"] === "normal") {
@@ -3065,8 +3081,9 @@ var jsPDF = (function(global) {
30653081
OBJECT : 1,
30663082
EMBED : 1
30673083
};
3084+
var listCount = 1;
30683085
DrillForContent = function(element, renderer, elementHandlers) {
3069-
var cn, cns, fragmentCSS, i, isBlock, l, px2pt, table2json;
3086+
var cn, cns, fragmentCSS, i, isBlock, l, px2pt, table2json, cb;
30703087
cns = element.childNodes;
30713088
cn = void 0;
30723089
fragmentCSS = GetCSS(element);
@@ -3103,21 +3120,51 @@ var jsPDF = (function(global) {
31033120
margins: renderer.pdf.margins_doc
31043121
});
31053122
renderer.y = renderer.pdf.lastCellPos.y + renderer.pdf.lastCellPos.h + 20;
3123+
} else if (cn.nodeName === "OL" || cn.nodeName === "UL") {
3124+
listCount = 1;
3125+
if (!elementHandledElsewhere(cn, renderer, elementHandlers)) {
3126+
DrillForContent(cn, renderer, elementHandlers);
3127+
}
3128+
renderer.y += 10;
3129+
} else if (cn.nodeName === "LI") {
3130+
var temp = renderer.x;
3131+
renderer.x += cn.parentNode.nodeName === "UL" ? 22 : 10;
3132+
renderer.y += 3;
3133+
if (!elementHandledElsewhere(cn, renderer, elementHandlers)) {
3134+
DrillForContent(cn, renderer, elementHandlers);
3135+
}
3136+
renderer.x = temp;
31063137
} else {
31073138
if (!elementHandledElsewhere(cn, renderer, elementHandlers)) {
31083139
DrillForContent(cn, renderer, elementHandlers);
31093140
}
31103141
}
31113142
} else if (cn.nodeType === 3) {
3112-
renderer.addText(cn.nodeValue, fragmentCSS);
3143+
var value = cn.nodeValue;
3144+
if (cn.nodeValue && cn.parentNode.nodeName === "LI") {
3145+
if (cn.parentNode.parentNode.nodeName === "OL") {
3146+
value = listCount++ + '. ' + value;
3147+
} else {
3148+
var fontPx = fragmentCSS["font-size"] * 16;
3149+
var radius = 2;
3150+
if(fontPx > 20){
3151+
radius = 3;
3152+
}
3153+
cb = function(x, y){
3154+
this.pdf.circle(x, y, radius, 'FD');
3155+
};
3156+
}
3157+
}
3158+
renderer.addText(value, fragmentCSS);
31133159
} else if (typeof cn === "string") {
31143160
renderer.addText(cn, fragmentCSS);
31153161
}
31163162
}
31173163
i++;
31183164
}
3165+
31193166
if (isBlock) {
3120-
return renderer.setBlockBoundary();
3167+
return renderer.setBlockBoundary(cb);
31213168
}
31223169
};
31233170
images = {};
@@ -3227,8 +3274,36 @@ var jsPDF = (function(global) {
32273274
}
32283275
}
32293276
}
3277+
3278+
//if text alignment was set, set margin/indent of each line
3279+
if (style['text-align'] !== undefined && (style['text-align'] === 'center' || style['text-align'] === 'right' || style['text-align'] === 'justify')) {
3280+
for(var i = 0; i < lines.length; ++i) {
3281+
var length = this.pdf.getStringUnitWidth(lines[i][0][0], fragmentSpecificMetrics) * fragmentSpecificMetrics.fontSize / k;
3282+
//if there is more than on line we have to clone the style object as all lines hold a reference on this object
3283+
if (i > 0) {
3284+
lines[i][0][1] = clone(lines[i][0][1]);
3285+
}
3286+
var space = (maxLineLength-length);
3287+
3288+
if (style['text-align'] === 'right') {
3289+
lines[i][0][1]['margin-left'] = space;
3290+
//if alignment is not right, it has to be center so split the space to the left and the right
3291+
} else if (style['text-align'] === 'center') {
3292+
lines[i][0][1]['margin-left'] = space/2;
3293+
//if justify was set, calculate the word spacing and define in by using the css property
3294+
} else if (style['text-align'] === 'justify') {
3295+
var countSpaces = lines[i][0][0].split(' ').length-1;
3296+
lines[i][0][1]['word-spacing'] = space/countSpaces;
3297+
//ignore the last line in justify mode
3298+
if (i === (lines.length-1)) {
3299+
lines[i][0][1]['word-spacing'] = 0;
3300+
}
3301+
}
3302+
}
3303+
}
3304+
32303305
return lines;
3231-
};
3306+
};
32323307
Renderer.prototype.RenderTextFragment = function(text, style) {
32333308
var defaultFontSize, font;
32343309
if (this.pdf.internal.pageSize.height - this.pdf.margins_doc.bottom < this.y + this.pdf.internal.getFontSize()) {
@@ -3239,10 +3314,22 @@ var jsPDF = (function(global) {
32393314
}
32403315
defaultFontSize = 12;
32413316
font = this.pdf.internal.getFont(style["font-family"], style["font-style"]);
3242-
return this.pdf.internal.write("/" + font.id, (defaultFontSize * style["font-size"]).toFixed(2), "Tf", "(" + this.pdf.internal.pdfEscape(text) + ") Tj");
3317+
3318+
//set the word spacing for e.g. justify style
3319+
if (style['word-spacing'] !== undefined && style['word-spacing'] > 0) {
3320+
this.pdf.internal.write(style['word-spacing'].toFixed(2), "Tw");
3321+
}
3322+
3323+
this.pdf.internal.write("/" + font.id, (defaultFontSize * style["font-size"]).toFixed(2), "Tf", "(" + this.pdf.internal.pdfEscape(text) + ") Tj");
3324+
3325+
//set the word spacing back to neutral => 0
3326+
if (style['word-spacing'] !== undefined) {
3327+
this.pdf.internal.write(0, "Tw");
3328+
}
3329+
32433330
};
3244-
Renderer.prototype.renderParagraph = function() {
3245-
var blockstyle, defaultFontSize, fontToUnitRatio, fragments, i, l, line, lines, maxLineHeight, out, paragraphspacing_after, paragraphspacing_before, priorblockstype, styles;
3331+
Renderer.prototype.renderParagraph = function(cb) {
3332+
var blockstyle, defaultFontSize, fontToUnitRatio, fragments, i, l, line, lines, maxLineHeight, out, paragraphspacing_after, paragraphspacing_before, priorblockstype, styles, fontSize;
32463333
fragments = PurgeWhiteSpace(this.paragraph.text);
32473334
styles = this.paragraph.style;
32483335
blockstyle = this.paragraph.blockstyle;
@@ -3268,18 +3355,32 @@ var jsPDF = (function(global) {
32683355
l = void 0;
32693356
this.y += paragraphspacing_before;
32703357
out("q", "BT", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), "Td");
3271-
while (lines.length) {
3358+
3359+
//stores the current indent of cursor position
3360+
var currentIndent = 0;
3361+
3362+
while (lines.length) {
32723363
line = lines.shift();
32733364
maxLineHeight = 0;
32743365
i = 0;
32753366
l = line.length;
32763367
while (i !== l) {
32773368
if (line[i][0].trim()) {
32783369
maxLineHeight = Math.max(maxLineHeight, line[i][1]["line-height"], line[i][1]["font-size"]);
3370+
fontSize = line[i][1]["font-size"] * 7;
32793371
}
32803372
i++;
32813373
}
3282-
out(0, (-1 * defaultFontSize * maxLineHeight).toFixed(2), "Td");
3374+
//if we have to move the cursor to adapt the indent
3375+
var indentMove = 0;
3376+
//if a margin was added (by e.g. a text-alignment), move the cursor
3377+
if (line[0][1]["margin-left"] !== undefined && line[0][1]["margin-left"] > 0) {
3378+
wantedIndent = this.pdf.internal.getCoordinateString(line[0][1]["margin-left"]);
3379+
indentMove = wantedIndent-currentIndent;
3380+
currentIndent = wantedIndent;
3381+
}
3382+
//move the cursor
3383+
out(indentMove, (-1 * defaultFontSize * maxLineHeight).toFixed(2), "Td");
32833384
i = 0;
32843385
l = line.length;
32853386
while (i !== l) {
@@ -3290,11 +3391,14 @@ var jsPDF = (function(global) {
32903391
}
32913392
this.y += maxLineHeight * fontToUnitRatio;
32923393
}
3394+
if (cb && typeof cb === "function") {
3395+
cb.call(this, this.x - 9, this.y - fontSize/2);
3396+
}
32933397
out("ET", "Q");
32943398
return this.y += paragraphspacing_after;
32953399
};
3296-
Renderer.prototype.setBlockBoundary = function() {
3297-
return this.renderParagraph();
3400+
Renderer.prototype.setBlockBoundary = function(cb) {
3401+
return this.renderParagraph(cb);
32983402
};
32993403
Renderer.prototype.setBlockStyle = function(css) {
33003404
return this.paragraph.blockstyle = css;
@@ -3332,6 +3436,12 @@ var jsPDF = (function(global) {
33323436
italic: "italic",
33333437
oblique: "italic"
33343438
};
3439+
TextAlignMap = {
3440+
left: "left",
3441+
right: "right",
3442+
center: "center",
3443+
justify: "justify"
3444+
};
33353445
UnitedNumberMap = {
33363446
normal: 1
33373447
/*
@@ -8586,6 +8696,13 @@ var FlateStream = (function() {
85868696
};
85878697
}
85888698

8699+
8700+
if(!Array.isArray) {
8701+
Array.isArray = function(arg) {
8702+
return Object.prototype.toString.call(arg) === '[object Array]';
8703+
};
8704+
}
8705+
85898706
if (!Array.prototype.forEach) {
85908707
Array.prototype.forEach = function(fun, thisArg) {
85918708
"use strict";

dist/jspdf.min.js

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/basic.html

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ <h2 style="font-size:120%">Header Two</h2>
213213
<p style="font-size:120%">This is a <em style="font-size:120%">new</em> paragraph.</p>
214214
This is more wrapping-less text.
215215
<p id="bypassme" style="font-size:120%">This paragraph will <strong style="font-size:120%">NOT</strong> be on resulting PDF because a special attached element handler will be looking for the ID - 'bypassme' - and should bypass rendering it.</p>
216-
<p style="font-size:120%">This is <strong style="font-size:120%">another</strong> paragraph.</p>
217-
<p>
216+
<p style="font-size:120%;text-align:center">This is <strong style="font-size:120%">another</strong> paragraph.</p>
217+
<p style="text-align:justify">
218218
Integer dignissim urna tortor? Cum rhoncus, a lacus ultricies tincidunt, tristique lundium enim urna, magna? Sed, enim penatibus? Lacus pellentesque integer et pulvinar tortor? Dapibus in arcu arcu, vut dolor? Et! Placerat pulvinar cursus, urna ultrices arcu nunc, a ultrices dictumst elementum? Magnis rhoncus pellentesque, egestas enim purus, augue et nascetur sociis enim rhoncus. Adipiscing augue placerat tincidunt pulvinar ridiculus. Porta in sociis arcu et placerat augue sit enim nec hac massa, turpis ridiculus nunc phasellus pulvinar proin sit pulvinar, ultrices aliquet placerat amet? Lorem nunc porttitor etiam risus tempor placerat amet non hac, nunc sed odio augue? Turpis, magnis. Lorem pid, a porttitor tincidunt adipiscing sagittis pellentesque, mattis amet, duis proin, penatibus lectus lorem eros, nisi, tempor phasellus, elit.
219219
</p>
220220
<h2>Image Support</h2>
@@ -225,7 +225,7 @@ <h2>Image Support</h2>
225225
<!-- ADD_PAGE -->
226226
<h2>New page added with html comment: ADD_PAGE</h2>
227227
<h2></h2>
228-
<p>HTML table</>
228+
<p>HTML Table:</p>
229229
<p>
230230
NOTES: Must set the COLGROUP tag with "with" on each COL tag as %, inspect the table. BTW the css does not have a good style to render the table on the html :P, feel free to the add the CSS.
231231
</p>
@@ -279,6 +279,23 @@ <h2></h2>
279279
</tr>
280280
</tvody>
281281
</table>
282+
<h2></h2>
283+
<h2></h2>
284+
<p>HTML Lists:</p>
285+
<div style="margin-left:20px">
286+
<ul>
287+
<li>Lorem Ipsum</li>
288+
<li>Dolor Sit amen</li>
289+
<li>Lorem Ipsum</li>
290+
<li>Dolor Sit amen</li>
291+
</ul>
292+
<ol>
293+
<li>Lorem Ipsum</li>
294+
<li>Dolor Sit amen</li>
295+
<li>Lorem Ipsum</li>
296+
<li>Dolor Sit amen</li>
297+
</ol>
298+
</div>
282299
</div>
283300
<div><p><pre>var pdf = new jsPDF('p', 'pt', 'letter')
284301

0 commit comments

Comments
 (0)