54
65
// starting from 0 and incrementing for each 256 glyphs.
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> {
61
73
static PassRefPtr<GlyphPage> create(GlyphPageTreeNode* owner)
63
75
return adoptRef(new GlyphPage(owner));
66
78
static const size_t size = 256; // Covers Latin-1 in a single page.
67
GlyphData m_glyphs[size];
68
GlyphPageTreeNode* m_owner;
70
const GlyphData& glyphDataForCharacter(UChar32 c) const { return m_glyphs[c % size]; }
80
unsigned indexForCharacter(UChar32 c) const { return c % size; }
81
GlyphData glyphDataForCharacter(UChar32 c) const
83
unsigned index = indexForCharacter(c);
84
return GlyphData(m_glyphs[index], m_glyphFontData[index]);
87
GlyphData glyphDataForIndex(unsigned index) const
90
return GlyphData(m_glyphs[index], m_glyphFontData[index]);
93
Glyph glyphAt(unsigned index) const
96
return m_glyphs[index];
99
const SimpleFontData* fontDataForCharacter(UChar32 c) const
101
return m_glyphFontData[indexForCharacter(c)];
71
104
void setGlyphDataForCharacter(UChar32 c, Glyph g, const SimpleFontData* f)
73
setGlyphDataForIndex(c % size, g, f);
106
setGlyphDataForIndex(indexForCharacter(c), g, f);
75
108
void setGlyphDataForIndex(unsigned index, Glyph g, const SimpleFontData* f)
77
110
ASSERT(index < size);
78
m_glyphs[index].glyph = g;
79
m_glyphs[index].fontData = f;
112
m_glyphFontData[index] = f;
114
void setGlyphDataForIndex(unsigned index, const GlyphData& glyphData)
116
setGlyphDataForIndex(index, glyphData.glyph, glyphData.fontData);
119
void copyFrom(const GlyphPage& other)
121
memcpy(m_glyphs, other.m_glyphs, sizeof(m_glyphs));
122
memcpy(m_glyphFontData, other.m_glyphFontData, sizeof(m_glyphFontData));
127
memset(m_glyphs, 0, sizeof(m_glyphs));
128
memset(m_glyphFontData, 0, sizeof(m_glyphFontData));
81
131
GlyphPageTreeNode* owner() const { return m_owner; }
83
133
// Implemented by the platform.