FontPlatformDataLinux.cpp [plain text]
#include "config.h"
#include "FontPlatformData.h"
#include "StringImpl.h"
#include "NotImplemented.h"
#include "SkPaint.h"
#include "SkTypeface.h"
namespace WebCore {
FontPlatformData::FontPlatformData(const FontPlatformData& src)
: m_typeface(src.m_typeface)
, m_textSize(src.m_textSize)
, m_fakeBold(src.m_fakeBold)
, m_fakeItalic(src.m_fakeItalic)
{
m_typeface->safeRef();
}
FontPlatformData::FontPlatformData(SkTypeface* tf, float textSize, bool fakeBold, bool fakeItalic)
: m_typeface(tf)
, m_textSize(textSize)
, m_fakeBold(fakeBold)
, m_fakeItalic(fakeItalic)
{
m_typeface->safeRef();
}
FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize)
: m_typeface(src.m_typeface)
, m_textSize(textSize)
, m_fakeBold(src.m_fakeBold)
, m_fakeItalic(src.m_fakeItalic)
{
m_typeface->safeRef();
}
FontPlatformData::~FontPlatformData()
{
m_typeface->safeUnref();
}
FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src)
{
SkRefCnt_SafeAssign(m_typeface, src.m_typeface);
m_textSize = src.m_textSize;
m_fakeBold = src.m_fakeBold;
m_fakeItalic = src.m_fakeItalic;
return *this;
}
void FontPlatformData::setupPaint(SkPaint* paint) const
{
const float ts = m_textSize > 0 ? m_textSize : 12;
paint->setAntiAlias(true);
paint->setSubpixelText(false);
paint->setTextSize(SkFloatToScalar(ts));
paint->setTypeface(m_typeface);
paint->setFakeBoldText(m_fakeBold);
paint->setTextSkewX(m_fakeItalic ? -SK_Scalar1 / 4 : 0);
}
SkFontID FontPlatformData::uniqueID() const
{
return m_typeface->uniqueID();
}
bool FontPlatformData::operator==(const FontPlatformData& a) const
{
bool typefacesEqual;
if (m_typeface == hashTableDeletedFontValue()
|| a.m_typeface == hashTableDeletedFontValue()
|| !m_typeface
|| !a.m_typeface)
typefacesEqual = m_typeface == a.m_typeface;
else
typefacesEqual = SkTypeface::Equal(m_typeface, a.m_typeface);
return typefacesEqual
&& m_textSize == a.m_textSize
&& m_fakeBold == a.m_fakeBold
&& m_fakeItalic == a.m_fakeItalic;
}
unsigned FontPlatformData::hash() const
{
unsigned h = SkTypeface::UniqueID(m_typeface);
h ^= 0x01010101 * ((static_cast<int>(m_fakeBold) << 1) | static_cast<int>(m_fakeItalic));
uint32_t textSizeBytes;
memcpy(&textSizeBytes, &m_textSize, sizeof(uint32_t));
h ^= textSizeBytes;
return h;
}
bool FontPlatformData::isFixedPitch() const
{
notImplemented();
return false;
}
}