Skip to content

Commit 2d2db01

Browse files
fix empty and unnecessarily wide glyphs
1 parent 0bf072c commit 2d2db01

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/browser/renderer/shared/TextureAtlas.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,18 @@ export class TextureAtlas implements ITextureAtlas {
684684

685685
// split the image into multiple images to fit into the texture
686686
const images: ImageData[] = [];
687-
let glyphWidth = allowedWidth;
688687
if (this._tmpCanvas.width > this._textureSize) {
689688
const step = this._textureSize-(2*padding);
690-
glyphWidth = step;
691-
for (let i = 0; i < this._tmpCanvas.width; i += step) {
692-
const width = Math.min(step, this._tmpCanvas.width - i);
689+
690+
const fullImageData = this._tmpCtx.getImageData(0, 0, this._tmpCanvas.width, this._tmpCanvas.height);
691+
if (!this._config.allowTransparency) {
692+
clearColor(fullImageData, backgroundColor, foregroundColor, enableClearThresholdCheck);
693+
}
694+
695+
this._findGlyphBoundingBox(fullImageData, this._workBoundingBox, fullImageData.width, restrictedPowerlineGlyph, customGlyph, padding);
696+
const end = this._workBoundingBox.right;
697+
for (let i = 0; i <= end; i += step) {
698+
const width = Math.min(step, end - i + 1);
693699
const image = this._tmpCtx.getImageData(i, 0, width, this._tmpCanvas.height);
694700
images.push(image);
695701
}
@@ -715,7 +721,7 @@ export class TextureAtlas implements ITextureAtlas {
715721
continue;
716722
}
717723

718-
const rasterizedGlyph = this._findGlyphBoundingBox(imageData, this._workBoundingBox, Math.min(glyphWidth, imageData.width), restrictedPowerlineGlyph, customGlyph, padding);
724+
const rasterizedGlyph = this._findGlyphBoundingBox(imageData, this._workBoundingBox, imageData.width, restrictedPowerlineGlyph, customGlyph, padding);
719725

720726
// Find the best atlas row to use
721727
let activePage: AtlasPage;
@@ -881,7 +887,7 @@ export class TextureAtlas implements ITextureAtlas {
881887
}
882888
boundingBox.left = 0;
883889
found = false;
884-
for (let x = 0; x < padding + width; x++) {
890+
for (let x = 0; x < width; x++) {
885891
for (let y = 0; y < height; y++) {
886892
const alphaOffset = y * imageData.width * 4 + x * 4 + 3;
887893
if (imageData.data[alphaOffset] !== 0) {
@@ -896,7 +902,7 @@ export class TextureAtlas implements ITextureAtlas {
896902
}
897903
boundingBox.right = width;
898904
found = false;
899-
for (let x = padding + width - 1; x >= padding; x--) {
905+
for (let x = width - 1; x >= 0; x--) {
900906
for (let y = 0; y < height; y++) {
901907
const alphaOffset = y * imageData.width * 4 + x * 4 + 3;
902908
if (imageData.data[alphaOffset] !== 0) {

0 commit comments

Comments
 (0)