Browse Source

macOS: Set CoreText underline property when creating native text layout

tags/2021-05-28
ed 5 years ago
parent
commit
4ddcc7bb61
1 changed files with 29 additions and 0 deletions
  1. +29
    -0
      modules/juce_graphics/native/juce_mac_Fonts.mm

+ 29
- 0
modules/juce_graphics/native/juce_mac_Fonts.mm View File

@@ -234,6 +234,15 @@ namespace CoreTextTypeLayout
ctFontRef = getFontWithPointSize (ctFontRef, attr.font.getHeight() * getHeightToPointsFactor (ctFontRef));
CFAttributedStringSetAttribute (attribString, range, kCTFontAttributeName, ctFontRef);
if (attr.font.isUnderlined())
{
auto underline = kCTUnderlineStyleSingle;
auto numberRef = CFNumberCreate (nullptr, kCFNumberIntType, &underline);
CFAttributedStringSetAttribute (attribString, range, kCTUnderlineStyleAttributeName, numberRef);
CFRelease (numberRef);
}
auto extraKerning = attr.font.getExtraKerningFactor();
if (extraKerning != 0)
@@ -463,6 +472,26 @@ namespace CoreTextTypeLayout
String::fromCFString (cfsFontStyle),
(float) (CTFontGetSize (ctRunFont) / fontHeightToPointsFactor));
auto isUnderlined = [&]
{
CFNumberRef underlineStyle;
if (CFDictionaryGetValueIfPresent (runAttributes, kCTUnderlineStyleAttributeName, (const void**) &underlineStyle))
{
if (CFGetTypeID (underlineStyle) == CFNumberGetTypeID())
{
int value = 0;
CFNumberGetValue (underlineStyle, kCFNumberLongType, (void*) &value);
return value != 0;
}
}
return false;
}();
glyphRun->font.setUnderline (isUnderlined);
CFRelease (cfsFontStyle);
CFRelease (cfsFontFamily);
}


Loading…
Cancel
Save