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 24 matching lines...) Expand all Loading... |
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 GlyphBuffer() : m_hasVerticalAdvances(false) { } | 45 bool isEmpty() const { return m_fontData.isEmpty(); } |
| 46 virtual bool hasOffsets() const { return false; } |
| 47 unsigned size() const { return m_fontData.size(); } |
46 | 48 |
47 bool isEmpty() const { return m_fontData.isEmpty(); } | 49 virtual void clear() |
48 unsigned size() const { return m_fontData.size(); } | |
49 bool hasVerticalAdvances() const { return m_hasVerticalAdvances; } | |
50 | |
51 void clear() | |
52 { | 50 { |
53 m_fontData.clear(); | 51 m_fontData.clear(); |
54 m_glyphs.clear(); | 52 m_glyphs.clear(); |
55 m_advances.clear(); | 53 m_advances.clear(); |
56 m_hasVerticalAdvances = false; | |
57 } | 54 } |
58 | 55 |
59 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } | 56 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } |
60 const FloatSize* advances(unsigned from) const { return m_advances.data() +
from; } | 57 const float* advances(unsigned from) const { return m_advances.data() + from
; } |
61 | |
62 const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[i
ndex]; } | 58 const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[i
ndex]; } |
63 | 59 |
64 Glyph glyphAt(unsigned index) const | 60 Glyph glyphAt(unsigned index) const |
65 { | 61 { |
66 return m_glyphs[index]; | 62 return m_glyphs[index]; |
67 } | 63 } |
68 | 64 |
69 FloatSize advanceAt(unsigned index) const | 65 float advanceAt(unsigned index) const |
70 { | 66 { |
71 return m_advances[index]; | 67 return m_advances[index]; |
72 } | 68 } |
73 | 69 |
74 void add(Glyph glyph, const SimpleFontData* font, float width) | 70 void add(Glyph glyph, const SimpleFontData* font, float width) |
75 { | 71 { |
76 m_fontData.append(font); | 72 m_fontData.append(font); |
77 m_glyphs.append(glyph); | 73 m_glyphs.append(glyph); |
78 m_advances.append(FloatSize(width, 0)); | 74 m_advances.append(width); |
79 } | 75 } |
80 | 76 |
81 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& advance) | 77 virtual void reverse() |
82 { | |
83 m_fontData.append(font); | |
84 m_glyphs.append(glyph); | |
85 m_advances.append(advance); | |
86 if (advance.height()) | |
87 m_hasVerticalAdvances = true; | |
88 } | |
89 | |
90 void reverse() | |
91 { | 78 { |
92 m_fontData.reverse(); | 79 m_fontData.reverse(); |
93 m_glyphs.reverse(); | 80 m_glyphs.reverse(); |
94 m_advances.reverse(); | 81 m_advances.reverse(); |
95 } | 82 } |
96 | 83 |
97 void setAdvanceWidth(unsigned index, float newWidth) | |
98 { | |
99 m_advances[index].setWidth(newWidth); | |
100 } | |
101 | |
102 void expandLastAdvance(float width) | 84 void expandLastAdvance(float width) |
103 { | 85 { |
104 ASSERT(!isEmpty()); | 86 ASSERT(!isEmpty()); |
105 FloatSize& lastAdvance = m_advances.last(); | 87 float& lastAdvance = m_advances.last(); |
106 lastAdvance.setWidth(lastAdvance.width() + width); | 88 lastAdvance += width; |
| 89 } |
| 90 |
| 91 protected: |
| 92 Vector<const SimpleFontData*, 2048> m_fontData; |
| 93 Vector<Glyph, 2048> m_glyphs; |
| 94 Vector<float, 2048> m_advances; |
| 95 }; |
| 96 |
| 97 |
| 98 class GlyphBufferWithOffsets : public GlyphBuffer { |
| 99 public: |
| 100 virtual bool hasOffsets() const OVERRIDE { return true; } |
| 101 |
| 102 virtual void clear() OVERRIDE |
| 103 { |
| 104 GlyphBuffer::clear(); |
| 105 m_offsets.clear(); |
| 106 } |
| 107 |
| 108 const FloatSize* offsets(unsigned from) const { return m_offsets.data() + fr
om; } |
| 109 |
| 110 FloatSize offsetAt(unsigned index) const |
| 111 { |
| 112 return m_offsets[index]; |
| 113 } |
| 114 |
| 115 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& offset, f
loat advance) |
| 116 { |
| 117 m_fontData.append(font); |
| 118 m_glyphs.append(glyph); |
| 119 m_offsets.append(offset); |
| 120 m_advances.append(advance); |
| 121 } |
| 122 |
| 123 virtual void reverse() OVERRIDE |
| 124 { |
| 125 GlyphBuffer::reverse(); |
| 126 m_offsets.reverse(); |
107 } | 127 } |
108 | 128 |
109 private: | 129 private: |
110 Vector<const SimpleFontData*, 2048> m_fontData; | 130 void add(Glyph glyph, const SimpleFontData* font, float width) |
111 Vector<Glyph, 2048> m_glyphs; | 131 { |
112 Vector<FloatSize, 2048> m_advances; | 132 ASSERT_NOT_REACHED(); |
113 bool m_hasVerticalAdvances; | 133 } |
| 134 |
| 135 Vector<FloatSize, 1024> m_offsets; |
114 }; | 136 }; |
115 | 137 |
116 } // namespace blink | 138 } // namespace blink |
117 | 139 |
118 #endif | 140 #endif |
OLD | NEW |