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