OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. |
3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com | 3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com |
4 * Copyright (C) 2007 Holger Hans Peter Freyther | 4 * Copyright (C) 2007 Holger Hans Peter Freyther |
5 * Copyright (C) 2007 Pioneer Research Center USA, Inc. | 5 * Copyright (C) 2007 Pioneer Research Center USA, Inc. |
6 * Copyright (C) 2010, 2011 Brent Fulgham <bfulgham@webkit.org> | 6 * Copyright (C) 2010, 2011 Brent Fulgham <bfulgham@webkit.org> |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #else | 29 #else |
30 | 30 |
31 #ifndef FontPlatformData_h | 31 #ifndef FontPlatformData_h |
32 #define FontPlatformData_h | 32 #define FontPlatformData_h |
33 | 33 |
34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
35 #include "platform/fonts/FontOrientation.h" | 35 #include "platform/fonts/FontOrientation.h" |
36 #include "platform/fonts/FontWidthVariant.h" | 36 #include "platform/fonts/FontWidthVariant.h" |
37 | 37 |
38 #if OS(MACOSX) | |
39 OBJC_CLASS NSFont; | 38 OBJC_CLASS NSFont; |
40 | 39 |
41 typedef struct CGFont* CGFontRef; | 40 typedef struct CGFont* CGFontRef; |
42 typedef const struct __CTFont* CTFontRef; | 41 typedef const struct __CTFont* CTFontRef; |
43 | 42 |
44 #include <CoreFoundation/CFBase.h> | 43 #include <CoreFoundation/CFBase.h> |
45 #include <objc/objc-auto.h> | 44 #include <objc/objc-auto.h> |
46 #endif | |
47 | 45 |
48 #include "wtf/Forward.h" | 46 #include "wtf/Forward.h" |
49 #include "wtf/HashTableDeletedValueType.h" | 47 #include "wtf/HashTableDeletedValueType.h" |
50 #include "wtf/PassRefPtr.h" | 48 #include "wtf/PassRefPtr.h" |
51 #include "wtf/RefCounted.h" | 49 #include "wtf/RefCounted.h" |
52 #include "wtf/RetainPtr.h" | 50 #include "wtf/RetainPtr.h" |
53 #include "wtf/text/StringImpl.h" | 51 #include "wtf/text/StringImpl.h" |
54 | 52 |
55 #if OS(MACOSX) | |
56 #include "platform/fonts/mac/MemoryActivatedFont.h" | 53 #include "platform/fonts/mac/MemoryActivatedFont.h" |
57 #include "third_party/skia/include/core/SkTypeface.h" | 54 #include "third_party/skia/include/core/SkTypeface.h" |
58 #endif | |
59 | 55 |
60 #if OS(MACOSX) | |
61 typedef struct CGFont* CGFontRef; | 56 typedef struct CGFont* CGFontRef; |
62 typedef const struct __CTFont* CTFontRef; | 57 typedef const struct __CTFont* CTFontRef; |
63 typedef UInt32 FMFont; | 58 typedef UInt32 FMFont; |
64 typedef FMFont ATSUFontID; | 59 typedef FMFont ATSUFontID; |
65 typedef UInt32 ATSFontRef; | 60 typedef UInt32 ATSFontRef; |
66 #endif | |
67 | 61 |
68 namespace blink { | 62 namespace blink { |
69 | 63 |
70 class FontDescription; | 64 class FontDescription; |
71 class SharedBuffer; | 65 class SharedBuffer; |
72 | 66 |
73 #if OS(MACOSX) | |
74 class HarfBuzzFace; | 67 class HarfBuzzFace; |
75 #endif | |
76 | 68 |
77 #if OS(MACOSX) | |
78 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef
>(nsFont); } | 69 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef
>(nsFont); } |
79 #endif | |
80 | 70 |
81 class PLATFORM_EXPORT FontPlatformData { | 71 class PLATFORM_EXPORT FontPlatformData { |
82 public: | 72 public: |
83 FontPlatformData(WTF::HashTableDeletedValueType); | 73 FontPlatformData(WTF::HashTableDeletedValueType); |
84 FontPlatformData(); | 74 FontPlatformData(); |
85 FontPlatformData(const FontPlatformData&); | 75 FontPlatformData(const FontPlatformData&); |
86 FontPlatformData(const FontDescription&, const AtomicString& family); | 76 FontPlatformData(const FontDescription&, const AtomicString& family); |
87 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, Font
Orientation = Horizontal, FontWidthVariant = RegularWidth); | 77 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, Font
Orientation = Horizontal, FontWidthVariant = RegularWidth); |
88 | |
89 #if OS(MACOSX) | |
90 FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool synth
eticOblique = false, | 78 FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool synth
eticOblique = false, |
91 FontOrientation = Horizontal, FontWidthVariant = RegularWid
th); | 79 FontOrientation = Horizontal, FontWidthVariant = RegularWid
th); |
92 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOb
lique, FontOrientation, FontWidthVariant); | 80 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOb
lique, FontOrientation, FontWidthVariant); |
93 #endif | |
94 | 81 |
95 ~FontPlatformData(); | 82 ~FontPlatformData(); |
96 | 83 |
97 #if OS(MACOSX) | |
98 NSFont* font() const { return m_font; } | 84 NSFont* font() const { return m_font; } |
99 void setFont(NSFont*); | 85 void setFont(NSFont*); |
100 #endif | |
101 | 86 |
102 #if OS(MACOSX) | |
103 CGFontRef cgFont() const { return m_cgFont.get(); } | 87 CGFontRef cgFont() const { return m_cgFont.get(); } |
104 CTFontRef ctFont() const; | 88 CTFontRef ctFont() const; |
105 SkTypeface* typeface() const; | 89 SkTypeface* typeface() const; |
106 | 90 |
107 bool roundsGlyphAdvances() const; | 91 bool roundsGlyphAdvances() const; |
108 bool allowsLigatures() const; | 92 bool allowsLigatures() const; |
109 #endif | |
110 | 93 |
111 String fontFamilyName() const; | 94 String fontFamilyName() const; |
112 bool isFixedPitch() const; | 95 bool isFixedPitch() const; |
113 float size() const { return m_size; } | 96 float size() const { return m_size; } |
114 void setSize(float size) { m_size = size; } | 97 void setSize(float size) { m_size = size; } |
115 bool syntheticBold() const { return m_syntheticBold; } | 98 bool syntheticBold() const { return m_syntheticBold; } |
116 bool syntheticOblique() const { return m_syntheticOblique; } | 99 bool syntheticOblique() const { return m_syntheticOblique; } |
117 bool isColorBitmapFont() const { return m_isColorBitmapFont; } | 100 bool isColorBitmapFont() const { return m_isColorBitmapFont; } |
118 bool isCompositeFontReference() const { return m_isCompositeFontReference; } | 101 bool isCompositeFontReference() const { return m_isCompositeFontReference; } |
119 | 102 |
120 FontOrientation orientation() const { return m_orientation; } | 103 FontOrientation orientation() const { return m_orientation; } |
121 FontWidthVariant widthVariant() const { return m_widthVariant; } | 104 FontWidthVariant widthVariant() const { return m_widthVariant; } |
122 | 105 |
123 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } | 106 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } |
124 | 107 |
125 #if OS(MACOSX) | |
126 HarfBuzzFace* harfBuzzFace(); | 108 HarfBuzzFace* harfBuzzFace(); |
127 #endif | |
128 | 109 |
129 unsigned hash() const | 110 unsigned hash() const |
130 { | 111 { |
131 #if OS(MACOSX) | |
132 ASSERT(m_font || !m_cgFont); | 112 ASSERT(m_font || !m_cgFont); |
133 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cas
t<uintptr_t>(m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique) }; | 113 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cas
t<uintptr_t>(m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique) }; |
134 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | 114 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); |
135 #endif | |
136 } | 115 } |
137 | 116 |
138 const FontPlatformData& operator=(const FontPlatformData&); | 117 const FontPlatformData& operator=(const FontPlatformData&); |
139 | 118 |
140 bool operator==(const FontPlatformData& other) const | 119 bool operator==(const FontPlatformData& other) const |
141 { | 120 { |
142 return platformIsEqual(other) | 121 return platformIsEqual(other) |
143 && m_size == other.m_size | 122 && m_size == other.m_size |
144 && m_syntheticBold == other.m_syntheticBold | 123 && m_syntheticBold == other.m_syntheticBold |
145 && m_syntheticOblique == other.m_syntheticOblique | 124 && m_syntheticOblique == other.m_syntheticOblique |
146 && m_isColorBitmapFont == other.m_isColorBitmapFont | 125 && m_isColorBitmapFont == other.m_isColorBitmapFont |
147 && m_isCompositeFontReference == other.m_isCompositeFontReference | 126 && m_isCompositeFontReference == other.m_isCompositeFontReference |
148 && m_orientation == other.m_orientation | 127 && m_orientation == other.m_orientation |
149 && m_widthVariant == other.m_widthVariant; | 128 && m_widthVariant == other.m_widthVariant; |
150 } | 129 } |
151 | 130 |
152 bool isHashTableDeletedValue() const | 131 bool isHashTableDeletedValue() const |
153 { | 132 { |
154 #if OS(MACOSX) | |
155 return m_font == hashTableDeletedFontValue(); | 133 return m_font == hashTableDeletedFontValue(); |
156 #endif | |
157 } | 134 } |
158 | 135 |
159 #ifndef NDEBUG | 136 #ifndef NDEBUG |
160 String description() const; | 137 String description() const; |
161 #endif | 138 #endif |
162 | 139 |
163 private: | 140 private: |
164 bool platformIsEqual(const FontPlatformData&) const; | 141 bool platformIsEqual(const FontPlatformData&) const; |
165 void platformDataInit(const FontPlatformData&); | 142 void platformDataInit(const FontPlatformData&); |
166 const FontPlatformData& platformDataAssign(const FontPlatformData&); | 143 const FontPlatformData& platformDataAssign(const FontPlatformData&); |
167 #if OS(MACOSX) | 144 #if OS(MACOSX) |
168 // Load various data about the font specified by |nsFont| with the size font
Size into the following output paramters: | 145 // Load various data about the font specified by |nsFont| with the size font
Size into the following output paramters: |
169 // Note: Callers should always take into account that for the Chromium port,
|outNSFont| isn't necessarily the same | 146 // Note: Callers should always take into account that for the Chromium port,
|outNSFont| isn't necessarily the same |
170 // font as |nsFont|. This because the sandbox may block loading of the origi
nal font. | 147 // font as |nsFont|. This because the sandbox may block loading of the origi
nal font. |
171 // * outNSFont - The font that was actually loaded, for the Chromium port th
is may be different than nsFont. | 148 // * outNSFont - The font that was actually loaded, for the Chromium port th
is may be different than nsFont. |
172 // The caller is responsible for calling CFRelease() on this parameter when
done with it. | 149 // The caller is responsible for calling CFRelease() on this parameter when
done with it. |
173 // * cgFont - CGFontRef representing the input font at the specified point s
ize. | 150 // * cgFont - CGFontRef representing the input font at the specified point s
ize. |
174 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); | 151 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); |
175 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont
*>(-1); } | 152 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont
*>(-1); } |
176 #endif | 153 #endif |
177 | 154 |
178 public: | 155 public: |
179 bool m_syntheticBold; | 156 bool m_syntheticBold; |
180 bool m_syntheticOblique; | 157 bool m_syntheticOblique; |
181 FontOrientation m_orientation; | 158 FontOrientation m_orientation; |
182 float m_size; | 159 float m_size; |
183 FontWidthVariant m_widthVariant; | 160 FontWidthVariant m_widthVariant; |
184 | 161 |
185 private: | 162 private: |
186 #if OS(MACOSX) | |
187 NSFont* m_font; | 163 NSFont* m_font; |
188 #endif | |
189 | |
190 #if OS(MACOSX) | |
191 RetainPtr<CGFontRef> m_cgFont; | 164 RetainPtr<CGFontRef> m_cgFont; |
192 mutable RetainPtr<CTFontRef> m_CTFont; | 165 mutable RetainPtr<CTFontRef> m_CTFont; |
193 | 166 |
194 RefPtr<MemoryActivatedFont> m_inMemoryFont; | 167 RefPtr<MemoryActivatedFont> m_inMemoryFont; |
195 RefPtr<HarfBuzzFace> m_harfBuzzFace; | 168 RefPtr<HarfBuzzFace> m_harfBuzzFace; |
196 mutable RefPtr<SkTypeface> m_typeface; | 169 mutable RefPtr<SkTypeface> m_typeface; |
197 #endif | |
198 | 170 |
199 bool m_isColorBitmapFont; | 171 bool m_isColorBitmapFont; |
200 bool m_isCompositeFontReference; | 172 bool m_isCompositeFontReference; |
201 }; | 173 }; |
202 | 174 |
203 } // namespace blink | 175 } // namespace blink |
204 | 176 |
205 #endif // FontPlatformData_h | 177 #endif // FontPlatformData_h |
206 | 178 |
207 #endif | 179 #endif |
OLD | NEW |