mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
More tweaking
This commit is contained in:
parent
3d580664ef
commit
61aafe5be9
3 changed files with 172 additions and 30 deletions
|
@ -1,4 +1,4 @@
|
||||||
var CHECKSUM = {
|
var CHECKSUM = {
|
||||||
build: 'cb0f5a10-ffa0-11e6-8b6b-33d14c4f116a'
|
build: '58962030-ffa1-11e6-968f-631ea26f4b97'
|
||||||
};
|
};
|
||||||
module.exports = CHECKSUM;
|
module.exports = CHECKSUM;
|
|
@ -13,18 +13,14 @@ 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 = 0;
|
bounds.width = -1;
|
||||||
bounds.height = 0;
|
bounds.height = -1;
|
||||||
|
|
||||||
// var sx = src.scaleX;
|
|
||||||
// var sy = src.scaleY;
|
|
||||||
// var prevX;
|
|
||||||
// var prevY;
|
|
||||||
|
|
||||||
var textureFrame = src.frame;
|
var textureFrame = src.frame;
|
||||||
|
|
||||||
|
@ -38,8 +34,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;
|
||||||
|
|
||||||
|
@ -49,8 +45,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);
|
||||||
|
|
||||||
|
@ -74,8 +70,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;
|
||||||
|
@ -89,25 +85,28 @@ 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);
|
||||||
|
|
||||||
xAdvance += glyph.xAdvance;
|
// var xs = x * scale;
|
||||||
indexCount += 1;
|
// var ys = y * scale;
|
||||||
lastGlyph = glyph;
|
|
||||||
lastCharCode = charCode;
|
|
||||||
|
|
||||||
if (x < bounds.x)
|
if (bounds.x > x)
|
||||||
{
|
{
|
||||||
bounds.x = x;
|
bounds.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y < bounds.y)
|
if (bounds.y > y)
|
||||||
{
|
{
|
||||||
bounds.y = y;
|
bounds.y = y;
|
||||||
}
|
}
|
||||||
|
@ -115,22 +114,26 @@ 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 (gw > bounds.width)
|
if (bounds.width < gw)
|
||||||
{
|
{
|
||||||
bounds.width = gw;
|
bounds.width = gw - bounds.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gh > bounds.height)
|
if (bounds.height < gh)
|
||||||
{
|
{
|
||||||
bounds.height = gh;
|
bounds.height = gh - bounds.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('Letter', text[index], 'code', charCode);
|
// console.log('Letter', text[index]);
|
||||||
// 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('xAdvance', xAdvance);
|
// console.log('bounds', bounds.width, bounds.height);
|
||||||
|
|
||||||
|
xAdvance += glyph.xAdvance;
|
||||||
|
indexCount += 1;
|
||||||
|
lastGlyph = glyph;
|
||||||
|
lastCharCode = charCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bounds;
|
return bounds;
|
||||||
|
|
139
v3/src/gameobjects/bitmaptext/_GetBitmapTextSize.js
Normal file
139
v3/src/gameobjects/bitmaptext/_GetBitmapTextSize.js
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
|
||||||
|
var GetBitmapTextSize = function (src)
|
||||||
|
{
|
||||||
|
var text = src.text;
|
||||||
|
var textLength = text.length;
|
||||||
|
|
||||||
|
var bounds = {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 0,
|
||||||
|
height: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
if (textLength === 0)
|
||||||
|
{
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
bounds.x = Number.MAX_VALUE;
|
||||||
|
bounds.y = Number.MAX_VALUE;
|
||||||
|
bounds.width = 0;
|
||||||
|
bounds.height = 0;
|
||||||
|
|
||||||
|
// var sx = src.scaleX;
|
||||||
|
// var sy = src.scaleY;
|
||||||
|
// var prevX;
|
||||||
|
// var prevY;
|
||||||
|
|
||||||
|
var textureFrame = src.frame;
|
||||||
|
|
||||||
|
var chars = src.fontData.chars;
|
||||||
|
var lineHeight = src.fontData.lineHeight;
|
||||||
|
|
||||||
|
var xAdvance = 0;
|
||||||
|
var yAdvance = 0;
|
||||||
|
|
||||||
|
var indexCount = 0;
|
||||||
|
var charCode = 0;
|
||||||
|
|
||||||
|
var glyph = null;
|
||||||
|
// var glyphX = 0;
|
||||||
|
// var glyphY = 0;
|
||||||
|
var glyphW = 0;
|
||||||
|
var glyphH = 0;
|
||||||
|
|
||||||
|
var x = 0;
|
||||||
|
var y = 0;
|
||||||
|
|
||||||
|
var lastGlyph = null;
|
||||||
|
var lastCharCode = 0;
|
||||||
|
|
||||||
|
// var textureX = textureFrame.cutX;
|
||||||
|
// var textureY = textureFrame.cutY;
|
||||||
|
|
||||||
|
var scale = (src.fontSize / src.fontData.size);
|
||||||
|
|
||||||
|
for (var index = 0; index < textLength; ++index)
|
||||||
|
{
|
||||||
|
charCode = text.charCodeAt(index);
|
||||||
|
|
||||||
|
if (charCode === 10)
|
||||||
|
{
|
||||||
|
xAdvance = 0;
|
||||||
|
indexCount = 0;
|
||||||
|
yAdvance += lineHeight;
|
||||||
|
lastGlyph = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
glyph = chars[charCode];
|
||||||
|
|
||||||
|
if (!glyph)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// glyphX = textureX + glyph.x;
|
||||||
|
// glyphY = textureY + glyph.y;
|
||||||
|
|
||||||
|
glyphW = glyph.width;
|
||||||
|
glyphH = glyph.height;
|
||||||
|
|
||||||
|
x = indexCount + glyph.xOffset + xAdvance;
|
||||||
|
y = glyph.yOffset + yAdvance;
|
||||||
|
|
||||||
|
if (lastGlyph !== null)
|
||||||
|
{
|
||||||
|
var kerningOffset = glyph.kerning[lastCharCode];
|
||||||
|
x += (kerningOffset !== undefined) ? kerningOffset : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevX = x;
|
||||||
|
// prevY = y;
|
||||||
|
|
||||||
|
x *= scale;
|
||||||
|
y *= scale;
|
||||||
|
|
||||||
|
// ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH);
|
||||||
|
|
||||||
|
xAdvance += glyph.xAdvance;
|
||||||
|
indexCount += 1;
|
||||||
|
lastGlyph = glyph;
|
||||||
|
lastCharCode = charCode;
|
||||||
|
|
||||||
|
if (x < bounds.x)
|
||||||
|
{
|
||||||
|
bounds.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y < bounds.y)
|
||||||
|
{
|
||||||
|
bounds.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
var gw = x + (glyphW * scale);
|
||||||
|
var gh = y + (glyphH * scale);
|
||||||
|
|
||||||
|
if (gw > bounds.width)
|
||||||
|
{
|
||||||
|
bounds.width = gw;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gh > bounds.height)
|
||||||
|
{
|
||||||
|
bounds.height = gh;
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log('Letter', text[index], 'code', charCode);
|
||||||
|
// console.log('pos', x, y);
|
||||||
|
// console.log('prev', prevX, prevY);
|
||||||
|
// console.log('wh', glyphW, glyphH);
|
||||||
|
// console.log('scaled', gw, gh);
|
||||||
|
// console.log('xAdvance', xAdvance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bounds;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = GetBitmapTextSize;
|
Loading…
Add table
Reference in a new issue