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>
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.
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.
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.
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"
29 #include "qt/FontPlatformData.h"
30 #elif PLATFORM(WIN) && OS(WINCE)
31 #include "wince/FontPlatformData.h"
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"
40 #ifndef FontPlatformData_h
41 #define FontPlatformData_h
43 #include "FontOrientation.h"
44 #include "FontWidthVariant.h"
45 #include "GlyphBuffer.h"
46 #include "TextOrientation.h"
49 #include "RefCountedGDIHandle.h"
53 #include <wtf/HashFunctions.h>
60 typedef struct CGFont* CGFontRef;
61 typedef const struct __CTFont* CTFontRef;
63 #include <CoreFoundation/CFBase.h>
64 #include <objc/objc-auto.h>
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>
73 #if PLATFORM(CHROMIUM) && OS(DARWIN)
74 #include "CrossProcessFontLoading.h"
78 typedef struct HFONT__* HFONT;
81 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
82 typedef struct CGFont* CGFontRef;
84 typedef const struct __CTFont* CTFontRef;
85 typedef UInt32 FMFont;
86 typedef FMFont ATSUFontID;
87 typedef UInt32 ATSFontRef;
93 class FontDescription;
96 #if PLATFORM(CHROMIUM) && OS(DARWIN)
101 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
104 class FontPlatformData {
106 FontPlatformData(WTF::HashTableDeletedValueType);
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);
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);
122 FontPlatformData(HFONT, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
124 FontPlatformData(HFONT, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
128 FontPlatformData(cairo_font_face_t*, float size, bool bold, bool italic);
134 HFONT hfont() const { return m_font ? m_font->handle() : 0; }
135 bool useGDI() const { return m_useGDI; }
137 NSFont* font() const { return m_font; }
138 void setFont(NSFont*);
141 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
143 CGFontRef cgFont() const { return m_cgFont.get(); }
144 CTFontRef ctFont() const;
146 bool roundsGlyphAdvances() const;
147 bool allowsLigatures() const;
149 CGFontRef cgFont() const { return m_cgFont.get(); }
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; }
161 bool isPrinterFont() const { return m_isPrinterFont; }
163 FontOrientation orientation() const { return m_orientation; }
164 TextOrientation textOrientation() const { return m_textOrientation; }
165 FontWidthVariant widthVariant() const { return m_widthVariant; }
167 void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
170 cairo_scaled_font_t* scaledFont() const { return m_scaledFont; }
173 #if PLATFORM(CHROMIUM) && OS(DARWIN)
174 HarfBuzzNGFace* harfbuzzFace();
177 unsigned hash() const
179 #if PLATFORM(WIN) && !USE(CAIRO)
180 return m_font ? m_font->hash() : 0;
182 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
183 ASSERT(m_font || !m_cgFont);
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);
188 return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont);
192 const FontPlatformData& operator=(const FontPlatformData&);
194 bool operator==(const FontPlatformData& other) const
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
203 && m_isPrinterFont == other.m_isPrinterFont
205 && m_orientation == other.m_orientation
206 && m_textOrientation == other.m_textOrientation
207 && m_widthVariant == other.m_widthVariant;
210 bool isHashTableDeletedValue() const
212 #if PLATFORM(WIN) && !USE(CAIRO)
213 return m_font.isHashTableDeletedValue();
215 return m_font == hashTableDeletedFontValue();
217 return m_scaledFont == hashTableDeletedFontValue();
221 #if PLATFORM(WIN) && (USE(CG) || USE(CAIRO))
222 PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
226 String description() const;
230 bool platformIsEqual(const FontPlatformData&) const;
231 void platformDataInit(const FontPlatformData&);
232 const FontPlatformData& platformDataAssign(const FontPlatformData&);
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); }
243 void platformDataInit(HFONT, float size, HDC, WCHAR* faceName);
247 static cairo_scaled_font_t* hashTableDeletedFontValue() { return reinterpret_cast<cairo_scaled_font_t*>(-1); }
251 bool m_syntheticBold;
252 bool m_syntheticOblique;
253 FontOrientation m_orientation;
254 TextOrientation m_textOrientation;
256 FontWidthVariant m_widthVariant;
262 RefPtr<RefCountedGDIHandle<HFONT> > m_font;
265 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
267 RetainPtr<CGFontRef> m_cgFont;
269 RetainPtr<CGFontRef> m_cgFont;
270 mutable RetainPtr<CTFontRef> m_CTFont;
275 cairo_scaled_font_t* m_scaledFont;
278 #if PLATFORM(CHROMIUM) && OS(DARWIN)
279 RefPtr<MemoryActivatedFont> m_inMemoryFont;
280 RefPtr<HarfBuzzNGFace> m_harfbuzzFace;
283 bool m_isColorBitmapFont;
284 bool m_isCompositeFontReference;
286 bool m_isPrinterFont;
294 } // namespace WebCore
296 #endif // FontPlatformData_h