OLD | NEW |
1 /* | 1 /* |
2 * This file is part of the internal font implementation. | 2 * This file is part of the internal font implementation. |
3 * | 3 * |
4 * Copyright (C) 2006, 2008, 2010 Apple Inc. All rights reserved. | 4 * Copyright (C) 2006, 2008, 2010 Apple Inc. All rights reserved. |
5 * Copyright (C) 2007-2008 Torch Mobile, Inc. | 5 * Copyright (C) 2007-2008 Torch Mobile, Inc. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "wtf/PassOwnPtr.h" | 40 #include "wtf/PassOwnPtr.h" |
41 #include "wtf/text/StringHash.h" | 41 #include "wtf/text/StringHash.h" |
42 #include "wtf/UnusedParam.h" | 42 #include "wtf/UnusedParam.h" |
43 | 43 |
44 #if OS(MACOSX) | 44 #if OS(MACOSX) |
45 #include "wtf/RetainPtr.h" | 45 #include "wtf/RetainPtr.h" |
46 #endif | 46 #endif |
47 | 47 |
48 namespace WebCore { | 48 namespace WebCore { |
49 | 49 |
| 50 class CSSFontFaceSource; |
50 class FontDescription; | 51 class FontDescription; |
51 class SharedBuffer; | 52 class SharedBuffer; |
52 struct WidthIterator; | 53 struct WidthIterator; |
53 | 54 |
54 enum FontDataVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMar
kVariant, BrokenIdeographVariant }; | 55 enum FontDataVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMar
kVariant, BrokenIdeographVariant }; |
55 enum Pitch { UnknownPitch, FixedPitch, VariablePitch }; | 56 enum Pitch { UnknownPitch, FixedPitch, VariablePitch }; |
56 | 57 |
57 class SimpleFontData : public FontData { | 58 class SimpleFontData : public FontData { |
58 public: | 59 public: |
59 class AdditionalFontData { | 60 class AdditionalFontData { |
60 WTF_MAKE_FAST_ALLOCATED; | 61 WTF_MAKE_FAST_ALLOCATED; |
61 public: | 62 public: |
62 virtual ~AdditionalFontData() { } | 63 virtual ~AdditionalFontData() { } |
63 | 64 |
64 virtual void initializeFontData(SimpleFontData*, float fontSize) = 0; | 65 virtual void initializeFontData(SimpleFontData*, float fontSize) = 0; |
65 virtual float widthForSVGGlyph(Glyph, float fontSize) const = 0; | 66 virtual float widthForSVGGlyph(Glyph, float fontSize) const = 0; |
66 virtual bool fillSVGGlyphPage(GlyphPage*, unsigned offset, unsigned leng
th, UChar* buffer, unsigned bufferLength, const SimpleFontData*) const = 0; | 67 virtual bool fillSVGGlyphPage(GlyphPage*, unsigned offset, unsigned leng
th, UChar* buffer, unsigned bufferLength, const SimpleFontData*) const = 0; |
67 virtual bool applySVGGlyphSelection(WidthIterator&, GlyphData&, bool mir
ror, int currentCharacter, unsigned& advanceLength) const = 0; | 68 virtual bool applySVGGlyphSelection(WidthIterator&, GlyphData&, bool mir
ror, int currentCharacter, unsigned& advanceLength) const = 0; |
68 }; | 69 }; |
69 | 70 |
70 // Used to create platform fonts. | 71 // Used to create platform fonts. |
71 static PassRefPtr<SimpleFontData> create(const FontPlatformData& platformDat
a, bool isCustomFont = false, bool isLoading = false, bool isTextOrientationFall
back = false) | 72 static PassRefPtr<SimpleFontData> create(const FontPlatformData& platformDat
a, bool isCustomFont = false, bool isLoadingFallback = false, bool isTextOrienta
tionFallback = false) |
72 { | 73 { |
73 return adoptRef(new SimpleFontData(platformData, isCustomFont, isLoading
, isTextOrientationFallback)); | 74 return adoptRef(new SimpleFontData(platformData, isCustomFont, isLoading
Fallback, isTextOrientationFallback)); |
74 } | 75 } |
75 | 76 |
76 // Used to create SVG Fonts. | 77 // Used to create SVG Fonts. |
77 static PassRefPtr<SimpleFontData> create(PassOwnPtr<AdditionalFontData> font
Data, float fontSize, bool syntheticBold, bool syntheticItalic) | 78 static PassRefPtr<SimpleFontData> create(PassOwnPtr<AdditionalFontData> font
Data, float fontSize, bool syntheticBold, bool syntheticItalic) |
78 { | 79 { |
79 return adoptRef(new SimpleFontData(fontData, fontSize, syntheticBold, sy
ntheticItalic)); | 80 return adoptRef(new SimpleFontData(fontData, fontSize, syntheticBold, sy
ntheticItalic)); |
80 } | 81 } |
81 | 82 |
82 virtual ~SimpleFontData(); | 83 virtual ~SimpleFontData(); |
83 | 84 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 virtual const SimpleFontData* fontDataForCharacter(UChar32) const; | 150 virtual const SimpleFontData* fontDataForCharacter(UChar32) const; |
150 virtual bool containsCharacters(const UChar*, int length) const; | 151 virtual bool containsCharacters(const UChar*, int length) const; |
151 | 152 |
152 Glyph glyphForCharacter(UChar32) const; | 153 Glyph glyphForCharacter(UChar32) const; |
153 | 154 |
154 void determinePitch(); | 155 void determinePitch(); |
155 Pitch pitch() const { return m_treatAsFixedPitch ? FixedPitch : VariablePitc
h; } | 156 Pitch pitch() const { return m_treatAsFixedPitch ? FixedPitch : VariablePitc
h; } |
156 | 157 |
157 AdditionalFontData* fontData() const { return m_fontData.get(); } | 158 AdditionalFontData* fontData() const { return m_fontData.get(); } |
158 bool isSVGFont() const { return m_fontData; } | 159 bool isSVGFont() const { return m_fontData; } |
| 160 bool isLoadingFallback() const { return m_customFontData.isLoadingFallback;
} |
159 | 161 |
160 virtual bool isCustomFont() const { return m_isCustomFont; } | 162 virtual bool isCustomFont() const { return m_customFontData.isCustomFont; } |
161 virtual bool isLoading() const { return m_isLoading; } | 163 virtual bool isLoading() const { return m_customFontData.isLoadingFallback &
& m_customFontData.isUsed; } |
162 virtual bool isSegmented() const; | 164 virtual bool isSegmented() const; |
163 | 165 |
164 const GlyphData& missingGlyphData() const { return m_missingGlyphData; } | 166 const GlyphData& missingGlyphData() const { return m_missingGlyphData; } |
165 void setMissingGlyphData(const GlyphData& glyphData) { m_missingGlyphData =
glyphData; } | 167 void setMissingGlyphData(const GlyphData& glyphData) { m_missingGlyphData =
glyphData; } |
166 | 168 |
| 169 void beginLoadIfNeeded() const; |
| 170 |
167 #ifndef NDEBUG | 171 #ifndef NDEBUG |
168 virtual String description() const; | 172 virtual String description() const; |
169 #endif | 173 #endif |
170 | 174 |
171 #if OS(MACOSX) | 175 #if OS(MACOSX) |
172 const SimpleFontData* getCompositeFontReferenceFontData(NSFont *key) const; | 176 const SimpleFontData* getCompositeFontReferenceFontData(NSFont *key) const; |
173 NSFont* getNSFont() const { return m_platformData.font(); } | 177 NSFont* getNSFont() const { return m_platformData.font(); } |
174 #endif | 178 #endif |
175 | 179 |
176 #if OS(MACOSX) | 180 #if OS(MACOSX) |
177 CFDictionaryRef getCFStringAttributes(TypesettingFeatures, FontOrientation)
const; | 181 CFDictionaryRef getCFStringAttributes(TypesettingFeatures, FontOrientation)
const; |
178 #endif | 182 #endif |
179 | 183 |
180 #if OS(MACOSX) || USE(HARFBUZZ) | 184 #if OS(MACOSX) || USE(HARFBUZZ) |
181 bool canRenderCombiningCharacterSequence(const UChar*, size_t) const; | 185 bool canRenderCombiningCharacterSequence(const UChar*, size_t) const; |
182 #endif | 186 #endif |
183 | 187 |
184 bool applyTransforms(GlyphBufferGlyph* glyphs, GlyphBufferAdvance* advances,
size_t glyphCount, TypesettingFeatures typesettingFeatures) const | 188 bool applyTransforms(GlyphBufferGlyph* glyphs, GlyphBufferAdvance* advances,
size_t glyphCount, TypesettingFeatures typesettingFeatures) const |
185 { | 189 { |
186 UNUSED_PARAM(glyphs); | 190 UNUSED_PARAM(glyphs); |
187 UNUSED_PARAM(advances); | 191 UNUSED_PARAM(advances); |
188 UNUSED_PARAM(glyphCount); | 192 UNUSED_PARAM(glyphCount); |
189 UNUSED_PARAM(typesettingFeatures); | 193 UNUSED_PARAM(typesettingFeatures); |
190 return false; | 194 return false; |
191 } | 195 } |
192 | 196 |
| 197 void setCSSFontFaceSource(CSSFontFaceSource* source) { m_customFontData.font
FaceSource = source; } |
| 198 void clearCSSFontFaceSource() { m_customFontData.fontFaceSource = 0; } |
| 199 |
193 private: | 200 private: |
194 SimpleFontData(const FontPlatformData&, bool isCustomFont = false, bool isLo
ading = false, bool isTextOrientationFallback = false); | 201 SimpleFontData(const FontPlatformData&, bool isCustomFont = false, bool isLo
adingFallback = false, bool isTextOrientationFallback = false); |
195 | 202 |
196 SimpleFontData(PassOwnPtr<AdditionalFontData> , float fontSize, bool synthet
icBold, bool syntheticItalic); | 203 SimpleFontData(PassOwnPtr<AdditionalFontData> , float fontSize, bool synthet
icBold, bool syntheticItalic); |
197 | 204 |
198 void platformInit(); | 205 void platformInit(); |
199 void platformGlyphInit(); | 206 void platformGlyphInit(); |
200 void platformCharWidthInit(); | 207 void platformCharWidthInit(); |
201 void platformDestroy(); | 208 void platformDestroy(); |
202 | 209 |
203 void initCharWidths(); | 210 void initCharWidths(); |
204 | 211 |
205 PassRefPtr<SimpleFontData> createScaledFontData(const FontDescription&, floa
t scaleFactor) const; | 212 PassRefPtr<SimpleFontData> createScaledFontData(const FontDescription&, floa
t scaleFactor) const; |
206 PassRefPtr<SimpleFontData> platformCreateScaledFontData(const FontDescriptio
n&, float scaleFactor) const; | 213 PassRefPtr<SimpleFontData> platformCreateScaledFontData(const FontDescriptio
n&, float scaleFactor) const; |
207 | 214 |
208 FontMetrics m_fontMetrics; | 215 FontMetrics m_fontMetrics; |
209 float m_maxCharWidth; | 216 float m_maxCharWidth; |
210 float m_avgCharWidth; | 217 float m_avgCharWidth; |
211 | 218 |
212 FontPlatformData m_platformData; | 219 FontPlatformData m_platformData; |
213 OwnPtr<AdditionalFontData> m_fontData; | 220 OwnPtr<AdditionalFontData> m_fontData; |
214 | 221 |
215 mutable OwnPtr<GlyphMetricsMap<FloatRect> > m_glyphToBoundsMap; | 222 mutable OwnPtr<GlyphMetricsMap<FloatRect> > m_glyphToBoundsMap; |
216 mutable GlyphMetricsMap<float> m_glyphToWidthMap; | 223 mutable GlyphMetricsMap<float> m_glyphToWidthMap; |
217 | 224 |
218 bool m_treatAsFixedPitch; | 225 bool m_treatAsFixedPitch; |
219 bool m_isCustomFont; // Whether or not we are custom font loaded via @font-
face | |
220 bool m_isLoading; // Whether or not this custom font is still in the act of
loading. | |
221 | 226 |
222 bool m_isTextOrientationFallback; | 227 bool m_isTextOrientationFallback; |
223 bool m_isBrokenIdeographFallback; | 228 bool m_isBrokenIdeographFallback; |
224 #if ENABLE(OPENTYPE_VERTICAL) | 229 #if ENABLE(OPENTYPE_VERTICAL) |
225 RefPtr<OpenTypeVerticalData> m_verticalData; | 230 RefPtr<OpenTypeVerticalData> m_verticalData; |
226 #endif | 231 #endif |
227 bool m_hasVerticalGlyphs; | 232 bool m_hasVerticalGlyphs; |
228 | 233 |
229 Glyph m_spaceGlyph; | 234 Glyph m_spaceGlyph; |
230 float m_spaceWidth; | 235 float m_spaceWidth; |
(...skipping 20 matching lines...) Expand all Loading... |
251 | 256 |
252 private: | 257 private: |
253 DerivedFontData(bool custom) | 258 DerivedFontData(bool custom) |
254 : forCustomFont(custom) | 259 : forCustomFont(custom) |
255 { | 260 { |
256 } | 261 } |
257 }; | 262 }; |
258 | 263 |
259 mutable OwnPtr<DerivedFontData> m_derivedFontData; | 264 mutable OwnPtr<DerivedFontData> m_derivedFontData; |
260 | 265 |
| 266 struct CustomFontData { |
| 267 CustomFontData(bool isCustomFont, bool isLoadingFallback) |
| 268 : isCustomFont(isCustomFont) |
| 269 , isLoadingFallback(isLoadingFallback) |
| 270 , isUsed(false) |
| 271 , fontFaceSource(0) |
| 272 { |
| 273 } |
| 274 bool isCustomFont; // Whether or not we are custom font loaded via @font
-face |
| 275 bool isLoadingFallback; // Whether or not this is a temporary font data
for a custom font which is not yet loaded. |
| 276 mutable bool isUsed; |
| 277 CSSFontFaceSource* fontFaceSource; |
| 278 }; |
| 279 CustomFontData m_customFontData; |
| 280 |
261 #if OS(MACOSX) | 281 #if OS(MACOSX) |
262 float m_syntheticBoldOffset; | 282 float m_syntheticBoldOffset; |
263 | 283 |
264 mutable HashMap<unsigned, RetainPtr<CFDictionaryRef> > m_CFStringAttributes; | 284 mutable HashMap<unsigned, RetainPtr<CFDictionaryRef> > m_CFStringAttributes; |
265 #endif | 285 #endif |
266 | 286 |
267 #if OS(MACOSX) || USE(HARFBUZZ) | 287 #if OS(MACOSX) || USE(HARFBUZZ) |
268 mutable OwnPtr<HashMap<String, bool> > m_combiningCharacterSequenceSupport; | 288 mutable OwnPtr<HashMap<String, bool> > m_combiningCharacterSequenceSupport; |
269 #endif | 289 #endif |
270 }; | 290 }; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 #endif | 329 #endif |
310 else | 330 else |
311 width = platformWidthForGlyph(glyph); | 331 width = platformWidthForGlyph(glyph); |
312 | 332 |
313 m_glyphToWidthMap.setMetricsForGlyph(glyph, width); | 333 m_glyphToWidthMap.setMetricsForGlyph(glyph, width); |
314 return width; | 334 return width; |
315 } | 335 } |
316 | 336 |
317 } // namespace WebCore | 337 } // namespace WebCore |
318 #endif // SimpleFontData_h | 338 #endif // SimpleFontData_h |
OLD | NEW |