Skip to content

Commit

Permalink
Add test cases for font file loading in 2D + WebGL
Browse files Browse the repository at this point in the history
  • Loading branch information
davepagurek committed Dec 15, 2024
1 parent 7fb18e8 commit 797e4e0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/webgl/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,11 @@ function text(p5, fn){
sh.setUniform('uStrokeImageSize', [strokeImageWidth, strokeImageHeight]);
sh.setUniform('uGridSize', [charGridWidth, charGridHeight]);
}

const curFillColor = this.states.fillSet ? this.states.curFillColor : [0, 0, 0, 255];

this._setGlobalUniforms(sh);
this._applyColorBlend(this.states.curFillColor);
this._applyColorBlend(curFillColor);

let g = this.geometryBufferCache.getGeometryByID('glyph');
if (!g) {
Expand All @@ -759,7 +762,7 @@ function text(p5, fn){
this._bindBuffer(this.geometryBufferCache.cache.glyph.indexBuffer, gl.ELEMENT_ARRAY_BUFFER);

// this will have to do for now...
sh.setUniform('uMaterialColor', this.states.curFillColor);
sh.setUniform('uMaterialColor', curFillColor);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);

try {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/visual/cases/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ visualSuite("Typography", function () {
p5.text('p5*js', 0, 10, p5.width);
screenshot();
});

visualTest('with a font file', async function(p5, screenshot) {
p5.createCanvas(100, 100);
const font = await p5.loadFont(
'/unit/assets/Inconsolata-Bold.ttf'
);
p5.textFont(font);
p5.textAlign(p5.LEFT, p5.TOP);
p5.textSize(35);
p5.text('p5*js', 0, 10, p5.width);
screenshot();
});

visualTest('with a font file in WebGL', async function(p5, screenshot) {
p5.createCanvas(100, 100, p5.WEBGL);
const font = await p5.loadFont(
'/unit/assets/Inconsolata-Bold.ttf'
);
p5.textFont(font);
p5.textAlign(p5.LEFT, p5.TOP);
p5.textSize(35);
p5.text('p5*js', -p5.width/2, -p5.height/2 + 10, p5.width);
screenshot();
});
});

visualSuite('textWeight', function() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}

0 comments on commit 797e4e0

Please sign in to comment.