TextLayout and truncated text and/or ellipsis


#1

Hi guys,

 

Waht's the easistest to truncate a TextLayout given a specific width or that it will use ellipsis ?

Currently it spans the text on multiple line (but there is not enough height so the text is cut off) and I don't want that :)

 

Thanks !


#2

What about adding a flag like in drawText to supports truncating in TextLayout ?

 

It seems that at least DirectWrite supports it. I was not able to make it work yet though.

 

Jules Kenobi, you are my only hope :)


#3

I don't think that's really what TextLayout was designed to do, it's all about breaking lines and making things fit!

If you just have a series of lines, why not just draw each one separately? (Or maybe drawMultiLineText will do what you want, I can't remember how that works)


#4

Actually this is not a series of line but a very long filename that I would like to display with elipsis .

Right now you cannot control the number of line that you want with TextLayout.

You can do that with drawText but it doesn't support easy non latin characters display (display of a filesystem with japanese file name in my case)

Looks like something like that should be added to DirectWrite code but it seems there is some issue because you give a very very big height 1.0e7f in createLayout


        DWRITE_TRIMMING trimming = {DWRITE_TRIMMING_GRANULARITY_CHARACTER, 0, 0};
        ComSmartPtr<IDWriteInlineObject> trimmingSign;
        hr = directWriteFactory->CreateEllipsisTrimmingSign(dwTextFormat, trimmingSign.resetAndGetPointerAddress());
        hr = dwTextFormat->SetTrimming(&trimming, trimmingSign);

#5

Why is the reason behind the 1.0e7f in setupLayout instead of layout.getHeight() ?

Thanks,


#6

Ok I see that it's 0 in fact.

Why not adding maxHeight to TextLayout::createLayout in that case and init it with it like maxWidth ?


#7

in OSX CoreText, this is handled by setting ctLineBreakMode to kCTLineBreakByTruncatingTail in createCFAttributedString

 

What about adding this info to AttributedString in th WordWrap enum ?


#8

To summarize:

 

Would be great to add a maxHeight to TextLayout::createLayout

 

Then add the following code to setupLayout in DirectWrite code right after setTextFormatProperties


DWRITE_TRIMMING trimming = {DWRITE_TRIMMING_GRANULARITY_CHARACTER, 0, 0}; 
ComSmartPtr<IDWriteInlineObject> trimmingSign; 
hr = directWriteFactory->CreateEllipsisTrimmingSign(dwTextFormat, trimmingSign.resetAndGetPointerAddress()); 
hr = dwTextFormat->SetTrimming(&trimming, trimmingSign);

so it cutoff the text (only in that case) if there is not enough height.

 

Having the right height will help CoreText as well.

I can live without the ellipsis handling but not be able to truncate the text given a max height is quite a deal breaker for me.

 

Thanks,

 


#9

Bump !


#10

Hey Jules, let me know what I should bring to the IRCAM meetup to motivate you to do this.

French cheese, wine, whatever you need :)


#11

Ho ho! I've not forgotten this one - I did start doing it but the changes ended up having more impact than I expected, so I didn't have time to finish. Will have it done before the Paris meet-up!


#12

Choose your gift then :)

 

Thanks ! 


#13

I've just committed some changes for this - only very lightly tested by me, so please let me know if it works for you!


#14

Works fine on Windows.

It seems to be not implemented on OSX.

You probably only need to do that in juce_mac_Fonts.mm line 388. It worked for me

 

-        const CGFloat boundsHeight = 1.0e6f;

+        const CGFloat boundsHeight = glyphLayout.getHeight();

 

Thanks,


#15

Ok, thanks!


#16

Reviving the dead here.
Would be great if there could be a way to force only one line in TextLayout.
I know that I could use the standard Graphics text drawing but my issue here is that it does not support automatic fallback font.

Thanks !


#17

bump :slight_smile:


#18

Looks like your last commit
https://github.com/WeAreROLI/JUCE/commit/5c854b49a8d358caa3056a5d9c057201424c0df2
fixed my issue if I set setWordWrap to none.
Was this intentional ?


#19

No… but if it accidentally fixed other problems, that’s great!