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 16 matching lines...) Expand all Loading... |
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/FloatSize.h" |
35 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
36 | 36 |
37 #if OS(MACOSX) | |
38 #include <ApplicationServices/ApplicationServices.h> | |
39 #endif | |
40 | |
41 namespace WebCore { | 37 namespace WebCore { |
42 | 38 |
43 class SimpleFontData; | 39 class SimpleFontData; |
44 | 40 |
45 // CG uses CGSize instead of FloatSize so that the result of advances() | |
46 // can be passed directly to CGContextShowGlyphsWithAdvances in FontMac.mm | |
47 #if OS(MACOSX) | |
48 struct GlyphBufferAdvance : CGSize { | |
49 public: | |
50 GlyphBufferAdvance(CGSize size) : CGSize(size) | |
51 { | |
52 } | |
53 | |
54 void setWidth(CGFloat width) { this->CGSize::width = width; } | |
55 CGFloat width() const { return this->CGSize::width; } | |
56 CGFloat height() const { return this->CGSize::height; } | |
57 }; | |
58 #else | |
59 typedef FloatSize GlyphBufferAdvance; | |
60 #endif | |
61 | |
62 class GlyphBuffer { | 41 class GlyphBuffer { |
63 public: | 42 public: |
64 bool isEmpty() const { return m_fontData.isEmpty(); } | 43 bool isEmpty() const { return m_fontData.isEmpty(); } |
65 unsigned size() const { return m_fontData.size(); } | 44 unsigned size() const { return m_fontData.size(); } |
66 | 45 |
67 void clear() | 46 void clear() |
68 { | 47 { |
69 m_fontData.clear(); | 48 m_fontData.clear(); |
70 m_glyphs.clear(); | 49 m_glyphs.clear(); |
71 m_advances.clear(); | 50 m_advances.clear(); |
72 } | 51 } |
73 | 52 |
74 Glyph* glyphs(unsigned from) { return m_glyphs.data() + from; } | 53 Glyph* glyphs(unsigned from) { return m_glyphs.data() + from; } |
75 GlyphBufferAdvance* advances(unsigned from) { return m_advances.data() + fro
m; } | 54 FloatSize* advances(unsigned from) { return m_advances.data() + from; } |
76 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } | 55 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } |
77 const GlyphBufferAdvance* advances(unsigned from) const { return m_advances.
data() + from; } | 56 const FloatSize* advances(unsigned from) const { return m_advances.data() +
from; } |
78 | 57 |
79 const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[i
ndex]; } | 58 const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[i
ndex]; } |
80 | 59 |
81 Glyph glyphAt(unsigned index) const | 60 Glyph glyphAt(unsigned index) const |
82 { | 61 { |
83 return m_glyphs[index]; | 62 return m_glyphs[index]; |
84 } | 63 } |
85 | 64 |
86 FloatSize advanceAt(unsigned index) const | 65 FloatSize advanceAt(unsigned index) const |
87 { | 66 { |
88 #if OS(MACOSX) | 67 return m_advances[index]; |
89 return FloatSize(m_advances[index]); | |
90 #else | |
91 return m_advances[index]; | |
92 #endif | |
93 } | 68 } |
94 | 69 |
95 void add(Glyph glyph, const SimpleFontData* font, float width) | 70 void add(Glyph glyph, const SimpleFontData* font, float width) |
96 { | 71 { |
97 m_fontData.append(font); | 72 add(glyph, font, FloatSize(width, 0)); |
98 m_glyphs.append(glyph); | |
99 | |
100 #if OS(MACOSX) | |
101 CGSize advance = { width, 0 }; | |
102 m_advances.append(advance); | |
103 #else | |
104 m_advances.append(FloatSize(width, 0)); | |
105 #endif | |
106 } | 73 } |
107 | 74 |
108 void add(Glyph glyph, const SimpleFontData* font, GlyphBufferAdvance advance
) | 75 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& advance) |
109 { | 76 { |
110 m_fontData.append(font); | 77 m_fontData.append(font); |
111 m_glyphs.append(glyph); | 78 m_glyphs.append(glyph); |
112 m_advances.append(advance); | 79 m_advances.append(advance); |
113 } | 80 } |
114 | 81 |
115 void reverse(unsigned from, unsigned length) | 82 void reverse(unsigned from, unsigned length) |
116 { | 83 { |
117 for (unsigned i = from, end = from + length - 1; i < end; ++i, --end) | 84 for (unsigned i = from, end = from + length - 1; i < end; ++i, --end) |
118 swap(i, end); | 85 swap(i, end); |
119 } | 86 } |
120 | 87 |
121 void expandLastAdvance(float width) | 88 void expandLastAdvance(float width) |
122 { | 89 { |
123 ASSERT(!isEmpty()); | 90 ASSERT(!isEmpty()); |
124 GlyphBufferAdvance& lastAdvance = m_advances.last(); | 91 FloatSize& lastAdvance = m_advances.last(); |
125 lastAdvance.setWidth(lastAdvance.width() + width); | 92 lastAdvance.setWidth(lastAdvance.width() + width); |
126 } | 93 } |
127 | 94 |
128 private: | 95 private: |
129 void swap(unsigned index1, unsigned index2) | 96 void swap(unsigned index1, unsigned index2) |
130 { | 97 { |
131 const SimpleFontData* f = m_fontData[index1]; | 98 const SimpleFontData* f = m_fontData[index1]; |
132 m_fontData[index1] = m_fontData[index2]; | 99 m_fontData[index1] = m_fontData[index2]; |
133 m_fontData[index2] = f; | 100 m_fontData[index2] = f; |
134 | 101 |
135 Glyph g = m_glyphs[index1]; | 102 Glyph g = m_glyphs[index1]; |
136 m_glyphs[index1] = m_glyphs[index2]; | 103 m_glyphs[index1] = m_glyphs[index2]; |
137 m_glyphs[index2] = g; | 104 m_glyphs[index2] = g; |
138 | 105 |
139 GlyphBufferAdvance s = m_advances[index1]; | 106 FloatSize s = m_advances[index1]; |
140 m_advances[index1] = m_advances[index2]; | 107 m_advances[index1] = m_advances[index2]; |
141 m_advances[index2] = s; | 108 m_advances[index2] = s; |
142 } | 109 } |
143 | 110 |
144 Vector<const SimpleFontData*, 2048> m_fontData; | 111 Vector<const SimpleFontData*, 2048> m_fontData; |
145 Vector<Glyph, 2048> m_glyphs; | 112 Vector<Glyph, 2048> m_glyphs; |
146 Vector<GlyphBufferAdvance, 2048> m_advances; | 113 Vector<FloatSize, 2048> m_advances; |
147 }; | 114 }; |
148 | 115 |
149 } | 116 } |
150 #endif | 117 #endif |
OLD | NEW |