• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the internal font implementation.
3  *
4  * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
5  * Copyright (C) 2007-2008 Torch Mobile, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #ifndef SimpleFontData_h
25 #define SimpleFontData_h
26 
27 #include "FontData.h"
28 #include "FontPlatformData.h"
29 #include "GlyphPageTreeNode.h"
30 #include "GlyphWidthMap.h"
31 #include "TypesettingFeatures.h"
32 #include <wtf/OwnPtr.h>
33 
34 #if USE(ATSUI)
35 typedef struct OpaqueATSUStyle* ATSUStyle;
36 #endif
37 
38 #if (PLATFORM(WIN) && !OS(WINCE)) \
39     || (OS(WINDOWS) && PLATFORM(WX))
40 #include <usp10.h>
41 #endif
42 
43 #if PLATFORM(CAIRO)
44 #include <cairo.h>
45 #endif
46 
47 #if PLATFORM(QT)
48 #include <QFont>
49 #endif
50 
51 #if PLATFORM(HAIKU)
52 #include <Font.h>
53 #endif
54 
55 namespace WebCore {
56 
57 class FontDescription;
58 class FontPlatformData;
59 class SharedBuffer;
60 class SVGFontData;
61 class WidthMap;
62 
63 enum Pitch { UnknownPitch, FixedPitch, VariablePitch };
64 
65 class SimpleFontData : public FontData {
66 public:
67     SimpleFontData(const FontPlatformData&, bool customFont = false, bool loading = false, SVGFontData* data = 0);
68     virtual ~SimpleFontData();
69 
70 public:
platformData()71     const FontPlatformData& platformData() const { return m_platformData; }
72     SimpleFontData* smallCapsFontData(const FontDescription& fontDescription) const;
73 
74     // vertical metrics
ascent()75     int ascent() const { return m_ascent; }
descent()76     int descent() const { return m_descent; }
lineSpacing()77     int lineSpacing() const { return m_lineSpacing; }
lineGap()78     int lineGap() const { return m_lineGap; }
maxCharWidth()79     float maxCharWidth() const { return m_maxCharWidth; }
avgCharWidth()80     float avgCharWidth() const { return m_avgCharWidth; }
xHeight()81     float xHeight() const { return m_xHeight; }
unitsPerEm()82     unsigned unitsPerEm() const { return m_unitsPerEm; }
83 
84     float widthForGlyph(Glyph) const;
85     float platformWidthForGlyph(Glyph) const;
86 
spaceWidth()87     float spaceWidth() const { return m_spaceWidth; }
adjustedSpaceWidth()88     float adjustedSpaceWidth() const { return m_adjustedSpaceWidth; }
89 
90 #if PLATFORM(CG) || PLATFORM(CAIRO) || (OS(WINDOWS) && PLATFORM(WX))
syntheticBoldOffset()91     float syntheticBoldOffset() const { return m_syntheticBoldOffset; }
92 #endif
93 
spaceGlyph()94     Glyph spaceGlyph() const { return m_spaceGlyph; }
95 
96     virtual const SimpleFontData* fontDataForCharacter(UChar32) const;
97     virtual bool containsCharacters(const UChar*, int length) const;
98 
99     void determinePitch();
pitch()100     Pitch pitch() const { return m_treatAsFixedPitch ? FixedPitch : VariablePitch; }
101 
102 #if ENABLE(SVG_FONTS)
svgFontData()103     SVGFontData* svgFontData() const { return m_svgFontData.get(); }
isSVGFont()104     bool isSVGFont() const { return m_svgFontData; }
105 #else
isSVGFont()106     bool isSVGFont() const { return false; }
107 #endif
108 
isCustomFont()109     virtual bool isCustomFont() const { return m_isCustomFont; }
isLoading()110     virtual bool isLoading() const { return m_isLoading; }
111     virtual bool isSegmented() const;
112 
missingGlyphData()113     const GlyphData& missingGlyphData() const { return m_missingGlyphData; }
114 
115 #ifndef NDEBUG
116     virtual String description() const;
117 #endif
118 
119 #if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && OS(DARWIN))
getNSFont()120     NSFont* getNSFont() const { return m_platformData.font(); }
121 #endif
122 
123 #if USE(CORE_TEXT)
124     CTFontRef getCTFont() const;
125     CFDictionaryRef getCFStringAttributes(TypesettingFeatures) const;
126 #endif
127 
128 #if USE(ATSUI)
129     void checkShapesArabic() const;
shapesArabic()130     bool shapesArabic() const
131     {
132         if (!m_checkedShapesArabic)
133             checkShapesArabic();
134         return m_shapesArabic;
135     }
136 #endif
137 
138 #if PLATFORM(QT)
getQtFont()139     QFont getQtFont() const { return m_platformData.font(); }
140 #endif
141 
142 #if PLATFORM(WIN) || (OS(WINDOWS) && PLATFORM(WX))
isSystemFont()143     bool isSystemFont() const { return m_isSystemFont; }
144 #if !OS(WINCE) // disable unused members to save space
145     SCRIPT_FONTPROPERTIES* scriptFontProperties() const;
scriptCache()146     SCRIPT_CACHE* scriptCache() const { return &m_scriptCache; }
147 #endif
148     static void setShouldApplyMacAscentHack(bool);
149     static bool shouldApplyMacAscentHack();
150 #endif
151 
152 #if PLATFORM(WX)
getWxFont()153     wxFont* getWxFont() const { return m_platformData.font(); }
154 #endif
155 
156 private:
157     void platformInit();
158     void platformGlyphInit();
159     void platformCharWidthInit();
160     void platformDestroy();
161 
162     void initCharWidths();
163 
164     void commonInit();
165 
166 #if (PLATFORM(WIN) && !OS(WINCE)) \
167     || (OS(WINDOWS) && PLATFORM(WX))
168     void initGDIFont();
169     void platformCommonDestroy();
170     float widthForGDIGlyph(Glyph glyph) const;
171 #endif
172 
173     int m_ascent;
174     int m_descent;
175     int m_lineSpacing;
176     int m_lineGap;
177     float m_maxCharWidth;
178     float m_avgCharWidth;
179     float m_xHeight;
180     unsigned m_unitsPerEm;
181 
182     FontPlatformData m_platformData;
183 
184     mutable GlyphWidthMap m_glyphToWidthMap;
185 
186     bool m_treatAsFixedPitch;
187 
188 #if ENABLE(SVG_FONTS)
189     OwnPtr<SVGFontData> m_svgFontData;
190 #endif
191 
192     bool m_isCustomFont;  // Whether or not we are custom font loaded via @font-face
193     bool m_isLoading; // Whether or not this custom font is still in the act of loading.
194 
195     Glyph m_spaceGlyph;
196     float m_spaceWidth;
197     float m_adjustedSpaceWidth;
198 
199     GlyphData m_missingGlyphData;
200 
201     mutable SimpleFontData* m_smallCapsFontData;
202 
203 #if PLATFORM(CG) || PLATFORM(CAIRO) || (OS(WINDOWS) && PLATFORM(WX))
204     float m_syntheticBoldOffset;
205 #endif
206 
207 #ifdef BUILDING_ON_TIGER
208 public:
209     void* m_styleGroup;
210 
211 private:
212 #endif
213 
214 #if USE(ATSUI)
215 public:
216     mutable HashMap<unsigned, ATSUStyle> m_ATSUStyleMap;
217     mutable bool m_ATSUMirrors;
218     mutable bool m_checkedShapesArabic;
219     mutable bool m_shapesArabic;
220 
221 private:
222 #endif
223 
224 #if USE(CORE_TEXT)
225     mutable RetainPtr<CTFontRef> m_CTFont;
226     mutable HashMap<unsigned, RetainPtr<CFDictionaryRef> > m_CFStringAttributes;
227 #endif
228 
229 #if PLATFORM(WIN) || (OS(WINDOWS) && PLATFORM(WX))
230     bool m_isSystemFont;
231 #if !OS(WINCE) // disable unused members to save space
232     mutable SCRIPT_CACHE m_scriptCache;
233     mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties;
234 #endif
235 #endif
236 };
237 
238 
239 #if !PLATFORM(QT)
widthForGlyph(Glyph glyph)240 ALWAYS_INLINE float SimpleFontData::widthForGlyph(Glyph glyph) const
241 {
242     float width = m_glyphToWidthMap.widthForGlyph(glyph);
243     if (width != cGlyphWidthUnknown)
244         return width;
245 
246     width = platformWidthForGlyph(glyph);
247     m_glyphToWidthMap.setWidthForGlyph(glyph, width);
248 
249     return width;
250 }
251 #endif
252 
253 } // namespace WebCore
254 
255 #endif // SimpleFontData_h
256