Skip to content

fontToPoints does not use textAlignment #8665

@R4chel

Description

@R4chel

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:

  1. load a font
  2. set textAlignment
  3. use the textToPoint() and draw those points
  4. change textAlignment and draw those points
  5. 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)
  }
}
Three parallel lines each with text made out of small black empty circles above them. The on at the top spells TOP, the one in the middle spells CENTER and the one on the bottom is BASELINE. Baseline is resting just on the bottom line but TOP and CENTER dip slightly below their respective lines

Some Extra Details

While trying to make a simple example for this issue I discovered a few related surprises:

  1. 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.
Three parallel lines each with text made out of small black empty circles above each one. The on at the top spells TOP, the one in the middle spells CENTER and the one on the bottom is BASELINE. All of the words are resting just on the respective line. In blue font in the upper right there is text saying p5 v1.9.0
  1. fontSize being set at the sketch level was also not respected but changed the alignment of all words

  2. My belief that the textAlignment should be used was based on the description on the p5 reference for textToPoints which mentions default textAlignment behavior.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions