=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js' --- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js 2015-10-15 20:11:45 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js 2015-10-23 09:59:53 +0000 @@ -475,12 +475,12 @@ var maxWidth = me.readInt16BinaryMessage(message, offset); offset = offset + 2; - var pheight = p2j.screen.layoutParagraphWorker(text, + var pheight = p2j.screen.layoutParagraphWorker(null, + text, font, 0, 0, - maxWidth, - false); + maxWidth); me.sendInt16BinaryMessage(0x06, pheight); break; === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2015-10-22 09:11:20 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2015-10-23 09:58:26 +0000 @@ -734,7 +734,7 @@ // TODO: this might need to be 'bottom', too this.ctx.textBaseline = 'top'; - me.layoutParagraphWorker(text, fontId, x, y, width, true); + me.layoutParagraphWorker(this.ctx, text, fontId, x, y, width); break; case ops.DRAW_LINE: @@ -2004,7 +2004,8 @@ * paragraph height while maintaining the supplied maximum width. * * @param {CanvasRenderingContext2D} ctx - * The canvas 2D graphics context on which to draw. + * The canvas 2D graphics context on which to draw, when ctx is set, + * the text should be drawn. * @param {String} txt * The paragraph text. * @param {Number} font @@ -2015,18 +2016,14 @@ * The drawing Y position, ignored if drawing is not required. * @param {Number} width * The maximum width used to layout the paragraph. - * @param {boolean} draw - * When true, this flag indicates that the text should be drawn on the - * current context. * * @return {Number} The paragraph height. */ - me.layoutParagraphWorker = function(ctx, txt, font, x, y, width, draw) + me.layoutParagraphWorker = function(ctx, txt, font, x, y, width) { var newLine = true; var i = 0; - - if (draw) + if (ctx) { // unless we are drawing, there is no need in changing the context font ctx.save(); @@ -2036,14 +2033,13 @@ var height = 0; var fheight = p2j.fonts.getFontHeight(font); - while (i < txt.length) { - var nextPos = findNextPos(txt, i, width); + var nextPos = findNextPos(font, txt, i, width); var line = txt.substring(i, nextPos); - if (draw) + if (ctx) { ctx.fillText(line, x, y); } @@ -2054,7 +2050,7 @@ height = height + fheight; } - if (draw) + if (ctx) { ctx.restore(); }