Skip to content

[p5.js 2.0 Bug Report]: textWidth ignores leading and trailing spacesΒ #8052

@ghost

Description

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.0.4

Web browser and version

Firefox 142.0 (64bit)

Operating system

MacOSX

Steps to reproduce this

In 2.0.4 the textWidth() function does not measure leading and trailing white space and treats a string comprising entirely of spaces as an empty string.

I suspect that the string being measured is being 'trimmed' of leading and trailing white space prior to calculating the text width.

Steps:

Run the code snippet:

  1. In 1.11.0 both p5js and js report the same text width
  2. In 2.0.4 the Javascript function behaves the same as before but the p5js textWidth function measures the text ignoring the leading and trailing spaces.

Snippet:

function setup() {
  createCanvas(640, 400);
  let s = "    Quark    ";
  console.log(textWidth(s));
  console.log(drawingContext.measureText(s).width);
}

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Completed

Relationships

None yet

Development

No branches or pull requests

Issue actions