Skip to content

Incorrect Bounding Box when TextAlign(CENTER, CENTER) #7984

@Iancam

Description

@Iancam

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

2.0.3

Web browser and version

Chrome 137.0.7151.68

Operating system

MacOSX

Steps to reproduce this

Steps:

The bug happens when the text is aligned (center, center), and the text has multiple lines.

Image

Snippet:

let font;

function preload() {
  font = loadFont("./CourierPrime-Regular.ttf");
}

function setup() {
  createCanvas(windowWidth, windowHeight);
  const myText = "La Garita Stock Driveway Road";
  const name = myText.split(" ").join("\n");
  textFont(font);
  textSize(12);
  textAlign(CENTER, CENTER);
  const bounds = font.textBounds(name, 200, 200);

  rect(bounds.x, bounds.y, bounds.w, bounds.h);
  text(name, 200, 200);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions