tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / FontPlatformData.h
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc.
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  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24
25 // FIXME: This is temporary until all ports switch to using this file.
26 #if (PLATFORM(CHROMIUM) && !OS(DARWIN)) || PLATFORM(BLACKBERRY)
27 #include "chromium/FontPlatformData.h"
28 #elif PLATFORM(QT)
29 #include "qt/FontPlatformData.h"
30 #elif PLATFORM(WIN) && OS(WINCE)
31 #include "wince/FontPlatformData.h"
32 #elif PLATFORM(WX)
33 #include "wx/FontPlatformData.h"
34 #elif (PLATFORM(EFL) || PLATFORM(GTK)) && USE(FREETYPE)
35 #include "freetype/FontPlatformData.h"
36 #elif (PLATFORM(EFL) || PLATFORM(GTK)) && USE(PANGO)
37 #include "pango/FontPlatformData.h"
38 #else
39
40 #ifndef FontPlatformData_h
41 #define FontPlatformData_h
42
43 #include "FontOrientation.h"
44 #include "FontWidthVariant.h"
45 #include "GlyphBuffer.h"
46 #include "TextOrientation.h"
47
48 #if PLATFORM(WIN)
49 #include "RefCountedGDIHandle.h"
50 #endif
51
52 #if USE(CAIRO)
53 #include <wtf/HashFunctions.h>
54 #include <cairo.h>
55 #endif
56
57 #if OS(DARWIN)
58 OBJC_CLASS NSFont;
59
60 typedef struct CGFont* CGFontRef;
61 typedef const struct __CTFont* CTFontRef;
62
63 #include <CoreFoundation/CFBase.h>
64 #include <objc/objc-auto.h>
65 #endif
66
67 #include <wtf/Forward.h>
68 #include <wtf/PassRefPtr.h>
69 #include <wtf/RefCounted.h>
70 #include <wtf/RetainPtr.h>
71 #include <wtf/text/StringImpl.h>
72
73 #if PLATFORM(CHROMIUM) && OS(DARWIN)
74 #include "CrossProcessFontLoading.h"  
75 #endif
76
77 #if PLATFORM(WIN)
78 typedef struct HFONT__* HFONT;
79 #endif
80
81 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
82 typedef struct CGFont* CGFontRef;
83 #if OS(DARWIN)
84 typedef const struct __CTFont* CTFontRef;
85 typedef UInt32 FMFont;
86 typedef FMFont ATSUFontID;
87 typedef UInt32 ATSFontRef;
88 #endif
89 #endif
90
91 namespace WebCore {
92
93 class FontDescription;
94 class SharedBuffer;
95
96 #if PLATFORM(CHROMIUM) && OS(DARWIN)
97 class HarfBuzzNGFace;
98 #endif
99
100 #if OS(DARWIN)
101 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
102 #endif
103
104 class FontPlatformData {
105 public:
106     FontPlatformData(WTF::HashTableDeletedValueType);
107     FontPlatformData();
108     FontPlatformData(const FontPlatformData&);
109     FontPlatformData(const FontDescription&, const AtomicString& family);
110     FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal,
111                      TextOrientation = TextOrientationVerticalRight, FontWidthVariant = RegularWidth);
112
113 #if OS(DARWIN)
114     FontPlatformData(NSFont*, float size, bool isPrinterFont = false, bool syntheticBold = false, bool syntheticOblique = false,
115                      FontOrientation = Horizontal, TextOrientation = TextOrientationVerticalRight, FontWidthVariant = RegularWidth);
116 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
117     FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation,
118                      TextOrientation, FontWidthVariant);
119 #endif
120 #endif
121 #if PLATFORM(WIN)
122     FontPlatformData(HFONT, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
123 #if USE(CG)
124     FontPlatformData(HFONT, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
125 #endif
126 #endif
127 #if USE(CAIRO)
128     FontPlatformData(cairo_font_face_t*, float size, bool bold, bool italic);
129 #endif
130
131     ~FontPlatformData();
132
133 #if PLATFORM(WIN)
134     HFONT hfont() const { return m_font ? m_font->handle() : 0; }
135     bool useGDI() const { return m_useGDI; }
136 #elif OS(DARWIN)
137     NSFont* font() const { return m_font; }
138     void setFont(NSFont*);
139 #endif
140
141 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
142 #if OS(DARWIN)
143     CGFontRef cgFont() const { return m_cgFont.get(); }
144     CTFontRef ctFont() const;
145
146     bool roundsGlyphAdvances() const;
147     bool allowsLigatures() const;
148 #else
149     CGFontRef cgFont() const { return m_cgFont.get(); }
150 #endif
151 #endif
152
153     bool isFixedPitch() const;
154     float size() const { return m_size; }
155     void setSize(float size) { m_size = size; }
156     bool syntheticBold() const { return m_syntheticBold; }
157     bool syntheticOblique() const { return m_syntheticOblique; }
158     bool isColorBitmapFont() const { return m_isColorBitmapFont; }
159     bool isCompositeFontReference() const { return m_isCompositeFontReference; }
160 #if OS(DARWIN)
161     bool isPrinterFont() const { return m_isPrinterFont; }
162 #endif
163     FontOrientation orientation() const { return m_orientation; }
164     TextOrientation textOrientation() const { return m_textOrientation; }
165     FontWidthVariant widthVariant() const { return m_widthVariant; }
166
167     void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
168
169 #if USE(CAIRO)
170     cairo_scaled_font_t* scaledFont() const { return m_scaledFont; }
171 #endif
172
173 #if PLATFORM(CHROMIUM) && OS(DARWIN)
174     HarfBuzzNGFace* harfbuzzFace();
175 #endif
176
177     unsigned hash() const
178     {
179 #if PLATFORM(WIN) && !USE(CAIRO)
180         return m_font ? m_font->hash() : 0;
181 #elif OS(DARWIN)
182 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
183         ASSERT(m_font || !m_cgFont);
184 #endif
185         uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, m_isPrinterFont << 4 | m_textOrientation << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique };
186         return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
187 #elif USE(CAIRO)
188         return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont);
189 #endif
190     }
191
192     const FontPlatformData& operator=(const FontPlatformData&);
193
194     bool operator==(const FontPlatformData& other) const
195     {
196         return platformIsEqual(other)
197             && m_size == other.m_size
198             && m_syntheticBold == other.m_syntheticBold
199             && m_syntheticOblique == other.m_syntheticOblique
200             && m_isColorBitmapFont == other.m_isColorBitmapFont
201             && m_isCompositeFontReference == other.m_isCompositeFontReference
202 #if OS(DARWIN)
203             && m_isPrinterFont == other.m_isPrinterFont
204 #endif
205             && m_orientation == other.m_orientation
206             && m_textOrientation == other.m_textOrientation
207             && m_widthVariant == other.m_widthVariant;
208     }
209
210     bool isHashTableDeletedValue() const
211     {
212 #if PLATFORM(WIN) && !USE(CAIRO)
213         return m_font.isHashTableDeletedValue();
214 #elif OS(DARWIN)
215         return m_font == hashTableDeletedFontValue();
216 #elif USE(CAIRO)
217         return m_scaledFont == hashTableDeletedFontValue();
218 #endif
219     }
220
221 #if PLATFORM(WIN) && (USE(CG) || USE(CAIRO))
222     PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
223 #endif
224
225 #ifndef NDEBUG
226     String description() const;
227 #endif
228
229 private:
230     bool platformIsEqual(const FontPlatformData&) const;
231     void platformDataInit(const FontPlatformData&);
232     const FontPlatformData& platformDataAssign(const FontPlatformData&);
233 #if OS(DARWIN)
234     // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters:
235     // Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same
236     // font as |nsFont|. This because the sandbox may block loading of the original font.
237     // * outNSFont - The font that was actually loaded, for the Chromium port this may be different than nsFont.
238     // The caller is responsible for calling CFRelease() on this parameter when done with it.
239     // * cgFont - CGFontRef representing the input font at the specified point size.
240     void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&);
241     static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont *>(-1); }
242 #elif PLATFORM(WIN)
243     void platformDataInit(HFONT, float size, HDC, WCHAR* faceName);
244 #endif
245
246 #if USE(CAIRO)
247     static cairo_scaled_font_t* hashTableDeletedFontValue() { return reinterpret_cast<cairo_scaled_font_t*>(-1); }
248 #endif
249
250 public:
251     bool m_syntheticBold;
252     bool m_syntheticOblique;
253     FontOrientation m_orientation;
254     TextOrientation m_textOrientation;
255     float m_size;
256     FontWidthVariant m_widthVariant;
257
258 private:
259 #if OS(DARWIN)
260     NSFont* m_font;
261 #elif PLATFORM(WIN)
262     RefPtr<RefCountedGDIHandle<HFONT> > m_font;
263 #endif
264
265 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
266 #if PLATFORM(WIN)
267     RetainPtr<CGFontRef> m_cgFont;
268 #else
269     RetainPtr<CGFontRef> m_cgFont;
270     mutable RetainPtr<CTFontRef> m_CTFont;
271 #endif
272 #endif
273
274 #if USE(CAIRO)
275     cairo_scaled_font_t* m_scaledFont;
276 #endif
277
278 #if PLATFORM(CHROMIUM) && OS(DARWIN)
279     RefPtr<MemoryActivatedFont> m_inMemoryFont;
280     RefPtr<HarfBuzzNGFace> m_harfbuzzFace;
281 #endif
282
283     bool m_isColorBitmapFont;
284     bool m_isCompositeFontReference;
285 #if OS(DARWIN)
286     bool m_isPrinterFont;
287 #endif
288
289 #if PLATFORM(WIN)
290     bool m_useGDI;
291 #endif
292 };
293
294 } // namespace WebCore
295
296 #endif // FontPlatformData_h
297
298 #endif