| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2009, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2009, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007-2008 Torch Mobile Inc. | 3 * Copyright (C) 2007-2008 Torch Mobile Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 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 | 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 | 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. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #ifndef GlyphBuffer_h | 30 #ifndef GlyphBuffer_h |
| 31 #define GlyphBuffer_h | 31 #define GlyphBuffer_h |
| 32 | 32 |
| 33 #include "platform/fonts/Glyph.h" | 33 #include "platform/fonts/Glyph.h" |
| 34 #include "platform/geometry/FloatSize.h" | 34 #include "platform/geometry/FloatPoint.h" |
| 35 #include "platform/heap/Heap.h" | 35 #include "platform/heap/Heap.h" |
| 36 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 class SimpleFontData; | 40 class SimpleFontData; |
| 41 | 41 |
| 42 class GlyphBuffer { | 42 class GlyphBuffer { |
| 43 STACK_ALLOCATED(); | 43 STACK_ALLOCATED(); |
| 44 public: | 44 public: |
| 45 bool isEmpty() const { return m_fontData.isEmpty(); } | 45 bool isEmpty() const { return m_fontData.isEmpty(); } |
| 46 bool hasOffsets() const { return !m_offsets.isEmpty(); } | 46 unsigned size() const |
| 47 unsigned size() const { return m_fontData.size(); } | 47 { |
| 48 ASSERT(m_fontData.size() == m_glyphs.size()); |
| 49 ASSERT(m_fontData.size() == m_offsets.size() || 2 * m_fontData.size() ==
m_offsets.size()); |
| 50 return m_fontData.size(); |
| 51 } |
| 48 | 52 |
| 49 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } | 53 bool hasVerticalOffsets() const |
| 50 const float* advances(unsigned from) const { return m_advances.data() + from
; } | 54 { |
| 51 const FloatSize* offsets(unsigned from) const { return m_offsets.data() + fr
om; } | 55 // We exclusively store either horizontal/x-only ofssets -- in which cas
e m_offsets.size == size, |
| 56 // or vertical/xy offsets -- in which case m_offsets.size == size * 2. |
| 57 return size() != m_offsets.size(); |
| 58 } |
| 59 |
| 60 const Glyph* glyphs(unsigned from) const |
| 61 { |
| 62 ASSERT(from < size()); |
| 63 return m_glyphs.data() + from; |
| 64 } |
| 65 |
| 66 // Depending on the GlyphBuffer-wide positioning mode, this either points to
an array of |
| 67 // x-only offsets for horizontal positioning ([x1, x2, ... xn]), or interlea
ved x,y offsets |
| 68 // for full positioning ([x1, y1, x2, y2, ... xn, yn]). |
| 69 const float* offsets(unsigned from) const |
| 70 { |
| 71 ASSERT(from < size()); |
| 72 return m_offsets.data() + (hasVerticalOffsets() ? from * 2 : from); |
| 73 } |
| 52 | 74 |
| 53 const SimpleFontData* fontDataAt(unsigned index) const | 75 const SimpleFontData* fontDataAt(unsigned index) const |
| 54 { | 76 { |
| 77 ASSERT(index < size()); |
| 55 return m_fontData[index]; | 78 return m_fontData[index]; |
| 56 } | 79 } |
| 57 | 80 |
| 58 Glyph glyphAt(unsigned index) const | 81 Glyph glyphAt(unsigned index) const |
| 59 { | 82 { |
| 83 ASSERT(index < size()); |
| 60 return m_glyphs[index]; | 84 return m_glyphs[index]; |
| 61 } | 85 } |
| 62 | 86 |
| 63 float advanceAt(unsigned index) const | 87 float xOffsetAt(unsigned index) const |
| 64 { | 88 { |
| 65 return m_advances[index]; | 89 ASSERT(index < size()); |
| 90 return hasVerticalOffsets() ? m_offsets[index * 2] : m_offsets[index]; |
| 91 |
| 66 } | 92 } |
| 67 | 93 |
| 68 void add(Glyph glyph, const SimpleFontData* font, float width) | 94 float yOffsetAt(unsigned index) const |
| 69 { | 95 { |
| 70 // should not mix offset/advance-only glyphs | 96 ASSERT(index < size()); |
| 71 ASSERT(!hasOffsets()); | 97 ASSERT(hasVerticalOffsets()); |
| 98 return m_offsets[index * 2 + 1]; |
| 99 } |
| 100 |
| 101 void add(Glyph glyph, const SimpleFontData* font, float x) |
| 102 { |
| 103 // cannot mix x-only/xy offsets |
| 104 ASSERT(!hasVerticalOffsets()); |
| 72 | 105 |
| 73 m_fontData.append(font); | 106 m_fontData.append(font); |
| 74 m_glyphs.append(glyph); | 107 m_glyphs.append(glyph); |
| 75 m_advances.append(width); | 108 m_offsets.append(x); |
| 76 } | 109 } |
| 77 | 110 |
| 78 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& offset, f
loat advance) | 111 void add(Glyph glyph, const SimpleFontData* font, const FloatPoint& offset) |
| 79 { | 112 { |
| 80 // should not mix offset/advance-only glyphs | 113 // cannot mix x-only/xy offsets |
| 81 ASSERT(size() == m_offsets.size()); | 114 ASSERT(isEmpty() || hasVerticalOffsets()); |
| 82 | 115 |
| 83 m_fontData.append(font); | 116 m_fontData.append(font); |
| 84 m_glyphs.append(glyph); | 117 m_glyphs.append(glyph); |
| 85 m_offsets.append(offset); | 118 m_offsets.append(offset.x()); |
| 86 m_advances.append(advance); | 119 m_offsets.append(offset.y()); |
| 87 } | 120 } |
| 88 | 121 |
| 89 void reverse() | 122 void reverseForSimpleRTL(float afterOffset, float totalWidth) |
| 90 { | 123 { |
| 124 ASSERT(!hasVerticalOffsets()); |
| 125 |
| 126 if (isEmpty()) |
| 127 return; |
| 128 |
| 91 m_fontData.reverse(); | 129 m_fontData.reverse(); |
| 92 m_glyphs.reverse(); | 130 m_glyphs.reverse(); |
| 93 m_advances.reverse(); | |
| 94 } | |
| 95 | 131 |
| 96 void expandLastAdvance(float width) | 132 // | .. [X0 X1 .. Xn] .. | |
| 97 { | 133 // ^ ^ ^ |
| 98 ASSERT(!isEmpty()); | 134 // 0 afterOffset totalWidth |
| 99 float& lastAdvance = m_advances.last(); | 135 // |
| 100 lastAdvance += width; | 136 // The input buffer is shaped using RTL advances, but since the right ed
ge is unknown at |
| 137 // that time, offsets are computed as if the advances were LTR. This met
hod performs the |
| 138 // required adjustments by reconstructing advances and positioning offse
ts in an RTL |
| 139 // progression. |
| 140 |
| 141 // FIXME: we should get rid of this (idea: store negative offsets while
shaping, |
| 142 // and adjust the initial advance accordingly -> should yield cor
rectly positioned |
| 143 // RTL glyphs without any post-shape munging). |
| 144 ASSERT_WITH_SECURITY_IMPLICATION(!m_offsets.isEmpty()); |
| 145 float x = totalWidth - m_offsets[0]; |
| 146 for (unsigned i = 0; i + 1 < m_offsets.size(); ++i) { |
| 147 float advance = m_offsets[i + 1] - m_offsets[i]; |
| 148 ASSERT(advance >= 0); |
| 149 x -= advance; |
| 150 m_offsets[i] = x; |
| 151 } |
| 152 float lastAdvance = afterOffset - m_offsets.last(); |
| 153 ASSERT(lastAdvance >= 0); |
| 154 m_offsets.last() = x - lastAdvance; |
| 155 |
| 156 m_offsets.reverse(); |
| 101 } | 157 } |
| 102 | 158 |
| 103 protected: | 159 protected: |
| 104 Vector<const SimpleFontData*, 2048> m_fontData; | 160 Vector<const SimpleFontData*, 2048> m_fontData; |
| 105 Vector<Glyph, 2048> m_glyphs; | 161 Vector<Glyph, 2048> m_glyphs; |
| 106 Vector<float, 2048> m_advances; | 162 |
| 107 Vector<FloatSize, 1024> m_offsets; | 163 // Glyph positioning: either x-only offsets, or interleaved x,y offsets |
| 164 // (depending on the buffer-wide positioning mode). This matches the |
| 165 // glyph positioning format used by Skia. |
| 166 Vector<float, 2048> m_offsets; |
| 108 }; | 167 }; |
| 109 | 168 |
| 110 } // namespace blink | 169 } // namespace blink |
| 111 | 170 |
| 112 #endif | 171 #endif |
| OLD | NEW |