• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2009, 2011 Apple Inc. All rights reserved.
3  * Copyright (C) 2007-2008 Torch Mobile Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
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
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.
28  */
29 
30 #ifndef GlyphBuffer_h
31 #define GlyphBuffer_h
32 
33 #include "platform/fonts/Glyph.h"
34 #include "platform/geometry/FloatSize.h"
35 #include "platform/heap/Heap.h"
36 #include "wtf/Vector.h"
37 
38 namespace blink {
39 
40 class SimpleFontData;
41 
42 class GlyphBuffer {
43     STACK_ALLOCATED();
44 public:
GlyphBuffer()45     GlyphBuffer() : m_hasVerticalAdvances(false) { }
46 
isEmpty()47     bool isEmpty() const { return m_fontData.isEmpty(); }
size()48     unsigned size() const { return m_fontData.size(); }
hasVerticalAdvances()49     bool hasVerticalAdvances() const { return m_hasVerticalAdvances; }
50 
clear()51     void clear()
52     {
53         m_fontData.clear();
54         m_glyphs.clear();
55         m_advances.clear();
56         m_hasVerticalAdvances = false;
57     }
58 
glyphs(unsigned from)59     const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; }
advances(unsigned from)60     const FloatSize* advances(unsigned from) const { return m_advances.data() + from; }
61 
fontDataAt(unsigned index)62     const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[index]; }
63 
glyphAt(unsigned index)64     Glyph glyphAt(unsigned index) const
65     {
66         return m_glyphs[index];
67     }
68 
advanceAt(unsigned index)69     FloatSize advanceAt(unsigned index) const
70     {
71         return m_advances[index];
72     }
73 
add(Glyph glyph,const SimpleFontData * font,float width)74     void add(Glyph glyph, const SimpleFontData* font, float width)
75     {
76         m_fontData.append(font);
77         m_glyphs.append(glyph);
78         m_advances.append(FloatSize(width, 0));
79     }
80 
add(Glyph glyph,const SimpleFontData * font,const FloatSize & advance)81     void add(Glyph glyph, const SimpleFontData* font, const FloatSize& advance)
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 
reverse()90     void reverse()
91     {
92         m_fontData.reverse();
93         m_glyphs.reverse();
94         m_advances.reverse();
95     }
96 
setAdvanceWidth(unsigned index,float newWidth)97     void setAdvanceWidth(unsigned index, float newWidth)
98     {
99         m_advances[index].setWidth(newWidth);
100     }
101 
expandLastAdvance(float width)102     void expandLastAdvance(float width)
103     {
104         ASSERT(!isEmpty());
105         FloatSize& lastAdvance = m_advances.last();
106         lastAdvance.setWidth(lastAdvance.width() + width);
107     }
108 
109 private:
110     Vector<const SimpleFontData*, 2048> m_fontData;
111     Vector<Glyph, 2048> m_glyphs;
112     Vector<FloatSize, 2048> m_advances;
113     bool m_hasVerticalAdvances;
114 };
115 
116 } // namespace blink
117 
118 #endif
119