Graphics

 View Only
  • 1.  Vertically Center Multiline Text with Changing Font Tags

    Posted 06-11-2020 16:12

    Greetings, I am having difficulties vertically centering Multi-line text that can have numerous and indeterminate font tags. Normally, I would change the pivot to the top of the text, take half the height and assign my position.

    However, this will not work if the font tag for the first line. The pivot point will remain the same distance from the default font’s baseline, but the new font could be any size, throwing off the alignment.

    The only solution I can find is to keep the pivot at 0 and have an on set text script that inserts a blank line with a set font tag so that the top line height is know and can be subtracted from the total height with the baseline pivot as a reference for centering.

    Is there a better way to accomplish this? Thanks for any help.



  • 2.  RE: Vertically Center Multiline Text with Changing Font Tags

    Posted 06-14-2020 01:31

    Hi Ryan,

    Trying to center a text using Visual Logic can be quite tedious, I know.

    As you have said in your question, the 0-position on the Y-axis of the textobject is on the baseline of the first line of the text which is making it difficult to handle.

    Luckily the BoundingBox-properties offer you a property called BoundingBox.Top. This tells you how much the distance there is between the default 0-point of the object and the top of the boundingbox.

    In the case of a text-object, it will tell you the distance between the baseline of the text and the top of the BoundingBox.

    So now that you know the height of the BoundingBox, you just need to divide that in two to get the center of the BoundingBox. However, since there's an offset of the baseline, you just need to subtract half of the BoundingBox.Height from the BoundingBox.Top and you get the center point of the textobject.

    Then you only need to fix the Y-Position of the textobject to the position where you need it.

     

     

    Hope it helps!

    Best regards,

    Ken


    #XPression


  • 3.  RE: Vertically Center Multiline Text with Changing Font Tags

    Posted 06-15-2020 13:37

    Thanks Ken,

    I don’t know how I’ve missed the Bounding Box Top property for so long, but that did the trick. Much obliged.


    #XPression