2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3 Copyright (C) 2008 Holger Hans Peter Freyther
4 Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
5 Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
22 This class provides all functionality needed for loading images, style sheets and html
23 pages from the web. It has a memory cache for these objects.
26 #include "FontCache.h"
28 #include "FontDescription.h"
29 #include "FontPlatformData.h"
31 #include "PlatformString.h"
33 #include <wtf/ListHashSet.h>
34 #include <wtf/StdLibExtras.h>
35 #include <wtf/text/StringHash.h>
38 #include <QFontDatabase>
40 #include <QTextLayout>
47 void FontCache::platformInit()
52 static QRawFont rawFontForCharacters(const QString& string, const QFont& requestedFont)
54 QFont font(requestedFont);
55 font.setStyleStrategy(QFont::NoFontMerging);
57 QTextLayout layout(string, font);
62 QList<QGlyphRun> glyphList = layout.glyphRuns();
64 ASSERT(glyphList.size() == 1);
66 const QGlyphRun& glyphs(glyphList.at(0));
67 QVector<quint32> glyphIndexes = glyphs.glyphIndexes();
69 if (glyphIndexes.isEmpty())
72 return glyphs.rawFont();
76 const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length)
79 QString qstring = QString::fromRawData(reinterpret_cast<const QChar*>(characters), length);
80 QRawFont computedFont = rawFontForCharacters(qstring, font.font());
81 if (!computedFont.isValid())
83 FontPlatformData alternateFont(computedFont);
84 return getCachedFontData(&alternateFont, DoNotRetain);
93 SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
98 SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription, ShouldRetain shouldRetain)
100 const AtomicString fallbackFamily = QFont(fontDescription.family().family()).lastResortFamily();
101 return getCachedFontData(new FontPlatformData(fontDescription, fallbackFamily), shouldRetain);
104 void FontCache::getTraitsInFamily(const AtomicString&, Vector<unsigned>&)
108 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
110 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
112 if (!db.hasFamily(familyName))
115 return new FontPlatformData(fontDescription, familyName);
118 } // namespace WebCore