54
60
// starting from 0 and incrementing for each 256 glyphs.
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> {
61
68
static PassRefPtr<GlyphPage> create(GlyphPageTreeNode* owner)
63
70
return adoptRef(new GlyphPage(owner));
66
73
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]; }
75
unsigned indexForCharacter(UChar32 c) const { return c % size; }
76
GlyphData glyphDataForCharacter(UChar32 c) const
78
unsigned index = indexForCharacter(c);
79
return GlyphData(m_glyphs[index], m_glyphFontData[index]);
82
GlyphData glyphDataForIndex(unsigned index) const
85
return GlyphData(m_glyphs[index], m_glyphFontData[index]);
88
Glyph glyphAt(unsigned index) const
91
return m_glyphs[index];
94
const SimpleFontData* fontDataForCharacter(UChar32 c) const
96
return m_glyphFontData[indexForCharacter(c)];
71
99
void setGlyphDataForCharacter(UChar32 c, Glyph g, const SimpleFontData* f)
73
setGlyphDataForIndex(c % size, g, f);
101
setGlyphDataForIndex(indexForCharacter(c), g, f);
75
103
void setGlyphDataForIndex(unsigned index, Glyph g, const SimpleFontData* f)
77
105
ASSERT(index < size);
78
m_glyphs[index].glyph = g;
79
m_glyphs[index].fontData = f;
107
m_glyphFontData[index] = f;
109
void setGlyphDataForIndex(unsigned index, const GlyphData& glyphData)
111
setGlyphDataForIndex(index, glyphData.glyph, glyphData.fontData);
114
void copyFrom(const GlyphPage& other)
116
memcpy(m_glyphs, other.m_glyphs, sizeof(m_glyphs));
117
memcpy(m_glyphFontData, other.m_glyphFontData, sizeof(m_glyphFontData));
122
memset(m_glyphs, 0, sizeof(m_glyphs));
123
memset(m_glyphFontData, 0, sizeof(m_glyphFontData));
81
126
GlyphPageTreeNode* owner() const { return m_owner; }
83
128
// Implemented by the platform.