FontFamilySpecificationCoreText.cpp [plain text]
#include "config.h"
#include "FontFamilySpecificationCoreText.h"
#include "FontCache.h"
#include "FontSelector.h"
#include <CoreText/CoreText.h>
#include <wtf/SoftLinking.h>
#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
SOFT_LINK_FRAMEWORK(CoreText);
SOFT_LINK_MAY_FAIL(CoreText, CTFontCopyPhysicalFont, CTFontRef, (CTFontRef font), (font));
#endif
namespace WebCore {
FontFamilySpecificationCoreText::FontFamilySpecificationCoreText(CTFontDescriptorRef fontDescriptor)
: m_fontDescriptor(fontDescriptor)
{
}
FontFamilySpecificationCoreText::~FontFamilySpecificationCoreText()
{
}
FontRanges FontFamilySpecificationCoreText::fontRanges(const FontDescription& fontDescription) const
{
auto size = fontDescription.computedSize();
auto font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr));
auto fontForSynthesisComputation = font;
#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
if (canLoadCTFontCopyPhysicalFont()) {
if (auto physicalFont = adoptCF(CTFontCopyPhysicalFont(font.get())))
fontForSynthesisComputation = physicalFont;
}
#endif
font = preparePlatformFont(font.get(), fontDescription, nullptr, nullptr, { }, fontDescription.computedSize());
bool syntheticBold, syntheticOblique;
std::tie(syntheticBold, syntheticOblique) = computeNecessarySynthesis(fontForSynthesisComputation.get(), fontDescription).boldObliquePair();
FontPlatformData fontPlatformData(font.get(), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.textRenderingMode());
return FontRanges(FontCache::singleton().fontForPlatformData(fontPlatformData));
}
}