This commit is contained in:
Richard Davey 2017-03-02 23:34:53 +00:00
parent a6140d8979
commit 3d580664ef
3 changed files with 31 additions and 34 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = { var CHECKSUM = {
build: '82b2d2f0-fefc-11e6-b3a1-070e51e60e5d' build: 'cb0f5a10-ffa0-11e6-8b6b-33d14c4f116a'
}; };
module.exports = CHECKSUM; module.exports = CHECKSUM;

View file

@ -130,7 +130,7 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
ctx.rotate(rotation); ctx.rotate(rotation);
ctx.scale(scale, scale); ctx.scale(scale, scale);
ctx.fillStyle = 'rgb(255,0,255)'; ctx.fillStyle = 'rgb(155,0,255)';
ctx.fillRect(0, 0, glyphW, glyphH); ctx.fillRect(0, 0, glyphW, glyphH);
// if (!window.bob) // if (!window.bob)

View file

@ -13,14 +13,18 @@ var GetBitmapTextSize = function (src)
if (textLength === 0) if (textLength === 0)
{ {
console.log('bailed');
return bounds; return bounds;
} }
bounds.x = Number.MAX_VALUE; bounds.x = Number.MAX_VALUE;
bounds.y = Number.MAX_VALUE; bounds.y = Number.MAX_VALUE;
bounds.width = -1; bounds.width = 0;
bounds.height = -1; bounds.height = 0;
// var sx = src.scaleX;
// var sy = src.scaleY;
// var prevX;
// var prevY;
var textureFrame = src.frame; var textureFrame = src.frame;
@ -34,8 +38,8 @@ var GetBitmapTextSize = function (src)
var charCode = 0; var charCode = 0;
var glyph = null; var glyph = null;
var glyphX = 0; // var glyphX = 0;
var glyphY = 0; // var glyphY = 0;
var glyphW = 0; var glyphW = 0;
var glyphH = 0; var glyphH = 0;
@ -45,8 +49,8 @@ var GetBitmapTextSize = function (src)
var lastGlyph = null; var lastGlyph = null;
var lastCharCode = 0; var lastCharCode = 0;
var textureX = textureFrame.cutX; // var textureX = textureFrame.cutX;
var textureY = textureFrame.cutY; // var textureY = textureFrame.cutY;
var scale = (src.fontSize / src.fontData.size); var scale = (src.fontSize / src.fontData.size);
@ -70,8 +74,8 @@ var GetBitmapTextSize = function (src)
continue; continue;
} }
glyphX = textureX + glyph.x; // glyphX = textureX + glyph.x;
glyphY = textureY + glyph.y; // glyphY = textureY + glyph.y;
glyphW = glyph.width; glyphW = glyph.width;
glyphH = glyph.height; glyphH = glyph.height;
@ -85,28 +89,25 @@ var GetBitmapTextSize = function (src)
x += (kerningOffset !== undefined) ? kerningOffset : 0; x += (kerningOffset !== undefined) ? kerningOffset : 0;
} }
// prevX = x;
// prevY = y;
x *= scale; x *= scale;
y *= scale; y *= scale;
// ctx.save();
// ctx.translate(x, y);
// ctx.rotate(rotation);
// ctx.scale(scale, scale);
// ctx.fillStyle = 'rgb(255,0,255)';
// ctx.fillRect(0, 0, glyphW, glyphH);
// ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH); // ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH);
// var xs = x * scale; xAdvance += glyph.xAdvance;
// var ys = y * scale; indexCount += 1;
lastGlyph = glyph;
lastCharCode = charCode;
if (bounds.x > x) if (x < bounds.x)
{ {
bounds.x = x; bounds.x = x;
} }
if (bounds.y > y) if (y < bounds.y)
{ {
bounds.y = y; bounds.y = y;
} }
@ -114,26 +115,22 @@ var GetBitmapTextSize = function (src)
var gw = x + (glyphW * scale); var gw = x + (glyphW * scale);
var gh = y + (glyphH * scale); var gh = y + (glyphH * scale);
if (bounds.width < gw) if (gw > bounds.width)
{ {
bounds.width = gw - bounds.x; bounds.width = gw;
} }
if (bounds.height < gh) if (gh > bounds.height)
{ {
bounds.height = gh - bounds.y; bounds.height = gh;
} }
// console.log('Letter', text[index]); // console.log('Letter', text[index], 'code', charCode);
// console.log('pos', x, y); // console.log('pos', x, y);
// console.log('prev', prevX, prevY);
// console.log('wh', glyphW, glyphH); // console.log('wh', glyphW, glyphH);
// console.log('scaled', gw, gh); // console.log('scaled', gw, gh);
// console.log('bounds', bounds.width, bounds.height); // console.log('xAdvance', xAdvance);
xAdvance += glyph.xAdvance;
indexCount += 1;
lastGlyph = glyph;
lastCharCode = charCode;
} }
return bounds; return bounds;