mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
List refactoring
This commit is contained in:
parent
c6baabc99c
commit
2841f19647
54
src/Parse.js
54
src/Parse.js
@ -114,20 +114,16 @@ _html2canvas.Parse = function ( images, options ) {
|
||||
switch(transform){
|
||||
case "lowercase":
|
||||
return text.toLowerCase();
|
||||
|
||||
case "capitalize":
|
||||
return text.replace( /(^|\s|:|-|\(|\))([a-z])/g , function (m, p1, p2) {
|
||||
if (m.length > 0) {
|
||||
return p1 + p2.toUpperCase();
|
||||
}
|
||||
} );
|
||||
|
||||
case "uppercase":
|
||||
return text.toUpperCase();
|
||||
|
||||
default:
|
||||
return text;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -381,30 +377,15 @@ _html2canvas.Parse = function ( images, options ) {
|
||||
|
||||
}
|
||||
|
||||
function renderListItem(element, stack, elBounds) {
|
||||
var position = getCSS(element, "listStylePosition"),
|
||||
x,
|
||||
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 );
|
||||
|
||||
function listItemText(element, type) {
|
||||
var currentIndex = elementIndex(element),
|
||||
text;
|
||||
switch(type){
|
||||
case "decimal":
|
||||
text = currentIndex;
|
||||
break;
|
||||
case "decimal-leading-zero":
|
||||
if (currentIndex.toString().length === 1){
|
||||
text = currentIndex = "0" + currentIndex.toString();
|
||||
}else{
|
||||
text = currentIndex.toString();
|
||||
}
|
||||
text = (currentIndex.toString().length === 1) ? currentIndex = "0" + currentIndex.toString() : currentIndex.toString();
|
||||
break;
|
||||
case "upper-roman":
|
||||
text = _html2canvas.Generate.ListRoman( currentIndex );
|
||||
@ -421,23 +402,24 @@ _html2canvas.Parse = function ( images, options ) {
|
||||
}
|
||||
|
||||
text += ". ";
|
||||
listBounds = listPosition(element, text);
|
||||
|
||||
switch(bold){
|
||||
case 401:
|
||||
bold = "bold";
|
||||
break;
|
||||
case 400:
|
||||
bold = "normal";
|
||||
break;
|
||||
return text;
|
||||
}
|
||||
|
||||
ctx.setVariable( "fillStyle", getCSS(element, "color") );
|
||||
ctx.setVariable( "font", getCSS(element, "fontVariant") + " " + bold + " " + getCSS(element, "fontStyle") + " " + getCSS(element, "fontSize") + " " + getCSS(element, "fontFamily") );
|
||||
function renderListItem(element, stack, elBounds) {
|
||||
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");
|
||||
// this.setFont(stack.ctx, element, false);
|
||||
x = elBounds.left;
|
||||
} else {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user