Skip to content

Using a custom TextStyle #138

Open
Open

Description

@benoitmasson

Hi, I can't find a way to customize the TextStyle in my calls to gc.FillString().

This type (and all its field, in particular Halign which I'm interested in) do not seem to be used in any of the packages.

Am I missing something, or is there another way to have gc.FillString() draw centered text?

Activity

  1. llgcode commented on Jan 3, 2018

    @llgcode
    Owner

    Hi @benoitmasson, it's not implemented yet.

  2. benoitmasson commented on Jan 3, 2018

    @benoitmasson
    Author

    OK, thanks for the quick response.

    Meanwhile I wrote a small workaround for my specific needs, in anybody has the same issue:

    func fillStringHCenteredAt(gc draw2d.GraphicContext, text string, x, y float64) float64 {
    	// draw text outside of image, to compute width without printing
    	w := gc.FillStringAt(text, 0, -1000)
    	// draw centered text
    	return gc.FillStringAt(text, x-w/2, y)
    }
  3. llgcode commented on Jan 4, 2018

    @llgcode
    Owner

    Hi @benoitmasson
    thanks for the function.
    There's a method here that can help you compute the size of the string. This method is only available in draw2dimg package.
    We need functions that computes metrics in draw2d base package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions