Skip to content

Commit e882f4a

Browse files
committed
Prototype of adding a large atlas page for overflow glyphs
Part of #5246
1 parent 601efc3 commit e882f4a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/browser/renderer/shared/TextureAtlas.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export class TextureAtlas implements ITextureAtlas {
7575
private _workAttributeData: AttributeData = new AttributeData();
7676

7777
private _textureSize: number = 512;
78+
// TODO: Use actual value
79+
private _deviceMaxTextureSize: number = 2048;
7880

7981
public static maxAtlasPages: number | undefined;
8082
public static maxTextureSize: number | undefined;
@@ -431,7 +433,7 @@ export class TextureAtlas implements ITextureAtlas {
431433
// Allow 1 cell width per character, with a minimum of 2 (CJK), plus some padding. This is used
432434
// to draw the glyph to the canvas as well as to restrict the bounding box search to ensure
433435
// giant ligatures (eg. =====>) don't impact overall performance.
434-
const allowedWidth = Math.min(this._config.deviceCellWidth * Math.max(chars.length, 2) + TMP_CANVAS_GLYPH_PADDING * 2, this._textureSize);
436+
const allowedWidth = Math.min(this._config.deviceCellWidth * Math.max(chars.length, 2) + TMP_CANVAS_GLYPH_PADDING * 2, this._deviceMaxTextureSize);
435437
if (this._tmpCanvas.width < allowedWidth) {
436438
this._tmpCanvas.width = allowedWidth;
437439
}
@@ -772,6 +774,21 @@ export class TextureAtlas implements ITextureAtlas {
772774
}
773775
}
774776

777+
// Create a new page for oversized glyphs as they come up
778+
if (rasterizedGlyph.size.x > this._textureSize) {
779+
// TODO: Move below after page merging to ensure page limit isn't hit
780+
const newPage = new AtlasPage(this._document, this._deviceMaxTextureSize);
781+
this.pages.push(newPage);
782+
783+
// Request the model to be cleared to refresh all texture pages.
784+
this._requestClearModel = true;
785+
this._onAddTextureAtlasCanvas.fire(newPage.canvas);
786+
787+
newPage.addGlyph(rasterizedGlyph);
788+
activePage.fixedRows.push(newPage.currentRow);
789+
break;
790+
}
791+
775792
// Create a new page if too much vertical space would be wasted or there is not enough room
776793
// left in the page. The previous active row will become fixed in the process as it now has a
777794
// fixed height

0 commit comments

Comments
 (0)