Support underline and strikethrough in wxMarkupToAttrString
Honor wxFont's strikethrough and underline attributes when converting label markup to NSAttributedString. On macOS, strikethrough and underline are properties of (rich) text, not of fonts, so a conversion like this is necessary.
This commit is contained in:
@@ -41,9 +41,7 @@ protected:
|
||||
// Apple documentation, attributed strings use "Helvetica 12" font by
|
||||
// default which is different from the system "Lucida Grande" font. So
|
||||
// we need to explicitly change the font for the entire string.
|
||||
[m_attrString addAttribute:NSFontAttributeName
|
||||
value:font.OSXGetNSFont()
|
||||
range:NSMakeRange(0, [m_attrString length])];
|
||||
ApplyFont(font, NSMakeRange(0, [m_attrString length]));
|
||||
|
||||
// Now translate the markup tags to corresponding attributes.
|
||||
wxMarkupParser parser(*this);
|
||||
@@ -58,6 +56,27 @@ protected:
|
||||
[m_attrString release];
|
||||
}
|
||||
|
||||
void ApplyFont(const wxFont& font, const NSRange& range)
|
||||
{
|
||||
[m_attrString addAttribute:NSFontAttributeName
|
||||
value:font.OSXGetNSFont()
|
||||
range:range];
|
||||
|
||||
if ( font.GetStrikethrough() )
|
||||
{
|
||||
[m_attrString addAttribute:NSStrikethroughStyleAttributeName
|
||||
value:@(NSUnderlineStyleSingle)
|
||||
range:range];
|
||||
}
|
||||
|
||||
if ( font.GetUnderlined() )
|
||||
{
|
||||
[m_attrString addAttribute:NSUnderlineStyleAttributeName
|
||||
value:@(NSUnderlineStyleSingle)
|
||||
range:range];
|
||||
}
|
||||
}
|
||||
|
||||
// prepare text chunk for display, e.g. strip mnemonics from it
|
||||
virtual wxString PrepareText(const wxString& text) = 0;
|
||||
|
||||
@@ -91,9 +110,7 @@ public:
|
||||
|
||||
const NSRange range = NSMakeRange(start, m_pos - start);
|
||||
|
||||
[m_attrString addAttribute:NSFontAttributeName
|
||||
value:attr.font.OSXGetNSFont()
|
||||
range:range];
|
||||
ApplyFont(attr.font, range);
|
||||
|
||||
if ( attr.foreground.IsOk() )
|
||||
{
|
||||
|
Reference in New Issue
Block a user