This source file includes following definitions.
- setupPaint
- getSystemTextFlags
- isWebFont
- computePaintTextFlags
- m_minSizeForAntiAlias
- m_minSizeForAntiAlias
- m_minSizeForAntiAlias
- m_minSizeForAntiAlias
- m_minSizeForAntiAlias
- m_minSizeForAntiAlias
- fontFamilyName
- isFixedPitch
- harfBuzzFace
- uniqueID
- defaultUseSubpixelPositioning
- description
#include "config.h"
#include "platform/fonts/FontPlatformData.h"
#include "SkTypeface.h"
#include "platform/LayoutTestSupport.h"
#include "platform/fonts/FontCache.h"
#include "platform/fonts/harfbuzz/HarfBuzzFace.h"
#include "platform/graphics/GraphicsContext.h"
#include "public/platform/Platform.h"
#include "public/platform/win/WebSandboxSupport.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/StdLibExtras.h"
#include <windows.h>
namespace WebCore {
void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext* context) const
{
const float ts = m_textSize >= 0 ? m_textSize : 12;
paint->setTextSize(SkFloatToScalar(m_textSize));
paint->setTypeface(typeface());
paint->setFakeBoldText(m_syntheticBold);
paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0);
uint32_t textFlags = paintTextFlags();
uint32_t flags = paint->getFlags();
static const uint32_t textFlagsMask = SkPaint::kAntiAlias_Flag |
SkPaint::kLCDRenderText_Flag |
SkPaint::kGenA8FromLCD_Flag;
flags &= ~textFlagsMask;
if (ts >= m_minSizeForAntiAlias) {
paint->setSubpixelText(m_useSubpixelPositioning);
if (context && !context->couldUseLCDRenderedText()) {
textFlags &= ~SkPaint::kLCDRenderText_Flag;
textFlags |= SkPaint::kGenA8FromLCD_Flag;
}
SkASSERT(!(textFlags & ~textFlagsMask));
flags |= textFlags;
} else {
paint->setSubpixelText(false);
}
paint->setFlags(flags);
}
static uint32_t getSystemTextFlags()
{
static bool gInited;
static uint32_t gFlags;
if (!gInited) {
BOOL enabled;
gFlags = 0;
if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) {
gFlags |= SkPaint::kAntiAlias_Flag;
UINT smoothType;
if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smoothType, 0)) {
if (FE_FONTSMOOTHINGCLEARTYPE == smoothType)
gFlags |= SkPaint::kLCDRenderText_Flag;
}
}
gInited = true;
}
return gFlags;
}
static bool isWebFont(const String& familyName)
{
return familyName.length() == 24
&& '=' == familyName[22] && '=' == familyName[23];
}
static int computePaintTextFlags(String fontFamilyName)
{
int textFlags = getSystemTextFlags();
if (isWebFont(fontFamilyName) && !isRunningLayoutTest())
textFlags |= SkPaint::kAntiAlias_Flag;
return textFlags;
}
FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
: m_textSize(-1)
, m_syntheticBold(false)
, m_syntheticItalic(false)
, m_orientation(Horizontal)
, m_typeface(adoptRef(SkTypeface::RefDefault()))
, m_paintTextFlags(0)
, m_isHashTableDeletedValue(true)
, m_useSubpixelPositioning(false)
, m_minSizeForAntiAlias(0)
{
}
FontPlatformData::FontPlatformData()
: m_textSize(0)
, m_syntheticBold(false)
, m_syntheticItalic(false)
, m_orientation(Horizontal)
, m_typeface(adoptRef(SkTypeface::RefDefault()))
, m_paintTextFlags(0)
, m_isHashTableDeletedValue(false)
, m_useSubpixelPositioning(false)
, m_minSizeForAntiAlias(0)
{
}
FontPlatformData::FontPlatformData(float size, bool bold, bool oblique)
: m_textSize(size)
, m_syntheticBold(false)
, m_syntheticItalic(false)
, m_orientation(Horizontal)
, m_typeface(adoptRef(SkTypeface::RefDefault()))
, m_paintTextFlags(0)
, m_isHashTableDeletedValue(false)
, m_useSubpixelPositioning(false)
, m_minSizeForAntiAlias(0)
{
}
FontPlatformData::FontPlatformData(const FontPlatformData& data)
: m_textSize(data.m_textSize)
, m_syntheticBold(data.m_syntheticBold)
, m_syntheticItalic(data.m_syntheticItalic)
, m_orientation(data.m_orientation)
, m_typeface(data.m_typeface)
, m_paintTextFlags(data.m_paintTextFlags)
, m_isHashTableDeletedValue(false)
, m_useSubpixelPositioning(data.m_useSubpixelPositioning)
, m_minSizeForAntiAlias(data.m_minSizeForAntiAlias)
{
}
FontPlatformData::FontPlatformData(const FontPlatformData& data, float textSize)
: m_textSize(textSize)
, m_syntheticBold(data.m_syntheticBold)
, m_syntheticItalic(data.m_syntheticItalic)
, m_orientation(data.m_orientation)
, m_typeface(data.m_typeface)
, m_paintTextFlags(data.m_paintTextFlags)
, m_isHashTableDeletedValue(false)
, m_useSubpixelPositioning(data.m_useSubpixelPositioning)
, m_minSizeForAntiAlias(data.m_minSizeForAntiAlias)
{
}
FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family,
float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation orientation,
bool useSubpixelPositioning)
: m_textSize(textSize)
, m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(orientation)
, m_typeface(tf)
, m_isHashTableDeletedValue(false)
, m_useSubpixelPositioning(useSubpixelPositioning)
, m_minSizeForAntiAlias(0)
{
m_paintTextFlags = computePaintTextFlags(fontFamilyName());
}
FontPlatformData::~FontPlatformData()
{
}
FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data)
{
if (this != &data) {
m_textSize = data.m_textSize;
m_syntheticBold = data.m_syntheticBold;
m_syntheticItalic = data.m_syntheticItalic;
m_orientation = data.m_orientation;
m_typeface = data.m_typeface;
m_paintTextFlags = data.m_paintTextFlags;
m_minSizeForAntiAlias = data.m_minSizeForAntiAlias;
}
return *this;
}
String FontPlatformData::fontFamilyName() const
{
ASSERT(typeface());
SkString familyName;
typeface()->getFamilyName(&familyName);
return String::fromUTF8(familyName.c_str());
}
bool FontPlatformData::isFixedPitch() const
{
return typeface() && typeface()->isFixedPitch();
}
bool FontPlatformData::operator==(const FontPlatformData& a) const
{
return SkTypeface::Equal(m_typeface.get(), a.m_typeface.get())
&& m_textSize == a.m_textSize
&& m_syntheticBold == a.m_syntheticBold
&& m_syntheticItalic == a.m_syntheticItalic
&& m_orientation == a.m_orientation
&& m_isHashTableDeletedValue == a.m_isHashTableDeletedValue;
}
HarfBuzzFace* FontPlatformData::harfBuzzFace() const
{
if (!m_harfBuzzFace)
m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this), uniqueID());
return m_harfBuzzFace.get();
}
SkFontID FontPlatformData::uniqueID() const
{
return m_typeface->uniqueID();
}
bool FontPlatformData::defaultUseSubpixelPositioning()
{
return FontCache::fontCache()->useSubpixelPositioning();
}
#ifndef NDEBUG
String FontPlatformData::description() const
{
return String();
}
#endif
}