2 * Copyright (C) 2006, 2009 Apple 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.
32 #include "FloatSize.h"
33 #include <wtf/UnusedParam.h>
34 #include <wtf/Vector.h>
38 #include <CoreText/CoreText.h>
40 #include <CoreGraphics/CoreGraphics.h>
49 typedef unsigned short Glyph
;
53 // FIXME: Why does Cairo use such a huge struct instead of just an offset into an array?
54 typedef cairo_glyph_t GlyphBufferGlyph
;
56 typedef Glyph GlyphBufferGlyph
;
59 // CG uses CGSize instead of FloatSize so that the result of advances()
60 // can be passed directly to CGContextShowGlyphsWithAdvances in FontMac.mm
62 typedef CGSize GlyphBufferAdvance
;
64 typedef FloatSize GlyphBufferAdvance
;
69 bool isEmpty() const { return m_fontData
.isEmpty(); }
70 int size() const { return m_fontData
.size(); }
82 GlyphBufferGlyph
* glyphs(int from
) { return m_glyphs
.data() + from
; }
83 GlyphBufferAdvance
* advances(int from
) { return m_advances
.data() + from
; }
84 const GlyphBufferGlyph
* glyphs(int from
) const { return m_glyphs
.data() + from
; }
85 const GlyphBufferAdvance
* advances(int from
) const { return m_advances
.data() + from
; }
87 const SimpleFontData
* fontDataAt(int index
) const { return m_fontData
[index
]; }
89 void swap(int index1
, int index2
)
91 const SimpleFontData
* f
= m_fontData
[index1
];
92 m_fontData
[index1
] = m_fontData
[index2
];
93 m_fontData
[index2
] = f
;
95 GlyphBufferGlyph g
= m_glyphs
[index1
];
96 m_glyphs
[index1
] = m_glyphs
[index2
];
99 GlyphBufferAdvance s
= m_advances
[index1
];
100 m_advances
[index1
] = m_advances
[index2
];
101 m_advances
[index2
] = s
;
104 FloatSize offset
= m_offsets
[index1
];
105 m_offsets
[index1
] = m_offsets
[index2
];
106 m_offsets
[index2
] = offset
;
110 Glyph
glyphAt(int index
) const
113 return m_glyphs
[index
].index
;
115 return m_glyphs
[index
];
119 float advanceAt(int index
) const
122 return m_advances
[index
].width
;
124 return m_advances
[index
].width();
128 FloatSize
offsetAt(int index
) const
131 return m_offsets
[index
];
138 void add(Glyph glyph
, const SimpleFontData
* font
, float width
, const FloatSize
* offset
= 0)
140 m_fontData
.append(font
);
143 cairo_glyph_t cairoGlyph
;
144 cairoGlyph
.index
= glyph
;
145 m_glyphs
.append(cairoGlyph
);
147 m_glyphs
.append(glyph
);
151 CGSize advance
= { width
, 0 };
152 m_advances
.append(advance
);
154 m_advances
.append(FloatSize(width
, 0));
159 m_offsets
.append(*offset
);
161 m_offsets
.append(FloatSize());
163 UNUSED_PARAM(offset
);
167 void add(Glyph glyph
, const SimpleFontData
* font
, GlyphBufferAdvance advance
)
169 m_fontData
.append(font
);
171 cairo_glyph_t cairoGlyph
;
172 cairoGlyph
.index
= glyph
;
173 m_glyphs
.append(cairoGlyph
);
175 m_glyphs
.append(glyph
);
178 m_advances
.append(advance
);
182 Vector
<const SimpleFontData
*, 2048> m_fontData
;
183 Vector
<GlyphBufferGlyph
, 2048> m_glyphs
;
184 Vector
<GlyphBufferAdvance
, 2048> m_advances
;
186 Vector
<FloatSize
, 2048> m_offsets
;