OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 13 matching lines...) Expand all Loading... |
24 */ | 24 */ |
25 | 25 |
26 #ifndef CSSFontFace_h | 26 #ifndef CSSFontFace_h |
27 #define CSSFontFace_h | 27 #define CSSFontFace_h |
28 | 28 |
29 #include "core/CoreExport.h" | 29 #include "core/CoreExport.h" |
30 #include "core/css/CSSFontFaceSource.h" | 30 #include "core/css/CSSFontFaceSource.h" |
31 #include "core/css/CSSSegmentedFontFace.h" | 31 #include "core/css/CSSSegmentedFontFace.h" |
32 #include "core/css/FontFace.h" | 32 #include "core/css/FontFace.h" |
33 #include "platform/fonts/SegmentedFontData.h" | 33 #include "platform/fonts/SegmentedFontData.h" |
| 34 #include "platform/fonts/UnicodeRangeSet.h" |
34 #include "wtf/Deque.h" | 35 #include "wtf/Deque.h" |
35 #include "wtf/Forward.h" | 36 #include "wtf/Forward.h" |
36 #include "wtf/PassRefPtr.h" | 37 #include "wtf/PassRefPtr.h" |
37 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
38 | 39 |
39 namespace blink { | 40 namespace blink { |
40 | 41 |
41 class FontDescription; | 42 class FontDescription; |
42 class RemoteFontFaceSource; | 43 class RemoteFontFaceSource; |
43 class SimpleFontData; | 44 class SimpleFontData; |
44 | 45 |
45 class CORE_EXPORT CSSFontFace final : public NoBaseWillBeGarbageCollectedFinaliz
ed<CSSFontFace> { | 46 class CORE_EXPORT CSSFontFace final : public NoBaseWillBeGarbageCollectedFinaliz
ed<CSSFontFace> { |
46 USING_FAST_MALLOC_WILL_BE_REMOVED(CSSFontFace); | 47 USING_FAST_MALLOC_WILL_BE_REMOVED(CSSFontFace); |
47 WTF_MAKE_NONCOPYABLE(CSSFontFace); | 48 WTF_MAKE_NONCOPYABLE(CSSFontFace); |
48 public: | 49 public: |
49 struct UnicodeRange; | |
50 class UnicodeRangeSet; | |
51 | |
52 CSSFontFace(FontFace* fontFace, Vector<UnicodeRange>& ranges) | 50 CSSFontFace(FontFace* fontFace, Vector<UnicodeRange>& ranges) |
53 : m_ranges(ranges) | 51 : m_ranges(ranges) |
54 , m_segmentedFontFace(nullptr) | 52 , m_segmentedFontFace(nullptr) |
55 , m_fontFace(fontFace) | 53 , m_fontFace(fontFace) |
56 { | 54 { |
57 ASSERT(m_fontFace); | 55 ASSERT(m_fontFace); |
58 } | 56 } |
59 | 57 |
60 FontFace* fontFace() const { return m_fontFace; } | 58 FontFace* fontFace() const { return m_fontFace; } |
61 | 59 |
62 UnicodeRangeSet& ranges() { return m_ranges; } | 60 UnicodeRangeSet& ranges() { return m_ranges; } |
63 | 61 |
64 void setSegmentedFontFace(CSSSegmentedFontFace*); | 62 void setSegmentedFontFace(CSSSegmentedFontFace*); |
65 void clearSegmentedFontFace() { m_segmentedFontFace = nullptr; } | 63 void clearSegmentedFontFace() { m_segmentedFontFace = nullptr; } |
66 | 64 |
67 bool isValid() const { return !m_sources.isEmpty(); } | 65 bool isValid() const { return !m_sources.isEmpty(); } |
68 | 66 |
69 void addSource(PassOwnPtrWillBeRawPtr<CSSFontFaceSource>); | 67 void addSource(PassOwnPtrWillBeRawPtr<CSSFontFaceSource>); |
70 | 68 |
71 void didBeginLoad(); | 69 void didBeginLoad(); |
72 void fontLoaded(RemoteFontFaceSource*); | 70 void fontLoaded(RemoteFontFaceSource*); |
73 void didBecomeVisibleFallback(RemoteFontFaceSource*); | 71 void didBecomeVisibleFallback(RemoteFontFaceSource*); |
74 | 72 |
75 PassRefPtr<SimpleFontData> getFontData(const FontDescription&); | 73 PassRefPtr<SimpleFontData> getFontData(const FontDescription&); |
76 | 74 |
77 struct UnicodeRange { | |
78 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
79 UnicodeRange(UChar32 from, UChar32 to) | |
80 : m_from(from) | |
81 , m_to(to) | |
82 { | |
83 } | |
84 | |
85 UChar32 from() const { return m_from; } | |
86 UChar32 to() const { return m_to; } | |
87 bool contains(UChar32 c) const { return m_from <= c && c <= m_to; } | |
88 bool operator<(const UnicodeRange& other) const { return m_from < other.
m_from; } | |
89 bool operator<(UChar32 c) const { return m_to < c; } | |
90 bool operator==(const FontDataRange& fontDataRange) const { return fontD
ataRange.from() == m_from && fontDataRange.to() == m_to; }; | |
91 | |
92 private: | |
93 UChar32 m_from; | |
94 UChar32 m_to; | |
95 }; | |
96 | |
97 class CORE_EXPORT UnicodeRangeSet { | |
98 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
99 public: | |
100 explicit UnicodeRangeSet(const Vector<UnicodeRange>&); | |
101 bool contains(UChar32) const; | |
102 bool contains(const FontDataRange&) const; | |
103 bool intersectsWith(const String&) const; | |
104 bool isEntireRange() const { return m_ranges.isEmpty(); } | |
105 size_t size() const { return m_ranges.size(); } | |
106 const UnicodeRange& rangeAt(size_t i) const { return m_ranges[i]; } | |
107 private: | |
108 Vector<UnicodeRange> m_ranges; // If empty, represents the whole code sp
ace. | |
109 }; | |
110 | |
111 FontFace::LoadStatusType loadStatus() const { return m_fontFace->loadStatus(
); } | 75 FontFace::LoadStatusType loadStatus() const { return m_fontFace->loadStatus(
); } |
112 bool maybeScheduleFontLoad(const FontDescription&, UChar32); | 76 bool maybeScheduleFontLoad(const FontDescription&, UChar32); |
113 bool maybeScheduleFontLoad(const FontDescription&, const FontDataRange&); | 77 bool maybeScheduleFontLoad(const FontDescription&, const FontDataRange&); |
114 void load(); | 78 void load(); |
115 void load(const FontDescription&); | 79 void load(const FontDescription&); |
116 | 80 |
117 bool hadBlankText() { return isValid() && m_sources.first()->hadBlankText();
} | 81 bool hadBlankText() { return isValid() && m_sources.first()->hadBlankText();
} |
118 | 82 |
119 DECLARE_TRACE(); | 83 DECLARE_TRACE(); |
120 | 84 |
121 private: | 85 private: |
122 void setLoadStatus(FontFace::LoadStatusType); | 86 void setLoadStatus(FontFace::LoadStatusType); |
123 | 87 |
124 UnicodeRangeSet m_ranges; | 88 UnicodeRangeSet m_ranges; |
125 RawPtrWillBeMember<CSSSegmentedFontFace> m_segmentedFontFace; | 89 RawPtrWillBeMember<CSSSegmentedFontFace> m_segmentedFontFace; |
126 WillBeHeapDeque<OwnPtrWillBeMember<CSSFontFaceSource>> m_sources; | 90 WillBeHeapDeque<OwnPtrWillBeMember<CSSFontFaceSource>> m_sources; |
127 RawPtrWillBeMember<FontFace> m_fontFace; | 91 RawPtrWillBeMember<FontFace> m_fontFace; |
128 }; | 92 }; |
129 | 93 |
130 } // namespace blink | 94 } // namespace blink |
131 | 95 |
132 #endif | 96 #endif |
OLD | NEW |