update files

This commit is contained in:
nuintun 2015-12-04 16:03:27 +08:00
parent af44644e98
commit d22eb5c1a0

View File

@ -186,9 +186,12 @@ function measureWidth(brush, text, font){
* @param background * @param background
*/ */
function drawBackground(brush, x, y, width, height, background){ function drawBackground(brush, x, y, width, height, background){
brush.save();
brush.fillStyle = background; brush.fillStyle = background;
brush.fillRect(x, y, width, height); brush.fillRect(x, y, width, height);
brush.restore();
} }
/** /**
@ -200,6 +203,7 @@ function drawBackground(brush, x, y, width, height, background){
* @param foreground * @param foreground
*/ */
function drawUnderline(brush, x, y, width, foreground){ function drawUnderline(brush, x, y, width, foreground){
brush.save();
brush.translate(0, parseInt(y) === y ? 0.5 : 0); brush.translate(0, parseInt(y) === y ? 0.5 : 0);
brush.lineWidth = 1; brush.lineWidth = 1;
@ -209,6 +213,7 @@ function drawUnderline(brush, x, y, width, foreground){
brush.moveTo(x, y); brush.moveTo(x, y);
brush.lineTo(x + width, y); brush.lineTo(x + width, y);
brush.stroke(); brush.stroke();
brush.restore();
} }
/** /**
@ -227,14 +232,14 @@ function drawLine(brush, text, x, styles){
var width = measureWidth(brush, text, font); var width = measureWidth(brush, text, font);
brush.save();
if (styles.background) { if (styles.background) {
y = (styles.font.lineHeight - styles.font.size) / 2; y = (styles.font.lineHeight - styles.font.size) / 2;
drawBackground(brush, x, y, width, styles.font.size, styles.background); drawBackground(brush, x, y, width, styles.font.size, styles.background);
} }
brush.save();
brush.font = font; brush.font = font;
brush.fillStyle = styles.foreground; brush.fillStyle = styles.foreground;
brush.textAlign = 'start'; brush.textAlign = 'start';
@ -242,6 +247,7 @@ function drawLine(brush, text, x, styles){
y = styles.font.lineHeight / 2; y = styles.font.lineHeight / 2;
brush.fillText(text, x, y); brush.fillText(text, x, y);
brush.restore();
if (styles.underline) { if (styles.underline) {
y = (styles.font.lineHeight + styles.font.size) / 2; y = (styles.font.lineHeight + styles.font.size) / 2;
@ -249,7 +255,5 @@ function drawLine(brush, text, x, styles){
drawUnderline(brush, x, y, width, styles.foreground); drawUnderline(brush, x, y, width, styles.foreground);
} }
brush.restore();
return x + width; return x + width;
} }