| OLD | NEW |
| (Empty) |
| 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 reserv
ed. | |
| 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 "FontFamilyNames.h" | |
| 29 #include "core/platform/graphics/FontCacheKey.h" | |
| 30 #include "core/platform/graphics/FontOrientation.h" | |
| 31 #include "core/platform/graphics/FontSmoothingMode.h" | |
| 32 #include "core/platform/graphics/FontTraitsMask.h" | |
| 33 #include "core/platform/graphics/FontWidthVariant.h" | |
| 34 #include "core/platform/graphics/TextRenderingMode.h" | |
| 35 #include "platform/fonts/FontFamily.h" | |
| 36 #include "platform/fonts/FontFeatureSettings.h" | |
| 37 #include "platform/text/NonCJKGlyphOrientation.h" | |
| 38 #include "wtf/MathExtras.h" | |
| 39 | |
| 40 #include "wtf/RefPtr.h" | |
| 41 | |
| 42 namespace WebCore { | |
| 43 | |
| 44 enum FontWeight { | |
| 45 FontWeight100, | |
| 46 FontWeight200, | |
| 47 FontWeight300, | |
| 48 FontWeight400, | |
| 49 FontWeight500, | |
| 50 FontWeight600, | |
| 51 FontWeight700, | |
| 52 FontWeight800, | |
| 53 FontWeight900, | |
| 54 FontWeightNormal = FontWeight400, | |
| 55 FontWeightBold = FontWeight700 | |
| 56 }; | |
| 57 | |
| 58 enum FontItalic { | |
| 59 FontItalicOff = 0, | |
| 60 FontItalicOn = 1 | |
| 61 }; | |
| 62 | |
| 63 enum FontSmallCaps { | |
| 64 FontSmallCapsOff = 0, | |
| 65 FontSmallCapsOn = 1 | |
| 66 }; | |
| 67 | |
| 68 class FontDescription { | |
| 69 public: | |
| 70 enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFam
ily, | |
| 71 MonospaceFamily, CursiveFamily, FantasyFamily, Pict
ographFamily }; | |
| 72 | |
| 73 enum Kerning { AutoKerning, NormalKerning, NoneKerning }; | |
| 74 | |
| 75 enum LigaturesState { NormalLigaturesState, DisabledLigaturesState, EnabledL
igaturesState }; | |
| 76 | |
| 77 FontDescription() | |
| 78 : m_specifiedSize(0) | |
| 79 , m_computedSize(0) | |
| 80 , m_orientation(Horizontal) | |
| 81 , m_nonCJKGlyphOrientation(NonCJKGlyphOrientationVerticalRight) | |
| 82 , m_widthVariant(RegularWidth) | |
| 83 , m_italic(FontItalicOff) | |
| 84 , m_smallCaps(FontSmallCapsOff) | |
| 85 , m_isAbsoluteSize(false) | |
| 86 , m_weight(FontWeightNormal) | |
| 87 , m_genericFamily(NoFamily) | |
| 88 , m_usePrinterFont(false) | |
| 89 , m_kerning(AutoKerning) | |
| 90 , m_commonLigaturesState(NormalLigaturesState) | |
| 91 , m_discretionaryLigaturesState(NormalLigaturesState) | |
| 92 , m_historicalLigaturesState(NormalLigaturesState) | |
| 93 , m_keywordSize(0) | |
| 94 , m_fontSmoothing(AutoSmoothing) | |
| 95 , m_textRendering(AutoTextRendering) | |
| 96 , m_isSpecifiedFont(false) | |
| 97 , m_script(USCRIPT_COMMON) | |
| 98 { | |
| 99 } | |
| 100 | |
| 101 bool operator==(const FontDescription&) const; | |
| 102 bool operator!=(const FontDescription& other) const { return !(*this == othe
r); } | |
| 103 | |
| 104 const FontFamily& family() const { return m_familyList; } | |
| 105 FontFamily& firstFamily() { return m_familyList; } | |
| 106 float specifiedSize() const { return m_specifiedSize; } | |
| 107 float computedSize() const { return m_computedSize; } | |
| 108 FontItalic italic() const { return static_cast<FontItalic>(m_italic); } | |
| 109 int computedPixelSize() const { return int(m_computedSize + 0.5f); } | |
| 110 FontSmallCaps smallCaps() const { return static_cast<FontSmallCaps>(m_smallC
aps); } | |
| 111 bool isAbsoluteSize() const { return m_isAbsoluteSize; } | |
| 112 FontWeight weight() const { return static_cast<FontWeight>(m_weight); } | |
| 113 FontWeight lighterWeight() const; | |
| 114 FontWeight bolderWeight() const; | |
| 115 GenericFamilyType genericFamily() const { return static_cast<GenericFamilyTy
pe>(m_genericFamily); } | |
| 116 bool usePrinterFont() const { return m_usePrinterFont; } | |
| 117 // only use fixed default size when there is only one font family, and that
family is "monospace" | |
| 118 bool useFixedDefaultSize() const { return genericFamily() == MonospaceFamily
&& !family().next() && family().family() == FontFamilyNames::webkit_monospace;
} | |
| 119 Kerning kerning() const { return static_cast<Kerning>(m_kerning); } | |
| 120 LigaturesState commonLigaturesState() const { return static_cast<LigaturesSt
ate>(m_commonLigaturesState); } | |
| 121 LigaturesState discretionaryLigaturesState() const { return static_cast<Liga
turesState>(m_discretionaryLigaturesState); } | |
| 122 LigaturesState historicalLigaturesState() const { return static_cast<Ligatur
esState>(m_historicalLigaturesState); } | |
| 123 unsigned keywordSize() const { return m_keywordSize; } | |
| 124 FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMo
de>(m_fontSmoothing); } | |
| 125 TextRenderingMode textRenderingMode() const { return static_cast<TextRenderi
ngMode>(m_textRendering); } | |
| 126 UScriptCode script() const { return static_cast<UScriptCode>(m_script); } | |
| 127 | |
| 128 FontTraitsMask traitsMask() const; | |
| 129 bool isSpecifiedFont() const { return m_isSpecifiedFont; } | |
| 130 FontOrientation orientation() const { return static_cast<FontOrientation>(m_
orientation); } | |
| 131 NonCJKGlyphOrientation nonCJKGlyphOrientation() const { return static_cast<N
onCJKGlyphOrientation>(m_nonCJKGlyphOrientation); } | |
| 132 FontWidthVariant widthVariant() const { return static_cast<FontWidthVariant>
(m_widthVariant); } | |
| 133 FontFeatureSettings* featureSettings() const { return m_featureSettings.get(
); } | |
| 134 FontDescription makeNormalFeatureSettings() const; | |
| 135 | |
| 136 float effectiveFontSize() const; // Returns either the computedSize or the c
omputedPixelSize | |
| 137 FontCacheKey cacheKey(const AtomicString& familyName, FontTraitsMask desired
Traits = static_cast<FontTraitsMask>(0)) const; | |
| 138 | |
| 139 void setFamily(const FontFamily& family) { m_familyList = family; } | |
| 140 void setComputedSize(float s) { m_computedSize = clampToFloat(s); } | |
| 141 void setSpecifiedSize(float s) { m_specifiedSize = clampToFloat(s); } | |
| 142 void setItalic(FontItalic i) { m_italic = i; } | |
| 143 void setItalic(bool i) { setItalic(i ? FontItalicOn : FontItalicOff); } | |
| 144 void setSmallCaps(FontSmallCaps c) { m_smallCaps = c; } | |
| 145 void setSmallCaps(bool c) { setSmallCaps(c ? FontSmallCapsOn : FontSmallCaps
Off); } | |
| 146 void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; } | |
| 147 void setWeight(FontWeight w) { m_weight = w; } | |
| 148 void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = g
enericFamily; } | |
| 149 #if OS(MACOSX) | |
| 150 void setUsePrinterFont(bool) { } | |
| 151 #else | |
| 152 void setUsePrinterFont(bool p) { m_usePrinterFont = p; } | |
| 153 #endif | |
| 154 void setKerning(Kerning kerning) { m_kerning = kerning; } | |
| 155 void setCommonLigaturesState(LigaturesState commonLigaturesState) { m_common
LigaturesState = commonLigaturesState; } | |
| 156 void setDiscretionaryLigaturesState(LigaturesState discretionaryLigaturesSta
te) { m_discretionaryLigaturesState = discretionaryLigaturesState; } | |
| 157 void setHistoricalLigaturesState(LigaturesState historicalLigaturesState) {
m_historicalLigaturesState = historicalLigaturesState; } | |
| 158 void setKeywordSize(unsigned s) { m_keywordSize = s; } | |
| 159 void setFontSmoothing(FontSmoothingMode smoothing) { m_fontSmoothing = smoot
hing; } | |
| 160 void setTextRenderingMode(TextRenderingMode rendering) { m_textRendering = r
endering; } | |
| 161 void setIsSpecifiedFont(bool isSpecifiedFont) { m_isSpecifiedFont = isSpecif
iedFont; } | |
| 162 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } | |
| 163 void setNonCJKGlyphOrientation(NonCJKGlyphOrientation orientation) { m_nonCJ
KGlyphOrientation = orientation; } | |
| 164 void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = width
Variant; } | |
| 165 void setScript(UScriptCode s) { m_script = s; } | |
| 166 void setFeatureSettings(PassRefPtr<FontFeatureSettings> settings) { m_featur
eSettings = settings; } | |
| 167 | |
| 168 private: | |
| 169 FontFamily m_familyList; // The list of font families to be used. | |
| 170 RefPtr<FontFeatureSettings> m_featureSettings; | |
| 171 | |
| 172 float m_specifiedSize; // Specified CSS value. Independent of rendering is
sues such as integer | |
| 173 // rounding, minimum font sizes, and zooming. | |
| 174 float m_computedSize; // Computed size adjusted for the minimum font size
and the zoom factor. | |
| 175 | |
| 176 unsigned m_orientation : 1; // FontOrientation - Whether the font is renderi
ng on a horizontal line or a vertical line. | |
| 177 unsigned m_nonCJKGlyphOrientation : 1; // NonCJKGlyphOrientation - Only used
by vertical text. Determines the default orientation for non-ideograph glyphs. | |
| 178 | |
| 179 unsigned m_widthVariant : 2; // FontWidthVariant | |
| 180 | |
| 181 unsigned m_italic : 1; // FontItalic | |
| 182 unsigned m_smallCaps : 1; // FontSmallCaps | |
| 183 unsigned m_isAbsoluteSize : 1; // Whether or not CSS specified an explicit s
ize | |
| 184 // (logical sizes like "medium" don't count). | |
| 185 unsigned m_weight : 8; // FontWeight | |
| 186 unsigned m_genericFamily : 3; // GenericFamilyType | |
| 187 unsigned m_usePrinterFont : 1; | |
| 188 | |
| 189 unsigned m_kerning : 2; // Kerning | |
| 190 | |
| 191 unsigned m_commonLigaturesState : 2; | |
| 192 unsigned m_discretionaryLigaturesState : 2; | |
| 193 unsigned m_historicalLigaturesState : 2; | |
| 194 | |
| 195 unsigned m_keywordSize : 4; // We cache whether or not a font is currently r
epresented by a CSS keyword (e.g., medium). If so, | |
| 196 // then we can accurately translate across different
generic families to adjust for different preference settings | |
| 197 // (e.g., 13px monospace vs. 16px everything else).
Sizes are 1-8 (like the HTML size values for <font>). | |
| 198 | |
| 199 unsigned m_fontSmoothing : 2; // FontSmoothingMode | |
| 200 unsigned m_textRendering : 2; // TextRenderingMode | |
| 201 unsigned m_isSpecifiedFont : 1; // True if a web page specifies a non-generi
c font family as the first font family. | |
| 202 unsigned m_script : 7; // Used to help choose an appropriate font for generi
c font families. | |
| 203 }; | |
| 204 | |
| 205 inline bool FontDescription::operator==(const FontDescription& other) const | |
| 206 { | |
| 207 return m_familyList == other.m_familyList | |
| 208 && m_specifiedSize == other.m_specifiedSize | |
| 209 && m_computedSize == other.m_computedSize | |
| 210 && m_italic == other.m_italic | |
| 211 && m_smallCaps == other.m_smallCaps | |
| 212 && m_isAbsoluteSize == other.m_isAbsoluteSize | |
| 213 && m_weight == other.m_weight | |
| 214 && m_genericFamily == other.m_genericFamily | |
| 215 && m_usePrinterFont == other.m_usePrinterFont | |
| 216 && m_kerning == other.m_kerning | |
| 217 && m_commonLigaturesState == other.m_commonLigaturesState | |
| 218 && m_discretionaryLigaturesState == other.m_discretionaryLigaturesState | |
| 219 && m_historicalLigaturesState == other.m_historicalLigaturesState | |
| 220 && m_keywordSize == other.m_keywordSize | |
| 221 && m_fontSmoothing == other.m_fontSmoothing | |
| 222 && m_textRendering == other.m_textRendering | |
| 223 && m_isSpecifiedFont == other.m_isSpecifiedFont | |
| 224 && m_orientation == other.m_orientation | |
| 225 && m_nonCJKGlyphOrientation == other.m_nonCJKGlyphOrientation | |
| 226 && m_widthVariant == other.m_widthVariant | |
| 227 && m_script == other.m_script | |
| 228 && m_featureSettings == other.m_featureSettings; | |
| 229 } | |
| 230 | |
| 231 } | |
| 232 | |
| 233 #endif | |
| OLD | NEW |