From 951b86ea6732cc4ecd1087f1cbd83c9dcc785a41 Mon Sep 17 00:00:00 2001 From: Nicolas PARIS Date: Sat, 27 Dec 2014 16:51:56 +0100 Subject: [PATCH] =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20src/?= =?UTF-8?q?graphics/graphics.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/graphics.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/graphics/graphics.js b/src/graphics/graphics.js index 285b056..601c4a0 100644 --- a/src/graphics/graphics.js +++ b/src/graphics/graphics.js @@ -267,7 +267,12 @@ var Graphics = function(canvas){ ctx.fillStyle = Colors.blend(color, alpha) // if (alpha>0) ctx.fillText(textStr, style.x, style.y); - if (alpha>0) ctx.fillText(textStr, Math.round(style.x), style.y); + var texts=textStr.split("
"); + style.y = style.y - ((parseInt(ctx.font)+2)*(texts.length-1))/2; + for (var k in texts) { + if (alpha>0) ctx.fillText(texts[k], Math.round(style.x), (style.y+((parseInt(ctx.font)+2)*k))); + // ctx.fillText(texts[k], left, (top+((parseInt(ctx.font)+2)*k))); + } ctx.restore() }, @@ -275,7 +280,12 @@ var Graphics = function(canvas){ style = objmerge(_fontStyle, style||{}) ctx.save() ctx.font = nano("{size}px {font}", style) - var width = ctx.measureText(textStr).width +var texts=textStr.split("
"); +var textStrMax = ""; +var width = 0; + for (var k in texts) { + width = width < ctx.measureText(texts[k]).width ? ctx.measureText(texts[k]).width : width + } ctx.restore() return width },