2 * Copyright (C) 2006, 2010, 2013-2015 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
24 #include "FontSelector.h"
25 #include "GlyphPage.h"
26 #include "SimpleFontData.h"
27 #include "WidthCache.h"
28 #include <wtf/Forward.h>
29 #include <wtf/MainThread.h>
32 #include "WebCoreThread.h"
37 class GraphicsContext;
39 class FontDescription;
40 class FontPlatformData;
43 class FontGlyphs : public RefCounted<FontGlyphs> {
44 WTF_MAKE_NONCOPYABLE(FontGlyphs);
46 static Ref<FontGlyphs> create(PassRefPtr<FontSelector> fontSelector) { return adoptRef(*new FontGlyphs(fontSelector)); }
47 static Ref<FontGlyphs> createForPlatformFont(const FontPlatformData& platformData) { return adoptRef(*new FontGlyphs(platformData)); }
51 bool isForPlatformFont() const { return m_isForPlatformFont; }
53 GlyphData glyphDataForCharacter(UChar32, const FontDescription&, FontDataVariant);
55 bool isFixedPitch(const FontDescription&);
56 void determinePitch(const FontDescription&);
58 bool isLoadingCustomFonts() const;
60 FontSelector* fontSelector() { return m_fontSelector.get(); }
61 // FIXME: It should be possible to combine fontSelectorVersion and generation.
62 unsigned fontSelectorVersion() const { return m_fontSelectorVersion; }
63 unsigned generation() const { return m_generation; }
65 WidthCache& widthCache() { return m_widthCache; }
66 const WidthCache& widthCache() const { return m_widthCache; }
68 const SimpleFontData& primarySimpleFontData(const FontDescription&);
69 WEBCORE_EXPORT const FontData* realizeFontDataAt(const FontDescription&, unsigned index);
72 FontGlyphs(PassRefPtr<FontSelector>);
73 FontGlyphs(const FontPlatformData&);
75 GlyphData glyphDataForSystemFallback(UChar32, const FontDescription&, FontDataVariant);
76 GlyphData glyphDataForNormalVariant(UChar32, const FontDescription&);
77 GlyphData glyphDataForVariant(UChar32, const FontDescription&, FontDataVariant, unsigned fallbackIndex);
79 Vector<Ref<FontData>, 1> m_realizedFontData;
81 RefPtr<GlyphPage> m_cachedPageZero;
82 HashMap<int, RefPtr<GlyphPage>> m_cachedPages;
84 HashSet<RefPtr<SimpleFontData>> m_systemFallbackFontDataSet;
86 const SimpleFontData* m_cachedPrimarySimpleFontData;
87 RefPtr<FontSelector> m_fontSelector;
88 WidthCache m_widthCache;
89 unsigned m_fontSelectorVersion;
90 unsigned short m_generation;
91 unsigned m_lastRealizedFamilyIndex { 0 };
92 Pitch m_pitch { UnknownPitch };
93 bool m_isForPlatformFont { false };
96 inline bool FontGlyphs::isFixedPitch(const FontDescription& description)
98 if (m_pitch == UnknownPitch)
99 determinePitch(description);
100 return m_pitch == FixedPitch;
103 inline const SimpleFontData& FontGlyphs::primarySimpleFontData(const FontDescription& description)
105 ASSERT(isMainThread());
106 if (!m_cachedPrimarySimpleFontData) {
107 auto& fontData = *realizeFontDataAt(description, 0);
108 m_cachedPrimarySimpleFontData = fontData.simpleFontDataForCharacter(' ');
109 if (!m_cachedPrimarySimpleFontData)
110 m_cachedPrimarySimpleFontData = &fontData.simpleFontDataForFirstRange();
112 return *m_cachedPrimarySimpleFontData;