2 * Copyright (C) 2006, 2007, 2008, 2010, 2013 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(BLACKBERRY)
27 #include "harfbuzz/FontPlatformDataHarfBuzz.h"
29 #include "qt/FontPlatformData.h"
31 #include "wince/FontPlatformData.h"
32 #elif PLATFORM(EFL) || PLATFORM(GTK) || PLATFORM(NIX)
33 #include "freetype/FontPlatformData.h"
36 #ifndef FontPlatformData_h
37 #define FontPlatformData_h
39 #include "FontOrientation.h"
40 #include "FontWidthVariant.h"
43 #include "RefCountedGDIHandle.h"
47 #include <wtf/HashFunctions.h>
54 typedef struct CGFont* CGFontRef;
55 typedef const struct __CTFont* CTFontRef;
58 #include <wtf/Forward.h>
59 #include <wtf/PassRefPtr.h>
60 #include <wtf/RefCounted.h>
61 #include <wtf/RetainPtr.h>
62 #include <wtf/text/StringImpl.h>
65 #include <wtf/win/GDIObject.h>
66 typedef struct HFONT__* HFONT;
70 typedef struct CGFont* CGFontRef;
72 typedef const struct __CTFont* CTFontRef;
73 typedef UInt32 FMFont;
74 typedef FMFont ATSUFontID;
75 typedef UInt32 ATSFontRef;
81 class FontDescription;
85 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
88 class FontPlatformData {
90 FontPlatformData(WTF::HashTableDeletedValueType);
92 FontPlatformData(const FontPlatformData&);
93 FontPlatformData(const FontDescription&, const AtomicString& family);
94 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
97 FontPlatformData(NSFont*, float size, bool isPrinterFont = false, bool syntheticBold = false, bool syntheticOblique = false,
98 FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
100 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant);
104 FontPlatformData(HFONT, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
106 FontPlatformData(HFONT, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
108 FontPlatformData(HFONT, cairo_font_face_t*, float size, bool bold, bool italic);
115 HFONT hfont() const { return m_font ? m_font->handle() : 0; }
116 bool useGDI() const { return m_useGDI; }
118 NSFont* font() const { return m_font; }
119 void setFont(NSFont*);
124 CGFontRef cgFont() const { return m_cgFont.get(); }
125 CTFontRef ctFont() const;
127 bool roundsGlyphAdvances() const;
128 bool allowsLigatures() const;
130 CGFontRef cgFont() const { return m_cgFont.get(); }
134 bool isFixedPitch() const;
135 float size() const { return m_size; }
136 void setSize(float size) { m_size = size; }
137 bool syntheticBold() const { return m_syntheticBold; }
138 bool syntheticOblique() const { return m_syntheticOblique; }
139 bool isColorBitmapFont() const { return m_isColorBitmapFont; }
140 bool isCompositeFontReference() const { return m_isCompositeFontReference; }
142 bool isPrinterFont() const { return m_isPrinterFont; }
144 FontOrientation orientation() const { return m_orientation; }
145 FontWidthVariant widthVariant() const { return m_widthVariant; }
147 void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
150 cairo_scaled_font_t* scaledFont() const { return m_scaledFont; }
153 unsigned hash() const
155 #if PLATFORM(WIN) && !USE(CAIRO)
156 return m_font ? m_font->hash() : 0;
159 ASSERT(m_font || !m_cgFont);
161 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cast<uintptr_t>(m_isPrinterFont << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique) };
162 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
164 return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont);
168 const FontPlatformData& operator=(const FontPlatformData&);
170 bool operator==(const FontPlatformData& other) const
172 return platformIsEqual(other)
173 && m_size == other.m_size
174 && m_syntheticBold == other.m_syntheticBold
175 && m_syntheticOblique == other.m_syntheticOblique
176 && m_isColorBitmapFont == other.m_isColorBitmapFont
177 && m_isCompositeFontReference == other.m_isCompositeFontReference
179 && m_isPrinterFont == other.m_isPrinterFont
181 && m_orientation == other.m_orientation
182 && m_widthVariant == other.m_widthVariant;
185 bool isHashTableDeletedValue() const
187 #if PLATFORM(WIN) && !USE(CAIRO)
188 return m_font.isHashTableDeletedValue();
190 return m_font == hashTableDeletedFontValue();
192 return m_scaledFont == hashTableDeletedFontValue();
196 #if PLATFORM(WIN) && (USE(CG) || USE(CAIRO))
197 PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
201 String description() const;
205 bool platformIsEqual(const FontPlatformData&) const;
206 void platformDataInit(const FontPlatformData&);
207 const FontPlatformData& platformDataAssign(const FontPlatformData&);
209 // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters:
210 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&);
211 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont *>(-1); }
213 void platformDataInit(HFONT, float size, HDC, WCHAR* faceName);
217 static cairo_scaled_font_t* hashTableDeletedFontValue() { return reinterpret_cast<cairo_scaled_font_t*>(-1); }
221 bool m_syntheticBold;
222 bool m_syntheticOblique;
223 FontOrientation m_orientation;
225 FontWidthVariant m_widthVariant;
231 RefPtr<RefCountedGDIHandle<HFONT> > m_font;
236 RetainPtr<CGFontRef> m_cgFont;
238 RetainPtr<CGFontRef> m_cgFont;
239 mutable RetainPtr<CTFontRef> m_CTFont;
244 cairo_scaled_font_t* m_scaledFont;
247 bool m_isColorBitmapFont;
248 bool m_isCompositeFontReference;
250 bool m_isPrinterFont;
258 } // namespace WebCore
260 #endif // FontPlatformData_h