update files

This commit is contained in:
nuintun 2015-12-04 15:59:25 +08:00
parent a80dd776d9
commit af44644e98

View File

@ -177,23 +177,38 @@ function measureWidth(brush, text, font){
} }
/** /**
* draw underline * drawBackground
* @param brush * @param brush
* @param fromX * @param x
* @param toX * @param y
* @param Y * @param width
* @param height
* @param background
*/
function drawBackground(brush, x, y, width, height, background){
brush.fillStyle = background;
brush.fillRect(x, y, width, height);
}
/**
* drawUnderline
* @param brush
* @param x
* @param y
* @param width
* @param foreground * @param foreground
*/ */
function underline(brush, fromX, toX, Y, 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;
brush.strokeStyle = foreground; brush.strokeStyle = foreground;
brush.beginPath(); brush.beginPath();
brush.moveTo(fromX, Y); brush.moveTo(x, y);
brush.lineTo(toX, Y); brush.lineTo(x + width, y);
brush.stroke(); brush.stroke();
brush.restore();
} }
/** /**
@ -212,18 +227,14 @@ function drawLine(brush, text, x, styles){
var width = measureWidth(brush, text, font); var width = measureWidth(brush, text, font);
if (styles.background) { brush.save();
brush.save();
brush.fillStyle = styles.background; if (styles.background) {
y = (styles.font.lineHeight - styles.font.size) / 2; y = (styles.font.lineHeight - styles.font.size) / 2;
brush.fillRect(x, y, width, styles.font.size); drawBackground(brush, x, y, width, styles.font.size, styles.background);
brush.restore();
} }
brush.save();
brush.font = font; brush.font = font;
brush.fillStyle = styles.foreground; brush.fillStyle = styles.foreground;
brush.textAlign = 'start'; brush.textAlign = 'start';
@ -231,13 +242,14 @@ 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;
underline(brush, x, x + width, y, styles.foreground); drawUnderline(brush, x, y, width, styles.foreground);
} }
brush.restore();
return x + width; return x + width;
} }