mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
fixed text draw issue for opera
This commit is contained in:
parent
e548851114
commit
71b0727125
@ -63,10 +63,14 @@ function html2canvas(el, userOptions) {
|
||||
|
||||
// test how to measure text bounding boxes
|
||||
this.useRangeBounds = false;
|
||||
|
||||
// Check disabled as Opera doesn't provide bounds.height/bottom even though it supports the method.
|
||||
// TODO take the check back into use, but fix the issue for Opera
|
||||
/*
|
||||
if (document.createRange){
|
||||
var r = document.createRange();
|
||||
this.useRangeBounds = new Boolean(r.getBoundingClientRect);
|
||||
}
|
||||
}*/
|
||||
|
||||
// Start script
|
||||
this.init();
|
||||
@ -143,6 +147,8 @@ html2canvas.prototype.start = function(){
|
||||
|
||||
if (this.images.length == 0 || this.imagesLoaded==this.images.length/2){
|
||||
this.log('Started parsing');
|
||||
this.bodyOverflow = document.getElementsByTagName('body')[0].style.overflow;
|
||||
document.getElementsByTagName('body')[0].style.overflow = "hidden";
|
||||
this.newElement(this.element);
|
||||
|
||||
this.parseElement(this.element);
|
||||
@ -157,6 +163,7 @@ html2canvas.prototype.start = function(){
|
||||
|
||||
html2canvas.prototype.finish = function(){
|
||||
this.log("Finished rendering");
|
||||
document.getElementsByTagName('body')[0].style.overflow = this.bodyOverflow;
|
||||
|
||||
if (this.opts.renderViewport){
|
||||
// let's crop it to viewport only then
|
||||
@ -507,6 +514,7 @@ html2canvas.prototype.printText = function(currentText,x,y){
|
||||
|
||||
// Drawing a rectangle
|
||||
html2canvas.prototype.newRect = function(x,y,w,h,bgcolor){
|
||||
|
||||
if (bgcolor!="transparent"){
|
||||
this.ctx.fillStyle = bgcolor;
|
||||
this.ctx.fillRect (x, y, w, h);
|
||||
@ -643,6 +651,10 @@ html2canvas.prototype.newText = function(el,textNode){
|
||||
wrapElement.appendChild(oldTextNode.cloneNode(true));
|
||||
parent.replaceChild(wrapElement,oldTextNode);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var bounds = this.getBounds(wrapElement);
|
||||
|
||||
|
||||
@ -652,6 +664,8 @@ html2canvas.prototype.newText = function(el,textNode){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
this.printText(oldTextNode.nodeValue,bounds.left,bounds.bottom);
|
||||
|
||||
switch(text_decoration) {
|
||||
|
5
build/html2canvas.min.js
vendored
5
build/html2canvas.min.js
vendored
@ -6,9 +6,10 @@
|
||||
* Released under MIT License
|
||||
*/
|
||||
|
||||
function html2canvas(a,b){this.opts=this.extendObj(b||{},{logging:!1,ready:function(a){document.body.appendChild(a)},renderViewport:!0});this.element=a;this.imagesLoaded=0;this.images=[];this.fontData=[];this.ignoreElements="IFRAME|OBJECT|PARAM";this.useRangeBounds=!1;if(document.createRange){var c=document.createRange();this.useRangeBounds=new Boolean(c.getBoundingClientRect)}this.init()}
|
||||
function html2canvas(a,b){this.opts=this.extendObj(b||{},{logging:!1,ready:function(a){document.body.appendChild(a)},renderViewport:!0});this.element=a;this.imagesLoaded=0;this.images=[];this.fontData=[];this.ignoreElements="IFRAME|OBJECT|PARAM";this.useRangeBounds=!1;this.init()}
|
||||
html2canvas.prototype.init=function(){var a=this;this.canvas=document.createElement("canvas");this.canvas.width=$(document).width();this.canvas.height=$(document).height()+10;if(this.canvas.getContext)this.ctx=this.canvas.getContext("2d");this.ctx?(this.ctx.textBaseline="bottom",this.log("Finding background images"),this.getImages(this.element),this.log("Finding images"),this.each(document.images,function(b,c){a.preloadImage(a.getAttr(c,"src"))}),this.images.length==0&&this.start()):this.log("Canvas not available")};
|
||||
html2canvas.prototype.start=function(){if(this.images.length==0||this.imagesLoaded==this.images.length/2)this.log("Started parsing"),this.newElement(this.element),this.parseElement(this.element)};html2canvas.prototype.finish=function(){this.log("Finished rendering");if(this.opts.renderViewport){var a=document.createElement("canvas");a.getContext("2d");a.width=window.innerWidth;a.height=window.innerHeight}this.opts.ready(this.canvas)};
|
||||
html2canvas.prototype.start=function(){if(this.images.length==0||this.imagesLoaded==this.images.length/2)this.log("Started parsing"),this.bodyOverflow=document.getElementsByTagName("body")[0].style.overflow,document.getElementsByTagName("body")[0].style.overflow="hidden",this.newElement(this.element),this.parseElement(this.element)};
|
||||
html2canvas.prototype.finish=function(){this.log("Finished rendering");document.getElementsByTagName("body")[0].style.overflow=this.bodyOverflow;if(this.opts.renderViewport){var a=document.createElement("canvas");a.getContext("2d");a.width=window.innerWidth;a.height=window.innerHeight}this.opts.ready(this.canvas)};
|
||||
html2canvas.prototype.drawBackground=function(a,b){var c=this.getCSS(a,"background-image"),e=this.getCSS(a,"background-repeat");if(typeof c!="undefined"&&/^(1|none)$/.test(c)==!1){var c=this.backgroundImageUrl(c),d=this.loadImage(c),h=this.getBackgroundPosition(a,b,d);if(d)switch(e){case "repeat-x":this.drawbackgroundRepeatX(d,h,b.left,b.top,b.width,b.height);break;case "repeat-y":this.drawbackgroundRepeatY(d,h,b.left,b.top,b.width,b.height);break;case "no-repeat":this.drawBackgroundRepeat(d,h.left+
|
||||
b.left,h.top+b.top,Math.min(b.width,d.width),Math.min(b.height,d.height),b.left,b.top);break;default:var g;h.top-=Math.ceil(h.top/d.height)*d.height;for(c=b.top+h.top;c<=b.height+b.top;)e=Math.min(d.height,b.height+b.top-c),e=Math.floor(c+d.height)>e+c?e+c-c:d.height,c<b.top?(g=b.top-c,c=b.top):g=0,this.drawbackgroundRepeatX(d,h,b.left,c,b.width,e),g>0&&(h.top+=g),c=Math.floor(c+d.height)-g}else this.log("Error loading background:"+c)}};
|
||||
html2canvas.prototype.backgroundImageUrl=function(a){a.substr(0,5)=='url("'?(a=a.substr(5),a=a.substr(0,a.length-2)):(a=a.substr(4),a=a.substr(0,a.length-1));return a};html2canvas.prototype.getBackgroundPosition=function(a,b,c){var e=this.getCSS(a,"background-position").split(" "),d;e[0].indexOf("%")!=-1?(d=parseFloat(e[0])/100,a=b.width*d-c.width*d):a=parseInt(e[0],10);e[1].indexOf("%")!=-1?(d=parseFloat(e[1])/100,b=b.height*d-c.height*d):b=parseInt(e[1],10);return{top:b,left:a}};
|
||||
|
@ -42,6 +42,7 @@
|
||||
timer = date.getTime();
|
||||
|
||||
new html2canvas(this.get(0), {
|
||||
loggine: true,
|
||||
ready: function(canvas) {
|
||||
|
||||
var finishTime = new Date();
|
||||
|
@ -33,10 +33,14 @@ function html2canvas(el, userOptions) {
|
||||
|
||||
// test how to measure text bounding boxes
|
||||
this.useRangeBounds = false;
|
||||
|
||||
// Check disabled as Opera doesn't provide bounds.height/bottom even though it supports the method.
|
||||
// TODO take the check back into use, but fix the issue for Opera
|
||||
/*
|
||||
if (document.createRange){
|
||||
var r = document.createRange();
|
||||
this.useRangeBounds = new Boolean(r.getBoundingClientRect);
|
||||
}
|
||||
}*/
|
||||
|
||||
// Start script
|
||||
this.init();
|
||||
@ -113,6 +117,8 @@ html2canvas.prototype.start = function(){
|
||||
|
||||
if (this.images.length == 0 || this.imagesLoaded==this.images.length/2){
|
||||
this.log('Started parsing');
|
||||
this.bodyOverflow = document.getElementsByTagName('body')[0].style.overflow;
|
||||
document.getElementsByTagName('body')[0].style.overflow = "hidden";
|
||||
this.newElement(this.element);
|
||||
|
||||
this.parseElement(this.element);
|
||||
@ -127,6 +133,7 @@ html2canvas.prototype.start = function(){
|
||||
|
||||
html2canvas.prototype.finish = function(){
|
||||
this.log("Finished rendering");
|
||||
document.getElementsByTagName('body')[0].style.overflow = this.bodyOverflow;
|
||||
|
||||
if (this.opts.renderViewport){
|
||||
// let's crop it to viewport only then
|
||||
|
@ -106,6 +106,7 @@ html2canvas.prototype.printText = function(currentText,x,y){
|
||||
|
||||
// Drawing a rectangle
|
||||
html2canvas.prototype.newRect = function(x,y,w,h,bgcolor){
|
||||
|
||||
if (bgcolor!="transparent"){
|
||||
this.ctx.fillStyle = bgcolor;
|
||||
this.ctx.fillRect (x, y, w, h);
|
||||
|
@ -61,6 +61,10 @@ html2canvas.prototype.newText = function(el,textNode){
|
||||
wrapElement.appendChild(oldTextNode.cloneNode(true));
|
||||
parent.replaceChild(wrapElement,oldTextNode);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var bounds = this.getBounds(wrapElement);
|
||||
|
||||
|
||||
@ -70,6 +74,8 @@ html2canvas.prototype.newText = function(el,textNode){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
this.printText(oldTextNode.nodeValue,bounds.left,bounds.bottom);
|
||||
|
||||
switch(text_decoration) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
timer = date.getTime();
|
||||
|
||||
new html2canvas(this.get(0), {
|
||||
loggine: true,
|
||||
ready: function(canvas) {
|
||||
|
||||
var finishTime = new Date();
|
||||
|
@ -15,6 +15,7 @@
|
||||
<script type="text/javascript" src="../build/jquery.plugin.html2canvas.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(window).ready(function() {
|
||||
|
||||
$('body').empty();
|
||||
$.each(['arial','verdana','tahoma','courier new'],function(i,e){
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user