1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-11 23:54:18 +00:00

macOS: Set CoreText underline property when creating native text layout

This commit is contained in:
ed 2020-08-03 19:32:15 +01:00
parent 12bff68e34
commit 4ddcc7bb61

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);
}