2 * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef FontPlatformData_h
32 #define FontPlatformData_h
35 #include "platform/PlatformExport.h"
36 #include "platform/SharedBuffer.h"
37 #include "platform/fonts/FontDescription.h"
38 #include "platform/fonts/FontOrientation.h"
39 #include "platform/fonts/FontRenderStyle.h"
40 #include "platform/fonts/opentype/OpenTypeVerticalData.h"
41 #include "wtf/Forward.h"
42 #include "wtf/HashTableDeletedValueType.h"
43 #include "wtf/RefPtr.h"
44 #include "wtf/text/CString.h"
45 #include "wtf/text/StringImpl.h"
50 typedef struct CGFont* CGFontRef;
51 typedef const struct __CTFont* CTFontRef;
53 #include "platform/fonts/mac/MemoryActivatedFont.h"
54 #include <CoreFoundation/CFBase.h>
55 #include <objc/objc-auto.h>
57 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
61 typedef uint32_t SkFontID;
65 class GraphicsContext;
68 class PLATFORM_EXPORT FontPlatformData {
70 // Used for deleted values in the font cache's hash tables. The hash table
71 // will create us with this structure, and it will compare other values
72 // to this "Deleted" one. It expects the Deleted one to be differentiable
73 // from the 0 one (created with the empty constructor), so we can't just
74 // set everything to 0.
75 FontPlatformData(WTF::HashTableDeletedValueType);
77 FontPlatformData(const FontPlatformData&);
78 FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
80 FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool syntheticItalic = false,
81 FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
82 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant);
84 FontPlatformData(PassRefPtr<SkTypeface>, const char* name, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, bool subpixelTextPosition = defaultUseSubpixelPositioning());
85 FontPlatformData(const FontPlatformData& src, float textSize);
90 NSFont* font() const { return m_font; }
91 void setFont(NSFont*);
93 CGFontRef cgFont() const { return m_cgFont.get(); }
94 CTFontRef ctFont() const;
96 bool roundsGlyphAdvances() const;
97 bool allowsLigatures() const;
99 bool isColorBitmapFont() const { return m_isColorBitmapFont; }
100 bool isCompositeFontReference() const { return m_isCompositeFontReference; }
102 FontWidthVariant widthVariant() const { return m_widthVariant; }
105 String fontFamilyName() const;
106 float size() const { return m_textSize; }
107 bool isFixedPitch() const;
108 bool syntheticBold() const { return m_syntheticBold; }
109 bool syntheticItalic() const { return m_syntheticItalic; }
111 SkTypeface* typeface() const;
112 HarfBuzzFace* harfBuzzFace() const;
113 SkFontID uniqueID() const;
114 unsigned hash() const;
116 FontOrientation orientation() const { return m_orientation; }
117 void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
118 void setSyntheticBold(bool syntheticBold) { m_syntheticBold = syntheticBold; }
119 void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheticItalic; }
120 bool operator==(const FontPlatformData&) const;
121 const FontPlatformData& operator=(const FontPlatformData&);
123 bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; }
125 void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; }
126 unsigned minSizeForAntiAlias() const { return m_minSizeForAntiAlias; }
127 void setMinSizeForSubpixel(float size) { m_minSizeForSubpixel = size; }
128 float minSizeForSubpixel() const { return m_minSizeForSubpixel; }
129 void setHinting(SkPaint::Hinting style)
131 m_style.useAutoHint = 0;
132 m_style.hintStyle = style;
135 bool fontContainsCharacter(UChar32 character);
137 #if ENABLE(OPENTYPE_VERTICAL)
138 PassRefPtr<OpenTypeVerticalData> verticalData() const;
139 PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
143 // The returned styles are all actual styles without FontRenderStyle::NoPreference.
144 const FontRenderStyle& fontRenderStyle() const { return m_style; }
145 void setupPaint(SkPaint*, GraphicsContext* = 0) const;
149 int paintTextFlags() const { return m_paintTextFlags; }
151 static void setHinting(SkPaint::Hinting);
152 static void setAutoHint(bool);
153 static void setUseBitmaps(bool);
154 static void setAntiAlias(bool);
155 static void setSubpixelRendering(bool);
160 bool static defaultUseSubpixelPositioning();
161 void querySystemForRenderStyle(bool useSkiaSubpixelPositioning);
163 // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters:
164 // Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same
165 // font as |nsFont|. This because the sandbox may block loading of the original font.
166 // * outNSFont - The font that was actually loaded, for the Chromium port this may be different than nsFont.
167 // The caller is responsible for calling CFRelease() on this parameter when done with it.
168 // * cgFont - CGFontRef representing the input font at the specified point size.
169 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&);
170 void platformDataInit(const FontPlatformData&);
171 const FontPlatformData& platformDataAssign(const FontPlatformData&);
172 bool isAATFont(CTFontRef) const;
175 mutable RefPtr<SkTypeface> m_typeface;
182 bool m_syntheticBold;
183 bool m_syntheticItalic;
184 FontOrientation m_orientation;
186 bool m_isColorBitmapFont;
187 bool m_isCompositeFontReference;
189 FontWidthVariant m_widthVariant;
193 RetainPtr<CGFontRef> m_cgFont;
194 mutable RetainPtr<CTFontRef> m_CTFont;
195 RefPtr<MemoryActivatedFont> m_inMemoryFont;
197 FontRenderStyle m_style;
200 mutable RefPtr<HarfBuzzFace> m_harfBuzzFace;
201 bool m_isHashTableDeletedValue;
203 int m_paintTextFlags;
204 bool m_useSubpixelPositioning;
205 unsigned m_minSizeForAntiAlias;
206 float m_minSizeForSubpixel;
212 #endif // ifdef FontPlatformData_h