Chromium Code Reviews| 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 const float* offsets(unsigned from) const | |
|
eae
2014/11/04 15:33:26
Using a float* to represent both the x and y offse
f(malita)
2014/11/04 21:52:22
Done.
| |
| 67 { | |
| 68 ASSERT(from < size()); | |
| 69 return m_offsets.data() + (hasVerticalOffsets() ? from * 2 : from); | |
| 70 } | |
| 52 | 71 |
| 53 const SimpleFontData* fontDataAt(unsigned index) const | 72 const SimpleFontData* fontDataAt(unsigned index) const |
| 54 { | 73 { |
| 74 ASSERT(index < size()); | |
| 55 return m_fontData[index]; | 75 return m_fontData[index]; |
| 56 } | 76 } |
| 57 | 77 |
| 58 Glyph glyphAt(unsigned index) const | 78 Glyph glyphAt(unsigned index) const |
| 59 { | 79 { |
| 80 ASSERT(index < size()); | |
| 60 return m_glyphs[index]; | 81 return m_glyphs[index]; |
| 61 } | 82 } |
| 62 | 83 |
| 63 float advanceAt(unsigned index) const | 84 float xOffsetAt(unsigned index) const |
| 64 { | 85 { |
| 65 return m_advances[index]; | 86 ASSERT(index < size()); |
| 87 return hasVerticalOffsets() ? m_offsets[index * 2] : m_offsets[index]; | |
| 88 | |
| 66 } | 89 } |
| 67 | 90 |
| 68 void add(Glyph glyph, const SimpleFontData* font, float width) | 91 float yOffsetAt(unsigned index) const |
| 69 { | 92 { |
| 70 // should not mix offset/advance-only glyphs | 93 ASSERT(index < size()); |
| 71 ASSERT(!hasOffsets()); | 94 ASSERT(hasVerticalOffsets()); |
| 95 return m_offsets[index * 2 + 1]; | |
| 96 } | |
| 97 | |
| 98 void add(Glyph glyph, const SimpleFontData* font, float x) | |
| 99 { | |
| 100 // cannot mix x-only/xy offsets | |
| 101 ASSERT(!hasVerticalOffsets()); | |
| 72 | 102 |
| 73 m_fontData.append(font); | 103 m_fontData.append(font); |
| 74 m_glyphs.append(glyph); | 104 m_glyphs.append(glyph); |
| 75 m_advances.append(width); | 105 m_offsets.append(x); |
| 76 } | 106 } |
| 77 | 107 |
| 78 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& offset, f loat advance) | 108 void add(Glyph glyph, const SimpleFontData* font, const FloatPoint& offset) |
| 79 { | 109 { |
| 80 // should not mix offset/advance-only glyphs | 110 // cannot mix x-only/xy offsets |
| 81 ASSERT(size() == m_offsets.size()); | 111 ASSERT(isEmpty() || hasVerticalOffsets()); |
| 82 | 112 |
| 83 m_fontData.append(font); | 113 m_fontData.append(font); |
| 84 m_glyphs.append(glyph); | 114 m_glyphs.append(glyph); |
| 85 m_offsets.append(offset); | 115 m_offsets.append(offset.x()); |
| 86 m_advances.append(advance); | 116 m_offsets.append(offset.y()); |
| 87 } | 117 } |
| 88 | 118 |
| 89 void reverse() | 119 void reverseForSimpleRTL(float afterOffset, float totalWidth) |
| 90 { | 120 { |
| 121 ASSERT(!hasVerticalOffsets()); | |
| 122 | |
| 123 if (isEmpty()) | |
| 124 return; | |
| 125 | |
| 91 m_fontData.reverse(); | 126 m_fontData.reverse(); |
| 92 m_glyphs.reverse(); | 127 m_glyphs.reverse(); |
| 93 m_advances.reverse(); | |
| 94 } | |
| 95 | 128 |
| 96 void expandLastAdvance(float width) | 129 // | .. [X0 X1 .. Xn] .. | |
| 97 { | 130 // ^ ^ ^ |
| 98 ASSERT(!isEmpty()); | 131 // 0 afterOffset totalWidth |
| 99 float& lastAdvance = m_advances.last(); | 132 // |
| 100 lastAdvance += width; | 133 // The input buffer is shaped using RTL advances, but since the right ed ge is unknown at |
| 134 // that time, offsets are computed as if the advances were LTR. This met hod performs the | |
| 135 // required adjustments by reconstructing advances and positioning offse ts in an RTL | |
| 136 // progression. | |
| 137 | |
| 138 // FIXME: we should get rid of this (idea: store negative offsets while shaping, | |
| 139 // and adjust the initial advance accordingly -> should yield cor rectly positioned | |
| 140 // RTL glyphs without any post-shape munging). | |
| 141 ASSERT_WITH_SECURITY_IMPLICATION(!m_offsets.isEmpty()); | |
| 142 float x = totalWidth - m_offsets[0]; | |
| 143 for (unsigned i = 0; i + 1 < m_offsets.size(); ++i) { | |
| 144 float advance = m_offsets[i + 1] - m_offsets[i]; | |
| 145 ASSERT(advance >= 0); | |
| 146 x -= advance; | |
| 147 m_offsets[i] = x; | |
| 148 } | |
| 149 float lastAdvance = afterOffset - m_offsets.last(); | |
| 150 ASSERT(lastAdvance >= 0); | |
| 151 m_offsets.last() = x - lastAdvance; | |
| 152 | |
| 153 m_offsets.reverse(); | |
| 101 } | 154 } |
| 102 | 155 |
| 103 protected: | 156 protected: |
| 104 Vector<const SimpleFontData*, 2048> m_fontData; | 157 Vector<const SimpleFontData*, 2048> m_fontData; |
| 105 Vector<Glyph, 2048> m_glyphs; | 158 Vector<Glyph, 2048> m_glyphs; |
| 106 Vector<float, 2048> m_advances; | 159 Vector<float, 2048> m_offsets; |
| 107 Vector<FloatSize, 1024> m_offsets; | |
| 108 }; | 160 }; |
| 109 | 161 |
| 110 } // namespace blink | 162 } // namespace blink |
| 111 | 163 |
| 112 #endif | 164 #endif |
| OLD | NEW |