#ifndef FontDescription_h
#define FontDescription_h
#include "FontFamily.h"
#include "FontOrientation.h"
#include "FontRenderingMode.h"
#include "FontSmoothingMode.h"
#include "FontTraitsMask.h"
#include "FontWidthVariant.h"
#include "TextOrientation.h"
#include "TextRenderingMode.h"
#include <wtf/MathExtras.h>
namespace WebCore {
enum FontWeight {
FontWeight100,
FontWeight200,
FontWeight300,
FontWeight400,
FontWeight500,
FontWeight600,
FontWeight700,
FontWeight800,
FontWeight900,
FontWeightNormal = FontWeight400,
FontWeightBold = FontWeight700
};
enum FontItalic {
FontItalicOff = 0,
FontItalicOn = 1
};
enum FontSmallCaps {
FontSmallCapsOff = 0,
FontSmallCapsOn = 1
};
class FontDescription {
public:
enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFamily,
MonospaceFamily, CursiveFamily, FantasyFamily };
FontDescription()
: m_specifiedSize(0)
, m_computedSize(0)
, m_orientation(Horizontal)
, m_textOrientation(TextOrientationVerticalRight)
, m_widthVariant(RegularWidth)
, m_italic(FontItalicOff)
, m_smallCaps(FontSmallCapsOff)
, m_isAbsoluteSize(false)
, m_weight(FontWeightNormal)
, m_genericFamily(NoFamily)
, m_usePrinterFont(false)
, m_renderingMode(NormalRenderingMode)
, m_keywordSize(0)
, m_fontSmoothing(AutoSmoothing)
, m_textRendering(AutoTextRendering)
, m_isSpecifiedFont(false)
{
}
bool operator==(const FontDescription&) const;
bool operator!=(const FontDescription& other) const { return !(*this == other); }
const FontFamily& family() const { return m_familyList; }
FontFamily& firstFamily() { return m_familyList; }
float specifiedSize() const { return m_specifiedSize; }
float computedSize() const { return m_computedSize; }
FontItalic italic() const { return static_cast<FontItalic>(m_italic); }
int computedPixelSize() const { return int(m_computedSize + 0.5f); }
FontSmallCaps smallCaps() const { return static_cast<FontSmallCaps>(m_smallCaps); }
bool isAbsoluteSize() const { return m_isAbsoluteSize; }
FontWeight weight() const { return static_cast<FontWeight>(m_weight); }
FontWeight lighterWeight() const;
FontWeight bolderWeight() const;
GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); }
bool usePrinterFont() const { return m_usePrinterFont; }
bool useFixedDefaultSize() const { return genericFamily() == MonospaceFamily && !family().next() && family().family() == "-webkit-monospace"; }
FontRenderingMode renderingMode() const { return static_cast<FontRenderingMode>(m_renderingMode); }
unsigned keywordSize() const { return m_keywordSize; }
FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMode>(m_fontSmoothing); }
TextRenderingMode textRenderingMode() const { return static_cast<TextRenderingMode>(m_textRendering); }
FontTraitsMask traitsMask() const;
bool isSpecifiedFont() const { return m_isSpecifiedFont; }
FontOrientation orientation() const { return m_orientation; }
TextOrientation textOrientation() const { return m_textOrientation; }
FontWidthVariant widthVariant() const { return m_widthVariant; }
void setFamily(const FontFamily& family) { m_familyList = family; }
void setComputedSize(float s) { ASSERT(isfinite(s)); m_computedSize = s; }
void setSpecifiedSize(float s) { ASSERT(isfinite(s)); m_specifiedSize = s; }
void setItalic(FontItalic i) { m_italic = i; }
void setItalic(bool i) { setItalic(i ? FontItalicOn : FontItalicOff); }
void setSmallCaps(FontSmallCaps c) { m_smallCaps = c; }
void setSmallCaps(bool c) { setSmallCaps(c ? FontSmallCapsOn : FontSmallCapsOff); }
void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; }
void setWeight(FontWeight w) { m_weight = w; }
void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = genericFamily; }
#if PLATFORM(CHROMIUM) && OS(DARWIN)
void setUsePrinterFont(bool) { }
#else
void setUsePrinterFont(bool p) { m_usePrinterFont = p; }
#endif
void setRenderingMode(FontRenderingMode mode) { m_renderingMode = mode; }
void setKeywordSize(unsigned s) { m_keywordSize = s; }
void setFontSmoothing(FontSmoothingMode smoothing) { m_fontSmoothing = smoothing; }
void setTextRenderingMode(TextRenderingMode rendering) { m_textRendering = rendering; }
void setIsSpecifiedFont(bool isSpecifiedFont) { m_isSpecifiedFont = isSpecifiedFont; }
void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
void setTextOrientation(TextOrientation textOrientation) { m_textOrientation = textOrientation; }
void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = widthVariant; }
private:
FontFamily m_familyList;
float m_specifiedSize; float m_computedSize;
FontOrientation m_orientation; TextOrientation m_textOrientation;
FontWidthVariant m_widthVariant;
unsigned m_italic : 1; unsigned m_smallCaps : 1; bool m_isAbsoluteSize : 1; unsigned m_weight : 8; unsigned m_genericFamily : 3; bool m_usePrinterFont : 1;
unsigned m_renderingMode : 1;
unsigned m_keywordSize : 4;
unsigned m_fontSmoothing : 2; unsigned m_textRendering : 2; bool m_isSpecifiedFont : 1; };
inline bool FontDescription::operator==(const FontDescription& other) const
{
return m_familyList == other.m_familyList
&& m_specifiedSize == other.m_specifiedSize
&& m_computedSize == other.m_computedSize
&& m_italic == other.m_italic
&& m_smallCaps == other.m_smallCaps
&& m_isAbsoluteSize == other.m_isAbsoluteSize
&& m_weight == other.m_weight
&& m_genericFamily == other.m_genericFamily
&& m_usePrinterFont == other.m_usePrinterFont
&& m_renderingMode == other.m_renderingMode
&& m_keywordSize == other.m_keywordSize
&& m_fontSmoothing == other.m_fontSmoothing
&& m_textRendering == other.m_textRendering
&& m_isSpecifiedFont == other.m_isSpecifiedFont
&& m_orientation == other.m_orientation
&& m_textOrientation == other.m_textOrientation
&& m_widthVariant == other.m_widthVariant;
}
}
#endif