|
3 | 3 | * Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
|
4 | 4 | * 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
|
5 | 5 | * 2014 Diego Casorran, https://github.com/diegocr
|
| 6 | + * 2014 Daniel Husar, https://github.com/danielhusar |
6 | 7 | *
|
7 | 8 | * Permission is hereby granted, free of charge, to any person obtaining
|
8 | 9 | * a copy of this software and associated documentation files (the
|
|
85 | 86 | return name;
|
86 | 87 | };
|
87 | 88 | ResolveUnitedNumber = function(css_line_height_string) {
|
| 89 | + |
| 90 | + //IE8 issues |
| 91 | + css_line_height_string = css_line_height_string === "auto" ? "0px" : css_line_height_string; |
| 92 | + if (css_line_height_string.indexOf("em") > -1 && !isNaN(Number(css_line_height_string.replace("em", "")))) { |
| 93 | + css_line_height_string = Number(css_line_height_string.replace("em", "")) * 18.719 + "px"; |
| 94 | + } |
| 95 | + if (css_line_height_string.indexOf("pt") > -1 && !isNaN(Number(css_line_height_string.replace("pt", "")))) { |
| 96 | + css_line_height_string = Number(css_line_height_string.replace("pt", "")) * 1.333 + "px"; |
| 97 | + } |
| 98 | + |
88 | 99 | var normal, undef, value;
|
89 | 100 | undef = void 0;
|
90 | 101 | normal = 16.00;
|
|
237 | 248 | OBJECT : 1,
|
238 | 249 | EMBED : 1
|
239 | 250 | };
|
| 251 | + var listCount = 1; |
240 | 252 | DrillForContent = function(element, renderer, elementHandlers) {
|
241 |
| - var cn, cns, fragmentCSS, i, isBlock, l, px2pt, table2json; |
| 253 | + var cn, cns, fragmentCSS, i, isBlock, l, px2pt, table2json, cb; |
242 | 254 | cns = element.childNodes;
|
243 | 255 | cn = void 0;
|
244 | 256 | fragmentCSS = GetCSS(element);
|
|
275 | 287 | margins: renderer.pdf.margins_doc
|
276 | 288 | });
|
277 | 289 | renderer.y = renderer.pdf.lastCellPos.y + renderer.pdf.lastCellPos.h + 20;
|
| 290 | + } else if (cn.nodeName === "OL" || cn.nodeName === "UL") { |
| 291 | + listCount = 1; |
| 292 | + if (!elementHandledElsewhere(cn, renderer, elementHandlers)) { |
| 293 | + DrillForContent(cn, renderer, elementHandlers); |
| 294 | + } |
| 295 | + renderer.y += 10; |
| 296 | + } else if (cn.nodeName === "LI") { |
| 297 | + var temp = renderer.x; |
| 298 | + renderer.x += cn.parentNode.nodeName === "UL" ? 22 : 10; |
| 299 | + renderer.y += 3; |
| 300 | + if (!elementHandledElsewhere(cn, renderer, elementHandlers)) { |
| 301 | + DrillForContent(cn, renderer, elementHandlers); |
| 302 | + } |
| 303 | + renderer.x = temp; |
278 | 304 | } else {
|
279 | 305 | if (!elementHandledElsewhere(cn, renderer, elementHandlers)) {
|
280 | 306 | DrillForContent(cn, renderer, elementHandlers);
|
281 | 307 | }
|
282 | 308 | }
|
283 | 309 | } else if (cn.nodeType === 3) {
|
284 |
| - renderer.addText(cn.nodeValue, fragmentCSS); |
| 310 | + var value = cn.nodeValue; |
| 311 | + if (cn.nodeValue && cn.parentNode.nodeName === "LI") { |
| 312 | + if (cn.parentNode.parentNode.nodeName === "OL") { |
| 313 | + value = listCount++ + '. ' + value; |
| 314 | + } else { |
| 315 | + var fontPx = fragmentCSS["font-size"] * 16; |
| 316 | + var radius = 2; |
| 317 | + if(fontPx > 20){ |
| 318 | + radius = 3; |
| 319 | + } |
| 320 | + cb = function(x, y){ |
| 321 | + this.pdf.circle(x, y, radius, 'FD'); |
| 322 | + }; |
| 323 | + } |
| 324 | + } |
| 325 | + renderer.addText(value, fragmentCSS); |
285 | 326 | } else if (typeof cn === "string") {
|
286 | 327 | renderer.addText(cn, fragmentCSS);
|
287 | 328 | }
|
288 | 329 | }
|
289 | 330 | i++;
|
290 | 331 | }
|
| 332 | + |
291 | 333 | if (isBlock) {
|
292 |
| - return renderer.setBlockBoundary(); |
| 334 | + return renderer.setBlockBoundary(cb); |
293 | 335 | }
|
294 | 336 | };
|
295 | 337 | images = {};
|
|
413 | 455 | font = this.pdf.internal.getFont(style["font-family"], style["font-style"]);
|
414 | 456 | return this.pdf.internal.write("/" + font.id, (defaultFontSize * style["font-size"]).toFixed(2), "Tf", "(" + this.pdf.internal.pdfEscape(text) + ") Tj");
|
415 | 457 | };
|
416 |
| - Renderer.prototype.renderParagraph = function() { |
417 |
| - var blockstyle, defaultFontSize, fontToUnitRatio, fragments, i, l, line, lines, maxLineHeight, out, paragraphspacing_after, paragraphspacing_before, priorblockstype, styles; |
| 458 | + Renderer.prototype.renderParagraph = function(cb) { |
| 459 | + var blockstyle, defaultFontSize, fontToUnitRatio, fragments, i, l, line, lines, maxLineHeight, out, paragraphspacing_after, paragraphspacing_before, priorblockstype, styles, fontSize; |
418 | 460 | fragments = PurgeWhiteSpace(this.paragraph.text);
|
419 | 461 | styles = this.paragraph.style;
|
420 | 462 | blockstyle = this.paragraph.blockstyle;
|
|
448 | 490 | while (i !== l) {
|
449 | 491 | if (line[i][0].trim()) {
|
450 | 492 | maxLineHeight = Math.max(maxLineHeight, line[i][1]["line-height"], line[i][1]["font-size"]);
|
| 493 | + fontSize = line[i][1]["font-size"] * 7; |
451 | 494 | }
|
452 | 495 | i++;
|
453 | 496 | }
|
|
462 | 505 | }
|
463 | 506 | this.y += maxLineHeight * fontToUnitRatio;
|
464 | 507 | }
|
| 508 | + if (cb && typeof cb === "function") { |
| 509 | + cb.call(this, this.x - 9, this.y - fontSize/2); |
| 510 | + } |
465 | 511 | out("ET", "Q");
|
466 | 512 | return this.y += paragraphspacing_after;
|
467 | 513 | };
|
468 |
| - Renderer.prototype.setBlockBoundary = function() { |
469 |
| - return this.renderParagraph(); |
| 514 | + Renderer.prototype.setBlockBoundary = function(cb) { |
| 515 | + return this.renderParagraph(cb); |
470 | 516 | };
|
471 | 517 | Renderer.prototype.setBlockStyle = function(css) {
|
472 | 518 | return this.paragraph.blockstyle = css;
|
|
0 commit comments