Skip to content

Commit a55e93b

Browse files
committed
added tests for #7984
1 parent dcd49bb commit a55e93b

File tree

23 files changed

+56
-0
lines changed

23 files changed

+56
-0
lines changed

test/unit/visual/cases/typography.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,56 @@ visualSuite('Typography', function () {
403403
});
404404
}
405405
);
406+
407+
visualTest(
408+
'all alignments with multi-line manual text, no box dimensions',
409+
async function (p5, screenshot) {
410+
const alignments = [
411+
{ alignX: p5.LEFT, alignY: p5.TOP },
412+
{ alignX: p5.CENTER, alignY: p5.TOP },
413+
{ alignX: p5.RIGHT, alignY: p5.TOP },
414+
{ alignX: p5.LEFT, alignY: p5.CENTER },
415+
{ alignX: p5.CENTER, alignY: p5.CENTER },
416+
{ alignX: p5.RIGHT, alignY: p5.CENTER },
417+
{ alignX: p5.LEFT, alignY: p5.BOTTOM },
418+
{ alignX: p5.CENTER, alignY: p5.BOTTOM },
419+
{ alignX: p5.RIGHT, alignY: p5.BOTTOM }
420+
];
421+
422+
p5.createCanvas(150, 100, mode === 'webgl' ? p5.WEBGL : undefined);
423+
if (mode === 'webgl') p5.translate(-p5.width/2, -p5.height/2);
424+
p5.textSize(20);
425+
426+
const font = await p5.loadFont(
427+
'/unit/assets/Inconsolata-Bold.ttf'
428+
);
429+
p5.textFont(font);
430+
431+
let xPos = 20;
432+
let yPos = 20;
433+
434+
alignments.forEach((alignment, i) => {
435+
p5.background(255);
436+
p5.push();
437+
p5.textAlign(alignment.alignX, alignment.alignY);
438+
439+
p5.fill(0);
440+
p5.noStroke();
441+
p5.text('Line 1\nLine 2\nLine 3', xPos, yPos);
442+
const bb = p5.textBounds(
443+
'Line 1\nLine 2\nLine 3',
444+
xPos,
445+
yPos
446+
);
447+
p5.noFill();
448+
p5.stroke('red');
449+
p5.rect(bb.x, bb.y, bb.w, bb.h);
450+
p5.pop();
451+
452+
screenshot();
453+
});
454+
}
455+
);
406456
});
407457
}
408458
});
2.64 KB
Loading
2.46 KB
Loading
1.65 KB
Loading
2.54 KB
Loading
2.39 KB
Loading
1.55 KB
Loading
1.95 KB
Loading
1.85 KB
Loading
1.22 KB
Loading

0 commit comments

Comments
 (0)