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"
38 #elif PLATFORM(ANDROID)
39 #include "android/FontPlatformData.h"
42 #ifndef FontPlatformData_h
43 #define FontPlatformData_h
45 #include "FontOrientation.h"
46 #include "FontWidthVariant.h"
47 #include "GlyphBuffer.h"
48 #include "TextOrientation.h"
51 #include "RefCountedGDIHandle.h"
55 #include "HashFunctions.h"
66 typedef struct CGFont* CGFontRef;
67 #ifndef BUILDING_ON_TIGER
68 typedef const struct __CTFont* CTFontRef;
71 #include <CoreFoundation/CFBase.h>
72 #include <objc/objc-auto.h>
75 #include <wtf/Forward.h>
76 #include <wtf/PassRefPtr.h>
77 #include <wtf/RefCounted.h>
78 #include <wtf/RetainPtr.h>
79 #include <wtf/text/StringImpl.h>
81 #if PLATFORM(CHROMIUM) && OS(DARWIN)
82 #include "CrossProcessFontLoading.h"
86 typedef struct HFONT__* HFONT;
89 #if USE(CG) || USE(SKIA_ON_MAC_CHROME)
90 typedef struct CGFont* CGFontRef;
92 #ifndef BUILDING_ON_TIGER
93 typedef const struct __CTFont* CTFontRef;
94 typedef UInt32 ATSUFontID;
95 typedef UInt32 ATSFontRef;
102 class FontDescription;
104 #if OS(DARWIN) && !defined(BUILDING_ON_TIGER)
105 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
108 class FontPlatformData {
110 FontPlatformData(WTF::HashTableDeletedValueType)
111 : m_syntheticBold(false)
112 , m_syntheticOblique(false)
113 , m_orientation(Horizontal)
114 , m_textOrientation(TextOrientationVerticalRight)
116 , m_widthVariant(RegularWidth)
118 , m_font(WTF::HashTableDeletedValue)
120 , m_font(hashTableDeletedFontValue())
122 #if USE(CG) && (defined(BUILDING_ON_TIGER) || PLATFORM(WIN))
125 , m_scaledFont(hashTableDeletedFontValue())
127 , m_isColorBitmapFont(false)
135 : m_syntheticBold(false)
136 , m_syntheticOblique(false)
137 , m_orientation(Horizontal)
138 , m_textOrientation(TextOrientationVerticalRight)
140 , m_widthVariant(RegularWidth)
144 #if USE(CG) && (defined(BUILDING_ON_TIGER) || PLATFORM(WIN))
149 , m_isColorBitmapFont(false)
156 FontPlatformData(const FontPlatformData&);
157 FontPlatformData(const FontDescription&, const AtomicString& family);
158 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation = Horizontal,
159 TextOrientation textOrientation = TextOrientationVerticalRight, FontWidthVariant widthVariant = RegularWidth)
160 : m_syntheticBold(syntheticBold)
161 , m_syntheticOblique(syntheticOblique)
162 , m_orientation(orientation)
163 , m_textOrientation(textOrientation)
165 , m_widthVariant(widthVariant)
169 #if USE(CG) && (defined(BUILDING_ON_TIGER) || PLATFORM(WIN))
174 , m_isColorBitmapFont(false)
182 FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool syntheticOblique = false, FontOrientation = Horizontal,
183 TextOrientation = TextOrientationVerticalRight, FontWidthVariant = RegularWidth);
184 #if USE(CG) || USE(SKIA_ON_MAC_CHROME)
185 FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation,
186 TextOrientation textOrientation, FontWidthVariant widthVariant)
187 : m_syntheticBold(syntheticBold)
188 , m_syntheticOblique(syntheticOblique)
189 , m_orientation(orientation)
190 , m_textOrientation(textOrientation)
192 , m_widthVariant(widthVariant)
195 , m_isColorBitmapFont(false)
201 FontPlatformData(HFONT, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
203 FontPlatformData(HFONT, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
207 FontPlatformData(cairo_font_face_t*, float size, bool bold, bool italic);
213 HFONT hfont() const { return m_font ? m_font->handle() : 0; }
214 bool useGDI() const { return m_useGDI; }
216 NSFont* font() const { return m_font; }
217 void setFont(NSFont*);
220 #if USE(CG) || USE(SKIA_ON_MAC_CHROME)
222 #ifndef BUILDING_ON_TIGER
223 CGFontRef cgFont() const { return m_cgFont.get(); }
225 CGFontRef cgFont() const { return m_cgFont; }
227 CTFontRef ctFont() const;
229 bool roundsGlyphAdvances() const;
230 bool allowsLigatures() const;
232 CGFontRef cgFont() const { return m_cgFont.get(); }
236 bool isFixedPitch() const;
237 float size() const { return m_size; }
238 void setSize(float size) { m_size = size; }
239 bool syntheticBold() const { return m_syntheticBold; }
240 bool syntheticOblique() const { return m_syntheticOblique; }
241 bool isColorBitmapFont() const { return m_isColorBitmapFont; }
242 FontOrientation orientation() const { return m_orientation; }
243 TextOrientation textOrientation() const { return m_textOrientation; }
244 FontWidthVariant widthVariant() const { return m_widthVariant; }
246 void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
249 cairo_scaled_font_t* scaledFont() const { return m_scaledFont; }
252 unsigned hash() const
254 #if PLATFORM(WIN) && !USE(CAIRO)
255 return m_font ? m_font->hash() : 0;
257 #if USE(CG) || USE(SKIA_ON_MAC_CHROME)
258 ASSERT(m_font || !m_cgFont);
260 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, m_textOrientation << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique };
261 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
263 return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont);
267 const FontPlatformData& operator=(const FontPlatformData&);
269 bool operator==(const FontPlatformData& other) const
271 return platformIsEqual(other)
272 && m_size == other.m_size
273 && m_syntheticBold == other.m_syntheticBold
274 && m_syntheticOblique == other.m_syntheticOblique
275 && m_isColorBitmapFont == other.m_isColorBitmapFont
276 && m_orientation == other.m_orientation
277 && m_textOrientation == other.m_textOrientation
278 && m_widthVariant == other.m_widthVariant;
281 bool isHashTableDeletedValue() const
283 #if PLATFORM(WIN) && !USE(CAIRO)
284 return m_font.isHashTableDeletedValue();
286 return m_font == hashTableDeletedFontValue();
288 return m_scaledFont == hashTableDeletedFontValue();
294 String description() const;
298 bool platformIsEqual(const FontPlatformData&) const;
299 void platformDataInit(const FontPlatformData&);
300 const FontPlatformData& platformDataAssign(const FontPlatformData&);
302 // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters:
303 // Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same
304 // font as |nsFont|. This because the sandbox may block loading of the original font.
305 // * outNSFont - The font that was actually loaded, for the Chromium port this may be different than nsFont.
306 // The caller is responsible for calling CFRelease() on this parameter when done with it.
307 // * cgFont - CGFontRef representing the input font at the specified point size.
308 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&);
309 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont *>(-1); }
311 void platformDataInit(HFONT, float size, HDC, WCHAR* faceName);
315 static cairo_scaled_font_t* hashTableDeletedFontValue() { return reinterpret_cast<cairo_scaled_font_t*>(-1); }
319 bool m_syntheticBold;
320 bool m_syntheticOblique;
321 FontOrientation m_orientation;
322 TextOrientation m_textOrientation;
324 FontWidthVariant m_widthVariant;
330 RefPtr<RefCountedGDIHandle<HFONT> > m_font;
333 #if USE(CG) || USE(SKIA_ON_MAC_CHROME)
335 RetainPtr<CGFontRef> m_cgFont;
337 #ifndef BUILDING_ON_TIGER
338 RetainPtr<CGFontRef> m_cgFont;
340 CGFontRef m_cgFont; // It is not necessary to refcount this, since either an NSFont owns it or some CachedFont has it referenced.
342 mutable RetainPtr<CTFontRef> m_CTFont;
347 cairo_scaled_font_t* m_scaledFont;
350 #if PLATFORM(CHROMIUM) && OS(DARWIN)
351 RefPtr<MemoryActivatedFont> m_inMemoryFont;
354 bool m_isColorBitmapFont;
361 } // namespace WebCore
363 #endif // FontPlatformData_h