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