Add restrictToCellHeight,Restore abnormal format

This commit is contained in:
tisilent
2023-08-09 11:53:30 +08:00
parent 3ba579f680
commit b8bf35be17
4 changed files with 28 additions and 20 deletions
@@ -375,9 +375,9 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
let glyph: IRasterizedGlyph; let glyph: IRasterizedGlyph;
if (chars && chars.length > 1) { if (chars && chars.length > 1) {
glyph = this._charAtlas.getRasterizedGlyphCombinedChar(chars, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext); glyph = this._charAtlas.getRasterizedGlyphCombinedChar(chars, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext, true);
} else { } else {
glyph = this._charAtlas.getRasterizedGlyph(cell.getCode() || WHITESPACE_CELL_CODE, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext); glyph = this._charAtlas.getRasterizedGlyph(cell.getCode() || WHITESPACE_CELL_CODE, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext, true);
} }
if (!glyph.size.x || !glyph.size.y) { if (!glyph.size.x || !glyph.size.y) {
return; return;
@@ -236,9 +236,9 @@ export class GlyphRenderer extends Disposable {
// Get the glyph // Get the glyph
if (chars && chars.length > 1) { if (chars && chars.length > 1) {
$glyph = this._atlas.getRasterizedGlyphCombinedChar(chars, bg, fg, ext); $glyph = this._atlas.getRasterizedGlyphCombinedChar(chars, bg, fg, ext, false);
} else { } else {
$glyph = this._atlas.getRasterizedGlyph(code, bg, fg, ext); $glyph = this._atlas.getRasterizedGlyph(code, bg, fg, ext, false);
} }
$leftCellPadding = Math.floor((this._dimensions.device.cell.width - this._dimensions.device.char.width) / 2); $leftCellPadding = Math.floor((this._dimensions.device.cell.width - this._dimensions.device.char.width) / 2);
+22 -14
View File
@@ -242,12 +242,12 @@ export class TextureAtlas implements ITextureAtlas {
} }
} }
public getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number): IRasterizedGlyph { public getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean): IRasterizedGlyph {
return this._getFromCacheMap(this._cacheMapCombined, chars, bg, fg, ext); return this._getFromCacheMap(this._cacheMapCombined, chars, bg, fg, ext, restrictToCellHeight);
} }
public getRasterizedGlyph(code: number, bg: number, fg: number, ext: number): IRasterizedGlyph { public getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, restrictToCellHeight: boolean): IRasterizedGlyph {
return this._getFromCacheMap(this._cacheMap, code, bg, fg, ext); return this._getFromCacheMap(this._cacheMap, code, bg, fg, ext, restrictToCellHeight);
} }
/** /**
@@ -258,11 +258,12 @@ export class TextureAtlas implements ITextureAtlas {
key: string | number, key: string | number,
bg: number, bg: number,
fg: number, fg: number,
ext: number ext: number,
restrictToCellHeight: boolean = false
): IRasterizedGlyph { ): IRasterizedGlyph {
$glyph = cacheMap.get(key, bg, fg, ext); $glyph = cacheMap.get(key, bg, fg, ext);
if (!$glyph) { if (!$glyph) {
$glyph = this._drawToCache(key, bg, fg, ext); $glyph = this._drawToCache(key, bg, fg, ext, restrictToCellHeight);
cacheMap.set(key, bg, fg, ext, $glyph); cacheMap.set(key, bg, fg, ext, $glyph);
} }
return $glyph; return $glyph;
@@ -414,7 +415,7 @@ export class TextureAtlas implements ITextureAtlas {
return color; return color;
} }
private _drawToCache(codeOrChars: number | string, bg: number, fg: number, ext: number): IRasterizedGlyph { private _drawToCache(codeOrChars: number | string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean = false): IRasterizedGlyph {
const chars = typeof codeOrChars === 'number' ? String.fromCharCode(codeOrChars) : codeOrChars; const chars = typeof codeOrChars === 'number' ? String.fromCharCode(codeOrChars) : codeOrChars;
// Uncomment for debugging // Uncomment for debugging
@@ -543,10 +544,17 @@ export class TextureAtlas implements ITextureAtlas {
const xChMid = xChLeft + this._config.deviceCellWidth / 2; const xChMid = xChLeft + this._config.deviceCellWidth / 2;
switch (this._workAttributeData.extended.underlineStyle) { switch (this._workAttributeData.extended.underlineStyle) {
case UnderlineStyle.DOUBLE: case UnderlineStyle.DOUBLE:
this._tmpCtx.moveTo(xChLeft, yTop - ySpace); if (restrictToCellHeight) {
this._tmpCtx.lineTo(xChRight, yTop - ySpace); this._tmpCtx.moveTo(xChLeft, yTop - ySpace);
this._tmpCtx.moveTo(xChLeft, yTop); this._tmpCtx.lineTo(xChRight, yTop - ySpace);
this._tmpCtx.lineTo(xChRight, yTop); this._tmpCtx.moveTo(xChLeft, yTop);
this._tmpCtx.lineTo(xChRight, yTop);
} else {
this._tmpCtx.moveTo(xChLeft, yTop);
this._tmpCtx.lineTo(xChRight, yTop);
this._tmpCtx.moveTo(xChLeft, yBot);
this._tmpCtx.lineTo(xChRight, yBot);
}
break; break;
case UnderlineStyle.CURLY: case UnderlineStyle.CURLY:
// Choose the bezier top and bottom based on the device pixel ratio, the curly line is // Choose the bezier top and bottom based on the device pixel ratio, the curly line is
@@ -1020,13 +1028,13 @@ function clearColor(imageData: ImageData, bg: IColor, fg: IColor, enableThreshol
for (let offset = 0; offset < imageData.data.length; offset += 4) { for (let offset = 0; offset < imageData.data.length; offset += 4) {
// Check exact match // Check exact match
if (imageData.data[offset] === r && if (imageData.data[offset] === r &&
imageData.data[offset + 1] === g && imageData.data[offset + 1] === g &&
imageData.data[offset + 2] === b) { imageData.data[offset + 2] === b) {
imageData.data[offset + 3] = 0; imageData.data[offset + 3] = 0;
} else { } else {
// Check the threshold based difference // Check the threshold based difference
if (enableThresholdCheck && if (enableThresholdCheck &&
(Math.abs(imageData.data[offset] - r) + (Math.abs(imageData.data[offset] - r) +
Math.abs(imageData.data[offset + 1] - g) + Math.abs(imageData.data[offset + 1] - g) +
Math.abs(imageData.data[offset + 2] - b)) < threshold) { Math.abs(imageData.data[offset + 2] - b)) < threshold) {
imageData.data[offset + 3] = 0; imageData.data[offset + 3] = 0;
+2 -2
View File
@@ -107,8 +107,8 @@ export interface ITextureAtlas extends IDisposable {
* Clear all glyphs from the texture atlas. * Clear all glyphs from the texture atlas.
*/ */
clearTexture(): void; clearTexture(): void;
getRasterizedGlyph(code: number, bg: number, fg: number, ext: number): IRasterizedGlyph; getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, restrictToCellHeight: boolean): IRasterizedGlyph;
getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number): IRasterizedGlyph; getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean): IRasterizedGlyph;
} }
/** /**