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 <unicode/umachine.h> |
26 | #include <wtf/HashSet.h> |
27 | #include <wtf/Vector.h> |
28 | |
29 | namespace WebCore { |
30 | |
31 | class FontCascade; |
32 | class GlyphBuffer; |
33 | class Font; |
34 | class TextRun; |
35 | struct GlyphData; |
36 | struct OriginalAdvancesForCharacterTreatedAsSpace; |
37 | |
38 | typedef Vector<std::pair<int, OriginalAdvancesForCharacterTreatedAsSpace>, 64> CharactersTreatedAsSpace; |
39 | |
40 | struct WidthIterator { |
41 | WTF_MAKE_FAST_ALLOCATED; |
42 | public: |
43 | WidthIterator(const FontCascade*, const TextRun&, HashSet<const Font*>* fallbackFonts = 0, bool accountForGlyphBounds = false, bool forTextEmphasis = false); |
44 | |
45 | unsigned advance(unsigned to, GlyphBuffer*); |
46 | bool advanceOneCharacter(float& width, GlyphBuffer&); |
47 | |
48 | float maxGlyphBoundingBoxY() const { ASSERT(m_accountForGlyphBounds); return m_maxGlyphBoundingBoxY; } |
49 | float minGlyphBoundingBoxY() const { ASSERT(m_accountForGlyphBounds); return m_minGlyphBoundingBoxY; } |
50 | float firstGlyphOverflow() const { ASSERT(m_accountForGlyphBounds); return m_firstGlyphOverflow; } |
51 | float lastGlyphOverflow() const { ASSERT(m_accountForGlyphBounds); return m_lastGlyphOverflow; } |
52 | |
53 | const TextRun& run() const { return m_run; } |
54 | float runWidthSoFar() const { return m_runWidthSoFar; } |
55 | |
56 | const FontCascade* m_font; |
57 | |
58 | const TextRun& m_run; |
59 | |
60 | unsigned m_currentCharacter; |
61 | float m_runWidthSoFar; |
62 | float m_expansion; |
63 | float m_expansionPerOpportunity; |
64 | bool m_isAfterExpansion; |
65 | float m_finalRoundingWidth; |
66 | |
67 | private: |
68 | GlyphData glyphDataForCharacter(UChar32, bool mirror); |
69 | template <typename TextIterator> |
70 | inline unsigned advanceInternal(TextIterator&, GlyphBuffer*); |
71 | |
72 | enum class TransformsType { None, Forced, NotForced }; |
73 | TransformsType shouldApplyFontTransforms(const GlyphBuffer*, unsigned lastGlyphCount, UChar32 previousCharacter) const; |
74 | float applyFontTransforms(GlyphBuffer*, bool ltr, unsigned& lastGlyphCount, const Font*, UChar32 previousCharacter, bool force, CharactersTreatedAsSpace&); |
75 | |
76 | HashSet<const Font*>* m_fallbackFonts { nullptr }; |
77 | bool m_accountForGlyphBounds { false }; |
78 | bool m_enableKerning { false }; |
79 | bool m_requiresShaping { false }; |
80 | bool m_forTextEmphasis { false }; |
81 | float m_maxGlyphBoundingBoxY { std::numeric_limits<float>::min() }; |
82 | float m_minGlyphBoundingBoxY { std::numeric_limits<float>::max() }; |
83 | float m_firstGlyphOverflow { 0 }; |
84 | float m_lastGlyphOverflow { 0 }; |
85 | }; |
86 | |
87 | } |
88 | |
89 | #endif |
90 | |