backgroundSize needs trimmed before second split

also move trimText to Util
This commit is contained in:
Andy Edinborough 2013-01-02 10:39:00 -06:00
parent 9ce03d6e86
commit 57d6003b65
2 changed files with 18 additions and 13 deletions

View File

@ -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 ];

View File

@ -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"]);