SimpleFontDataCoreText.cpp [plain text]
#include "config.h"
#include "Font.h"
#include <CoreText/CoreText.h>
#include <pal/spi/cocoa/CoreTextSPI.h>
namespace WebCore {
RetainPtr<CFDictionaryRef> Font::getCFStringAttributes(bool enableKerning, FontOrientation orientation, const AtomString& locale) const
{
CFTypeRef keys[5];
CFTypeRef values[5];
keys[0] = kCTFontAttributeName;
values[0] = platformData().ctFont();
size_t count = 1;
#if USE(CTFONTSHAPEGLYPHS)
RetainPtr<CFStringRef> localeString;
if (!locale.isEmpty()) {
localeString = locale.string().createCFString();
keys[count] = kCTLanguageAttributeName;
values[count] = localeString.get();
++count;
}
#else
UNUSED_PARAM(locale);
#endif
static CTParagraphStyleRef paragraphStyle = [] {
auto paragraphStyle = CTParagraphStyleCreate(nullptr, 0);
CTParagraphStyleSetCompositionLanguage(paragraphStyle, kCTCompositionLanguageNone);
return paragraphStyle;
}();
keys[count] = kCTParagraphStyleAttributeName;
values[count] = paragraphStyle;
++count;
if (!enableKerning) {
const float zero = 0;
static CFNumberRef zeroKerningValue = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &zero);
keys[count] = kCTKernAttributeName;
values[count] = zeroKerningValue;
++count;
}
if (orientation == FontOrientation::Vertical) {
keys[count] = kCTVerticalFormsAttributeName;
values[count] = kCFBooleanTrue;
++count;
}
ASSERT(count <= WTF_ARRAY_LENGTH(keys));
return adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, count, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
}
}