FontDescription.cpp [plain text]
#include "config.h"
#include "FontDescription.h"
namespace WebCore {
struct SameSizeAsFontDescription {
Vector<AtomicString, 1> families;
RefPtr<FontFeatureSettings> m_featureSettings;
float sizes[2];
uint32_t bitfields;
uint32_t bitfields2 : 8;
};
COMPILE_ASSERT(sizeof(FontDescription) == sizeof(SameSizeAsFontDescription), FontDescription_should_stay_small);
FontWeight FontDescription::lighterWeight(void) const
{
switch (m_weight) {
case FontWeight100:
case FontWeight200:
return FontWeight100;
case FontWeight300:
return FontWeight200;
case FontWeight400:
case FontWeight500:
return FontWeight300;
case FontWeight600:
case FontWeight700:
return FontWeight400;
case FontWeight800:
return FontWeight500;
case FontWeight900:
return FontWeight700;
}
ASSERT_NOT_REACHED();
return FontWeightNormal;
}
FontWeight FontDescription::bolderWeight(void) const
{
switch (m_weight) {
case FontWeight100:
case FontWeight200:
return FontWeight300;
case FontWeight300:
return FontWeight400;
case FontWeight400:
case FontWeight500:
return FontWeight700;
case FontWeight600:
case FontWeight700:
return FontWeight800;
case FontWeight800:
case FontWeight900:
return FontWeight900;
}
ASSERT_NOT_REACHED();
return FontWeightNormal;
}
FontTraitsMask FontDescription::traitsMask() const
{
return static_cast<FontTraitsMask>((m_italic ? FontStyleItalicMask : FontStyleNormalMask)
| (m_smallCaps ? FontVariantSmallCapsMask : FontVariantNormalMask)
| (FontWeight100Mask << (m_weight - FontWeight100)));
}
FontDescription FontDescription::makeNormalFeatureSettings() const
{
FontDescription normalDescription(*this);
normalDescription.setFeatureSettings(0);
return normalDescription;
}
#if ENABLE(IOS_TEXT_AUTOSIZING)
bool FontDescription::familiesEqualForTextAutoSizing(const FontDescription& other) const
{
unsigned thisFamilyCount = familyCount();
unsigned otherFamilyCount = other.familyCount();
if (thisFamilyCount != otherFamilyCount)
return false;
for (unsigned i = 0; i < thisFamilyCount; ++i) {
if (!equalIgnoringCase(familyAt(i), other.familyAt(i)))
return false;
}
return true;
}
#endif // ENABLE(IOS_TEXT_AUTOSIZING)
}