~ubuntu-branches/ubuntu/karmic/webkit/karmic-proposed

« back to all changes in this revision

Viewing changes to WebCore/platform/graphics/GlyphPageTreeNode.h

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-05-15 18:30:58 UTC
  • mto: (4.4.1 sid) (1.2.2 upstream) (16.1.1 lucid)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20090515183058-35m5or0ufm5tutud
Tags: upstream-1.1.7
ImportĀ upstreamĀ versionĀ 1.1.7

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>
45
46
// Holds the glyph index and the corresponding SimpleFontData information for a given
46
47
// character.
47
48
struct GlyphData {
 
49
    GlyphData(Glyph g = 0, const SimpleFontData* f = 0)
 
50
        : glyph(g)
 
51
        , fontData(f)
 
52
    {
 
53
    }
48
54
    Glyph glyph;
49
55
    const SimpleFontData* fontData;
50
56
};
54
60
// starting from 0 and incrementing for each 256 glyphs.
55
61
//
56
62
// 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,
 
63
// missing in the primary font. It is owned by exactly one GlyphPageTreeNode,
58
64
// although multiple nodes may reference it as their "page" if they are supposed
59
65
// to be overriding the parent's node, but provide no additional information.
60
 
struct GlyphPage : public RefCounted<GlyphPage> {
 
66
class GlyphPage : public RefCounted<GlyphPage> {
 
67
public:
61
68
    static PassRefPtr<GlyphPage> create(GlyphPageTreeNode* owner)
62
69
    {
63
70
        return adoptRef(new GlyphPage(owner));
64
71
    }
65
72
 
66
73
    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]; }
 
74
 
 
75
    unsigned indexForCharacter(UChar32 c) const { return c % size; }
 
76
    GlyphData glyphDataForCharacter(UChar32 c) const
 
77
    {
 
78
        unsigned index = indexForCharacter(c);
 
79
        return GlyphData(m_glyphs[index], m_glyphFontData[index]);
 
80
    }
 
81
 
 
82
    GlyphData glyphDataForIndex(unsigned index) const
 
83
    {
 
84
        ASSERT(index < size);
 
85
        return GlyphData(m_glyphs[index], m_glyphFontData[index]);
 
86
    }
 
87
 
 
88
    Glyph glyphAt(unsigned index) const
 
89
    {
 
90
        ASSERT(index < size);
 
91
        return m_glyphs[index];
 
92
    }
 
93
 
 
94
    const SimpleFontData* fontDataForCharacter(UChar32 c) const
 
95
    {
 
96
        return m_glyphFontData[indexForCharacter(c)];
 
97
    }
 
98
 
71
99
    void setGlyphDataForCharacter(UChar32 c, Glyph g, const SimpleFontData* f)
72
100
    {
73
 
        setGlyphDataForIndex(c % size, g, f);
 
101
        setGlyphDataForIndex(indexForCharacter(c), g, f);
74
102
    }
75
103
    void setGlyphDataForIndex(unsigned index, Glyph g, const SimpleFontData* f)
76
104
    {
77
105
        ASSERT(index < size);
78
 
        m_glyphs[index].glyph = g;
79
 
        m_glyphs[index].fontData = f;
80
 
    }
 
106
        m_glyphs[index] = g;
 
107
        m_glyphFontData[index] = f;
 
108
    }
 
109
    void setGlyphDataForIndex(unsigned index, const GlyphData& glyphData)
 
110
    {
 
111
        setGlyphDataForIndex(index, glyphData.glyph, glyphData.fontData);
 
112
    }
 
113
    
 
114
    void copyFrom(const GlyphPage& other)
 
115
    {
 
116
        memcpy(m_glyphs, other.m_glyphs, sizeof(m_glyphs));
 
117
        memcpy(m_glyphFontData, other.m_glyphFontData, sizeof(m_glyphFontData));
 
118
    }
 
119
 
 
120
    void clear()
 
121
    {
 
122
        memset(m_glyphs, 0, sizeof(m_glyphs));
 
123
        memset(m_glyphFontData, 0, sizeof(m_glyphFontData));
 
124
    }
 
125
    
81
126
    GlyphPageTreeNode* owner() const { return m_owner; }
82
127
 
83
128
    // Implemented by the platform.
88
133
        : m_owner(owner)
89
134
    {
90
135
    }
 
136
 
 
137
    // Separate arrays, rather than array of GlyphData, to save space.
 
138
    Glyph m_glyphs[size];
 
139
    const SimpleFontData* m_glyphFontData[size];
 
140
 
 
141
    GlyphPageTreeNode* m_owner;
91
142
};
92
143
 
93
144
// The glyph page tree is a data structure that maps (FontData, glyph page number)