mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
backgroundSize needs trimmed before second split
also move trimText to Util
This commit is contained in:
parent
9ce03d6e86
commit
57d6003b65
11
src/Core.js
11
src/Core.js
@ -14,6 +14,13 @@ function h2clog(a) {
|
|||||||
|
|
||||||
_html2canvas.Util = {};
|
_html2canvas.Util = {};
|
||||||
|
|
||||||
|
_html2canvas.Util.trimText = (function(native){
|
||||||
|
return function(input){
|
||||||
|
if(native) { return native.apply( input ); }
|
||||||
|
else { return ((input || '') + '').replace( /^\s+|\s+$/ , '' ); }
|
||||||
|
};
|
||||||
|
})( String.prototype.trim );
|
||||||
|
|
||||||
_html2canvas.Util.parseBackgroundImage = function (value) {
|
_html2canvas.Util.parseBackgroundImage = function (value) {
|
||||||
var whitespace = ' \r\n\t',
|
var whitespace = ' \r\n\t',
|
||||||
method, definition, prefix, prefix_i, block, results = [],
|
method, definition, prefix, prefix_i, block, results = [],
|
||||||
@ -190,8 +197,10 @@ _html2canvas.Util.getCSS = function (el, attribute, index) {
|
|||||||
if ( isBackgroundSizePosition ) {
|
if ( isBackgroundSizePosition ) {
|
||||||
val = (val || '').split( ',' );
|
val = (val || '').split( ',' );
|
||||||
val = val[index || 0] || val[0] || 'auto';
|
val = val[index || 0] || val[0] || 'auto';
|
||||||
val = val.split(' ');
|
val = _html2canvas.Util.trimText( val ).split( ' ' );
|
||||||
|
|
||||||
if(attribute === 'backgroundSize' && (!val[ 0 ] || val[ 0 ].match( /cover|contain|auto/ ))) {
|
if(attribute === 'backgroundSize' && (!val[ 0 ] || val[ 0 ].match( /cover|contain|auto/ ))) {
|
||||||
|
//these values will be handled in the parent function
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
val[ 0 ] = ( val[ 0 ].indexOf( "%" ) === -1 ) ? toPX( attribute + "X", val[ 0 ] ) : val[ 0 ];
|
val[ 0 ] = ( val[ 0 ].indexOf( "%" ) === -1 ) ? toPX( attribute + "X", val[ 0 ] ) : val[ 0 ];
|
||||||
|
10
src/Parse.js
10
src/Parse.js
@ -61,12 +61,8 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
return (/^(normal|none|0px)$/.test(letter_spacing));
|
return (/^(normal|none|0px)$/.test(letter_spacing));
|
||||||
}
|
}
|
||||||
|
|
||||||
function trimText (text) {
|
|
||||||
return text.replace(/^\s*/g, "").replace(/\s*$/g, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawText(currentText, x, y, ctx){
|
function drawText(currentText, x, y, ctx){
|
||||||
if (currentText !== null && trimText(currentText).length > 0) {
|
if (currentText !== null && _html2canvas.Util.trimText(currentText).length > 0) {
|
||||||
ctx.fillText(currentText, x, y);
|
ctx.fillText(currentText, x, y);
|
||||||
numDraws+=1;
|
numDraws+=1;
|
||||||
}
|
}
|
||||||
@ -116,7 +112,7 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
function getTextBounds(state, text, textDecoration, isLast) {
|
function getTextBounds(state, text, textDecoration, isLast) {
|
||||||
var bounds;
|
var bounds;
|
||||||
if (support.rangeBounds) {
|
if (support.rangeBounds) {
|
||||||
if (textDecoration !== "none" || trimText(text).length !== 0) {
|
if (textDecoration !== "none" || _html2canvas.Util.trimText(text).length !== 0) {
|
||||||
bounds = textRangeBounds(text, state.node, state.textOffset);
|
bounds = textRangeBounds(text, state.node, state.textOffset);
|
||||||
}
|
}
|
||||||
state.textOffset += text.length;
|
state.textOffset += text.length;
|
||||||
@ -160,7 +156,7 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
textOffset: 0
|
textOffset: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
if (trimText(textNode.nodeValue).length > 0) {
|
if (_html2canvas.Util.trimText(textNode.nodeValue).length > 0) {
|
||||||
textNode.nodeValue = textTransform(textNode.nodeValue, getCSS(el, "textTransform"));
|
textNode.nodeValue = textTransform(textNode.nodeValue, getCSS(el, "textTransform"));
|
||||||
textAlign = textAlign.replace(["-webkit-auto"],["auto"]);
|
textAlign = textAlign.replace(["-webkit-auto"],["auto"]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user