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