Most appropriate sub-area of p5.js?
p5.js version
2.2.3
Web browser and version
All
Operating system
All
Steps to reproduce this
Steps:
- Set a font and text size
push()
- Change the text size
- Measure something with
fontWidth(...)
pop()
- Measure something again
The measurements should be different after the pop since the text size should return to normal. This works when in 2D mode, but doesn't in WebGL mode. I think that's because in 2D mode, the text measurement canvas IS the main canvas, so pushes and pops apply to it. In WebGL mode, it is a separate canvas, so there are no pushes/pops.
Snippet:
let font
async function setup() {
createCanvas(400, 400, WEBGL); // Try without WEBGL too
font = await loadFont('https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfMZhrib2Bg-4.ttf')
push()
textFont(font)
textSize(12)
push()
textSize(20)
console.log(fontWidth('X'))
pop()
console.log(fontWidth('X'))
pop()
}
Live: https://editor.p5js.org/davepagurek/sketches/Am5XG1E1O
In WebGL, I get the same value logged twice. In 2D mode, I get different values.
Most appropriate sub-area of p5.js?
p5.js version
2.2.3
Web browser and version
All
Operating system
All
Steps to reproduce this
Steps:
push()fontWidth(...)pop()The measurements should be different after the pop since the text size should return to normal. This works when in 2D mode, but doesn't in WebGL mode. I think that's because in 2D mode, the text measurement canvas IS the main canvas, so pushes and pops apply to it. In WebGL mode, it is a separate canvas, so there are no pushes/pops.
Snippet:
Live: https://editor.p5js.org/davepagurek/sketches/Am5XG1E1O
In WebGL, I get the same value logged twice. In 2D mode, I get different values.