Chromium Code Reviews| 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(DARWIN) | 44 #if OS(DARWIN) |
| 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_isLoadingFallback; } | |
| 159 | 161 |
| 160 virtual bool isCustomFont() const { return m_isCustomFont; } | 162 virtual bool isCustomFont() const { return m_isCustomFont; } |
| 161 virtual bool isLoading() const { return m_isLoading; } | 163 virtual bool isLoading() const { return m_isLoadingFallback && m_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(DARWIN) | 175 #if OS(DARWIN) |
| 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(DARWIN) | 180 #if OS(DARWIN) |
| 177 CFDictionaryRef getCFStringAttributes(TypesettingFeatures, FontOrientation) const; | 181 CFDictionaryRef getCFStringAttributes(TypesettingFeatures, FontOrientation) const; |
| 178 #endif | 182 #endif |
| 179 | 183 |
| 180 #if OS(DARWIN) || USE(HARFBUZZ) | 184 #if OS(DARWIN) || 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_fontFaceSource = so urce; } | |
| 198 void clearCSSFontFaceSource() { m_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 | 226 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. | 227 bool m_isLoadingFallback; // Whether or not this is a temporary font data fo r a custom font which is not yet loaded. |
| 221 | 228 |
| 222 bool m_isTextOrientationFallback; | 229 bool m_isTextOrientationFallback; |
| 223 bool m_isBrokenIdeographFallback; | 230 bool m_isBrokenIdeographFallback; |
| 224 #if ENABLE(OPENTYPE_VERTICAL) | 231 #if ENABLE(OPENTYPE_VERTICAL) |
| 225 RefPtr<OpenTypeVerticalData> m_verticalData; | 232 RefPtr<OpenTypeVerticalData> m_verticalData; |
| 226 #endif | 233 #endif |
| 227 bool m_hasVerticalGlyphs; | 234 bool m_hasVerticalGlyphs; |
| 228 | 235 |
| 229 Glyph m_spaceGlyph; | 236 Glyph m_spaceGlyph; |
| 230 float m_spaceWidth; | 237 float m_spaceWidth; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 251 | 258 |
| 252 private: | 259 private: |
| 253 DerivedFontData(bool custom) | 260 DerivedFontData(bool custom) |
| 254 : forCustomFont(custom) | 261 : forCustomFont(custom) |
| 255 { | 262 { |
| 256 } | 263 } |
| 257 }; | 264 }; |
| 258 | 265 |
| 259 mutable OwnPtr<DerivedFontData> m_derivedFontData; | 266 mutable OwnPtr<DerivedFontData> m_derivedFontData; |
| 260 | 267 |
| 268 mutable bool m_isUsed; | |
|
eseidel
2013/09/10 15:07:26
I see. Normally we don't have non-used SimpleFont
Kunihiko Sakamoto
2013/09/11 13:28:09
Thanks for the suggestion. Moved these fields to a
| |
| 269 CSSFontFaceSource* m_fontFaceSource; | |
| 270 | |
| 261 #if OS(DARWIN) | 271 #if OS(DARWIN) |
| 262 float m_syntheticBoldOffset; | 272 float m_syntheticBoldOffset; |
| 263 | 273 |
| 264 mutable HashMap<unsigned, RetainPtr<CFDictionaryRef> > m_CFStringAttributes; | 274 mutable HashMap<unsigned, RetainPtr<CFDictionaryRef> > m_CFStringAttributes; |
| 265 #endif | 275 #endif |
| 266 | 276 |
| 267 #if OS(DARWIN) || USE(HARFBUZZ) | 277 #if OS(DARWIN) || USE(HARFBUZZ) |
| 268 mutable OwnPtr<HashMap<String, bool> > m_combiningCharacterSequenceSupport; | 278 mutable OwnPtr<HashMap<String, bool> > m_combiningCharacterSequenceSupport; |
| 269 #endif | 279 #endif |
| 270 }; | 280 }; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 #endif | 319 #endif |
| 310 else | 320 else |
| 311 width = platformWidthForGlyph(glyph); | 321 width = platformWidthForGlyph(glyph); |
| 312 | 322 |
| 313 m_glyphToWidthMap.setMetricsForGlyph(glyph, width); | 323 m_glyphToWidthMap.setMetricsForGlyph(glyph, width); |
| 314 return width; | 324 return width; |
| 315 } | 325 } |
| 316 | 326 |
| 317 } // namespace WebCore | 327 } // namespace WebCore |
| 318 #endif // SimpleFontData_h | 328 #endif // SimpleFontData_h |
| OLD | NEW |