OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2006, 2009, 2011 Apple Inc. All rights reserved. | |
3 * Copyright (C) 2007-2008 Torch Mobile Inc. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * | |
9 * 1. Redistributions of source code must retain the above copyright | |
10 * notice, this list of conditions and the following disclaimer. | |
11 * 2. Redistributions in binary form must reproduce the above copyright | |
12 * notice, this list of conditions and the following disclaimer in the | |
13 * documentation and/or other materials provided with the distribution. | |
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
15 * its contributors may be used to endorse or promote products derived | |
16 * from this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 */ | |
29 | |
30 #ifndef GlyphBuffer_h | |
31 #define GlyphBuffer_h | |
32 | |
33 #include "platform/fonts/Glyph.h" | |
34 #include "platform/geometry/FloatPoint.h" | |
35 #include "platform/heap/Heap.h" | |
36 #include "wtf/Vector.h" | |
37 | |
38 namespace blink { | |
39 | |
40 class SimpleFontData; | |
41 | |
42 class GlyphBuffer { | |
43 STACK_ALLOCATED(); | |
44 | |
45 public: | |
46 enum class Type { Normal, TextIntercepts }; | |
47 explicit GlyphBuffer(Type type = Type::Normal) : m_type(type) {} | |
48 | |
49 Type type() const { return m_type; } | |
50 | |
51 bool isEmpty() const { return m_fontData.isEmpty(); } | |
52 unsigned size() const { | |
53 ASSERT(m_fontData.size() == m_glyphs.size()); | |
54 ASSERT(m_fontData.size() == m_offsets.size() || | |
55 2 * m_fontData.size() == m_offsets.size()); | |
56 return m_fontData.size(); | |
57 } | |
58 | |
59 bool hasVerticalOffsets() const { | |
60 // We exclusively store either horizontal/x-only ofssets -- in which case | |
61 // m_offsets.size == size, or vertical/xy offsets -- in which case | |
62 // m_offsets.size == size * 2. | |
63 return size() != m_offsets.size(); | |
64 } | |
65 | |
66 const Glyph* glyphs(unsigned from) const { | |
67 ASSERT(from < size()); | |
68 return m_glyphs.data() + from; | |
69 } | |
70 | |
71 // Depending on the GlyphBuffer-wide positioning mode, this either points to | |
72 // an array of x-only offsets for horizontal positioning ([x1, x2, ... xn]), | |
73 // or interleaved x,y offsets for full positioning ([x1, y1, ... xn, yn]). | |
74 const float* offsets(unsigned from) const { | |
75 ASSERT(from < size()); | |
76 return m_offsets.data() + (hasVerticalOffsets() ? from * 2 : from); | |
77 } | |
78 | |
79 const SimpleFontData* fontDataAt(unsigned index) const { | |
80 ASSERT(index < size()); | |
81 return m_fontData[index]; | |
82 } | |
83 | |
84 Glyph glyphAt(unsigned index) const { | |
85 ASSERT(index < size()); | |
86 return m_glyphs[index]; | |
87 } | |
88 | |
89 float xOffsetAt(unsigned index) const { | |
90 ASSERT(index < size()); | |
91 return hasVerticalOffsets() ? m_offsets[index * 2] : m_offsets[index]; | |
92 } | |
93 | |
94 float yOffsetAt(unsigned index) const { | |
95 ASSERT(index < size()); | |
96 ASSERT(hasVerticalOffsets()); | |
97 return m_offsets[index * 2 + 1]; | |
98 } | |
99 | |
100 void add(Glyph glyph, const SimpleFontData* font, float x) { | |
101 // cannot mix x-only/xy offsets | |
102 ASSERT(!hasVerticalOffsets()); | |
103 | |
104 m_fontData.push_back(font); | |
105 m_glyphs.push_back(glyph); | |
106 m_offsets.push_back(x); | |
107 } | |
108 | |
109 void add(Glyph glyph, const SimpleFontData* font, const FloatPoint& offset) { | |
110 // cannot mix x-only/xy offsets | |
111 ASSERT(isEmpty() || hasVerticalOffsets()); | |
112 | |
113 m_fontData.push_back(font); | |
114 m_glyphs.push_back(glyph); | |
115 m_offsets.push_back(offset.x()); | |
116 m_offsets.push_back(offset.y()); | |
117 } | |
118 | |
119 protected: | |
120 Vector<const SimpleFontData*, 2048> m_fontData; | |
121 Vector<Glyph, 2048> m_glyphs; | |
122 | |
123 // Glyph positioning: either x-only offsets, or interleaved x,y offsets | |
124 // (depending on the buffer-wide positioning mode). This matches the | |
125 // glyph positioning format used by Skia. | |
126 Vector<float, 2048> m_offsets; | |
127 | |
128 Type m_type; | |
129 }; | |
130 | |
131 } // namespace blink | |
132 | |
133 #endif | |
OLD | NEW |