Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textToPoints() not handling line-breaks correctly #5474

Closed
dhowe opened this issue Nov 12, 2021 · 9 comments · Fixed by #6184
Closed

textToPoints() not handling line-breaks correctly #5474

dhowe opened this issue Nov 12, 2021 · 9 comments · Fixed by #6184

Comments

@dhowe
Copy link
Contributor

dhowe commented Nov 12, 2021

textToPoints() inserts a blank character instead of a line-break

For the string 'B\nA', text() (in white) handles linebreak correctly, while textToPoints() does not:

image

// load font first

function setup() {
  createCanvas(400, 400);
  textFont(font, 100);
  pts = font.textToPoints('B\nA', 0, 0, 100, {
    sampleFactor: 0.4 // increase for more points
  });
  background(0);
  fill(255);
  noLoop()
}

function draw() {
  text('B\nA', 200, 200)
  pts.forEach(p => circle(200 + p.x, 200 + p.y, 3));
}
@sixhat
Copy link
Contributor

sixhat commented Nov 13, 2021

Does this happen with other non-printing characters, like '\t', spaces, etc?

@dhowe
Copy link
Contributor Author

dhowe commented Nov 13, 2021

tab and spaces, definitely not
I suppose we will need to catch line break chars (\r, \n etc.) and handle linebreaks manually

@ffd8
Copy link
Contributor

ffd8 commented Dec 10, 2021

Being able to add \n line breaks to textToPoints() would be huge and oh so useful!
I'm not so sure that opentype.js supports it?

@dhowe
Copy link
Contributor Author

dhowe commented Dec 10, 2021

I don't think so, but that is not required - we would just need to compute the layout for the entire string (as we do with text()), then get the points for each line (after line breaks) separately

Meantime, the following workaround should support most users: pass each line to textToPoints() separately

@Ashley-Y-Lin
Copy link

Is anyone currently working on this?

@dhowe
Copy link
Contributor Author

dhowe commented Mar 25, 2023

Not to my knowledge

@Decoy4ever
Copy link
Contributor

Hey, my group and I from the University of Adelaide want to tackle this issue as part of an open-source contribution project. Is the issue still available to for us to tackle?

@davepagurek
Copy link
Contributor

I believe it's still up for grabs! I'll assign it to you.

@munusshih
Copy link
Contributor

Hi guys! I'm working on this issue as part of my GSoC project. I will do a pull request by adopting most of @Decoy4ever 's suggestion here (#6163) and fix this in the future version of p5 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants