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)
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 "HashFunctions.h"
64 typedef struct CGFont* CGFontRef;
65 typedef const struct __CTFont* CTFontRef;
67 #include <CoreFoundation/CFBase.h>
68 #include <objc/objc-auto.h>
71 #include <wtf/Forward.h>
72 #include <wtf/PassRefPtr.h>
73 #include <wtf/RefCounted.h>
74 #include <wtf/RetainPtr.h>
75 #include <wtf/text/StringImpl.h>
77 #if PLATFORM(CHROMIUM) && OS(DARWIN)
78 #include "CrossProcessFontLoading.h"
82 typedef struct HFONT__* HFONT;
85 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
86 typedef struct CGFont* CGFontRef;
88 typedef const struct __CTFont* CTFontRef;
89 typedef UInt32 FMFont;
90 typedef FMFont ATSUFontID;
91 typedef UInt32 ATSFontRef;
97 class FontDescription;
100 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
103 class FontPlatformData {
105 FontPlatformData(WTF::HashTableDeletedValueType)
106 : m_syntheticBold(false)
107 , m_syntheticOblique(false)
108 , m_orientation(Horizontal)
109 , m_textOrientation(TextOrientationVerticalRight)
111 , m_widthVariant(RegularWidth)
113 , m_font(WTF::HashTableDeletedValue)
115 , m_font(hashTableDeletedFontValue())
117 #if USE(CG) && PLATFORM(WIN)
120 , m_scaledFont(hashTableDeletedFontValue())
122 , m_isColorBitmapFont(false)
130 : m_syntheticBold(false)
131 , m_syntheticOblique(false)
132 , m_orientation(Horizontal)
133 , m_textOrientation(TextOrientationVerticalRight)
135 , m_widthVariant(RegularWidth)
139 #if USE(CG) && PLATFORM(WIN)
144 , m_isColorBitmapFont(false)
151 FontPlatformData(const FontPlatformData&);
152 FontPlatformData(const FontDescription&, const AtomicString& family);
153 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation = Horizontal,
154 TextOrientation textOrientation = TextOrientationVerticalRight, FontWidthVariant widthVariant = RegularWidth)
155 : m_syntheticBold(syntheticBold)
156 , m_syntheticOblique(syntheticOblique)
157 , m_orientation(orientation)
158 , m_textOrientation(textOrientation)
160 , m_widthVariant(widthVariant)
164 #if USE(CG) && PLATFORM(WIN)
169 , m_isColorBitmapFont(false)
177 FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool syntheticOblique = false, FontOrientation = Horizontal,
178 TextOrientation = TextOrientationVerticalRight, FontWidthVariant = RegularWidth);
179 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
180 FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation,
181 TextOrientation textOrientation, FontWidthVariant widthVariant)
182 : m_syntheticBold(syntheticBold)
183 , m_syntheticOblique(syntheticOblique)
184 , m_orientation(orientation)
185 , m_textOrientation(textOrientation)
187 , m_widthVariant(widthVariant)
190 , m_isColorBitmapFont(false)
196 FontPlatformData(HFONT, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
198 FontPlatformData(HFONT, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
202 FontPlatformData(cairo_font_face_t*, float size, bool bold, bool italic);
208 HFONT hfont() const { return m_font ? m_font->handle() : 0; }
209 bool useGDI() const { return m_useGDI; }
211 NSFont* font() const { return m_font; }
212 void setFont(NSFont*);
215 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
217 CGFontRef cgFont() const { return m_cgFont.get(); }
218 CTFontRef ctFont() const;
220 bool roundsGlyphAdvances() const;
221 bool allowsLigatures() const;
223 CGFontRef cgFont() const { return m_cgFont.get(); }
227 bool isFixedPitch() const;
228 float size() const { return m_size; }
229 void setSize(float size) { m_size = size; }
230 bool syntheticBold() const { return m_syntheticBold; }
231 bool syntheticOblique() const { return m_syntheticOblique; }
232 bool isColorBitmapFont() const { return m_isColorBitmapFont; }
233 FontOrientation orientation() const { return m_orientation; }
234 TextOrientation textOrientation() const { return m_textOrientation; }
235 FontWidthVariant widthVariant() const { return m_widthVariant; }
237 void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
240 cairo_scaled_font_t* scaledFont() const { return m_scaledFont; }
243 unsigned hash() const
245 #if PLATFORM(WIN) && !USE(CAIRO)
246 return m_font ? m_font->hash() : 0;
248 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
249 ASSERT(m_font || !m_cgFont);
251 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, m_textOrientation << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique };
252 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
254 return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont);
258 const FontPlatformData& operator=(const FontPlatformData&);
260 bool operator==(const FontPlatformData& other) const
262 return platformIsEqual(other)
263 && m_size == other.m_size
264 && m_syntheticBold == other.m_syntheticBold
265 && m_syntheticOblique == other.m_syntheticOblique
266 && m_isColorBitmapFont == other.m_isColorBitmapFont
267 && m_orientation == other.m_orientation
268 && m_textOrientation == other.m_textOrientation
269 && m_widthVariant == other.m_widthVariant;
272 bool isHashTableDeletedValue() const
274 #if PLATFORM(WIN) && !USE(CAIRO)
275 return m_font.isHashTableDeletedValue();
277 return m_font == hashTableDeletedFontValue();
279 return m_scaledFont == hashTableDeletedFontValue();
285 String description() const;
289 bool platformIsEqual(const FontPlatformData&) const;
290 void platformDataInit(const FontPlatformData&);
291 const FontPlatformData& platformDataAssign(const FontPlatformData&);
293 // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters:
294 // Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same
295 // font as |nsFont|. This because the sandbox may block loading of the original font.
296 // * outNSFont - The font that was actually loaded, for the Chromium port this may be different than nsFont.
297 // The caller is responsible for calling CFRelease() on this parameter when done with it.
298 // * cgFont - CGFontRef representing the input font at the specified point size.
299 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&);
300 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont *>(-1); }
302 void platformDataInit(HFONT, float size, HDC, WCHAR* faceName);
306 static cairo_scaled_font_t* hashTableDeletedFontValue() { return reinterpret_cast<cairo_scaled_font_t*>(-1); }
310 bool m_syntheticBold;
311 bool m_syntheticOblique;
312 FontOrientation m_orientation;
313 TextOrientation m_textOrientation;
315 FontWidthVariant m_widthVariant;
321 RefPtr<RefCountedGDIHandle<HFONT> > m_font;
324 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
326 RetainPtr<CGFontRef> m_cgFont;
328 RetainPtr<CGFontRef> m_cgFont;
329 mutable RetainPtr<CTFontRef> m_CTFont;
334 cairo_scaled_font_t* m_scaledFont;
337 #if PLATFORM(CHROMIUM) && OS(DARWIN)
338 RefPtr<MemoryActivatedFont> m_inMemoryFont;
341 bool m_isColorBitmapFont;
348 } // namespace WebCore
350 #endif // FontPlatformData_h