Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Using a character that is missing from a font atlas no longer causes additional dropped characters #1443

Merged
merged 4 commits into from
Nov 16, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/framework/components/element/text-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ Object.assign(pc, function () {
for (i = 0; i < textLength; i++) {
var char = symbols[i];
var info = this._font.data.chars[char];
if (!info) continue;

if (!info) {
charactersPerTexture[map]++;
continue;
}
var map = info.map;

if (!charactersPerTexture[map])
Expand Down Expand Up @@ -409,10 +411,11 @@ Object.assign(pc, function () {
var quadsize = 1;
var glyphMinX = 0;
var glyphWidth = 0;
var size;

data = json.chars[char];
if (data && data.scale) {
var size = (data.width + data.height) / 2;
size = (data.width + data.height) / 2;
scale = (size / MAGIC) * this._fontSize / size;
quadsize = (size / MAGIC) * this._fontSize / data.scale;
advance = data.xadvance * scale;
Expand All @@ -427,8 +430,20 @@ Object.assign(pc, function () {
glyphMinX = 0;
}
} else {
// get a default size for a missing character
var chars = Object.keys(json.chars)
if (chars.length) {
var defaultChar = json.chars[Object.keys(json.chars)[0]];
size = (defaultChar.width + defaultChar.height) / 2;
} else {
// nothing to work with here!
size = 1;
}

scale = (size / MAGIC) * this._fontSize / size;

// missing character
advance = 1;
advance = size * scale;
x = 0;
y = 0;
quadsize = this._fontSize;
Expand Down