⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glyphpagetreenode.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1.  Redistributions of source code must retain the above copyright *     notice, this list of conditions and the following disclaimer.  * 2.  Redistributions in binary form must reproduce the above copyright *     notice, this list of conditions and the following disclaimer in the *     documentation and/or other materials provided with the distribution.  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of *     its contributors may be used to endorse or promote products derived *     from this software without specific prior written permission.  * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#include "config.h"#include "GlyphPageTreeNode.h"#include "CharacterNames.h"#include "SegmentedFontData.h"#include "SimpleFontData.h"#include <wtf/unicode/Unicode.h>namespace WebCore {using std::max;using std::min;HashMap<int, GlyphPageTreeNode*>* GlyphPageTreeNode::roots = 0;GlyphPageTreeNode* GlyphPageTreeNode::pageZeroRoot = 0;GlyphPageTreeNode* GlyphPageTreeNode::getRoot(unsigned pageNumber){    static bool initialized;    if (!initialized) {        initialized = true;        roots = new HashMap<int, GlyphPageTreeNode*>;        pageZeroRoot = new GlyphPageTreeNode;    }    GlyphPageTreeNode* node = pageNumber ? roots->get(pageNumber) : pageZeroRoot;    if (!node) {        node = new GlyphPageTreeNode;#ifndef NDEBUG        node->m_pageNumber = pageNumber;#endif        if (pageNumber)            roots->set(pageNumber, node);        else            pageZeroRoot = node;    }    return node;}size_t GlyphPageTreeNode::treeGlyphPageCount(){    size_t count = 0;    if (roots) {        HashMap<int, GlyphPageTreeNode*>::iterator end = roots->end();        for (HashMap<int, GlyphPageTreeNode*>::iterator it = roots->begin(); it != end; ++it)            count += it->second->pageCount();    }        if (pageZeroRoot)        count += pageZeroRoot->pageCount();    return count;}size_t GlyphPageTreeNode::pageCount() const{    size_t count = m_page && m_page->owner() == this ? 1 : 0;    HashMap<const FontData*, GlyphPageTreeNode*>::const_iterator end = m_children.end();    for (HashMap<const FontData*, GlyphPageTreeNode*>::const_iterator it = m_children.begin(); it != end; ++it)        count += it->second->pageCount();    return count;}void GlyphPageTreeNode::pruneTreeCustomFontData(const FontData* fontData){    // Enumerate all the roots and prune any tree that contains our custom font data.    if (roots) {        HashMap<int, GlyphPageTreeNode*>::iterator end = roots->end();        for (HashMap<int, GlyphPageTreeNode*>::iterator it = roots->begin(); it != end; ++it)            it->second->pruneCustomFontData(fontData);    }        if (pageZeroRoot)        pageZeroRoot->pruneCustomFontData(fontData);}void GlyphPageTreeNode::pruneTreeFontData(const SimpleFontData* fontData){    if (roots) {        HashMap<int, GlyphPageTreeNode*>::iterator end = roots->end();        for (HashMap<int, GlyphPageTreeNode*>::iterator it = roots->begin(); it != end; ++it)            it->second->pruneFontData(fontData);    }        if (pageZeroRoot)        pageZeroRoot->pruneFontData(fontData);}GlyphPageTreeNode::~GlyphPageTreeNode(){    deleteAllValues(m_children);    delete m_systemFallbackChild;}void GlyphPageTreeNode::initializePage(const FontData* fontData, unsigned pageNumber){    ASSERT(!m_page);    // This function must not be called for the root of the tree, because that    // level does not contain any glyphs.    ASSERT(m_level > 0 && m_parent);    // The parent's page will be 0 if we are level one or the parent's font data    // did not contain any glyphs for that page.    GlyphPage* parentPage = m_parent->page();    // NULL FontData means we're being asked for the system fallback font.    if (fontData) {        if (m_level == 1) {            // Children of the root hold pure pages. These will cover only one            // font data's glyphs, and will have glyph index 0 if the font data does not            // contain the glyph.            unsigned start = pageNumber * GlyphPage::size;            UChar buffer[GlyphPage::size * 2 + 2];            unsigned bufferLength;            unsigned i;            // Fill in a buffer with the entire "page" of characters that we want to look up glyphs for.            if (start < 0x10000) {                bufferLength = GlyphPage::size;                for (i = 0; i < GlyphPage::size; i++)                    buffer[i] = start + i;                if (start == 0) {                    // Control characters must not render at all.                    for (i = 0; i < 0x20; ++i)                        buffer[i] = zeroWidthSpace;                    for (i = 0x7F; i < 0xA0; i++)                        buffer[i] = zeroWidthSpace;                    // \n, \t, and nonbreaking space must render as a space.                    buffer[(int)'\n'] = ' ';                    buffer[(int)'\t'] = ' ';                    buffer[noBreakSpace] = ' ';                } else if (start == (leftToRightMark & ~(GlyphPage::size - 1))) {                    // LRM, RLM, LRE, RLE and PDF must not render at all.                    buffer[leftToRightMark - start] = zeroWidthSpace;                    buffer[rightToLeftMark - start] = zeroWidthSpace;                    buffer[leftToRightEmbed - start] = zeroWidthSpace;                    buffer[rightToLeftEmbed - start] = zeroWidthSpace;                    buffer[leftToRightOverride - start] = zeroWidthSpace;                    buffer[rightToLeftOverride - start] = zeroWidthSpace;                    buffer[popDirectionalFormatting - start] = zeroWidthSpace;                } else if (start == (objectReplacementCharacter & ~(GlyphPage::size - 1))) {                    // Object replacement character must not render at all.                    buffer[objectReplacementCharacter - start] = zeroWidthSpace;                }            } else {                bufferLength = GlyphPage::size * 2;                for (i = 0; i < GlyphPage::size; i++) {                    int c = i + start;                    buffer[i * 2] = U16_LEAD(c);                    buffer[i * 2 + 1] = U16_TRAIL(c);                }            }                        m_page = GlyphPage::create(this);            // Now that we have a buffer full of characters, we want to get back an array            // of glyph indices.  This part involves calling into the platform-specific             // routine of our glyph map for actually filling in the page with the glyphs.            // Success is not guaranteed. For example, Times fails to fill page 260, giving glyph data            // for only 128 out of 256 characters.            bool haveGlyphs;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -