initial import
[vuplus_webkit] / Source / WebCore / platform / graphics / WidthIterator.h
1 /*
2  * Copyright (C) 2003, 2006, 2008, 2011 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Holger Hans Peter Freyther
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21
22 #ifndef WidthIterator_h
23 #define WidthIterator_h
24
25 #include "SVGGlyph.h"
26 #include <wtf/HashSet.h>
27 #include <wtf/Vector.h>
28 #include <wtf/unicode/Unicode.h>
29
30 namespace WebCore {
31
32 class Font;
33 class GlyphBuffer;
34 class SimpleFontData;
35 class TextRun;
36 struct GlyphData;
37
38 struct WidthIterator {
39     WidthIterator(const Font*, const TextRun&, HashSet<const SimpleFontData*>* fallbackFonts = 0, bool accountForGlyphBounds = false, bool forTextEmphasis = false);
40
41     unsigned advance(int to, GlyphBuffer* = 0);
42     bool advanceOneCharacter(float& width, GlyphBuffer* = 0);
43
44     float maxGlyphBoundingBoxY() const { ASSERT(m_accountForGlyphBounds); return m_maxGlyphBoundingBoxY; }
45     float minGlyphBoundingBoxY() const { ASSERT(m_accountForGlyphBounds); return m_minGlyphBoundingBoxY; }
46     float firstGlyphOverflow() const { ASSERT(m_accountForGlyphBounds); return m_firstGlyphOverflow; }
47     float lastGlyphOverflow() const { ASSERT(m_accountForGlyphBounds); return m_lastGlyphOverflow; }
48
49     const TextRun& run() const { return m_run; }
50     float runWidthSoFar() const { return m_runWidthSoFar; }
51
52 #if ENABLE(SVG_FONTS)
53     String lastGlyphName() const { return m_lastGlyphName; }
54     void setLastGlyphName(const String& name) { m_lastGlyphName = name; }
55     Vector<SVGGlyph::ArabicForm>& arabicForms() { return m_arabicForms; }
56 #endif
57
58     const Font* m_font;
59
60     const TextRun& m_run;
61
62     unsigned m_currentCharacter;
63     float m_runWidthSoFar;
64     float m_expansion;
65     float m_expansionPerOpportunity;
66     bool m_isAfterExpansion;
67     float m_finalRoundingWidth;
68
69 #if ENABLE(SVG_FONTS)
70     String m_lastGlyphName;
71     Vector<SVGGlyph::ArabicForm> m_arabicForms;
72 #endif
73
74 private:
75     GlyphData glyphDataForCharacter(UChar32, bool mirror, int currentCharacter, unsigned& advanceLength);
76
77     HashSet<const SimpleFontData*>* m_fallbackFonts;
78     bool m_accountForGlyphBounds;
79     float m_maxGlyphBoundingBoxY;
80     float m_minGlyphBoundingBoxY;
81     float m_firstGlyphOverflow;
82     float m_lastGlyphOverflow;
83     bool m_forTextEmphasis;
84 };
85
86 }
87
88 #endif