|
76 | 76 | },
|
77 | 77 |
|
78 | 78 | setFillStyle : function(style) {
|
| 79 | + if (style.charAt(0) != '#') { |
| 80 | + style = this.internal.colorNameToHex(style); |
| 81 | + if (!style) { |
| 82 | + style = '#000000'; |
| 83 | + } |
| 84 | + } |
79 | 85 | this.ctx.fillStyle = style;
|
80 | 86 | var r = this.ctx.fillStyle.substring(1, 3);
|
81 | 87 | r = parseInt(r, 16);
|
|
88 | 94 | },
|
89 | 95 |
|
90 | 96 | setStrokeStyle : function(style) {
|
| 97 | + if (style.charAt(0) != '#') { |
| 98 | + style = this.internal.colorNameToHex(style); |
| 99 | + if (!style) { |
| 100 | + style = '#000000'; |
| 101 | + } |
| 102 | + } |
91 | 103 | this.ctx.strokeStyle = style;
|
92 | 104 | var r = this.ctx.strokeStyle.substring(1, 3);
|
93 | 105 | r = parseInt(r, 16);
|
|
177 | 189 | var rx = /data:image\/(\w+).*/i;
|
178 | 190 | var m = rx.exec(img);
|
179 | 191 | if (m != null) {
|
180 |
| - format = m[1] |
| 192 | + format = m[1]; |
181 | 193 | } else {
|
182 |
| - format = "jpeg"; |
| 194 | + //format = "jpeg"; |
| 195 | + format = "png"; |
183 | 196 | }
|
184 | 197 | this.pdf.addImage(img, format, x, y, w, h);
|
185 | 198 | },
|
|
271 | 284 |
|
272 | 285 | _getBaseline : function(y) {
|
273 | 286 | var height = parseInt(this.pdf.internal.getFontSize());
|
274 |
| - //TODO Get this from font |
| 287 | + //TODO Get descent from font descriptor |
275 | 288 | var descent = height * .25;
|
276 | 289 | switch (this.ctx.textBaseline) {
|
277 | 290 | case 'bottom':
|
|
283 | 296 | case 'middle':
|
284 | 297 | return y + height / 2 - descent;
|
285 | 298 | case 'ideographic':
|
| 299 | + //TODO not implemented |
286 | 300 | return y;
|
287 | 301 | case 'alphabetic':
|
288 | 302 | default:
|
|
421 | 435 | };
|
422 | 436 | }
|
423 | 437 |
|
424 |
| - return this; |
425 |
| -})(jsPDF.API); |
| 438 | + c2d.internal.colorNameToHex = function(color) { |
| 439 | + var colors = { |
| 440 | + "aliceblue" : "#f0f8ff", |
| 441 | + "antiquewhite" : "#faebd7", |
| 442 | + "aqua" : "#00ffff", |
| 443 | + "aquamarine" : "#7fffd4", |
| 444 | + "azure" : "#f0ffff", |
| 445 | + "beige" : "#f5f5dc", |
| 446 | + "bisque" : "#ffe4c4", |
| 447 | + "black" : "#000000", |
| 448 | + "blanchedalmond" : "#ffebcd", |
| 449 | + "blue" : "#0000ff", |
| 450 | + "blueviolet" : "#8a2be2", |
| 451 | + "brown" : "#a52a2a", |
| 452 | + "burlywood" : "#deb887", |
| 453 | + "cadetblue" : "#5f9ea0", |
| 454 | + "chartreuse" : "#7fff00", |
| 455 | + "chocolate" : "#d2691e", |
| 456 | + "coral" : "#ff7f50", |
| 457 | + "cornflowerblue" : "#6495ed", |
| 458 | + "cornsilk" : "#fff8dc", |
| 459 | + "crimson" : "#dc143c", |
| 460 | + "cyan" : "#00ffff", |
| 461 | + "darkblue" : "#00008b", |
| 462 | + "darkcyan" : "#008b8b", |
| 463 | + "darkgoldenrod" : "#b8860b", |
| 464 | + "darkgray" : "#a9a9a9", |
| 465 | + "darkgreen" : "#006400", |
| 466 | + "darkkhaki" : "#bdb76b", |
| 467 | + "darkmagenta" : "#8b008b", |
| 468 | + "darkolivegreen" : "#556b2f", |
| 469 | + "darkorange" : "#ff8c00", |
| 470 | + "darkorchid" : "#9932cc", |
| 471 | + "darkred" : "#8b0000", |
| 472 | + "darksalmon" : "#e9967a", |
| 473 | + "darkseagreen" : "#8fbc8f", |
| 474 | + "darkslateblue" : "#483d8b", |
| 475 | + "darkslategray" : "#2f4f4f", |
| 476 | + "darkturquoise" : "#00ced1", |
| 477 | + "darkviolet" : "#9400d3", |
| 478 | + "deeppink" : "#ff1493", |
| 479 | + "deepskyblue" : "#00bfff", |
| 480 | + "dimgray" : "#696969", |
| 481 | + "dodgerblue" : "#1e90ff", |
| 482 | + "firebrick" : "#b22222", |
| 483 | + "floralwhite" : "#fffaf0", |
| 484 | + "forestgreen" : "#228b22", |
| 485 | + "fuchsia" : "#ff00ff", |
| 486 | + "gainsboro" : "#dcdcdc", |
| 487 | + "ghostwhite" : "#f8f8ff", |
| 488 | + "gold" : "#ffd700", |
| 489 | + "goldenrod" : "#daa520", |
| 490 | + "gray" : "#808080", |
| 491 | + "green" : "#008000", |
| 492 | + "greenyellow" : "#adff2f", |
| 493 | + "honeydew" : "#f0fff0", |
| 494 | + "hotpink" : "#ff69b4", |
| 495 | + "indianred " : "#cd5c5c", |
| 496 | + "indigo" : "#4b0082", |
| 497 | + "ivory" : "#fffff0", |
| 498 | + "khaki" : "#f0e68c", |
| 499 | + "lavender" : "#e6e6fa", |
| 500 | + "lavenderblush" : "#fff0f5", |
| 501 | + "lawngreen" : "#7cfc00", |
| 502 | + "lemonchiffon" : "#fffacd", |
| 503 | + "lightblue" : "#add8e6", |
| 504 | + "lightcoral" : "#f08080", |
| 505 | + "lightcyan" : "#e0ffff", |
| 506 | + "lightgoldenrodyellow" : "#fafad2", |
| 507 | + "lightgrey" : "#d3d3d3", |
| 508 | + "lightgreen" : "#90ee90", |
| 509 | + "lightpink" : "#ffb6c1", |
| 510 | + "lightsalmon" : "#ffa07a", |
| 511 | + "lightseagreen" : "#20b2aa", |
| 512 | + "lightskyblue" : "#87cefa", |
| 513 | + "lightslategray" : "#778899", |
| 514 | + "lightsteelblue" : "#b0c4de", |
| 515 | + "lightyellow" : "#ffffe0", |
| 516 | + "lime" : "#00ff00", |
| 517 | + "limegreen" : "#32cd32", |
| 518 | + "linen" : "#faf0e6", |
| 519 | + "magenta" : "#ff00ff", |
| 520 | + "maroon" : "#800000", |
| 521 | + "mediumaquamarine" : "#66cdaa", |
| 522 | + "mediumblue" : "#0000cd", |
| 523 | + "mediumorchid" : "#ba55d3", |
| 524 | + "mediumpurple" : "#9370d8", |
| 525 | + "mediumseagreen" : "#3cb371", |
| 526 | + "mediumslateblue" : "#7b68ee", |
| 527 | + "mediumspringgreen" : "#00fa9a", |
| 528 | + "mediumturquoise" : "#48d1cc", |
| 529 | + "mediumvioletred" : "#c71585", |
| 530 | + "midnightblue" : "#191970", |
| 531 | + "mintcream" : "#f5fffa", |
| 532 | + "mistyrose" : "#ffe4e1", |
| 533 | + "moccasin" : "#ffe4b5", |
| 534 | + "navajowhite" : "#ffdead", |
| 535 | + "navy" : "#000080", |
| 536 | + "oldlace" : "#fdf5e6", |
| 537 | + "olive" : "#808000", |
| 538 | + "olivedrab" : "#6b8e23", |
| 539 | + "orange" : "#ffa500", |
| 540 | + "orangered" : "#ff4500", |
| 541 | + "orchid" : "#da70d6", |
| 542 | + "palegoldenrod" : "#eee8aa", |
| 543 | + "palegreen" : "#98fb98", |
| 544 | + "paleturquoise" : "#afeeee", |
| 545 | + "palevioletred" : "#d87093", |
| 546 | + "papayawhip" : "#ffefd5", |
| 547 | + "peachpuff" : "#ffdab9", |
| 548 | + "peru" : "#cd853f", |
| 549 | + "pink" : "#ffc0cb", |
| 550 | + "plum" : "#dda0dd", |
| 551 | + "powderblue" : "#b0e0e6", |
| 552 | + "purple" : "#800080", |
| 553 | + "red" : "#ff0000", |
| 554 | + "rosybrown" : "#bc8f8f", |
| 555 | + "royalblue" : "#4169e1", |
| 556 | + "saddlebrown" : "#8b4513", |
| 557 | + "salmon" : "#fa8072", |
| 558 | + "sandybrown" : "#f4a460", |
| 559 | + "seagreen" : "#2e8b57", |
| 560 | + "seashell" : "#fff5ee", |
| 561 | + "sienna" : "#a0522d", |
| 562 | + "silver" : "#c0c0c0", |
| 563 | + "skyblue" : "#87ceeb", |
| 564 | + "slateblue" : "#6a5acd", |
| 565 | + "slategray" : "#708090", |
| 566 | + "snow" : "#fffafa", |
| 567 | + "springgreen" : "#00ff7f", |
| 568 | + "steelblue" : "#4682b4", |
| 569 | + "tan" : "#d2b48c", |
| 570 | + "teal" : "#008080", |
| 571 | + "thistle" : "#d8bfd8", |
| 572 | + "tomato" : "#ff6347", |
| 573 | + "turquoise" : "#40e0d0", |
| 574 | + "violet" : "#ee82ee", |
| 575 | + "wheat" : "#f5deb3", |
| 576 | + "white" : "#ffffff", |
| 577 | + "whitesmoke" : "#f5f5f5", |
| 578 | + "yellow" : "#ffff00", |
| 579 | + "yellowgreen" : "#9acd32" |
| 580 | + }; |
426 | 581 |
|
427 |
| -function context() { |
428 |
| - this.fillStyle = '#000000'; |
429 |
| - this.strokeStyle = '#000000'; |
430 |
| - this.font = "12pt times"; |
431 |
| - this.textBaseline = 'alphabetic'; //top,bottom,middle,ideographic,alphabetic,hanging |
432 |
| - this.lineWidth = 1; |
433 |
| - this.lineJoin = 'miter'; //round, bevel, miter |
434 |
| - this.lineCap = 'butt'; //butt, round, square |
435 |
| - //TODO miter limit //default 10 |
436 |
| - |
437 |
| - this.copy = function(ctx) { |
438 |
| - this.fillStyle = ctx.fillStyle; |
439 |
| - this.strokeStyle = ctx.strokeStyle; |
440 |
| - this.font = ctx.font; |
441 |
| - this.lineWidth = ctx.lineWidth; |
442 |
| - this.lineJoin = ctx.lineJoin; |
443 |
| - this.lineCap = ctx.lineCap; |
444 |
| - this.textBaseline = ctx.textBaseline; |
445 |
| - this._fontSize = ctx._fontSize; |
| 582 | + if (typeof colors[color.toLowerCase()] != 'undefined') |
| 583 | + return colors[color.toLowerCase()]; |
| 584 | + |
| 585 | + return false; |
446 | 586 | };
|
447 |
| -} |
| 587 | + |
| 588 | + function context() { |
| 589 | + this.fillStyle = '#000000'; |
| 590 | + this.strokeStyle = '#000000'; |
| 591 | + this.font = "12pt times"; |
| 592 | + this.textBaseline = 'alphabetic'; //top,bottom,middle,ideographic,alphabetic,hanging |
| 593 | + this.lineWidth = 1; |
| 594 | + this.lineJoin = 'miter'; //round, bevel, miter |
| 595 | + this.lineCap = 'butt'; //butt, round, square |
| 596 | + //TODO miter limit //default 10 |
| 597 | + |
| 598 | + this.copy = function(ctx) { |
| 599 | + this.fillStyle = ctx.fillStyle; |
| 600 | + this.strokeStyle = ctx.strokeStyle; |
| 601 | + this.font = ctx.font; |
| 602 | + this.lineWidth = ctx.lineWidth; |
| 603 | + this.lineJoin = ctx.lineJoin; |
| 604 | + this.lineCap = ctx.lineCap; |
| 605 | + this.textBaseline = ctx.textBaseline; |
| 606 | + this._fontSize = ctx._fontSize; |
| 607 | + }; |
| 608 | + } |
| 609 | + |
| 610 | + return this; |
| 611 | +})(jsPDF.API); |
0 commit comments