summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontFallbackListQt.cpp
blob: 29e77189f99d4d72e0333ab5df2401edc69bed5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
    Copyright (C) 2008 Holger Hans Peter Freyther

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

    Replacement of the stock FontFallbackList as Qt is going to find us a
    replacement font, will do caching and the other stuff we implement in
    WebKit.
*/

#include "config.h"
#include "FontFallbackList.h"

#include "Font.h"
#include "SegmentedFontData.h"

#include <QDebug>

namespace WebCore {

FontFallbackList::FontFallbackList()
    : m_pageZero(0)
    , m_cachedPrimarySimpleFontData(0)
    , m_fontSelector(0)
    , m_familyIndex(0)
    , m_pitch(UnknownPitch)
    , m_loadingCustomFonts(false)
    , m_generation(0)
{
}

void FontFallbackList::invalidate(WTF::PassRefPtr<WebCore::FontSelector> fontSelector)
{
    releaseFontData();
    m_fontList.clear();
    m_pageZero = 0;
    m_pages.clear();
    m_cachedPrimarySimpleFontData = 0;
    m_familyIndex = 0;
    m_pitch = UnknownPitch;
    m_loadingCustomFonts = false;
    m_fontSelector = fontSelector;
    m_generation = 0;
}

void FontFallbackList::releaseFontData()
{
    if (m_fontList.size())
        delete m_fontList[0].first;
    m_fontList.clear();
}

void FontFallbackList::determinePitch(const WebCore::Font* font) const
{
    const FontData* fontData = primaryFontData(font);
    if (!fontData->isSegmented())
        m_pitch = static_cast<const SimpleFontData*>(fontData)->pitch();
    else {
        const SegmentedFontData* segmentedFontData = static_cast<const SegmentedFontData*>(fontData);
        unsigned numRanges = segmentedFontData->numRanges();
        if (numRanges == 1)
            m_pitch = segmentedFontData->rangeAt(0).fontData()->pitch();
        else
            m_pitch = VariablePitch;
    }
}

const FontData* FontFallbackList::fontDataAt(const WebCore::Font* _font, unsigned index) const
{
    if (index != 0)
        return 0;

    // Use the FontSelector to get a WebCore font and then fallback to Qt
    const FontDescription& description = _font->fontDescription();
    const FontFamily* family = &description.family();
    while (family) {
        if (m_fontSelector) {
            FontData* data = m_fontSelector->getFontData(description, family->family());
            if (data) {
                if (data->isLoading())
                    m_loadingCustomFonts = true;
                return data;
            }
        }
        family = family->next();
    }

    if (m_fontList.size())
        return m_fontList[0].first;

    const FontData* result = new SimpleFontData(FontPlatformData(description), _font->wordSpacing(), _font->letterSpacing());
    m_fontList.append(pair<const FontData*, bool>(result, result->isCustomFont()));
    return result;
}

const FontData* FontFallbackList::fontDataForCharacters(const WebCore::Font* font, const UChar*, int) const
{
    return primaryFontData(font);
}

void FontFallbackList::setPlatformFont(const WebCore::FontPlatformData& platformData)
{
    m_familyIndex = cAllFamiliesScanned;
}

}