Skip to content

[p5.js 2.0 Bug Report]: textToContours is broken under textAlign(CENTER,CENTER) and use linebreak #8079

@inaridarkfox4231

Description

@inaridarkfox4231

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.5

Web browser and version

Chrome

Operating system

Windows

Steps to reproduce this

Steps:

  1. Use textToContours with 4 arguments, and use linebreak for texts.
  2. It works fine when alignment is LEFT and TOP.
  3. However, if alignment is CENTER,CENTER, it will not work properly.

Snippet:

DEMO

let font;

async function setup() {
  createCanvas(400, 400);
  font = await loadFont('https://inaridarkfox4231.github.io/assets/fonts/SourceSerif4.ttf');
  
  background(200);
  textAlign(LEFT,TOP); // no error
  //textAlign(CENTER, CENTER); // error
  textSize(120);
  
  // Get the point array.
  let contours = font.textToContours("H\nY", width/2, height/2, { sampleFactor: 0.5 });
  
  beginShape();
  for (const pts of contours) {
    beginContour();
    for (const pt of pts) {
      vertex(pt.x, pt.y);
    }
    endContour(CLOSE);
  }
  endShape();
}

case: LEFT,TOP

Image

case: CENTER,CENTER

Image

Additional Information

It seems to work fine with 6 arguments.

Image

It's clear that no errors occur. However, I don't understand the specifications, so I don't know anything more. It's a wierd function. I can’t help.

Probably here is the cause for this:
_parseArgs

However, this is just a guess, and even if this was the cause, I don't know how to fix it.

That's all.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions