OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. | 2 * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved. |
3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com | |
4 * Copyright (C) 2007 Holger Hans Peter Freyther | |
5 * Copyright (C) 2007 Pioneer Research Center USA, Inc. | |
6 * Copyright (C) 2010, 2011 Brent Fulgham <bfulgham@webkit.org> | |
7 * | 3 * |
8 * This library is free software; you can redistribute it and/or | 4 * Redistribution and use in source and binary forms, with or without |
9 * modify it under the terms of the GNU Library General Public | 5 * modification, are permitted provided that the following conditions are |
10 * License as published by the Free Software Foundation; either | 6 * met: |
11 * version 2 of the License, or (at your option) any later version. | |
12 * | 7 * |
13 * This library is distributed in the hope that it will be useful, | 8 * * Redistributions of source code must retain the above copyright |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 * notice, this list of conditions and the following disclaimer. |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 10 * * Redistributions in binary form must reproduce the above |
16 * Library General Public License for more details. | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * You should have received a copy of the GNU Library General Public License | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * along with this library; see the file COPYING.LIB. If not, write to | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * Boston, MA 02110-1301, USA. | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
23 */ | 29 */ |
24 | 30 |
25 // FIXME: This is temporary until mac switch to using FontPlatformDataHarfBuzz.h
and we merge it with this file. | |
26 #if !OS(MACOSX) | |
27 #include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h" | |
28 | |
29 #else | |
30 | |
31 #ifndef FontPlatformData_h | 31 #ifndef FontPlatformData_h |
32 #define FontPlatformData_h | 32 #define FontPlatformData_h |
33 | 33 |
| 34 #include "SkPaint.h" |
34 #include "platform/PlatformExport.h" | 35 #include "platform/PlatformExport.h" |
| 36 #include "platform/SharedBuffer.h" |
| 37 #include "platform/fonts/FontDescription.h" |
35 #include "platform/fonts/FontOrientation.h" | 38 #include "platform/fonts/FontOrientation.h" |
36 #include "platform/fonts/FontWidthVariant.h" | 39 #include "platform/fonts/FontRenderStyle.h" |
| 40 #include "platform/fonts/opentype/OpenTypeVerticalData.h" |
| 41 #include "wtf/Forward.h" |
| 42 #include "wtf/HashTableDeletedValueType.h" |
| 43 #include "wtf/RefPtr.h" |
| 44 #include "wtf/text/CString.h" |
| 45 #include "wtf/text/StringImpl.h" |
37 | 46 |
| 47 #if OS(MACOSX) |
38 OBJC_CLASS NSFont; | 48 OBJC_CLASS NSFont; |
39 | 49 |
40 typedef struct CGFont* CGFontRef; | 50 typedef struct CGFont* CGFontRef; |
41 typedef const struct __CTFont* CTFontRef; | 51 typedef const struct __CTFont* CTFontRef; |
42 | 52 |
| 53 #include "platform/fonts/mac/MemoryActivatedFont.h" |
43 #include <CoreFoundation/CFBase.h> | 54 #include <CoreFoundation/CFBase.h> |
44 #include <objc/objc-auto.h> | 55 #include <objc/objc-auto.h> |
45 | 56 |
46 #include "wtf/Forward.h" | 57 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef
>(nsFont); } |
47 #include "wtf/HashTableDeletedValueType.h" | 58 #endif // OS(MACOSX) |
48 #include "wtf/PassRefPtr.h" | |
49 #include "wtf/RefCounted.h" | |
50 #include "wtf/RetainPtr.h" | |
51 #include "wtf/text/StringImpl.h" | |
52 | 59 |
53 #include "platform/fonts/mac/MemoryActivatedFont.h" | 60 class SkTypeface; |
54 #include "third_party/skia/include/core/SkTypeface.h" | 61 typedef uint32_t SkFontID; |
55 | |
56 typedef struct CGFont* CGFontRef; | |
57 typedef const struct __CTFont* CTFontRef; | |
58 typedef UInt32 FMFont; | |
59 typedef FMFont ATSUFontID; | |
60 typedef UInt32 ATSFontRef; | |
61 | 62 |
62 namespace blink { | 63 namespace blink { |
63 | 64 |
| 65 class GraphicsContext; |
64 class HarfBuzzFace; | 66 class HarfBuzzFace; |
65 | 67 |
66 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef
>(nsFont); } | |
67 | |
68 class PLATFORM_EXPORT FontPlatformData { | 68 class PLATFORM_EXPORT FontPlatformData { |
69 public: | 69 public: |
| 70 // 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 |
| 72 // 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 |
| 74 // set everything to 0. |
70 FontPlatformData(WTF::HashTableDeletedValueType); | 75 FontPlatformData(WTF::HashTableDeletedValueType); |
71 FontPlatformData(); | 76 FontPlatformData(); |
72 FontPlatformData(const FontPlatformData&); | 77 FontPlatformData(const FontPlatformData&); |
73 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, Font
Orientation = Horizontal, FontWidthVariant = RegularWidth); | 78 #if OS(MACOSX) |
74 FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool synth
eticOblique = false, | 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, |
75 FontOrientation = Horizontal, FontWidthVariant = RegularWid
th); | 81 FontOrientation = Horizontal, FontWidthVariant = RegularWid
th); |
76 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOb
lique, FontOrientation, FontWidthVariant); | 82 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOb
lique, FontOrientation, FontWidthVariant); |
77 | 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()); |
| 86 FontPlatformData(const FontPlatformData& src, float textSize); |
| 87 #endif |
78 ~FontPlatformData(); | 88 ~FontPlatformData(); |
79 | 89 |
| 90 #if OS(MACOSX) |
80 NSFont* font() const { return m_font; } | 91 NSFont* font() const { return m_font; } |
81 void setFont(NSFont*); | 92 void setFont(NSFont*); |
82 | 93 |
83 CGFontRef cgFont() const { return m_cgFont.get(); } | 94 CGFontRef cgFont() const { return m_cgFont.get(); } |
84 CTFontRef ctFont() const; | 95 CTFontRef ctFont() const; |
85 SkTypeface* typeface() const; | |
86 | 96 |
87 bool roundsGlyphAdvances() const; | 97 bool roundsGlyphAdvances() const; |
88 bool allowsLigatures() const; | 98 bool allowsLigatures() const; |
89 | 99 |
90 String fontFamilyName() const; | |
91 bool isFixedPitch() const; | |
92 float size() const { return m_size; } | |
93 void setSize(float size) { m_size = size; } | |
94 bool syntheticBold() const { return m_syntheticBold; } | |
95 bool syntheticOblique() const { return m_syntheticOblique; } | |
96 bool isColorBitmapFont() const { return m_isColorBitmapFont; } | 100 bool isColorBitmapFont() const { return m_isColorBitmapFont; } |
97 bool isCompositeFontReference() const { return m_isCompositeFontReference; } | 101 bool isCompositeFontReference() const { return m_isCompositeFontReference; } |
98 | 102 |
| 103 FontWidthVariant widthVariant() const { return m_widthVariant; } |
| 104 #endif |
| 105 |
| 106 String fontFamilyName() const; |
| 107 float size() const { return m_textSize; } |
| 108 bool isFixedPitch() const; |
| 109 bool syntheticBold() const { return m_syntheticBold; } |
| 110 bool syntheticItalic() const { return m_syntheticItalic; } |
| 111 |
| 112 SkTypeface* typeface() const; |
| 113 HarfBuzzFace* harfBuzzFace() const; |
| 114 SkFontID uniqueID() const; |
| 115 unsigned hash() const; |
| 116 |
99 FontOrientation orientation() const { return m_orientation; } | 117 FontOrientation orientation() const { return m_orientation; } |
100 FontWidthVariant widthVariant() const { return m_widthVariant; } | 118 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } |
| 119 void setSyntheticBold(bool syntheticBold) { m_syntheticBold = syntheticBold;
} |
| 120 void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheti
cItalic; } |
| 121 bool operator==(const FontPlatformData&) const; |
| 122 const FontPlatformData& operator=(const FontPlatformData&); |
| 123 bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; } |
| 124 #if OS(WIN) |
| 125 void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; } |
| 126 unsigned minSizeForAntiAlias() const { return m_minSizeForAntiAlias; } |
| 127 void setHinting(SkPaint::Hinting style) |
| 128 { |
| 129 m_style.useAutoHint = 0; |
| 130 m_style.hintStyle = style; |
| 131 } |
| 132 #endif |
| 133 bool fontContainsCharacter(UChar32 character); |
101 | 134 |
102 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } | 135 #if ENABLE(OPENTYPE_VERTICAL) |
103 | 136 PassRefPtr<OpenTypeVerticalData> verticalData() const; |
104 HarfBuzzFace* harfBuzzFace(); | 137 PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const; |
105 | 138 #endif |
106 unsigned hash() const | |
107 { | |
108 ASSERT(m_font || !m_cgFont); | |
109 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cas
t<uintptr_t>(m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique) }; | |
110 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | |
111 } | |
112 | |
113 const FontPlatformData& operator=(const FontPlatformData&); | |
114 | |
115 bool operator==(const FontPlatformData& other) const | |
116 { | |
117 return platformIsEqual(other) | |
118 && m_size == other.m_size | |
119 && m_syntheticBold == other.m_syntheticBold | |
120 && m_syntheticOblique == other.m_syntheticOblique | |
121 && m_isColorBitmapFont == other.m_isColorBitmapFont | |
122 && m_isCompositeFontReference == other.m_isCompositeFontReference | |
123 && m_orientation == other.m_orientation | |
124 && m_widthVariant == other.m_widthVariant; | |
125 } | |
126 | |
127 bool isHashTableDeletedValue() const | |
128 { | |
129 return m_font == hashTableDeletedFontValue(); | |
130 } | |
131 | 139 |
132 #ifndef NDEBUG | 140 #ifndef NDEBUG |
133 String description() const; | 141 String description() const; |
134 #endif | 142 #endif |
135 | 143 |
| 144 #if !OS(MACOSX) |
| 145 // The returned styles are all actual styles without FontRenderStyle::NoPref
erence. |
| 146 const FontRenderStyle& fontRenderStyle() const { return m_style; } |
| 147 void setupPaint(SkPaint*, GraphicsContext* = 0) const; |
| 148 #endif |
| 149 |
| 150 #if OS(WIN) |
| 151 int paintTextFlags() const { return m_paintTextFlags; } |
| 152 #else |
| 153 static void setHinting(SkPaint::Hinting); |
| 154 static void setAutoHint(bool); |
| 155 static void setUseBitmaps(bool); |
| 156 static void setAntiAlias(bool); |
| 157 static void setSubpixelRendering(bool); |
| 158 #endif |
| 159 |
136 private: | 160 private: |
137 bool platformIsEqual(const FontPlatformData&) const; | 161 #if !OS(MACOSX) |
138 void platformDataInit(const FontPlatformData&); | 162 bool static defaultUseSubpixelPositioning(); |
139 const FontPlatformData& platformDataAssign(const FontPlatformData&); | 163 void querySystemForRenderStyle(bool useSkiaSubpixelPositioning); |
140 #if OS(MACOSX) | 164 #else |
141 // Load various data about the font specified by |nsFont| with the size font
Size into the following output paramters: | 165 // Load various data about the font specified by |nsFont| with the size font
Size into the following output paramters: |
142 // Note: Callers should always take into account that for the Chromium port,
|outNSFont| isn't necessarily the same | 166 // Note: Callers should always take into account that for the Chromium port,
|outNSFont| isn't necessarily the same |
143 // font as |nsFont|. This because the sandbox may block loading of the origi
nal font. | 167 // font as |nsFont|. This because the sandbox may block loading of the origi
nal font. |
144 // * outNSFont - The font that was actually loaded, for the Chromium port th
is may be different than nsFont. | 168 // * outNSFont - The font that was actually loaded, for the Chromium port th
is may be different than nsFont. |
145 // The caller is responsible for calling CFRelease() on this parameter when
done with it. | 169 // The caller is responsible for calling CFRelease() on this parameter when
done with it. |
146 // * cgFont - CGFontRef representing the input font at the specified point s
ize. | 170 // * cgFont - CGFontRef representing the input font at the specified point s
ize. |
147 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); | 171 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); |
148 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont
*>(-1); } | 172 |
| 173 bool platformIsEqual(const FontPlatformData&) const; |
| 174 void platformDataInit(const FontPlatformData&); |
| 175 const FontPlatformData& platformDataAssign(const FontPlatformData&); |
| 176 #endif |
| 177 |
| 178 mutable RefPtr<SkTypeface> m_typeface; |
| 179 #if !OS(WIN) |
| 180 CString m_family; |
149 #endif | 181 #endif |
150 | 182 |
151 public: | 183 public: |
| 184 float m_textSize; |
152 bool m_syntheticBold; | 185 bool m_syntheticBold; |
153 bool m_syntheticOblique; | 186 bool m_syntheticItalic; |
154 FontOrientation m_orientation; | 187 FontOrientation m_orientation; |
155 float m_size; | 188 #if OS(MACOSX) |
| 189 bool m_isColorBitmapFont; |
| 190 bool m_isCompositeFontReference; |
156 FontWidthVariant m_widthVariant; | 191 FontWidthVariant m_widthVariant; |
157 | 192 #endif |
158 private: | 193 private: |
| 194 #if OS(MACOSX) |
159 NSFont* m_font; | 195 NSFont* m_font; |
160 RetainPtr<CGFontRef> m_cgFont; | 196 RetainPtr<CGFontRef> m_cgFont; |
161 mutable RetainPtr<CTFontRef> m_CTFont; | 197 mutable RetainPtr<CTFontRef> m_CTFont; |
| 198 RefPtr<MemoryActivatedFont> m_inMemoryFont; |
| 199 #else |
| 200 FontRenderStyle m_style; |
| 201 #endif |
162 | 202 |
163 RefPtr<MemoryActivatedFont> m_inMemoryFont; | 203 mutable RefPtr<HarfBuzzFace> m_harfBuzzFace; |
164 RefPtr<HarfBuzzFace> m_harfBuzzFace; | 204 bool m_isHashTableDeletedValue; |
165 mutable RefPtr<SkTypeface> m_typeface; | 205 #if OS(WIN) |
166 | 206 int m_paintTextFlags; |
167 bool m_isColorBitmapFont; | 207 bool m_useSubpixelPositioning; |
168 bool m_isCompositeFontReference; | 208 unsigned m_minSizeForAntiAlias; |
| 209 #endif |
169 }; | 210 }; |
170 | 211 |
171 } // namespace blink | 212 } // namespace blink |
172 | 213 |
173 #endif // FontPlatformData_h | 214 #endif // ifdef FontPlatformData_h |
174 | |
175 #endif | |
OLD | NEW |