bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 1 | /* |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 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. |
| 16 | * |
| 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. |
| 27 | */ |
| 28 | |
kjk | 5514898 | 2007-02-08 22:37:14 +0000 | [diff] [blame] | 29 | #ifndef GlyphPageTreeNode_h |
| 30 | #define GlyphPageTreeNode_h |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 31 | |
zimmermann@webkit.org | 1aa1005 | 2011-04-21 13:34:36 +0000 | [diff] [blame] | 32 | #include "GlyphPage.h" |
dimich@chromium.org | 0570dd5 | 2009-05-07 23:11:37 +0000 | [diff] [blame] | 33 | #include <string.h> |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 34 | #include <wtf/HashMap.h> |
kling@webkit.org | 151bdd5 | 2012-10-10 05:28:35 +0000 | [diff] [blame] | 35 | #include <wtf/OwnPtr.h> |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 36 | #include <wtf/PassRefPtr.h> |
ggaren@apple.com | 58ea1c1 | 2007-11-14 02:05:26 +0000 | [diff] [blame] | 37 | #include <wtf/RefCounted.h> |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 38 | #include <wtf/unicode/Unicode.h> |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 39 | |
mitz@apple.com | bbf453a | 2009-07-25 03:50:23 +0000 | [diff] [blame] | 40 | #ifndef NDEBUG |
| 41 | void showGlyphPageTrees(); |
| 42 | void showGlyphPageTree(unsigned pageNumber); |
| 43 | #endif |
| 44 | |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 45 | namespace WebCore { |
| 46 | |
| 47 | class FontData; |
mitz@apple.com | 648b73b | 2008-01-07 23:32:55 +0000 | [diff] [blame] | 48 | class SimpleFontData; |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 49 | |
hyatt | 8ad991c | 2007-05-08 00:57:09 +0000 | [diff] [blame] | 50 | // The glyph page tree is a data structure that maps (FontData, glyph page number) |
| 51 | // to a GlyphPage. Level 0 (the "root") is special. There is one root |
| 52 | // GlyphPageTreeNode for each glyph page number. The roots do not have a |
| 53 | // GlyphPage associated with them, and their initializePage() function is never |
| 54 | // called to fill the glyphs. |
| 55 | // |
| 56 | // Each root node maps a FontData pointer to another GlyphPageTreeNode at |
| 57 | // level 1 (the "root child") that stores the actual glyphs for a specific font data. |
| 58 | // These nodes will only have a GlyphPage if they have glyphs for that range. |
| 59 | // |
| 60 | // Levels greater than one correspond to subsequent levels of the fallback list |
| 61 | // for that font. These levels override their parent's page of glyphs by |
| 62 | // filling in holes with the new font (thus making a more complete page). |
| 63 | // |
| 64 | // A NULL FontData pointer corresponds to the system fallback |
| 65 | // font. It is tracked separately from the regular pages and overrides so that |
| 66 | // the glyph pages do not get polluted with these last-resort glyphs. The |
| 67 | // system fallback page is not populated at construction like the other pages, |
| 68 | // but on demand for each glyph, because the system may need to use different |
| 69 | // fallback fonts for each. This lazy population is done by the Font. |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 70 | class GlyphPageTreeNode { |
zoltan@webkit.org | 2eb7bec | 2012-09-14 09:12:48 +0000 | [diff] [blame] | 71 | WTF_MAKE_FAST_ALLOCATED; |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 72 | public: |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 73 | static GlyphPageTreeNode* getRootChild(const FontData* fontData, unsigned pageNumber) |
| 74 | { |
| 75 | return getRoot(pageNumber)->getChild(fontData, pageNumber); |
| 76 | } |
| 77 | |
oliver | d6ae496 | 2007-10-12 14:55:24 +0000 | [diff] [blame] | 78 | static void pruneTreeCustomFontData(const FontData*); |
mitz@apple.com | bdb9ed5 | 2008-05-12 21:02:27 +0000 | [diff] [blame] | 79 | static void pruneTreeFontData(const SimpleFontData*); |
oliver | d6ae496 | 2007-10-12 14:55:24 +0000 | [diff] [blame] | 80 | |
| 81 | void pruneCustomFontData(const FontData*); |
mitz@apple.com | bdb9ed5 | 2008-05-12 21:02:27 +0000 | [diff] [blame] | 82 | void pruneFontData(const SimpleFontData*, unsigned level = 0); |
oliver | d6ae496 | 2007-10-12 14:55:24 +0000 | [diff] [blame] | 83 | |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 84 | GlyphPageTreeNode* parent() const { return m_parent; } |
| 85 | GlyphPageTreeNode* getChild(const FontData*, unsigned pageNumber); |
| 86 | |
hyatt | 8ad991c | 2007-05-08 00:57:09 +0000 | [diff] [blame] | 87 | // Returns a page of glyphs (or NULL if there are no glyphs in this page's character range). |
oliver | d6ae496 | 2007-10-12 14:55:24 +0000 | [diff] [blame] | 88 | GlyphPage* page() const { return m_page.get(); } |
hyatt | 8ad991c | 2007-05-08 00:57:09 +0000 | [diff] [blame] | 89 | |
| 90 | // Returns the level of this node. See class-level comment. |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 91 | unsigned level() const { return m_level; } |
hyatt | 8ad991c | 2007-05-08 00:57:09 +0000 | [diff] [blame] | 92 | |
| 93 | // The system fallback font has special rules (see above). |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 94 | bool isSystemFallback() const { return m_isSystemFallback; } |
| 95 | |
mitz@apple.com | bdb9ed5 | 2008-05-12 21:02:27 +0000 | [diff] [blame] | 96 | static size_t treeGlyphPageCount(); |
| 97 | size_t pageCount() const; |
| 98 | |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 99 | private: |
kling@webkit.org | 151bdd5 | 2012-10-10 05:28:35 +0000 | [diff] [blame] | 100 | GlyphPageTreeNode() |
| 101 | : m_parent(0) |
| 102 | , m_level(0) |
| 103 | , m_isSystemFallback(false) |
| 104 | , m_customFontCount(0) |
| 105 | #ifndef NDEBUG |
| 106 | , m_pageNumber(0) |
| 107 | #endif |
| 108 | { |
| 109 | } |
| 110 | |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 111 | static GlyphPageTreeNode* getRoot(unsigned pageNumber); |
| 112 | void initializePage(const FontData*, unsigned pageNumber); |
| 113 | |
mitz@apple.com | bbf453a | 2009-07-25 03:50:23 +0000 | [diff] [blame] | 114 | #ifndef NDEBUG |
| 115 | void showSubtree(); |
| 116 | #endif |
| 117 | |
kling@webkit.org | 151bdd5 | 2012-10-10 05:28:35 +0000 | [diff] [blame] | 118 | static HashMap<int, GlyphPageTreeNode*>* roots; |
| 119 | static GlyphPageTreeNode* pageZeroRoot; |
| 120 | |
| 121 | typedef HashMap<const FontData*, OwnPtr<GlyphPageTreeNode> > GlyphPageTreeNodeMap; |
| 122 | |
| 123 | GlyphPageTreeNodeMap m_children; |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 124 | GlyphPageTreeNode* m_parent; |
oliver | d6ae496 | 2007-10-12 14:55:24 +0000 | [diff] [blame] | 125 | RefPtr<GlyphPage> m_page; |
weinig@apple.com | 5e7f9c5 | 2010-05-16 23:42:41 +0000 | [diff] [blame] | 126 | unsigned m_level : 31; |
| 127 | bool m_isSystemFallback : 1; |
| 128 | unsigned m_customFontCount; |
kling@webkit.org | 151bdd5 | 2012-10-10 05:28:35 +0000 | [diff] [blame] | 129 | OwnPtr<GlyphPageTreeNode> m_systemFallbackChild; |
oliver | d6ae496 | 2007-10-12 14:55:24 +0000 | [diff] [blame] | 130 | |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 131 | #ifndef NDEBUG |
| 132 | unsigned m_pageNumber; |
mitz@apple.com | bbf453a | 2009-07-25 03:50:23 +0000 | [diff] [blame] | 133 | |
kling@webkit.org | 151bdd5 | 2012-10-10 05:28:35 +0000 | [diff] [blame] | 134 | friend void ::showGlyphPageTrees(); |
mitz@apple.com | bbf453a | 2009-07-25 03:50:23 +0000 | [diff] [blame] | 135 | friend void ::showGlyphPageTree(unsigned pageNumber); |
bdash | d0f5421 | 2007-01-19 01:08:03 +0000 | [diff] [blame] | 136 | #endif |
| 137 | }; |
| 138 | |
| 139 | } // namespace WebCore |
| 140 | |
| 141 | #endif // GlyphPageTreeNode_h |