1 /*
2  * Copyright (C) 2006, 2007, 2008 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 Igalia S.L.
7  * All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public License
20  * along with this library; see the file COPYING.LIB.  If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  *
24  */
25 
26 #ifndef FontPlatformDataFreeType_h
27 #define FontPlatformDataFreeType_h
28 
29 #include "FontDescription.h"
30 #include "FontOrientation.h"
31 #include "GlyphBuffer.h"
32 #include "HashFunctions.h"
33 #include "RefPtrCairo.h"
34 #include <wtf/Forward.h>
35 
36 typedef struct _FcFontSet FcFontSet;
37 
38 namespace WebCore {
39 
40 class FontPlatformData {
41 public:
FontPlatformData(WTF::HashTableDeletedValueType)42     FontPlatformData(WTF::HashTableDeletedValueType)
43         : m_fallbacks(0)
44         , m_size(0)
45         , m_syntheticBold(false)
46         , m_syntheticOblique(false)
47         , m_scaledFont(hashTableDeletedFontValue())
48         { }
49 
FontPlatformData()50     FontPlatformData()
51         : m_fallbacks(0)
52         , m_size(0)
53         , m_syntheticBold(false)
54         , m_syntheticOblique(false)
55         , m_scaledFont(0)
56         { }
57 
58     FontPlatformData(FcPattern*, const FontDescription&);
59     FontPlatformData(cairo_font_face_t* fontFace, float size, bool bold, bool italic);
60     FontPlatformData(float size, bool bold, bool italic);
61     FontPlatformData(const FontPlatformData&);
62     FontPlatformData(const FontPlatformData&, float size);
63 
64     ~FontPlatformData();
65 
66     bool isFixedPitch();
size()67     float size() const { return m_size; }
setSize(float size)68     void setSize(float size) { m_size = size; }
syntheticBold()69     bool syntheticBold() const { return m_syntheticBold; }
syntheticOblique()70     bool syntheticOblique() const { return m_syntheticOblique; }
71     bool hasCompatibleCharmap();
72 
orientation()73     FontOrientation orientation() const { return Horizontal; } // FIXME: Implement.
setOrientation(FontOrientation)74     void setOrientation(FontOrientation) { } // FIXME: Implement.
75 
scaledFont()76     cairo_scaled_font_t* scaledFont() const { return m_scaledFont; }
77 
hash()78     unsigned hash() const
79     {
80         return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont);
81     }
82 
83     bool operator==(const FontPlatformData&) const;
84     FontPlatformData& operator=(const FontPlatformData&);
isHashTableDeletedValue()85     bool isHashTableDeletedValue() const
86     {
87         return m_scaledFont == hashTableDeletedFontValue();
88     }
89 
90 #ifndef NDEBUG
91     String description() const;
92 #endif
93 
94     RefPtr<FcPattern> m_pattern;
95     mutable FcFontSet* m_fallbacks; // Initialized lazily.
96     float m_size;
97     bool m_syntheticBold;
98     bool m_syntheticOblique;
99     bool m_fixedWidth;
100     cairo_scaled_font_t* m_scaledFont;
101 
102 private:
103     void initializeWithFontFace(cairo_font_face_t*);
hashTableDeletedFontValue()104     static cairo_scaled_font_t* hashTableDeletedFontValue() { return reinterpret_cast<cairo_scaled_font_t*>(-1); }
105 };
106 
107 }
108 
109 #endif // FontPlatformDataFreeType_h
110