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>
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.
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.
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_
25 #ifndef FontDescription_h
26 #define FontDescription_h
28 #include "FontFamily.h"
29 #include "FontFeatureSettings.h"
30 #include "FontOrientation.h"
31 #include "FontRenderingMode.h"
32 #include "FontSmoothingMode.h"
33 #include "FontTraitsMask.h"
34 #include "FontWidthVariant.h"
35 #include "TextOrientation.h"
36 #include "TextRenderingMode.h"
37 #include "WebKitFontFamilyNames.h"
38 #include <wtf/MathExtras.h>
40 #include <wtf/RefPtr.h>
44 using namespace WebKitFontFamilyNames;
56 FontWeightNormal = FontWeight400,
57 FontWeightBold = FontWeight700
70 class FontDescription {
72 enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFamily,
73 MonospaceFamily, CursiveFamily, FantasyFamily, PictographFamily };
75 enum Kerning { AutoKerning, NormalKerning, NoneKerning };
77 enum LigaturesState { NormalLigaturesState, DisabledLigaturesState, EnabledLigaturesState };
82 , m_orientation(Horizontal)
83 , m_textOrientation(TextOrientationVerticalRight)
84 , m_widthVariant(RegularWidth)
85 , m_italic(FontItalicOff)
86 , m_smallCaps(FontSmallCapsOff)
87 , m_isAbsoluteSize(false)
88 , m_weight(FontWeightNormal)
89 , m_genericFamily(NoFamily)
90 , m_usePrinterFont(false)
91 , m_renderingMode(NormalRenderingMode)
92 , m_kerning(AutoKerning)
93 , m_commonLigaturesState(NormalLigaturesState)
94 , m_discretionaryLigaturesState(NormalLigaturesState)
95 , m_historicalLigaturesState(NormalLigaturesState)
97 , m_fontSmoothing(AutoSmoothing)
98 , m_textRendering(AutoTextRendering)
99 , m_isSpecifiedFont(false)
100 , m_script(USCRIPT_COMMON)
104 bool operator==(const FontDescription&) const;
105 bool operator!=(const FontDescription& other) const { return !(*this == other); }
107 const FontFamily& family() const { return m_familyList; }
108 FontFamily& firstFamily() { return m_familyList; }
109 float specifiedSize() const { return m_specifiedSize; }
110 float computedSize() const { return m_computedSize; }
111 FontItalic italic() const { return static_cast<FontItalic>(m_italic); }
112 int computedPixelSize() const { return int(m_computedSize + 0.5f); }
113 FontSmallCaps smallCaps() const { return static_cast<FontSmallCaps>(m_smallCaps); }
114 bool isAbsoluteSize() const { return m_isAbsoluteSize; }
115 FontWeight weight() const { return static_cast<FontWeight>(m_weight); }
116 FontWeight lighterWeight() const;
117 FontWeight bolderWeight() const;
118 GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); }
119 bool usePrinterFont() const { return m_usePrinterFont; }
120 // only use fixed default size when there is only one font family, and that family is "monospace"
121 bool useFixedDefaultSize() const { return genericFamily() == MonospaceFamily && !family().next() && family().family() == monospaceFamily; }
122 FontRenderingMode renderingMode() const { return static_cast<FontRenderingMode>(m_renderingMode); }
123 Kerning kerning() const { return static_cast<Kerning>(m_kerning); }
124 LigaturesState commonLigaturesState() const { return static_cast<LigaturesState>(m_commonLigaturesState); }
125 LigaturesState discretionaryLigaturesState() const { return static_cast<LigaturesState>(m_discretionaryLigaturesState); }
126 LigaturesState historicalLigaturesState() const { return static_cast<LigaturesState>(m_historicalLigaturesState); }
127 unsigned keywordSize() const { return m_keywordSize; }
128 FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMode>(m_fontSmoothing); }
129 TextRenderingMode textRenderingMode() const { return static_cast<TextRenderingMode>(m_textRendering); }
130 UScriptCode script() const { return static_cast<UScriptCode>(m_script); }
132 FontTraitsMask traitsMask() const;
133 bool isSpecifiedFont() const { return m_isSpecifiedFont; }
134 FontOrientation orientation() const { return static_cast<FontOrientation>(m_orientation); }
135 TextOrientation textOrientation() const { return static_cast<TextOrientation>(m_textOrientation); }
136 FontWidthVariant widthVariant() const { return static_cast<FontWidthVariant>(m_widthVariant); }
137 FontFeatureSettings* featureSettings() const { return m_featureSettings.get(); }
138 FontDescription makeNormalFeatureSettings() const;
140 void setFamily(const FontFamily& family) { m_familyList = family; }
141 void setComputedSize(float s) { m_computedSize = clampToFloat(s); }
142 void setSpecifiedSize(float s) { m_specifiedSize = clampToFloat(s); }
143 void setItalic(FontItalic i) { m_italic = i; }
144 void setItalic(bool i) { setItalic(i ? FontItalicOn : FontItalicOff); }
145 void setSmallCaps(FontSmallCaps c) { m_smallCaps = c; }
146 void setSmallCaps(bool c) { setSmallCaps(c ? FontSmallCapsOn : FontSmallCapsOff); }
147 void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; }
148 void setWeight(FontWeight w) { m_weight = w; }
149 void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = genericFamily; }
150 #if PLATFORM(CHROMIUM) && OS(DARWIN)
151 void setUsePrinterFont(bool) { }
153 void setUsePrinterFont(bool p) { m_usePrinterFont = p; }
155 void setRenderingMode(FontRenderingMode mode) { m_renderingMode = mode; }
156 void setKerning(Kerning kerning) { m_kerning = kerning; }
157 void setCommonLigaturesState(LigaturesState commonLigaturesState) { m_commonLigaturesState = commonLigaturesState; }
158 void setDiscretionaryLigaturesState(LigaturesState discretionaryLigaturesState) { m_discretionaryLigaturesState = discretionaryLigaturesState; }
159 void setHistoricalLigaturesState(LigaturesState historicalLigaturesState) { m_historicalLigaturesState = historicalLigaturesState; }
160 void setKeywordSize(unsigned s) { m_keywordSize = s; }
161 void setFontSmoothing(FontSmoothingMode smoothing) { m_fontSmoothing = smoothing; }
162 void setTextRenderingMode(TextRenderingMode rendering) { m_textRendering = rendering; }
163 void setIsSpecifiedFont(bool isSpecifiedFont) { m_isSpecifiedFont = isSpecifiedFont; }
164 void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
165 void setTextOrientation(TextOrientation textOrientation) { m_textOrientation = textOrientation; }
166 void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = widthVariant; }
167 void setScript(UScriptCode s) { m_script = s; }
168 void setFeatureSettings(PassRefPtr<FontFeatureSettings> settings) { m_featureSettings = settings; }
171 FontFamily m_familyList; // The list of font families to be used.
172 RefPtr<FontFeatureSettings> m_featureSettings;
174 float m_specifiedSize; // Specified CSS value. Independent of rendering issues such as integer
175 // rounding, minimum font sizes, and zooming.
176 float m_computedSize; // Computed size adjusted for the minimum font size and the zoom factor.
178 unsigned m_orientation : 1; // FontOrientation - Whether the font is rendering on a horizontal line or a vertical line.
179 unsigned m_textOrientation : 1; // TextOrientation - Only used by vertical text. Determines the default orientation for non-ideograph glyphs.
181 unsigned m_widthVariant : 2; // FontWidthVariant
183 unsigned m_italic : 1; // FontItalic
184 unsigned m_smallCaps : 1; // FontSmallCaps
185 unsigned m_isAbsoluteSize : 1; // Whether or not CSS specified an explicit size
186 // (logical sizes like "medium" don't count).
187 unsigned m_weight : 8; // FontWeight
188 unsigned m_genericFamily : 3; // GenericFamilyType
189 unsigned m_usePrinterFont : 1;
191 unsigned m_renderingMode : 1; // Used to switch between CG and GDI text on Windows.
192 unsigned m_kerning : 2; // Kerning
194 unsigned m_commonLigaturesState : 2;
195 unsigned m_discretionaryLigaturesState : 2;
196 unsigned m_historicalLigaturesState : 2;
198 unsigned m_keywordSize : 4; // We cache whether or not a font is currently represented by a CSS keyword (e.g., medium). If so,
199 // then we can accurately translate across different generic families to adjust for different preference settings
200 // (e.g., 13px monospace vs. 16px everything else). Sizes are 1-8 (like the HTML size values for <font>).
202 unsigned m_fontSmoothing : 2; // FontSmoothingMode
203 unsigned m_textRendering : 2; // TextRenderingMode
204 unsigned m_isSpecifiedFont : 1; // True if a web page specifies a non-generic font family as the first font family.
205 unsigned m_script : 7; // Used to help choose an appropriate font for generic font families.
208 inline bool FontDescription::operator==(const FontDescription& other) const
210 return m_familyList == other.m_familyList
211 && m_specifiedSize == other.m_specifiedSize
212 && m_computedSize == other.m_computedSize
213 && m_italic == other.m_italic
214 && m_smallCaps == other.m_smallCaps
215 && m_isAbsoluteSize == other.m_isAbsoluteSize
216 && m_weight == other.m_weight
217 && m_genericFamily == other.m_genericFamily
218 && m_usePrinterFont == other.m_usePrinterFont
219 && m_renderingMode == other.m_renderingMode
220 && m_kerning == other.m_kerning
221 && m_commonLigaturesState == other.m_commonLigaturesState
222 && m_discretionaryLigaturesState == other.m_discretionaryLigaturesState
223 && m_historicalLigaturesState == other.m_historicalLigaturesState
224 && m_keywordSize == other.m_keywordSize
225 && m_fontSmoothing == other.m_fontSmoothing
226 && m_textRendering == other.m_textRendering
227 && m_isSpecifiedFont == other.m_isSpecifiedFont
228 && m_orientation == other.m_orientation
229 && m_textOrientation == other.m_textOrientation
230 && m_widthVariant == other.m_widthVariant
231 && m_script == other.m_script
232 && m_featureSettings == other.m_featureSettings;