]> git.saurik.com Git - iphone-api.git/blob - WebCore/FontDescription.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / FontDescription.h
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 "FontRenderingMode.h"
30 #include "FontTraitsMask.h"
31
32 namespace WebCore {
33
34 enum FontWeight {
35 FontWeight100,
36 FontWeight200,
37 FontWeight300,
38 FontWeight400,
39 FontWeight500,
40 FontWeight600,
41 FontWeight700,
42 FontWeight800,
43 FontWeight900,
44 FontWeightNormal = FontWeight400,
45 FontWeightBold = FontWeight700
46 };
47
48 class FontDescription {
49 public:
50 enum GenericFamilyType { NoFamily, StandardFamily, SerifFamily, SansSerifFamily,
51 MonospaceFamily, CursiveFamily, FantasyFamily };
52
53 FontDescription()
54 : m_specifiedSize(0)
55 , m_computedSize(0)
56 , m_italic(false)
57 , m_smallCaps(false)
58 , m_isAbsoluteSize(false)
59 , m_weight(FontWeightNormal)
60 , m_genericFamily(NoFamily)
61 , m_usePrinterFont(false)
62 , m_renderingMode(NormalRenderingMode)
63 , m_keywordSize(0)
64 {
65 }
66
67 bool operator==(const FontDescription&) const;
68 bool operator!=(const FontDescription& other) const { return !(*this == other); }
69
70 const FontFamily& family() const { return m_familyList; }
71 FontFamily& firstFamily() { return m_familyList; }
72 float specifiedSize() const { return m_specifiedSize; }
73 float computedSize() const { return m_computedSize; }
74 bool italic() const { return m_italic; }
75 int computedPixelSize() const { return int(m_computedSize + 0.5f); }
76 bool smallCaps() const { return m_smallCaps; }
77 bool isAbsoluteSize() const { return m_isAbsoluteSize; }
78 FontWeight weight() const { return static_cast<FontWeight>(m_weight); }
79 FontWeight lighterWeight() const;
80 FontWeight bolderWeight() const;
81 GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); }
82 bool usePrinterFont() const { return m_usePrinterFont; }
83 FontRenderingMode renderingMode() const { return static_cast<FontRenderingMode>(m_renderingMode); }
84 int keywordSize() const { return m_keywordSize; }
85
86 FontTraitsMask traitsMask() const;
87
88 void setFamily(const FontFamily& family) { m_familyList = family; }
89 void setComputedSize(float s) { m_computedSize = s; }
90 void setSpecifiedSize(float s) { m_specifiedSize = s; }
91 void setItalic(bool i) { m_italic = i; }
92 void setSmallCaps(bool c) { m_smallCaps = c; }
93 void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; }
94 void setWeight(FontWeight w) { m_weight = w; }
95 void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = genericFamily; }
96 void setUsePrinterFont(bool p) { m_usePrinterFont = p; }
97 void setRenderingMode(FontRenderingMode mode) { m_renderingMode = mode; }
98 void setKeywordSize(int s) { m_keywordSize = s; }
99
100 bool equalForTextAutoSizing (const FontDescription& other) const {
101 return m_familyList == other.m_familyList
102 && m_specifiedSize == other.m_specifiedSize
103 && m_smallCaps == other.m_smallCaps
104 && m_isAbsoluteSize == other.m_isAbsoluteSize
105 && m_genericFamily == other.m_genericFamily
106 && m_usePrinterFont == other.m_usePrinterFont;
107 }
108
109 private:
110 FontFamily m_familyList; // The list of font families to be used.
111
112 float m_specifiedSize; // Specified CSS value. Independent of rendering issues such as integer
113 // rounding, minimum font sizes, and zooming.
114 float m_computedSize; // Computed size adjusted for the minimum font size and the zoom factor.
115
116 bool m_italic : 1;
117 bool m_smallCaps : 1;
118 bool m_isAbsoluteSize : 1; // Whether or not CSS specified an explicit size
119 // (logical sizes like "medium" don't count).
120 unsigned m_weight : 8; // FontWeight
121 unsigned m_genericFamily : 3; // GenericFamilyType
122 bool m_usePrinterFont : 1;
123
124 unsigned m_renderingMode : 1; // Used to switch between CG and GDI text on Windows.
125
126 int m_keywordSize : 4; // We cache whether or not a font is currently represented by a CSS keyword (e.g., medium). If so,
127 // then we can accurately translate across different generic families to adjust for different preference settings
128 // (e.g., 13px monospace vs. 16px everything else). Sizes are 1-8 (like the HTML size values for <font>).
129 };
130
131 inline bool FontDescription::operator==(const FontDescription& other) const
132 {
133 return m_familyList == other.m_familyList
134 && m_specifiedSize == other.m_specifiedSize
135 && m_computedSize == other.m_computedSize
136 && m_italic == other.m_italic
137 && m_smallCaps == other.m_smallCaps
138 && m_isAbsoluteSize == other.m_isAbsoluteSize
139 && m_weight == other.m_weight
140 && m_genericFamily == other.m_genericFamily
141 && m_usePrinterFont == other.m_usePrinterFont
142 && m_renderingMode == other.m_renderingMode
143 && m_keywordSize == other.m_keywordSize;
144 }
145
146 }
147
148 #endif