This source file includes following definitions.
- platformInit
- platformFallbackForCharacter
- getLastResortFallbackFont
- createTypeface
- createFontPlatformData
#include "config.h"
#include "SkFontMgr.h"
#include "SkTypeface.h"
#include "platform/NotImplemented.h"
#include "platform/fonts/AlternateFontFamily.h"
#include "platform/fonts/FontCache.h"
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/SimpleFontData.h"
#include "wtf/Assertions.h"
#include "wtf/text/AtomicString.h"
#include "wtf/text/CString.h"
#include <unicode/locid.h>
namespace WebCore {
void FontCache::platformInit()
{
}
#if !OS(WIN) && !OS(ANDROID)
PassRefPtr<SimpleFontData> FontCache::platformFallbackForCharacter(const FontDescription& fontDescription, UChar32 c, const SimpleFontData*)
{
icu::Locale locale = icu::Locale::getDefault();
FontCache::SimpleFontFamily family;
FontCache::getFontFamilyForCharacter(c, locale.getLanguage(), &family);
if (family.name.isEmpty())
return nullptr;
AtomicString atomicFamily(family.name);
bool shouldSetSyntheticBold = false;
bool shouldSetSyntheticItalic = false;
FontDescription description(fontDescription);
if (family.isBold && description.weight() < FontWeightBold)
description.setWeight(FontWeightBold);
if (!family.isBold && description.weight() >= FontWeightBold) {
shouldSetSyntheticBold = true;
description.setWeight(FontWeightNormal);
}
if (family.isItalic && description.style() == FontStyleNormal)
description.setStyle(FontStyleItalic);
if (!family.isItalic && description.style() == FontStyleItalic) {
shouldSetSyntheticItalic = true;
description.setStyle(FontStyleNormal);
}
FontPlatformData* substitutePlatformData = getFontPlatformData(description, atomicFamily);
if (!substitutePlatformData)
return nullptr;
FontPlatformData platformData = FontPlatformData(*substitutePlatformData);
platformData.setSyntheticBold(shouldSetSyntheticBold);
platformData.setSyntheticItalic(shouldSetSyntheticItalic);
return fontDataFromFontPlatformData(&platformData, DoNotRetain);
}
#endif
PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescription& description, ShouldRetain shouldRetain)
{
const AtomicString fallbackFontFamily = getFallbackFontFamily(description);
const FontPlatformData* fontPlatformData = getFontPlatformData(description, fallbackFontFamily);
if (!fontPlatformData) {
DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("Sans", AtomicString::ConstructFromLiteral));
fontPlatformData = getFontPlatformData(description, sansStr);
}
if (!fontPlatformData) {
DEFINE_STATIC_LOCAL(const AtomicString, arialStr, ("Arial", AtomicString::ConstructFromLiteral));
fontPlatformData = getFontPlatformData(description, arialStr);
}
ASSERT(fontPlatformData);
return fontDataFromFontPlatformData(fontPlatformData, shouldRetain);
}
PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDescription, const AtomicString& family, CString& name)
{
if (!family.length() || family.startsWith("-webkit-")) {
name = getFallbackFontFamily(fontDescription).string().utf8();
} else {
name = family.utf8();
}
int style = SkTypeface::kNormal;
if (fontDescription.weight() >= FontWeightBold)
style |= SkTypeface::kBold;
if (fontDescription.style())
style |= SkTypeface::kItalic;
#if OS(WIN)
if (m_fontManager)
return adoptRef(m_fontManager->legacyCreateTypeface(name.data(), style));
#endif
return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypeface::Style>(style)));
}
#if !OS(WIN)
FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family, float fontSize)
{
CString name;
RefPtr<SkTypeface> tf(createTypeface(fontDescription, family, name));
if (!tf)
return 0;
FontPlatformData* result = new FontPlatformData(tf,
name.data(),
fontSize,
(fontDescription.weight() >= FontWeightBold && !tf->isBold()) || fontDescription.isSyntheticBold(),
(fontDescription.style() && !tf->isItalic()) || fontDescription.isSyntheticItalic(),
fontDescription.orientation(),
fontDescription.useSubpixelPositioning());
return result;
}
#endif
}