From aea2a2d91cbcf12f608769158cff7eed3b5a9bfa Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 4 Dec 2014 15:49:36 -0800 Subject: [PATCH] Fix text anchor handling --- midp/gfx.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/midp/gfx.js b/midp/gfx.js index a9d4f14b5..60beeacfc 100644 --- a/midp/gfx.js +++ b/midp/gfx.js @@ -353,16 +353,21 @@ var w = withFont(g.class.getField("I.currentFont.Ljavax/microedition/lcdui/Font;").get(g), c, str); c.textAlign = "left"; c.textBaseline = "top"; - if (anchor & RIGHT) + + if (anchor & RIGHT) { x -= w; - if (anchor & HCENTER) - x -= (w/2)|0; - if (anchor & BOTTOM) + } else if (anchor & HCENTER) { + x -= (w >>> 1) | 0; + } + + if (anchor & BOTTOM) { c.textBaseline = "bottom"; - if (anchor & VCENTER) - c.textBaseline = "middle"; - if (anchor & BASELINE) + } else if (anchor & BASELINE) { c.textBaseline = "alphabetic"; + } else if (anchor & VCENTER) { + throw new JavaException("java/lang/IllegalArgumentException", "VCENTER not allowed with text"); + } + cb(x, y, w); }); }