2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef GLYPH_BUFFER_H
30 #define GLYPH_BUFFER_H
32 // MAX_GLYPH_EXPANSION is the maximum numbers of glyphs that may be
33 // use to represent a single Unicode code point.
34 #define MAX_GLYPH_EXPANSION 4
35 #define GLYPH_BUFFER_SIZE 2048
38 #include <ApplicationServices/ApplicationServices.h>
39 #elif PLATFORM(WIN) || PLATFORM(GDK)
41 #include "FloatSize.h"
44 #include <wtf/Vector.h>
48 typedef unsigned short Glyph;
52 typedef Glyph GlyphBufferGlyph;
53 typedef CGSize GlyphBufferAdvance;
54 #elif PLATFORM(WIN) || PLATFORM(GDK)
55 typedef cairo_glyph_t GlyphBufferGlyph;
56 typedef FloatSize GlyphBufferAdvance;
64 bool isEmpty() const { return m_fontData.isEmpty(); }
65 int size() const { return m_fontData.size(); }
74 GlyphBufferGlyph* glyphs(int from) const { return ((GlyphBufferGlyph*)m_glyphs.data()) + from; }
75 GlyphBufferAdvance* advances(int from) const { return ((GlyphBufferAdvance*)m_advances.data()) + from; }
77 const FontData* fontDataAt(int index) const { return m_fontData[index]; }
79 void swap(int index1, int index2)
81 const FontData* f = m_fontData[index1];
82 m_fontData[index1] = m_fontData[index2];
83 m_fontData[index2] = f;
85 GlyphBufferGlyph g = m_glyphs[index1];
86 m_glyphs[index1] = m_glyphs[index2];
89 GlyphBufferAdvance s = m_advances[index1];
90 m_advances[index1] = m_advances[index2];
91 m_advances[index2] = s;
94 Glyph glyphAt(int index) const
97 return m_glyphs[index];
98 #elif PLATFORM(WIN) || PLATFORM(GDK)
99 return m_glyphs[index].index;
103 float advanceAt(int index) const
106 return m_advances[index].width;
107 #elif PLATFORM(WIN) || PLATFORM(GDK)
108 return m_advances[index].width();
112 void add(Glyph glyph, const FontData* font, float width)
114 m_fontData.append(font);
116 m_glyphs.append(glyph);
118 advance.width = width;
120 m_advances.append(advance);
121 #elif PLATFORM(WIN) || PLATFORM(GDK)
122 cairo_glyph_t cairoGlyph;
123 cairoGlyph.index = glyph;
125 m_glyphs.append(cairoGlyph);
126 m_advances.append(FloatSize(width, 0));
131 Vector<const FontData*, GLYPH_BUFFER_SIZE> m_fontData;
132 Vector<GlyphBufferGlyph, GLYPH_BUFFER_SIZE> m_glyphs;
133 Vector<GlyphBufferAdvance, GLYPH_BUFFER_SIZE> m_advances;