1. Ross Light
  2. gopdf
  3. Issues
Issue #4 resolved

no API to get text width

Erwin 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 repo owner

    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 reporter

    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