Skip to content

Commit

Permalink
exclude bold&italic variants from merge, limit glyph calc to latin + …
Browse files Browse the repository at this point in the history
…latin supplement
  • Loading branch information
jerch committed Jul 25, 2023
1 parent 3715301 commit ad14554
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/browser/renderer/dom/DomRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ let nextTerminalId = 1;
// font metrics calc settings
const enum FontMetrics {
START = 32, // start codepoint
MAX = 1424, // only calc up to this codepoint
MAX = 256, // only calc up to this codepoint (256 means only Basic Latin + Latin-1 Supplement)
BATCH_SIZE = 30, // amount of codepoints to calc in a single batch (sync & blocking)
THRESHOLD = 0.005 // relative deviation from cell width
THRESHOLD = 0.005 // allowed relative deviation from cell width
}

/**
Expand Down Expand Up @@ -122,8 +122,8 @@ export class DomRenderer extends Disposable implements IRenderer {
container.style.fontSize = `${this._optionsService.rawOptions.fontSize}px`;

const cellWidth = this.dimensions.css.cell.width;
const lower = cellWidth * (1 - FontMetrics.THRESHOLD);
const upper = cellWidth * (1 + FontMetrics.THRESHOLD);
const lower = 10 * cellWidth * (1 - FontMetrics.THRESHOLD);
const upper = 10 * cellWidth * (1 + FontMetrics.THRESHOLD);
const end = Math.min(this._metricsPos + FontMetrics.BATCH_SIZE, FontMetrics.MAX);

for (let i = this._metricsPos; i < end; ++i) {
Expand All @@ -136,7 +136,7 @@ export class DomRenderer extends Disposable implements IRenderer {

const collection = container.children;
for (let i = 0; i < collection.length; ++i) {
const width = collection[i].getBoundingClientRect().width / 10;
const width = collection[i].getBoundingClientRect().width;
this._fontMetrics[i + this._metricsPos] = +(width < lower || width > upper);
}
container.remove();
Expand Down
8 changes: 7 additions & 1 deletion src/browser/renderer/dom/DomRendererRowFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class DomRendererRowFactory {
const isNull = cc === NULL_CELL_CODE && width === NULL_CELL_WIDTH;
const isCombined = cell.isCombined();
const isLinkHover = isHover && x >= linkState[1] && x <= linkState[2];
const isBoldOrItalic = cell.isBold() && cell.isItalic();

if (!charElement) {
charElement = this._document.createElement('span');
Expand Down Expand Up @@ -378,7 +379,12 @@ export class DomRendererRowFactory {


// account first char for later merge if it meets the start conditions
if ((isNull || (width === 1 && !isCombined && cc < 1424 && !metrics[cc])) && !isInSelection && !isCursorCell) {
if (
(isNull || (width === 1 && !isCombined && cc < 1424 && !metrics[cc]))
&& !isBoldOrItalic
&& !isInSelection
&& !isCursorCell
) {
cellAmount++;
} else {
// every non-mergeable char gets directly written to its own span
Expand Down

0 comments on commit ad14554

Please sign in to comment.