]>
git.saurik.com Git - iphone-api.git/blob - WebCore/GlyphPageTreeNode.h
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef GlyphPageTreeNode_h
30 #define GlyphPageTreeNode_h
32 #include <wtf/HashMap.h>
33 #include <wtf/PassRefPtr.h>
34 #include <wtf/RefCounted.h>
35 #include <wtf/unicode/Unicode.h>
40 class GlyphPageTreeNode
;
43 typedef unsigned short Glyph
;
45 // Holds the glyph index and the corresponding SimpleFontData information for a given
49 const SimpleFontData
* fontData
;
52 // A GlyphPage contains a fixed-size set of GlyphData mappings for a contiguous
53 // range of characters in the Unicode code space. GlyphPages are indexed
54 // starting from 0 and incrementing for each 256 glyphs.
56 // 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,
58 // although multiple nodes may reference it as their "page" if they are supposed
59 // to be overriding the parent's node, but provide no additional information.
60 struct GlyphPage
: public RefCounted
<GlyphPage
> {
61 static PassRefPtr
<GlyphPage
> create(GlyphPageTreeNode
* owner
)
63 return adoptRef(new GlyphPage(owner
));
66 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
]; }
71 void setGlyphDataForCharacter(UChar32 c
, Glyph g
, const SimpleFontData
* f
)
73 setGlyphDataForIndex(c
% size
, g
, f
);
75 void setGlyphDataForIndex(unsigned index
, Glyph g
, const SimpleFontData
* f
)
78 m_glyphs
[index
].glyph
= g
;
79 m_glyphs
[index
].fontData
= f
;
81 GlyphPageTreeNode
* owner() const { return m_owner
; }
83 // Implemented by the platform.
84 bool fill(unsigned offset
, unsigned length
, UChar
* characterBuffer
, unsigned bufferLength
, const SimpleFontData
*);
87 GlyphPage(GlyphPageTreeNode
* owner
)
93 // The glyph page tree is a data structure that maps (FontData, glyph page number)
94 // to a GlyphPage. Level 0 (the "root") is special. There is one root
95 // GlyphPageTreeNode for each glyph page number. The roots do not have a
96 // GlyphPage associated with them, and their initializePage() function is never
97 // called to fill the glyphs.
99 // Each root node maps a FontData pointer to another GlyphPageTreeNode at
100 // level 1 (the "root child") that stores the actual glyphs for a specific font data.
101 // These nodes will only have a GlyphPage if they have glyphs for that range.
103 // Levels greater than one correspond to subsequent levels of the fallback list
104 // for that font. These levels override their parent's page of glyphs by
105 // filling in holes with the new font (thus making a more complete page).
107 // A NULL FontData pointer corresponds to the system fallback
108 // font. It is tracked separately from the regular pages and overrides so that
109 // the glyph pages do not get polluted with these last-resort glyphs. The
110 // system fallback page is not populated at construction like the other pages,
111 // but on demand for each glyph, because the system may need to use different
112 // fallback fonts for each. This lazy population is done by the Font.
113 class GlyphPageTreeNode
{
118 , m_isSystemFallback(false)
119 , m_systemFallbackChild(0)
120 , m_customFontCount(0)
127 ~GlyphPageTreeNode();
129 static HashMap
<int, GlyphPageTreeNode
*>* roots
;
130 static GlyphPageTreeNode
* pageZeroRoot
;
132 static GlyphPageTreeNode
* getRootChild(const FontData
* fontData
, unsigned pageNumber
)
134 return getRoot(pageNumber
)->getChild(fontData
, pageNumber
);
137 static void pruneTreeCustomFontData(const FontData
*);
138 static void pruneTreeFontData(const SimpleFontData
*);
140 void pruneCustomFontData(const FontData
*);
141 void pruneFontData(const SimpleFontData
*, unsigned level
= 0);
143 GlyphPageTreeNode
* parent() const { return m_parent
; }
144 GlyphPageTreeNode
* getChild(const FontData
*, unsigned pageNumber
);
146 // Returns a page of glyphs (or NULL if there are no glyphs in this page's character range).
147 GlyphPage
* page() const { return m_page
.get(); }
149 // Returns the level of this node. See class-level comment.
150 unsigned level() const { return m_level
; }
152 // The system fallback font has special rules (see above).
153 bool isSystemFallback() const { return m_isSystemFallback
; }
155 static size_t treeGlyphPageCount();
156 size_t pageCount() const;
159 static GlyphPageTreeNode
* getRoot(unsigned pageNumber
);
160 void initializePage(const FontData
*, unsigned pageNumber
);
162 GlyphPageTreeNode
* m_parent
;
163 RefPtr
<GlyphPage
> m_page
;
165 bool m_isSystemFallback
;
166 HashMap
<const FontData
*, GlyphPageTreeNode
*> m_children
;
167 GlyphPageTreeNode
* m_systemFallbackChild
;
168 unsigned m_customFontCount
;
171 unsigned m_pageNumber
;
175 } // namespace WebCore
177 #endif // GlyphPageTreeNode_h