OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef ShapeResult_h | 31 #ifndef ShapeResult_h |
32 #define ShapeResult_h | 32 #define ShapeResult_h |
33 | 33 |
34 #include "platform/geometry/FloatPoint.h" | 34 #include "platform/PlatformExport.h" |
35 #include "platform/geometry/FloatRect.h" | 35 #include "platform/geometry/FloatRect.h" |
36 #include "platform/text/TextRun.h" | 36 #include "platform/text/TextDirection.h" |
37 #include "wtf/HashSet.h" | 37 #include "wtf/HashSet.h" |
38 #include "wtf/Noncopyable.h" | 38 #include "wtf/Noncopyable.h" |
39 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
| 40 #include "wtf/RefCounted.h" |
40 #include "wtf/Vector.h" | 41 #include "wtf/Vector.h" |
41 | 42 |
42 namespace blink { | 43 namespace blink { |
43 | 44 |
44 class Font; | 45 class Font; |
45 class GlyphBuffer; | |
46 class ShapeResultBuffer; | |
47 class SimpleFontData; | 46 class SimpleFontData; |
48 class HarfBuzzShaper; | 47 class TextRun; |
49 struct GlyphData; | 48 struct GlyphData; |
50 | 49 |
51 class PLATFORM_EXPORT ShapeResult : public RefCounted<ShapeResult> { | 50 class PLATFORM_EXPORT ShapeResult : public RefCounted<ShapeResult> { |
52 WTF_MAKE_NONCOPYABLE(ShapeResult); | 51 WTF_MAKE_NONCOPYABLE(ShapeResult); |
53 public: | 52 public: |
54 static PassRefPtr<ShapeResult> create(const Font* font, | 53 static PassRefPtr<ShapeResult> create(const Font* font, |
55 unsigned numCharacters, TextDirection direction) | 54 unsigned numCharacters, TextDirection direction) |
56 { | 55 { |
57 return adoptRef(new ShapeResult(font, numCharacters, direction)); | 56 return adoptRef(new ShapeResult(font, numCharacters, direction)); |
58 } | 57 } |
59 static PassRefPtr<ShapeResult> createForTabulationCharacters(const Font*, | 58 static PassRefPtr<ShapeResult> createForTabulationCharacters(const Font*, |
60 const TextRun&, float positionOffset, unsigned count); | 59 const TextRun&, float positionOffset, unsigned count); |
61 ~ShapeResult(); | 60 ~ShapeResult(); |
62 | 61 |
63 float width() { return m_width; } | 62 float width() const { return m_width; } |
64 FloatRect bounds() { return m_glyphBoundingBox; } | 63 const FloatRect& bounds() const { return m_glyphBoundingBox; } |
65 unsigned numCharacters() const { return m_numCharacters; } | 64 unsigned numCharacters() const { return m_numCharacters; } |
66 void fallbackFonts(HashSet<const SimpleFontData*>*) const; | 65 void fallbackFonts(HashSet<const SimpleFontData*>*) const; |
67 bool hasVerticalOffsets() const { return m_hasVerticalOffsets; } | 66 bool hasVerticalOffsets() const { return m_hasVerticalOffsets; } |
68 | 67 |
69 // TODO(fmalita): relocate these to ShapeResultBuffer | |
70 static int offsetForPosition(const ShapeResultBuffer&, | |
71 const TextRun&, float targetX); | |
72 static float fillGlyphBuffer(const ShapeResultBuffer&, | |
73 GlyphBuffer*, const TextRun&, unsigned from, unsigned to); | |
74 static float fillGlyphBufferForTextEmphasis(const ShapeResultBuffer&, | |
75 GlyphBuffer*, const TextRun&, const GlyphData* emphasisData, | |
76 unsigned from, unsigned to); | |
77 static FloatRect selectionRect(const ShapeResultBuffer&, | |
78 TextDirection, float totalWidth, const FloatPoint&, int height, | |
79 unsigned from, unsigned to); | |
80 | |
81 // For memory reporting. | 68 // For memory reporting. |
82 size_t byteSize(); | 69 size_t byteSize(); |
83 | 70 |
| 71 int offsetForPosition(float targetX) const; |
| 72 |
84 protected: | 73 protected: |
85 struct RunInfo; | 74 struct RunInfo; |
86 #if COMPILER(MSVC) | 75 #if COMPILER(MSVC) |
87 friend struct ::WTF::OwnedPtrDeleter<RunInfo>; | 76 friend struct ::WTF::OwnedPtrDeleter<RunInfo>; |
88 #endif | 77 #endif |
89 | 78 |
90 ShapeResult(const Font*, unsigned numCharacters, TextDirection); | 79 ShapeResult(const Font*, unsigned numCharacters, TextDirection); |
91 | 80 |
92 // TODO(fmalita): relocate these to ShapeResultBuffer | |
93 int offsetForPosition(float targetX); | |
94 template<TextDirection> | |
95 static float fillGlyphBufferForRun(GlyphBuffer*, const RunInfo*, | |
96 float initialAdvance, unsigned from, unsigned to, unsigned runOffset); | |
97 | |
98 static float fillGlyphBufferForTextEmphasisRun(GlyphBuffer*, const RunInfo*, | |
99 const TextRun&, const GlyphData*, float initialAdvance, | |
100 unsigned from, unsigned to, unsigned runOffset); | |
101 | |
102 static float fillFastHorizontalGlyphBuffer(const ShapeResultBuffer&, | |
103 GlyphBuffer*, TextDirection); | |
104 | |
105 float m_width; | 81 float m_width; |
106 FloatRect m_glyphBoundingBox; | 82 FloatRect m_glyphBoundingBox; |
107 Vector<OwnPtr<RunInfo>> m_runs; | 83 Vector<OwnPtr<RunInfo>> m_runs; |
108 RefPtr<SimpleFontData> m_primaryFont; | 84 RefPtr<SimpleFontData> m_primaryFont; |
109 | 85 |
110 unsigned m_numCharacters; | 86 unsigned m_numCharacters; |
111 unsigned m_numGlyphs : 30; | 87 unsigned m_numGlyphs : 30; |
112 | 88 |
113 // Overall direction for the TextRun, dictates which order each individual | 89 // Overall direction for the TextRun, dictates which order each individual |
114 // sub run (represented by RunInfo structs in the m_runs vector) can have a | 90 // sub run (represented by RunInfo structs in the m_runs vector) can have a |
115 // different text direction. | 91 // different text direction. |
116 unsigned m_direction : 1; | 92 unsigned m_direction : 1; |
117 | 93 |
118 // Tracks whether any runs contain glyphs with a y-offset != 0. | 94 // Tracks whether any runs contain glyphs with a y-offset != 0. |
119 unsigned m_hasVerticalOffsets : 1; | 95 unsigned m_hasVerticalOffsets : 1; |
120 | 96 |
121 friend class HarfBuzzShaper; | 97 friend class HarfBuzzShaper; |
122 }; | 98 friend class ShapeResultBuffer; |
123 | |
124 class ShapeResultBuffer { | |
125 WTF_MAKE_NONCOPYABLE(ShapeResultBuffer); | |
126 STACK_ALLOCATED(); | |
127 public: | |
128 ShapeResultBuffer() | |
129 : m_hasVerticalOffsets(false) { } | |
130 | |
131 void appendResult(PassRefPtr<ShapeResult> result) | |
132 { | |
133 m_hasVerticalOffsets |= result->hasVerticalOffsets(); | |
134 m_results.append(result); | |
135 } | |
136 | |
137 bool hasVerticalOffsets() const { return m_hasVerticalOffsets; } | |
138 | |
139 // Empirically, cases where we get more than 50 ShapeResults are extremely r
are. | |
140 typedef Vector<RefPtr<ShapeResult>, 64> ShapeResultVector; | |
141 const ShapeResultVector& results() const { return m_results; } | |
142 | |
143 private: | |
144 ShapeResultVector m_results; | |
145 bool m_hasVerticalOffsets; | |
146 }; | 99 }; |
147 | 100 |
148 } // namespace blink | 101 } // namespace blink |
149 | 102 |
150 #endif // ShapeResult_h | 103 #endif // ShapeResult_h |
OLD | NEW |