1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org) 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIother.m_ If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USm_ 22 * 23 */ 24 25 #ifndef FontDescription_h 26 #define FontDescription_h 27 28 #include "FontFamily.h" 29 #include "FontOrientation.h" 30 #include "FontRenderingMode.h" 31 #include "FontSmoothingMode.h" 32 #include "FontTraitsMask.h" 33 #include "FontWidthVariant.h" 34 #include "TextOrientation.h" 35 #include "TextRenderingMode.h" 36 37 namespace WebCore { 38 39 enum FontWeight { 40 FontWeight100, 41 FontWeight200, 42 FontWeight300, 43 FontWeight400, 44 FontWeight500, 45 FontWeight600, 46 FontWeight700, 47 FontWeight800, 48 FontWeight900, 49 FontWeightNormal = FontWeight400, 50 FontWeightBold = FontWeight700 51 }; 52 53 class FontDescription { 54 public: 55 enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFamily, 56 MonospaceFamily, CursiveFamily, FantasyFamily }; 57 FontDescription()58 FontDescription() 59 : m_specifiedSize(0) 60 , m_computedSize(0) 61 , m_orientation(Horizontal) 62 , m_textOrientation(TextOrientationVerticalRight) 63 , m_widthVariant(RegularWidth) 64 , m_italic(false) 65 , m_smallCaps(false) 66 , m_isAbsoluteSize(false) 67 , m_weight(FontWeightNormal) 68 , m_genericFamily(NoFamily) 69 , m_usePrinterFont(false) 70 , m_renderingMode(NormalRenderingMode) 71 , m_keywordSize(0) 72 , m_fontSmoothing(AutoSmoothing) 73 , m_textRendering(AutoTextRendering) 74 , m_isSpecifiedFont(false) 75 { 76 } 77 78 bool operator==(const FontDescription&) const; 79 bool operator!=(const FontDescription& other) const { return !(*this == other); } 80 family()81 const FontFamily& family() const { return m_familyList; } firstFamily()82 FontFamily& firstFamily() { return m_familyList; } specifiedSize()83 float specifiedSize() const { return m_specifiedSize; } computedSize()84 float computedSize() const { return m_computedSize; } italic()85 bool italic() const { return m_italic; } computedPixelSize()86 int computedPixelSize() const { return int(m_computedSize + 0.5f); } smallCaps()87 bool smallCaps() const { return m_smallCaps; } isAbsoluteSize()88 bool isAbsoluteSize() const { return m_isAbsoluteSize; } weight()89 FontWeight weight() const { return static_cast<FontWeight>(m_weight); } 90 FontWeight lighterWeight() const; 91 FontWeight bolderWeight() const; genericFamily()92 GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); } usePrinterFont()93 bool usePrinterFont() const { return m_usePrinterFont; } 94 // only use fixed default size when there is only one font family, and that family is "monospace" useFixedDefaultSize()95 bool useFixedDefaultSize() const { return genericFamily() == MonospaceFamily && !family().next() && family().family() == "-webkit-monospace"; } renderingMode()96 FontRenderingMode renderingMode() const { return static_cast<FontRenderingMode>(m_renderingMode); } keywordSize()97 unsigned keywordSize() const { return m_keywordSize; } fontSmoothing()98 FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMode>(m_fontSmoothing); } textRenderingMode()99 TextRenderingMode textRenderingMode() const { return static_cast<TextRenderingMode>(m_textRendering); } 100 101 FontTraitsMask traitsMask() const; isSpecifiedFont()102 bool isSpecifiedFont() const { return m_isSpecifiedFont; } orientation()103 FontOrientation orientation() const { return m_orientation; } textOrientation()104 TextOrientation textOrientation() const { return m_textOrientation; } widthVariant()105 FontWidthVariant widthVariant() const { return m_widthVariant; } 106 setFamily(const FontFamily & family)107 void setFamily(const FontFamily& family) { m_familyList = family; } setComputedSize(float s)108 void setComputedSize(float s) { m_computedSize = s; } setSpecifiedSize(float s)109 void setSpecifiedSize(float s) { m_specifiedSize = s; } setItalic(bool i)110 void setItalic(bool i) { m_italic = i; } setSmallCaps(bool c)111 void setSmallCaps(bool c) { m_smallCaps = c; } setIsAbsoluteSize(bool s)112 void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; } setWeight(FontWeight w)113 void setWeight(FontWeight w) { m_weight = w; } setGenericFamily(GenericFamilyType genericFamily)114 void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = genericFamily; } 115 #if PLATFORM(CHROMIUM) && OS(DARWIN) setUsePrinterFont(bool)116 void setUsePrinterFont(bool) { } 117 #else setUsePrinterFont(bool p)118 void setUsePrinterFont(bool p) { m_usePrinterFont = p; } 119 #endif setRenderingMode(FontRenderingMode mode)120 void setRenderingMode(FontRenderingMode mode) { m_renderingMode = mode; } setKeywordSize(unsigned s)121 void setKeywordSize(unsigned s) { m_keywordSize = s; } setFontSmoothing(FontSmoothingMode smoothing)122 void setFontSmoothing(FontSmoothingMode smoothing) { m_fontSmoothing = smoothing; } setTextRenderingMode(TextRenderingMode rendering)123 void setTextRenderingMode(TextRenderingMode rendering) { m_textRendering = rendering; } setIsSpecifiedFont(bool isSpecifiedFont)124 void setIsSpecifiedFont(bool isSpecifiedFont) { m_isSpecifiedFont = isSpecifiedFont; } setOrientation(FontOrientation orientation)125 void setOrientation(FontOrientation orientation) { m_orientation = orientation; } setTextOrientation(TextOrientation textOrientation)126 void setTextOrientation(TextOrientation textOrientation) { m_textOrientation = textOrientation; } setWidthVariant(FontWidthVariant widthVariant)127 void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = widthVariant; } 128 129 private: 130 FontFamily m_familyList; // The list of font families to be used. 131 132 float m_specifiedSize; // Specified CSS value. Independent of rendering issues such as integer 133 // rounding, minimum font sizes, and zooming. 134 float m_computedSize; // Computed size adjusted for the minimum font size and the zoom factor. 135 136 FontOrientation m_orientation; // Whether the font is rendering on a horizontal line or a vertical line. 137 TextOrientation m_textOrientation; // Only used by vertical text. Determines the default orientation for non-ideograph glyphs. 138 139 FontWidthVariant m_widthVariant; 140 141 bool m_italic : 1; 142 bool m_smallCaps : 1; 143 bool m_isAbsoluteSize : 1; // Whether or not CSS specified an explicit size 144 // (logical sizes like "medium" don't count). 145 unsigned m_weight : 8; // FontWeight 146 unsigned m_genericFamily : 3; // GenericFamilyType 147 bool m_usePrinterFont : 1; 148 149 unsigned m_renderingMode : 1; // Used to switch between CG and GDI text on Windows. 150 151 unsigned m_keywordSize : 4; // We cache whether or not a font is currently represented by a CSS keyword (e.g., medium). If so, 152 // then we can accurately translate across different generic families to adjust for different preference settings 153 // (e.g., 13px monospace vs. 16px everything else). Sizes are 1-8 (like the HTML size values for <font>). 154 155 unsigned m_fontSmoothing : 2; // FontSmoothingMode 156 unsigned m_textRendering : 2; // TextRenderingMode 157 bool m_isSpecifiedFont : 1; // True if a web page specifies a non-generic font family as the first font family. 158 }; 159 160 inline bool FontDescription::operator==(const FontDescription& other) const 161 { 162 return m_familyList == other.m_familyList 163 && m_specifiedSize == other.m_specifiedSize 164 && m_computedSize == other.m_computedSize 165 && m_italic == other.m_italic 166 && m_smallCaps == other.m_smallCaps 167 && m_isAbsoluteSize == other.m_isAbsoluteSize 168 && m_weight == other.m_weight 169 && m_genericFamily == other.m_genericFamily 170 && m_usePrinterFont == other.m_usePrinterFont 171 && m_renderingMode == other.m_renderingMode 172 && m_keywordSize == other.m_keywordSize 173 && m_fontSmoothing == other.m_fontSmoothing 174 && m_textRendering == other.m_textRendering 175 && m_isSpecifiedFont == other.m_isSpecifiedFont 176 && m_orientation == other.m_orientation 177 && m_textOrientation == other.m_textOrientation 178 && m_widthVariant == other.m_widthVariant; 179 } 180 181 } 182 183 #endif 184