no API to get text width

Erwin Driessens avatarErwin Driessens created an issue

I am in need of a method to get the text width of a string in the current font and size, before I call DraxText(), in order to position the piece of text precisely. I'm working on a graphing subsystem and am labeling things with short texts. I have looked at the sources and i see there is a computeStringWidth() that is called in Text.Text(). I'll try to use Text.X() and see if i can somehow use that to get the width of my labels. I am unsure how one would proceed to layout text using the current functionality. How can one for instance space words so that they fit nicely in a column?

Comments (3)

  1. Ross Light

    I think you already have your answer: you can use the X() method after you've sent your text. I agree there are some shortcomings to this approach, but there's a wider problem of how to address arbitrary fonts that this library sidesteps.

    Erwin, if you could send future questions about this library as Bitbucket messages instead of filing bugs, I'd appreciate it.

  2. Erwin Driessens

    Sorry, i don't know about bitbucket messages, i would prefer those as well. Will figure them out asap.

    Indeed, i experimented with X() and i have all my labels perfectly aligned now :) After thinking about it some more, i figure that an application that lays out text for a PDF just uses lots of small strings (like individual words) and positions them only after Text.Text() and Text.X(), after which it can make decisions where to draw them.

    This is workable, please consider my "issue" a non-issue. And thanks for sharing your code, i am glad i am able to generate PDF files in Go!

  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.