Skip to content

Commit 1579069

Browse files
committed
Pixel accurate character data
1 parent eef67b6 commit 1579069

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

src/gameobjects/bitmaptext/GetBitmapTextSize.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ var GetBitmapTextSize = function (src, round, includeChars, out)
7979

8080
var glyph = null;
8181

82+
var align = src._align;
83+
8284
var x = 0;
8385
var y = 0;
8486

@@ -381,10 +383,12 @@ var GetBitmapTextSize = function (src, round, includeChars, out)
381383
characters.push({
382384
char: text[i],
383385
code: charCode,
384-
x: xAdvance * sx,
385-
y: yAdvance * sy,
386-
w: charWidth * sx,
387-
h: lineHeight * sy
386+
x: (glyph.xOffset + xAdvance) * sx,
387+
y: (glyph.yOffset + yAdvance) * sy,
388+
w: glyph.width * sx,
389+
h: glyph.height * sy,
390+
line: currentLine,
391+
glyph: glyph
388392
});
389393
}
390394

@@ -419,6 +423,24 @@ var GetBitmapTextSize = function (src, round, includeChars, out)
419423
shortestLine = currentLineWidth;
420424
}
421425

426+
// Adjust all of the character positions based on alignment
427+
if (align > 0)
428+
{
429+
for (var c = 0; c < characters.length; c++)
430+
{
431+
var currentChar = characters[c];
432+
433+
if (align === 1)
434+
{
435+
currentChar.x += ((longestLine - lineWidths[currentChar.line]) / 2);
436+
}
437+
else if (align === 2)
438+
{
439+
currentChar.x += (longestLine - lineWidths[currentChar.line]);
440+
}
441+
}
442+
}
443+
422444
var local = out.local;
423445
var global = out.global;
424446
var lines = out.lines;

0 commit comments

Comments
 (0)