• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FontPlatformDataLinux_h
32 #define FontPlatformDataLinux_h
33 
34 #include "FontOrientation.h"
35 #include "FontRenderStyle.h"
36 #include "TextOrientation.h"
37 #include <wtf/Forward.h>
38 #include <wtf/RefPtr.h>
39 #include <wtf/text/CString.h>
40 #include <wtf/text/StringImpl.h>
41 #include <SkPaint.h>
42 
43 class SkTypeface;
44 typedef uint32_t SkFontID;
45 
46 struct HB_FaceRec_;
47 
48 namespace WebCore {
49 
50 class FontDescription;
51 
52 // -----------------------------------------------------------------------------
53 // FontPlatformData is the handle which WebKit has on a specific face. A face
54 // is the tuple of (font, size, ...etc). Here we are just wrapping a Skia
55 // SkTypeface pointer and dealing with the reference counting etc.
56 // -----------------------------------------------------------------------------
57 class FontPlatformData {
58 public:
59     // Used for deleted values in the font cache's hash tables. The hash table
60     // will create us with this structure, and it will compare other values
61     // to this "Deleted" one. It expects the Deleted one to be differentiable
62     // from the NULL one (created with the empty constructor), so we can't just
63     // set everything to NULL.
FontPlatformData(WTF::HashTableDeletedValueType)64     FontPlatformData(WTF::HashTableDeletedValueType)
65         : m_typeface(hashTableDeletedFontValue())
66         , m_textSize(0)
67         , m_emSizeInFontUnits(0)
68         , m_fakeBold(false)
69         , m_fakeItalic(false)
70         , m_orientation(Horizontal)
71         , m_textOrientation(TextOrientationVerticalRight)
72         { }
73 
FontPlatformData()74     FontPlatformData()
75         : m_typeface(0)
76         , m_textSize(0)
77         , m_emSizeInFontUnits(0)
78         , m_fakeBold(false)
79         , m_fakeItalic(false)
80         , m_orientation(Horizontal)
81         , m_textOrientation(TextOrientationVerticalRight)
82         { }
83 
FontPlatformData(float textSize,bool fakeBold,bool fakeItalic)84     FontPlatformData(float textSize, bool fakeBold, bool fakeItalic)
85         : m_typeface(0)
86         , m_textSize(textSize)
87         , m_emSizeInFontUnits(0)
88         , m_fakeBold(fakeBold)
89         , m_fakeItalic(fakeItalic)
90         , m_orientation(Horizontal)
91         , m_textOrientation(TextOrientationVerticalRight)
92         { }
93 
94     FontPlatformData(const FontPlatformData&);
95     FontPlatformData(SkTypeface*, const char* name, float textSize, bool fakeBold, bool fakeItalic, FontOrientation = Horizontal, TextOrientation = TextOrientationVerticalRight);
96     FontPlatformData(const FontPlatformData& src, float textSize);
97     ~FontPlatformData();
98 
99     // -------------------------------------------------------------------------
100     // Return true iff this font is monospaced (i.e. every glyph has an equal x
101     // advance)
102     // -------------------------------------------------------------------------
103     bool isFixedPitch() const;
104 
105     // -------------------------------------------------------------------------
106     // Setup a Skia painting context to use this font.
107     // -------------------------------------------------------------------------
108     void setupPaint(SkPaint*) const;
109 
110     // -------------------------------------------------------------------------
111     // Return Skia's unique id for this font. This encodes both the style and
112     // the font's file name so refers to a single face.
113     // -------------------------------------------------------------------------
114     SkFontID uniqueID() const;
115 
116     unsigned hash() const;
size()117     float size() const { return m_textSize; }
118     int emSizeInFontUnits() const;
119 
orientation()120     FontOrientation orientation() const { return m_orientation; }
setOrientation(FontOrientation orientation)121     void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
122 
123     bool operator==(const FontPlatformData&) const;
124     FontPlatformData& operator=(const FontPlatformData&);
isHashTableDeletedValue()125     bool isHashTableDeletedValue() const { return m_typeface == hashTableDeletedFontValue(); }
126 
127 #ifndef NDEBUG
128     String description() const;
129 #endif
130 
131     HB_FaceRec_* harfbuzzFace() const;
132 
133     // -------------------------------------------------------------------------
134     // Global font preferences...
135 
136     static void setHinting(SkPaint::Hinting);
137     static void setAntiAlias(bool on);
138     static void setSubpixelGlyphs(bool on);
139 
140 private:
141     class RefCountedHarfbuzzFace : public RefCounted<RefCountedHarfbuzzFace> {
142     public:
create(HB_FaceRec_ * harfbuzzFace)143         static PassRefPtr<RefCountedHarfbuzzFace> create(HB_FaceRec_* harfbuzzFace)
144         {
145             return adoptRef(new RefCountedHarfbuzzFace(harfbuzzFace));
146         }
147 
148         ~RefCountedHarfbuzzFace();
149 
face()150         HB_FaceRec_* face() const { return m_harfbuzzFace; }
151 
152     private:
RefCountedHarfbuzzFace(HB_FaceRec_ * harfbuzzFace)153         RefCountedHarfbuzzFace(HB_FaceRec_* harfbuzzFace) : m_harfbuzzFace(harfbuzzFace)
154         {
155         }
156 
157         HB_FaceRec_* m_harfbuzzFace;
158     };
159 
160     void querySystemForRenderStyle();
161 
162     // FIXME: Could SkAutoUnref be used here?
163     SkTypeface* m_typeface;
164     CString m_family;
165     float m_textSize;
166     mutable int m_emSizeInFontUnits;
167     bool m_fakeBold;
168     bool m_fakeItalic;
169     FontOrientation m_orientation;
170     TextOrientation m_textOrientation;
171     FontRenderStyle m_style;
172     mutable RefPtr<RefCountedHarfbuzzFace> m_harfbuzzFace;
173 
hashTableDeletedFontValue()174     SkTypeface* hashTableDeletedFontValue() const { return reinterpret_cast<SkTypeface*>(-1); }
175 };
176 
177 }  // namespace WebCore
178 
179 #endif  // ifdef FontPlatformData_h
180