[Solved] Specifying a maximum width for long caption text while for shorter strings occupying a shorter width?
Posted: 2019-10-01T20:31:15-07:00
Following on from my previous topic about an existing label setup I then began looking into 'caption' which shares the same syntax as 'label' but allows for automatic text wrapping when paired with the -size option.
The goal I had was to define a maximum width for a caption to wrap text at, while for text strings shorter than that width (ie: strings that only require a single line) for the width dimension to match that of the text string instead of being the fixed width.
For example as a brief snippet, adjusted from code of the linked previous topic, I can create a caption width of 150px:
And with a longer string for comparison, showing the wrapping:
Is there a way to avoid the additional whitespace for single line text strings shorter than the maximum width specified, that is font independent? As my assumption is that glyph widths would differ between fonts so I'm not sure that calculating string length alone would work.
Goal for shorter strings (note: the red seen is just the background of the image I had beneath for the example screenshots):
The goal I had was to define a maximum width for a caption to wrap text at, while for text strings shorter than that width (ie: strings that only require a single line) for the width dimension to match that of the text string instead of being the fixed width.
For example as a brief snippet, adjusted from code of the linked previous topic, I can create a caption width of 150px:
Code: Select all
-size 150x caption:"My text string here"
And with a longer string for comparison, showing the wrapping:
Is there a way to avoid the additional whitespace for single line text strings shorter than the maximum width specified, that is font independent? As my assumption is that glyph widths would differ between fonts so I'm not sure that calculating string length alone would work.
Goal for shorter strings (note: the red seen is just the background of the image I had beneath for the example screenshots):