FontPlatformDataQt.cpp [plain text]
#include "config.h"
#include "FontPlatformData.h"
#include "PlatformString.h"
namespace WebCore {
static inline QFont::Weight toQFontWeight(FontWeight fontWeight)
{
switch (fontWeight) {
case FontWeight100:
case FontWeight200:
return QFont::Light; case FontWeight600:
return QFont::DemiBold; case FontWeight700:
case FontWeight800:
return QFont::Bold; case FontWeight900:
return QFont::Black; case FontWeight300:
case FontWeight400:
case FontWeight500:
default:
return QFont::Normal; }
}
static inline bool isEmptyValue(const float size, const bool bold, const bool oblique)
{
return !bold && !oblique && size == 0.f;
}
FontPlatformData::FontPlatformData(float size, bool bold, bool oblique)
{
if (!isEmptyValue(size, bold, oblique))
m_data = adoptRef(new FontPlatformDataPrivate(size, bold, oblique));
}
FontPlatformData::FontPlatformData(const FontDescription& description, const AtomicString& familyName, int wordSpacing, int letterSpacing)
: m_data(adoptRef(new FontPlatformDataPrivate()))
{
#if !HAVE(QRAWFONT)
QFont& font = m_data->font;
#else
QFont font;
#endif
int requestedSize = description.computedPixelSize();
font.setFamily(familyName);
font.setPixelSize(requestedSize);
font.setItalic(description.italic());
font.setWeight(toQFontWeight(description.weight()));
font.setWordSpacing(wordSpacing);
font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
m_data->bold = font.bold();
#if !HAVE(QRAWFONT)
const bool smallCaps = description.smallCaps();
font.setCapitalization(smallCaps ? QFont::SmallCaps : QFont::MixedCase);
m_data->size = (!requestedSize) ? requestedSize : font.pixelSize();
#else
m_data->rawFont = QRawFont::fromFont(font, QFontDatabase::Any);
m_data->size = requestedSize;
#endif
}
#if HAVE(QRAWFONT)
FontPlatformData::FontPlatformData(const FontPlatformData& other, float size)
: m_data(adoptRef(new FontPlatformDataPrivate()))
{
m_data->rawFont = other.m_data->rawFont;
m_data->bold = other.m_data->bold;
m_data->oblique = other.m_data->oblique;
m_data->rawFont.setPixelSize(size);
m_data->size = m_data->rawFont.pixelSize();
}
#endif // HAVE(QRAWFONT)
bool FontPlatformData::operator==(const FontPlatformData& other) const
{
if (m_data == other.m_data)
return true;
if (!m_data || !other.m_data || m_data->isDeletedValue || other.m_data->isDeletedValue)
return false;
const bool equals = (m_data->size == other.m_data->size
&& m_data->bold == other.m_data->bold
&& m_data->oblique == other.m_data->oblique
#if !HAVE(QRAWFONT)
&& m_data->font == other.m_data->font);
#else
&& m_data->rawFont == other.m_data->rawFont);
#endif
return equals;
}
unsigned FontPlatformData::hash() const
{
if (!m_data)
return 0;
if (m_data->isDeletedValue)
return 1;
#if !HAVE(QRAWFONT)
return (qHash(m_data->font.toString()) ^ qHash(m_data->bold)
^ qHash(m_data->oblique))
^ qHash(*reinterpret_cast<quint32*>(&m_data->size));
#else
return qHash(m_data->rawFont.familyName()) ^ qHash(m_data->rawFont.style())
^ qHash(m_data->rawFont.weight())
^ qHash(*reinterpret_cast<quint32*>(&m_data->size));
#endif
}
#ifndef NDEBUG
String FontPlatformData::description() const
{
return String();
}
#endif
}