AttributedString not drawing underline for underlined fonts


#1

Is it possible that AttributedString ignores fonts being underlined and just draws it without the underline?


#2

It is quite possible, I don't know offhand..


#3

Well, I just checked it in the Demo solution.

This code produces no underlined font:

        Font font (fonts [rowNumber]);

        font.setUnderline(true); //Added this line

        AttributedString s;
        s.setWordWrap (AttributedString::none);
        s.setJustification (Justification::centredLeft);
        s.append (font.getTypefaceName(), font.withPointHeight (height * 0.7f), Colours::black);
        s.append ("   " + font.getTypefaceName(), Font (height * 0.5f, Font::italic), Colours::grey);
        s.draw (g, Rectangle<int> (width, height).expanded (-4, 50).toFloat());

Is this the intended behaviour for AttributedString?

 


#4

No, it's not the intended behaviour, but the AttributedString does rely on OS functions to do that layout, and to tell it which font to use, and OS typefaces don't preserve the underline flag. Not sure how I could fix that without a lot of effort.


#5

Any alternatives you recommend? Or just use Graphics::drawText?


#6

That would certainly work. TextLayout/GlyphArrangement may also work.


#7

I am having the same issue with underlining, however I am using a textlayout for this.  Any clues on how to underline a range of text would be greatly appreciated.

 

Thanks,
Darren

 

  


#8

Using the data after a createlayout I can get the glyph positions and just use this to "draw" an underline.  If there is a more elegant solution I am all ears.