Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / fonts / FontPlatformData.h
1 /*
2  * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 #ifndef FontPlatformData_h
32 #define FontPlatformData_h
33
34 #include "SkPaint.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"
46
47 #if OS(MACOSX)
48 OBJC_CLASS NSFont;
49
50 typedef struct CGFont* CGFontRef;
51 typedef const struct __CTFont* CTFontRef;
52
53 #include "platform/fonts/mac/MemoryActivatedFont.h"
54 #include <CoreFoundation/CFBase.h>
55 #include <objc/objc-auto.h>
56
57 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
58 #endif // OS(MACOSX)
59
60 class SkTypeface;
61 typedef uint32_t SkFontID;
62
63 namespace blink {
64
65 class Font;
66 class GraphicsContext;
67 class HarfBuzzFace;
68
69 class PLATFORM_EXPORT FontPlatformData {
70 public:
71     // Used for deleted values in the font cache's hash tables. The hash table
72     // will create us with this structure, and it will compare other values
73     // to this "Deleted" one. It expects the Deleted one to be differentiable
74     // from the 0 one (created with the empty constructor), so we can't just
75     // set everything to 0.
76     FontPlatformData(WTF::HashTableDeletedValueType);
77     FontPlatformData();
78     FontPlatformData(const FontPlatformData&);
79     FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
80     FontPlatformData(const FontPlatformData& src, float textSize);
81 #if OS(MACOSX)
82     FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool syntheticItalic = false,
83                      FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
84     FontPlatformData(CGFontRef, PassRefPtr<SkTypeface>, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant);
85 #else
86     FontPlatformData(PassRefPtr<SkTypeface>, const char* name, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, bool subpixelTextPosition = defaultUseSubpixelPositioning());
87 #endif
88     ~FontPlatformData();
89
90 #if OS(MACOSX)
91     NSFont* font() const { return m_font; }
92     void setFont(NSFont*);
93
94     CGFontRef cgFont() const { return m_cgFont.get(); }
95     CTFontRef ctFont() const;
96
97     bool roundsGlyphAdvances() const;
98     bool allowsLigatures() const;
99
100     bool isColorBitmapFont() const { return m_isColorBitmapFont; }
101     bool isCompositeFontReference() const { return m_isCompositeFontReference; }
102
103     FontWidthVariant widthVariant() const { return m_widthVariant; }
104 #endif
105
106     String fontFamilyName() const;
107     float size() const { return m_textSize; }
108     bool isFixedPitch() const;
109     bool syntheticBold() const { return m_syntheticBold; }
110     bool syntheticItalic() const { return m_syntheticItalic; }
111
112     SkTypeface* typeface() const;
113     HarfBuzzFace* harfBuzzFace() const;
114     SkFontID uniqueID() const;
115     unsigned hash() const;
116
117     FontOrientation orientation() const { return m_orientation; }
118     void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
119     void setSyntheticBold(bool syntheticBold) { m_syntheticBold = syntheticBold; }
120     void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheticItalic; }
121     bool operator==(const FontPlatformData&) const;
122     const FontPlatformData& operator=(const FontPlatformData&);
123
124     bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; }
125 #if OS(WIN)
126     void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; }
127     unsigned minSizeForAntiAlias() const { return m_minSizeForAntiAlias; }
128     void setMinSizeForSubpixel(float size) { m_minSizeForSubpixel = size; }
129     float minSizeForSubpixel() const { return m_minSizeForSubpixel; }
130     void setHinting(SkPaint::Hinting style)
131     {
132         m_style.useAutoHint = 0;
133         m_style.hintStyle = style;
134     }
135 #endif
136     bool fontContainsCharacter(UChar32 character);
137
138 #if ENABLE(OPENTYPE_VERTICAL)
139     PassRefPtr<OpenTypeVerticalData> verticalData() const;
140     PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
141 #endif
142
143 #if !OS(MACOSX)
144     // The returned styles are all actual styles without FontRenderStyle::NoPreference.
145     const FontRenderStyle& fontRenderStyle() const { return m_style; }
146 #endif
147     void setupPaint(SkPaint*, GraphicsContext* = 0, const Font* = 0) const;
148
149 #if OS(WIN)
150     int paintTextFlags() const { return m_paintTextFlags; }
151 #else
152     static void setHinting(SkPaint::Hinting);
153     static void setAutoHint(bool);
154     static void setUseBitmaps(bool);
155     static void setAntiAlias(bool);
156     static void setSubpixelRendering(bool);
157 #endif
158
159 private:
160 #if !OS(MACOSX)
161     bool static defaultUseSubpixelPositioning();
162     void querySystemForRenderStyle(bool useSkiaSubpixelPositioning);
163 #else
164     // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters:
165     // Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same
166     // font as |nsFont|. This because the sandbox may block loading of the original font.
167     // * outNSFont - The font that was actually loaded, for the Chromium port this may be different than nsFont.
168     // The caller is responsible for calling CFRelease() on this parameter when done with it.
169     // * cgFont - CGFontRef representing the input font at the specified point size.
170     void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&);
171     void platformDataInit(const FontPlatformData&);
172     const FontPlatformData& platformDataAssign(const FontPlatformData&);
173     bool isAATFont(CTFontRef) const;
174 #endif
175
176     mutable RefPtr<SkTypeface> m_typeface;
177 #if !OS(WIN)
178     CString m_family;
179 #endif
180
181 public:
182     float m_textSize;
183     bool m_syntheticBold;
184     bool m_syntheticItalic;
185     FontOrientation m_orientation;
186 #if OS(MACOSX)
187     bool m_isColorBitmapFont;
188     bool m_isCompositeFontReference;
189 #endif
190     FontWidthVariant m_widthVariant;
191 private:
192 #if OS(MACOSX)
193     NSFont* m_font;
194     RetainPtr<CGFontRef> m_cgFont;
195     mutable RetainPtr<CTFontRef> m_CTFont;
196     RefPtr<MemoryActivatedFont> m_inMemoryFont;
197 #else
198     FontRenderStyle m_style;
199 #endif
200
201     mutable RefPtr<HarfBuzzFace> m_harfBuzzFace;
202     bool m_isHashTableDeletedValue;
203 #if OS(WIN)
204     int m_paintTextFlags;
205     bool m_useSubpixelPositioning;
206     unsigned m_minSizeForAntiAlias;
207     float m_minSizeForSubpixel;
208 #endif
209 };
210
211 } // namespace blink
212
213 #endif // ifdef FontPlatformData_h