OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef FontPlatformData_h | 31 #ifndef FontPlatformDataHarfBuzz_h |
32 #define FontPlatformData_h | 32 #define FontPlatformDataHarfBuzz_h |
33 | 33 |
34 #include "SkPaint.h" | 34 #include "SkPaint.h" |
35 #include "platform/PlatformExport.h" | |
36 #include "platform/SharedBuffer.h" | 35 #include "platform/SharedBuffer.h" |
37 #include "platform/fonts/FontDescription.h" | 36 #include "platform/fonts/FontDescription.h" |
38 #include "platform/fonts/FontOrientation.h" | 37 #include "platform/fonts/FontOrientation.h" |
39 #include "platform/fonts/FontRenderStyle.h" | 38 #include "platform/fonts/FontRenderStyle.h" |
40 #include "platform/fonts/opentype/OpenTypeVerticalData.h" | 39 #include "platform/fonts/opentype/OpenTypeVerticalData.h" |
41 #include "wtf/Forward.h" | 40 #include "wtf/Forward.h" |
42 #include "wtf/HashTableDeletedValueType.h" | 41 #include "wtf/HashTableDeletedValueType.h" |
43 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
44 #include "wtf/text/CString.h" | 43 #include "wtf/text/CString.h" |
45 #include "wtf/text/StringImpl.h" | 44 #include "wtf/text/StringImpl.h" |
46 | 45 |
47 #if OS(MACOSX) | |
48 OBJC_CLASS NSFont; | |
49 | |
50 typedef struct CGFont* CGFontRef; | |
51 typedef const struct __CTFont* CTFontRef; | |
52 | |
53 #include "platform/fonts/mac/MemoryActivatedFont.h" | |
54 #include <CoreFoundation/CFBase.h> | |
55 #include <objc/objc-auto.h> | |
56 | |
57 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef
>(nsFont); } | |
58 #endif // OS(MACOSX) | |
59 | |
60 class SkTypeface; | 46 class SkTypeface; |
61 typedef uint32_t SkFontID; | 47 typedef uint32_t SkFontID; |
62 | 48 |
63 namespace blink { | 49 namespace blink { |
64 | 50 |
65 class GraphicsContext; | 51 class GraphicsContext; |
66 class HarfBuzzFace; | 52 class HarfBuzzFace; |
67 | 53 |
68 class PLATFORM_EXPORT FontPlatformData { | 54 class PLATFORM_EXPORT FontPlatformData { |
69 public: | 55 public: |
70 // Used for deleted values in the font cache's hash tables. The hash table | 56 // Used for deleted values in the font cache's hash tables. The hash table |
71 // will create us with this structure, and it will compare other values | 57 // will create us with this structure, and it will compare other values |
72 // to this "Deleted" one. It expects the Deleted one to be differentiable | 58 // to this "Deleted" one. It expects the Deleted one to be differentiable |
73 // from the 0 one (created with the empty constructor), so we can't just | 59 // from the 0 one (created with the empty constructor), so we can't just |
74 // set everything to 0. | 60 // set everything to 0. |
75 FontPlatformData(WTF::HashTableDeletedValueType); | 61 FontPlatformData(WTF::HashTableDeletedValueType); |
76 FontPlatformData(); | 62 FontPlatformData(); |
| 63 FontPlatformData(float textSize, bool syntheticBold, bool syntheticItalic); |
77 FontPlatformData(const FontPlatformData&); | 64 FontPlatformData(const FontPlatformData&); |
78 #if OS(MACOSX) | |
79 FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontO
rientation = Horizontal, FontWidthVariant = RegularWidth); | |
80 FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool synth
eticItalic = false, | |
81 FontOrientation = Horizontal, FontWidthVariant = RegularWid
th); | |
82 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOb
lique, FontOrientation, FontWidthVariant); | |
83 #else | |
84 FontPlatformData(float textSize, bool syntheticBold, bool syntheticItalic); | |
85 FontPlatformData(PassRefPtr<SkTypeface>, const char* name, float textSize, b
ool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, bool subp
ixelTextPosition = defaultUseSubpixelPositioning()); | 65 FontPlatformData(PassRefPtr<SkTypeface>, const char* name, float textSize, b
ool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, bool subp
ixelTextPosition = defaultUseSubpixelPositioning()); |
86 FontPlatformData(const FontPlatformData& src, float textSize); | 66 FontPlatformData(const FontPlatformData& src, float textSize); |
87 #endif | |
88 ~FontPlatformData(); | 67 ~FontPlatformData(); |
89 | 68 |
90 #if OS(MACOSX) | |
91 NSFont* font() const { return m_font; } | |
92 void setFont(NSFont*); | |
93 | |
94 CGFontRef cgFont() const { return m_cgFont.get(); } | |
95 CTFontRef ctFont() const; | |
96 | |
97 bool roundsGlyphAdvances() const; | |
98 bool allowsLigatures() const; | |
99 | |
100 bool isColorBitmapFont() const { return m_isColorBitmapFont; } | |
101 bool isCompositeFontReference() const { return m_isCompositeFontReference; } | |
102 | |
103 FontWidthVariant widthVariant() const { return m_widthVariant; } | |
104 #endif | |
105 | |
106 String fontFamilyName() const; | 69 String fontFamilyName() const; |
107 float size() const { return m_textSize; } | 70 float size() const { return m_textSize; } |
108 bool isFixedPitch() const; | 71 bool isFixedPitch() const; |
109 bool syntheticBold() const { return m_syntheticBold; } | |
110 bool syntheticItalic() const { return m_syntheticItalic; } | |
111 | 72 |
112 SkTypeface* typeface() const; | 73 SkTypeface* typeface() const { return m_typeface.get(); } |
113 HarfBuzzFace* harfBuzzFace() const; | 74 HarfBuzzFace* harfBuzzFace() const; |
114 SkFontID uniqueID() const; | 75 SkFontID uniqueID() const; |
115 unsigned hash() const; | 76 unsigned hash() const; |
116 | 77 |
117 FontOrientation orientation() const { return m_orientation; } | 78 FontOrientation orientation() const { return m_orientation; } |
118 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } | 79 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } |
119 void setSyntheticBold(bool syntheticBold) { m_syntheticBold = syntheticBold;
} | 80 void setSyntheticBold(bool syntheticBold) { m_syntheticBold = syntheticBold;
} |
120 void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheti
cItalic; } | 81 void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheti
cItalic; } |
121 bool operator==(const FontPlatformData&) const; | 82 bool operator==(const FontPlatformData&) const; |
122 const FontPlatformData& operator=(const FontPlatformData&); | 83 FontPlatformData& operator=(const FontPlatformData&); |
123 bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; } | 84 bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; } |
124 #if OS(WIN) | 85 #if OS(WIN) |
125 void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; } | 86 void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; } |
126 unsigned minSizeForAntiAlias() const { return m_minSizeForAntiAlias; } | 87 unsigned minSizeForAntiAlias() const { return m_minSizeForAntiAlias; } |
| 88 void setMinSizeForSubpixel(float size) { m_minSizeForSubpixel = size; } |
| 89 float minSizeForSubpixel() const { return m_minSizeForSubpixel; } |
127 void setHinting(SkPaint::Hinting style) | 90 void setHinting(SkPaint::Hinting style) |
128 { | 91 { |
129 m_style.useAutoHint = 0; | 92 m_style.useAutoHint = 0; |
130 m_style.hintStyle = style; | 93 m_style.hintStyle = style; |
131 } | 94 } |
132 #endif | 95 #endif |
133 bool fontContainsCharacter(UChar32 character); | 96 bool fontContainsCharacter(UChar32 character); |
134 | 97 |
135 #if ENABLE(OPENTYPE_VERTICAL) | 98 #if ENABLE(OPENTYPE_VERTICAL) |
136 PassRefPtr<OpenTypeVerticalData> verticalData() const; | 99 PassRefPtr<OpenTypeVerticalData> verticalData() const; |
137 PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const; | 100 PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const; |
138 #endif | 101 #endif |
139 | 102 |
140 #ifndef NDEBUG | 103 #ifndef NDEBUG |
141 String description() const; | 104 String description() const; |
142 #endif | 105 #endif |
143 | 106 |
144 #if !OS(MACOSX) | |
145 // The returned styles are all actual styles without FontRenderStyle::NoPref
erence. | 107 // The returned styles are all actual styles without FontRenderStyle::NoPref
erence. |
146 const FontRenderStyle& fontRenderStyle() const { return m_style; } | 108 const FontRenderStyle& fontRenderStyle() const { return m_style; } |
147 void setupPaint(SkPaint*, GraphicsContext* = 0) const; | 109 void setupPaint(SkPaint*, GraphicsContext* = 0) const; |
148 #endif | |
149 | 110 |
150 #if OS(WIN) | 111 #if OS(WIN) |
151 int paintTextFlags() const { return m_paintTextFlags; } | 112 int paintTextFlags() const { return m_paintTextFlags; } |
152 #else | 113 #else |
153 static void setHinting(SkPaint::Hinting); | 114 static void setHinting(SkPaint::Hinting); |
154 static void setAutoHint(bool); | 115 static void setAutoHint(bool); |
155 static void setUseBitmaps(bool); | 116 static void setUseBitmaps(bool); |
156 static void setAntiAlias(bool); | 117 static void setAntiAlias(bool); |
157 static void setSubpixelRendering(bool); | 118 static void setSubpixelRendering(bool); |
158 #endif | 119 #endif |
159 | 120 |
160 private: | 121 private: |
161 #if !OS(MACOSX) | |
162 bool static defaultUseSubpixelPositioning(); | 122 bool static defaultUseSubpixelPositioning(); |
163 void querySystemForRenderStyle(bool useSkiaSubpixelPositioning); | 123 void querySystemForRenderStyle(bool useSkiaSubpixelPositioning); |
164 #else | |
165 // Load various data about the font specified by |nsFont| with the size font
Size into the following output paramters: | |
166 // Note: Callers should always take into account that for the Chromium port,
|outNSFont| isn't necessarily the same | |
167 // font as |nsFont|. This because the sandbox may block loading of the origi
nal font. | |
168 // * outNSFont - The font that was actually loaded, for the Chromium port th
is may be different than nsFont. | |
169 // The caller is responsible for calling CFRelease() on this parameter when
done with it. | |
170 // * cgFont - CGFontRef representing the input font at the specified point s
ize. | |
171 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); | |
172 | 124 |
173 bool platformIsEqual(const FontPlatformData&) const; | 125 RefPtr<SkTypeface> m_typeface; |
174 void platformDataInit(const FontPlatformData&); | |
175 const FontPlatformData& platformDataAssign(const FontPlatformData&); | |
176 #endif | |
177 | |
178 mutable RefPtr<SkTypeface> m_typeface; | |
179 #if !OS(WIN) | 126 #if !OS(WIN) |
180 CString m_family; | 127 CString m_family; |
181 #endif | 128 #endif |
182 | |
183 public: | |
184 float m_textSize; | 129 float m_textSize; |
185 bool m_syntheticBold; | 130 bool m_syntheticBold; |
186 bool m_syntheticItalic; | 131 bool m_syntheticItalic; |
187 FontOrientation m_orientation; | 132 FontOrientation m_orientation; |
188 #if OS(MACOSX) | |
189 bool m_isColorBitmapFont; | |
190 bool m_isCompositeFontReference; | |
191 FontWidthVariant m_widthVariant; | |
192 #endif | |
193 private: | |
194 #if OS(MACOSX) | |
195 NSFont* m_font; | |
196 RetainPtr<CGFontRef> m_cgFont; | |
197 mutable RetainPtr<CTFontRef> m_CTFont; | |
198 RefPtr<MemoryActivatedFont> m_inMemoryFont; | |
199 #else | |
200 FontRenderStyle m_style; | 133 FontRenderStyle m_style; |
201 #endif | |
202 | |
203 mutable RefPtr<HarfBuzzFace> m_harfBuzzFace; | 134 mutable RefPtr<HarfBuzzFace> m_harfBuzzFace; |
204 bool m_isHashTableDeletedValue; | 135 bool m_isHashTableDeletedValue; |
205 #if OS(WIN) | 136 #if OS(WIN) |
206 int m_paintTextFlags; | 137 int m_paintTextFlags; |
207 bool m_useSubpixelPositioning; | 138 bool m_useSubpixelPositioning; |
208 unsigned m_minSizeForAntiAlias; | 139 unsigned m_minSizeForAntiAlias; |
| 140 float m_minSizeForSubpixel; |
209 #endif | 141 #endif |
210 }; | 142 }; |
211 | 143 |
212 } // namespace blink | 144 } // namespace blink |
213 | 145 |
214 #endif // ifdef FontPlatformData_h | 146 #endif // ifdef FontPlatformDataHarfBuzz_h |
OLD | NEW |