2 * Copyright (C) 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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "CSSSegmentedFontFace.h"
29 #include "CSSFontFace.h"
30 #include "CSSFontSelector.h"
31 #include "FontDescription.h"
32 #include "SegmentedFontData.h"
33 #include "SimpleFontData.h"
37 CSSSegmentedFontFace::CSSSegmentedFontFace(CSSFontSelector* fontSelector)
38 : m_fontSelector(fontSelector)
42 CSSSegmentedFontFace::~CSSSegmentedFontFace()
47 void CSSSegmentedFontFace::pruneTable()
49 // Make sure the glyph page tree prunes out all uses of this custom font.
50 if (m_fontDataTable.isEmpty())
52 HashMap<unsigned, SegmentedFontData*>::iterator end = m_fontDataTable.end();
53 for (HashMap<unsigned, SegmentedFontData*>::iterator it = m_fontDataTable.begin(); it != end; ++it)
54 GlyphPageTreeNode::pruneTreeCustomFontData(it->second);
55 deleteAllValues(m_fontDataTable);
56 m_fontDataTable.clear();
59 bool CSSSegmentedFontFace::isLoaded() const
61 unsigned size = m_ranges.size();
62 for (unsigned i = 0; i < size; i++) {
63 if (!m_ranges[i].fontFace()->isLoaded())
69 bool CSSSegmentedFontFace::isValid() const
71 unsigned size = m_ranges.size();
72 for (unsigned i = 0; i < size; i++) {
73 if (!m_ranges[i].fontFace()->isValid())
79 void CSSSegmentedFontFace::fontLoaded(CSSFontFace*)
83 return m_fontSelector->fontLoaded(this);
86 void CSSSegmentedFontFace::overlayRange(UChar32 from, UChar32 to, PassRefPtr<CSSFontFace> fontFace)
89 fontFace->setSegmentedFontFace(this);
91 unsigned size = m_ranges.size();
93 Vector<FontFaceRange, 8> oldRanges = m_ranges;
95 for (unsigned i = 0; i < size; i++) {
96 const FontFaceRange& range = oldRanges[i];
97 if (range.from() >= to || range.to() <= from)
98 m_ranges.append(range);
99 else if (range.from() < from) {
100 m_ranges.append(FontFaceRange(range.from(), from, range.fontFace()));
102 m_ranges.append(FontFaceRange(to, range.to(), range.fontFace()));
103 } else if (range.to() > to)
104 m_ranges.append(FontFaceRange(to, range.to(), range.fontFace()));
107 m_ranges.append(FontFaceRange(from, to, fontFace));
110 FontData* CSSSegmentedFontFace::getFontData(const FontDescription& fontDescription, bool syntheticBold, bool syntheticItalic)
115 unsigned hashKey = fontDescription.computedPixelSize() << 2 | (syntheticBold ? 0 : 2) | (syntheticItalic ? 0 : 1);
117 SegmentedFontData* fontData = m_fontDataTable.get(hashKey);
121 fontData = new SegmentedFontData();
123 unsigned size = m_ranges.size();
124 for (unsigned i = 0; i < size; i++) {
125 if (const FontData* rangeFontData = m_ranges[i].fontFace()->getFontData(fontDescription, syntheticBold, syntheticItalic)) {
126 ASSERT(!rangeFontData->isSegmented());
127 fontData->appendRange(FontDataRange(m_ranges[i].from(), m_ranges[i].to(), static_cast<const SimpleFontData*>(rangeFontData)));
130 m_fontDataTable.set(hashKey, fontData);