-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Open
Labels
Description
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- p5.strands
- WebGL
- DevOps, Build process, Unit testing
- Internationalization (i18n)
- Friendly Errors
- Other (specify if possible)
p5.js version
v.1.9.0 but also tried v1.11.11 and saw different issues
Web browser and version
safar v26.1
Operating system
Mac OS 15.7.3
Steps to reproduce this
Steps:
- load a font
- set textAlignment
- use the
textToPoint()and draw those points - change textAlignment and draw those points
- the text does not move
Snippet:
This snippet is a modified version of the textAlign example.
let fontSize = 100;
function preload() {
font = loadFont("/assets/inconsolata.otf");
}
function setup() {
createCanvas(1000, 1000);
textFont(font);
background(200);
strokeWeight(0.5);
// First line.
line(0, 120, width, 120);
textAlign(CENTER, TOP);
drawPoints(font.textToPoints('TOP', 50, 120, fontSize));
// Second line.
line(0, 370, width, 370);
textAlign(CENTER, CENTER);
drawPoints(font.textToPoints('CENTER', 50, 370, fontSize));
// Third line.
line(0, 620, width, 620);
textAlign(CENTER, BASELINE);
drawPoints(font.textToPoints('BASELINE', 50, 620, fontSize));
// Fourth line.
line(0, 970, width, 970);
textAlign(CENTER, BOTTOM);
drawPoints(font.textToPoints('BOTTOM', 50, 970, fontSize));
describe('The words "TOP", "CENTER", "BASELINE", and "BOTTOM" each drawn relative to a horizontal line. Their positions demonstrate different vertical alignments.');
}
function drawPoints(pts) {
for (pt of pts) {
circle(pt.x, pt.y, 2)
}
}
Some Extra Details
While trying to make a simple example for this issue I discovered a few related surprises:
- I was initially on p5 v.1.9.0 and the text alignment wasn't respected but when I switched to v.1.11.11 all of the points that were being drawn shifted slightly down.
-
fontSize being set at the sketch level was also not respected but changed the alignment of all words
-
My belief that the textAlignment should be used was based on the description on the p5 reference for textToPoints which mentions default textAlignment behavior.
Reactions are currently unavailable