Skip to content

Commit 5630471

Browse files
authored
Merge pull request #5684 from Tyriar/5681
Make 0x1FB98 and 0x1FB99 perfectly tile
2 parents 452ee50 + e0c59e6 commit 5630471

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ export const customGlyphDefinitions: { [index: string]: CustomGlyphCharacterDefi
644644
] },
645645

646646
// Diagonal fill characters (1FB98-1FB99)
647-
'\u{1FB98}': { type: CustomGlyphDefinitionType.PATH_FUNCTION, data: 'M0,0 L1,1 M0,.25 L.75,1 M0,.5 L.5,1 M0,.75 L.25,1 M.25,0 L1,.75 M.5,0 L1,.5 M.75,0 L1,.25', strokeWidth: 1 }, // UPPER LEFT TO LOWER RIGHT FILL
648-
'\u{1FB99}': { type: CustomGlyphDefinitionType.PATH_FUNCTION, data: 'M0,.25 L.25,0 M0,.5 L.5,0 M0,.75 L.75,0 M0,1 L1,0 M.25,1 L1,.25 M.5,1 L1,.5 M.75,1 L1,.75', strokeWidth: 1 }, // UPPER RIGHT TO LOWER LEFT FILL
647+
'\u{1FB98}': { type: CustomGlyphDefinitionType.PATH_FUNCTION, data: 'M-0.25,-0.25 L1.25,1.25 M-0.25,0 L1,1.25 M-0.25,0.25 L0.75,1.25 M-0.25,0.5 L0.5,1.25 M0,-0.25 L1.25,1 M0.25,-0.25 L1.25,0.75 M0.5,-0.25 L1.25,0.5 M-0.25,0.75 L0.25,1.25 M0.75,-0.25 L1.25,0.25', strokeWidth: 1 }, // UPPER LEFT TO LOWER RIGHT FILL
648+
'\u{1FB99}': { type: CustomGlyphDefinitionType.PATH_FUNCTION, data: 'M-0.25,0.5 L0.5,-0.25 M-0.25,0.75 L0.75,-0.25 M-0.25,1 L1,-0.25 M-0.25,1.25 L1.25,-0.25 M0,1.25 L1.25,0 M0.25,1.25 L1.25,0.25 M0.5,1.25 L1.25,0.5 M-0.25,0.25 L0.25,-0.25 M0.75,1.25 L1.25,0.75', strokeWidth: 1 }, // UPPER RIGHT TO LOWER LEFT FILL
649649

650650
// Smooth mosaic terminal graphic characters (1FB9A-1FB9B)
651651
'\u{1FB9A}': { type: CustomGlyphDefinitionType.VECTOR_SHAPE, data: { d: 'M0,0 L.5,.5 L0,1 L1,1 L.5,.5 L1,0', type: CustomGlyphVectorType.FILL } }, // UPPER AND LOWER TRIANGULAR HALF BLOCK

addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,11 @@ function drawPathFunctionCharacter(
512512
devicePixelRatio: number,
513513
strokeWidth?: number
514514
): void {
515+
ctx.save();
516+
ctx.beginPath();
517+
ctx.rect(xOffset, yOffset, deviceCellWidth, deviceCellHeight);
518+
ctx.clip();
519+
515520
ctx.beginPath();
516521
let actualInstructions: string;
517522
if (typeof charDefinition === 'function') {
@@ -538,7 +543,7 @@ function drawPathFunctionCharacter(
538543
if (!args[0] || !args[1]) {
539544
continue;
540545
}
541-
f(ctx, translateArgs(args, deviceCellWidth, deviceCellHeight, xOffset, yOffset, true, devicePixelRatio), state);
546+
f(ctx, translateArgs(args, deviceCellWidth, deviceCellHeight, xOffset, yOffset, true, devicePixelRatio, 0, 0, false), state);
542547
state.lastCommand = type;
543548
}
544549
if (strokeWidth !== undefined) {
@@ -549,6 +554,7 @@ function drawPathFunctionCharacter(
549554
ctx.fill();
550555
}
551556
ctx.closePath();
557+
ctx.restore();
552558
}
553559

554560
/**
@@ -697,7 +703,7 @@ const svgToCanvasInstructionMap: { [index: string]: (ctx: CanvasRenderingContext
697703
}
698704
};
699705

700-
function translateArgs(args: string[], cellWidth: number, cellHeight: number, xOffset: number, yOffset: number, doClamp: boolean, devicePixelRatio: number, leftPadding: number = 0, rightPadding: number = 0): number[] {
706+
function translateArgs(args: string[], cellWidth: number, cellHeight: number, xOffset: number, yOffset: number, doClamp: boolean, devicePixelRatio: number, leftPadding: number = 0, rightPadding: number = 0, clampToCell: boolean = true): number[] {
701707
const result = args.map(e => parseFloat(e) || parseInt(e));
702708

703709
if (result.length < 2) {
@@ -707,10 +713,11 @@ function translateArgs(args: string[], cellWidth: number, cellHeight: number, xO
707713
for (let x = 0; x < result.length; x += 2) {
708714
// Translate from 0-1 to 0-cellWidth
709715
result[x] *= cellWidth - (leftPadding * devicePixelRatio) - (rightPadding * devicePixelRatio);
710-
// Ensure coordinate doesn't escape cell bounds and round to the nearest 0.5 to ensure a crisp
711-
// line at 100% devicePixelRatio
716+
// Round to the nearest 0.5 to ensure a crisp line at 100% devicePixelRatio, and optionally
717+
// clamp to the cell bounds.
712718
if (doClamp && result[x] !== 0) {
713-
result[x] = clamp(Math.round(result[x] + 0.5) - 0.5, cellWidth, 0);
719+
const rounded = Math.round(result[x] + 0.5) - 0.5;
720+
result[x] = clampToCell ? clamp(rounded, cellWidth, 0) : rounded;
714721
}
715722
// Apply the cell's offset (ie. x*cellWidth)
716723
result[x] += xOffset + (leftPadding * devicePixelRatio);
@@ -719,10 +726,11 @@ function translateArgs(args: string[], cellWidth: number, cellHeight: number, xO
719726
for (let y = 1; y < result.length; y += 2) {
720727
// Translate from 0-1 to 0-cellHeight
721728
result[y] *= cellHeight;
722-
// Ensure coordinate doesn't escape cell bounds and round to the nearest 0.5 to ensure a crisp
723-
// line at 100% devicePixelRatio
729+
// Round to the nearest 0.5 to ensure a crisp line at 100% devicePixelRatio, and optionally
730+
// clamp to the cell bounds.
724731
if (doClamp && result[y] !== 0) {
725-
result[y] = clamp(Math.round(result[y] + 0.5) - 0.5, cellHeight, 0);
732+
const rounded = Math.round(result[y] + 0.5) - 0.5;
733+
result[y] = clampToCell ? clamp(rounded, cellHeight, 0) : rounded;
726734
}
727735
// Apply the cell's offset (ie. x*cellHeight)
728736
result[y] += yOffset;

0 commit comments

Comments
 (0)