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