~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/WebCore/platform/graphics/GlyphPageTreeNode.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#ifndef GlyphPageTreeNode_h
30
30
#define GlyphPageTreeNode_h
31
31
 
 
32
#include <string.h>
32
33
#include <wtf/HashMap.h>
33
34
#include <wtf/PassRefPtr.h>
34
35
#include <wtf/RefCounted.h>
35
36
#include <wtf/unicode/Unicode.h>
36
37
 
 
38
#ifndef NDEBUG
 
39
void showGlyphPageTrees();
 
40
void showGlyphPageTree(unsigned pageNumber);
 
41
#endif
 
42
 
37
43
namespace WebCore {
38
44
 
39
45
class FontData;
45
51
// Holds the glyph index and the corresponding SimpleFontData information for a given
46
52
// character.
47
53
struct GlyphData {
 
54
    GlyphData(Glyph g = 0, const SimpleFontData* f = 0)
 
55
        : glyph(g)
 
56
        , fontData(f)
 
57
    {
 
58
    }
48
59
    Glyph glyph;
49
60
    const SimpleFontData* fontData;
50
61
};
54
65
// starting from 0 and incrementing for each 256 glyphs.
55
66
//
56
67
// One page may actually include glyphs from other fonts if the characters are
57
 
// missing in the parimary font. It is owned by exactly one GlyphPageTreeNode,
 
68
// missing in the primary font. It is owned by exactly one GlyphPageTreeNode,
58
69
// although multiple nodes may reference it as their "page" if they are supposed
59
70
// to be overriding the parent's node, but provide no additional information.
60
 
struct GlyphPage : public RefCounted<GlyphPage> {
 
71
class GlyphPage : public RefCounted<GlyphPage> {
 
72
public:
61
73
    static PassRefPtr<GlyphPage> create(GlyphPageTreeNode* owner)
62
74
    {
63
75
        return adoptRef(new GlyphPage(owner));
64
76
    }
65
77
 
66
78
    static const size_t size = 256; // Covers Latin-1 in a single page.
67
 
    GlyphData m_glyphs[size];
68
 
    GlyphPageTreeNode* m_owner;
69
 
 
70
 
    const GlyphData& glyphDataForCharacter(UChar32 c) const { return m_glyphs[c % size]; }
 
79
 
 
80
    unsigned indexForCharacter(UChar32 c) const { return c % size; }
 
81
    GlyphData glyphDataForCharacter(UChar32 c) const
 
82
    {
 
83
        unsigned index = indexForCharacter(c);
 
84
        return GlyphData(m_glyphs[index], m_glyphFontData[index]);
 
85
    }
 
86
 
 
87
    GlyphData glyphDataForIndex(unsigned index) const
 
88
    {
 
89
        ASSERT(index < size);
 
90
        return GlyphData(m_glyphs[index], m_glyphFontData[index]);
 
91
    }
 
92
 
 
93
    Glyph glyphAt(unsigned index) const
 
94
    {
 
95
        ASSERT(index < size);
 
96
        return m_glyphs[index];
 
97
    }
 
98
 
 
99
    const SimpleFontData* fontDataForCharacter(UChar32 c) const
 
100
    {
 
101
        return m_glyphFontData[indexForCharacter(c)];
 
102
    }
 
103
 
71
104
    void setGlyphDataForCharacter(UChar32 c, Glyph g, const SimpleFontData* f)
72
105
    {
73
 
        setGlyphDataForIndex(c % size, g, f);
 
106
        setGlyphDataForIndex(indexForCharacter(c), g, f);
74
107
    }
75
108
    void setGlyphDataForIndex(unsigned index, Glyph g, const SimpleFontData* f)
76
109
    {
77
110
        ASSERT(index < size);
78
 
        m_glyphs[index].glyph = g;
79
 
        m_glyphs[index].fontData = f;
80
 
    }
 
111
        m_glyphs[index] = g;
 
112
        m_glyphFontData[index] = f;
 
113
    }
 
114
    void setGlyphDataForIndex(unsigned index, const GlyphData& glyphData)
 
115
    {
 
116
        setGlyphDataForIndex(index, glyphData.glyph, glyphData.fontData);
 
117
    }
 
118
    
 
119
    void copyFrom(const GlyphPage& other)
 
120
    {
 
121
        memcpy(m_glyphs, other.m_glyphs, sizeof(m_glyphs));
 
122
        memcpy(m_glyphFontData, other.m_glyphFontData, sizeof(m_glyphFontData));
 
123
    }
 
124
 
 
125
    void clear()
 
126
    {
 
127
        memset(m_glyphs, 0, sizeof(m_glyphs));
 
128
        memset(m_glyphFontData, 0, sizeof(m_glyphFontData));
 
129
    }
 
130
    
81
131
    GlyphPageTreeNode* owner() const { return m_owner; }
82
132
 
83
133
    // Implemented by the platform.
88
138
        : m_owner(owner)
89
139
    {
90
140
    }
 
141
 
 
142
    // Separate arrays, rather than array of GlyphData, to save space.
 
143
    Glyph m_glyphs[size];
 
144
    const SimpleFontData* m_glyphFontData[size];
 
145
 
 
146
    GlyphPageTreeNode* m_owner;
91
147
};
92
148
 
93
149
// The glyph page tree is a data structure that maps (FontData, glyph page number)
159
215
    static GlyphPageTreeNode* getRoot(unsigned pageNumber);
160
216
    void initializePage(const FontData*, unsigned pageNumber);
161
217
 
 
218
#ifndef NDEBUG
 
219
    void showSubtree();
 
220
#endif
 
221
 
162
222
    GlyphPageTreeNode* m_parent;
163
223
    RefPtr<GlyphPage> m_page;
164
224
    unsigned m_level;
169
229
 
170
230
#ifndef NDEBUG
171
231
    unsigned m_pageNumber;
 
232
 
 
233
    friend void ::showGlyphPageTree(unsigned pageNumber);
172
234
#endif
173
235
};
174
236