List refactoring

This commit is contained in:
MoyuScript 2012-11-25 23:36:28 +02:00
parent 7b26e80cd8
commit d89c37223a

View File

@ -114,20 +114,16 @@ _html2canvas.Parse = function ( images, options ) {
switch(transform){ switch(transform){
case "lowercase": case "lowercase":
return text.toLowerCase(); return text.toLowerCase();
case "capitalize": case "capitalize":
return text.replace( /(^|\s|:|-|\(|\))([a-z])/g , function (m, p1, p2) { return text.replace( /(^|\s|:|-|\(|\))([a-z])/g , function (m, p1, p2) {
if (m.length > 0) { if (m.length > 0) {
return p1 + p2.toUpperCase(); return p1 + p2.toUpperCase();
} }
} ); } );
case "uppercase": case "uppercase":
return text.toUpperCase(); return text.toUpperCase();
default: default:
return text; return text;
} }
} }
@ -381,30 +377,15 @@ _html2canvas.Parse = function ( images, options ) {
} }
function renderListItem(element, stack, elBounds) { function listItemText(element, type) {
var position = getCSS(element, "listStylePosition"), var currentIndex = elementIndex(element),
x, text;
y,
type = getCSS(element, "listStyleType"),
currentIndex,
text,
listBounds,
bold = getCSS(element, "fontWeight");
if (/^(decimal|decimal-leading-zero|upper-alpha|upper-latin|upper-roman|lower-alpha|lower-greek|lower-latin|lower-roman)$/i.test(type)) {
currentIndex = elementIndex( element );
switch(type){ switch(type){
case "decimal": case "decimal":
text = currentIndex; text = currentIndex;
break; break;
case "decimal-leading-zero": case "decimal-leading-zero":
if (currentIndex.toString().length === 1){ text = (currentIndex.toString().length === 1) ? currentIndex = "0" + currentIndex.toString() : currentIndex.toString();
text = currentIndex = "0" + currentIndex.toString();
}else{
text = currentIndex.toString();
}
break; break;
case "upper-roman": case "upper-roman":
text = _html2canvas.Generate.ListRoman( currentIndex ); text = _html2canvas.Generate.ListRoman( currentIndex );
@ -421,23 +402,24 @@ _html2canvas.Parse = function ( images, options ) {
} }
text += ". "; text += ". ";
listBounds = listPosition(element, text); return text;
switch(bold){
case 401:
bold = "bold";
break;
case 400:
bold = "normal";
break;
} }
ctx.setVariable( "fillStyle", getCSS(element, "color") ); function renderListItem(element, stack, elBounds) {
ctx.setVariable( "font", getCSS(element, "fontVariant") + " " + bold + " " + getCSS(element, "fontStyle") + " " + getCSS(element, "fontSize") + " " + getCSS(element, "fontFamily") ); var position = getCSS(element, "listStylePosition"),
x,
y,
text,
type = getCSS(element, "listStyleType"),
listBounds;
if ( position === "inside" ) { if (/^(decimal|decimal-leading-zero|upper-alpha|upper-latin|upper-roman|lower-alpha|lower-greek|lower-latin|lower-roman)$/i.test(type)) {
text = listItemText(element, type);
listBounds = listPosition(element, text);
setTextVariables(ctx, element, "none", getCSS(element, "color"));
if (position === "inside") {
ctx.setVariable("textAlign", "left"); ctx.setVariable("textAlign", "left");
// this.setFont(stack.ctx, element, false);
x = elBounds.left; x = elBounds.left;
} else { } else {
return; return;