Forums > Dev

Text truncation

February 24, 2011 | 1:29 am

Hi there,

a few standard externals (textbutton, tab, etc….) feature a text truncation attribute that allows the user to truncate text that does not fit in the object box. Usually the truncation options are to truncate from the right, from the left or from the middle of the word or sentence.

For example:
I love Max/MSP

I love M… [truncate from the right]
I lo…/MSP [truncate from the middle]
…Max/MSP [truncate from the left]

I haven’t found any such feature built in the JGraphics API nor in textfield or textlayout, with the only exception of a TEXT_JUSTIFICATION_USEELLIPSIS flag which just allows truncation from the right.

I am wondering if there are other techniques or other not documented flags that allow to easily implement the above mentioned behavior.

Thank you for any help.

- Luigi


February 24, 2011 | 2:09 am

TEXT_JUSTIFICATION_USEELLIPSIS is the only one available. textbutton and tab have custom hand made truncation (just a few text measurement and string manipulation).


February 24, 2011 | 11:24 am

Ah, I see…

Would it be possible to post a brief code snippet to show how it’s done?

Thanks Emmanuel.

- Luigi


February 24, 2011 | 5:26 pm

AFAIR it’s just something which uses jfont_text_measure() and reduce the number of characters in a while loop.

something like:

do
    jfont_text_measure(jf, getyourtext(), &w, &h);
while ( w > thewidthyouhave && --sizeofthetext > 1)

getyourtext() just insert the … in the middle or at then end depending on the mode.


Viewing 4 posts - 1 through 4 (of 4 total)