2 * Copyright (C) 2003, 2006, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Holger Hans Peter Freyther
4 * Copyright (C) 2014 Google Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef WidthIterator_h
24 #define WidthIterator_h
26 #include "platform/PlatformExport.h"
27 #include "platform/fonts/SVGGlyph.h"
28 #include "platform/text/TextRun.h"
29 #include "wtf/HashSet.h"
30 #include "wtf/unicode/Unicode.h"
31 #include "wtf/Vector.h"
41 struct PLATFORM_EXPORT WidthIterator {
42 WTF_MAKE_FAST_ALLOCATED;
44 WidthIterator(const Font*, const TextRun&, HashSet<const SimpleFontData*>* fallbackFonts = 0, bool accountForGlyphBounds = false, bool forTextEmphasis = false);
46 unsigned advance(int to, GlyphBuffer* = 0);
47 bool advanceOneCharacter(float& width);
49 float maxGlyphBoundingBoxY() const { ASSERT(m_accountForGlyphBounds); return m_maxGlyphBoundingBoxY; }
50 float minGlyphBoundingBoxY() const { ASSERT(m_accountForGlyphBounds); return m_minGlyphBoundingBoxY; }
51 float firstGlyphOverflow() const { ASSERT(m_accountForGlyphBounds); return m_firstGlyphOverflow; }
52 float lastGlyphOverflow() const { ASSERT(m_accountForGlyphBounds); return m_lastGlyphOverflow; }
54 const TextRun& run() const { return m_run; }
55 float runWidthSoFar() const { return m_runWidthSoFar; }
58 Vector<SVGGlyph::ArabicForm>& arabicForms() { return m_arabicForms; }
65 unsigned m_currentCharacter;
66 float m_runWidthSoFar;
68 float m_expansionPerOpportunity;
69 bool m_isAfterExpansion;
72 Vector<SVGGlyph::ArabicForm> m_arabicForms;
76 struct CharacterData {
78 unsigned clusterLength;
82 GlyphData glyphDataForCharacter(CharacterData&, bool normalizeSpace = false);
83 float characterWidth(UChar32, const GlyphData&) const;
84 void cacheFallbackFont(const SimpleFontData*, const SimpleFontData* primaryFont);
85 float adjustSpacing(float, const CharacterData&, const SimpleFontData&, GlyphBuffer*);
86 void updateGlyphBounds(const GlyphData&, float width, bool firstCharacter);
88 template <typename TextIterator>
89 unsigned advanceInternal(TextIterator&, GlyphBuffer*);
91 HashSet<const SimpleFontData*>* m_fallbackFonts;
92 float m_maxGlyphBoundingBoxY;
93 float m_minGlyphBoundingBoxY;
94 float m_firstGlyphOverflow;
95 float m_lastGlyphOverflow;
97 bool m_accountForGlyphBounds : 1;
98 bool m_forTextEmphasis : 1;