OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
3 * Copyright (C) 2008 Holger Hans Peter Freyther | 3 * Copyright (C) 2008 Holger Hans Peter Freyther |
4 * Copyright (C) 2014 Google Inc. All rights reserved. | 4 * Copyright (C) 2014 Google Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "platform/fonts/Font.h" | 27 #include "platform/fonts/Font.h" |
28 #include "platform/fonts/FontPlatformFeatures.h" | 28 #include "platform/fonts/FontPlatformFeatures.h" |
29 #include "platform/fonts/GlyphBuffer.h" | 29 #include "platform/fonts/GlyphBuffer.h" |
30 #include "platform/fonts/Latin1TextIterator.h" | 30 #include "platform/fonts/Latin1TextIterator.h" |
31 #include "platform/fonts/SimpleFontData.h" | 31 #include "platform/fonts/SimpleFontData.h" |
32 #include "platform/text/SurrogatePairAwareTextIterator.h" | 32 #include "platform/text/SurrogatePairAwareTextIterator.h" |
33 #include "wtf/MathExtras.h" | 33 #include "wtf/MathExtras.h" |
34 | 34 |
35 using namespace WTF; | 35 using namespace WTF; |
36 using namespace Unicode; | 36 using namespace Unicode; |
37 using namespace std; | |
38 | 37 |
39 namespace blink { | 38 namespace blink { |
40 | 39 |
41 WidthIterator::WidthIterator(const Font* font, const TextRun& run, HashSet<const
SimpleFontData*>* fallbackFonts, bool accountForGlyphBounds, bool forTextEmphas
is) | 40 WidthIterator::WidthIterator(const Font* font, const TextRun& run, HashSet<const
SimpleFontData*>* fallbackFonts, bool accountForGlyphBounds, bool forTextEmphas
is) |
42 : m_font(font) | 41 : m_font(font) |
43 , m_run(run) | 42 , m_run(run) |
44 , m_currentCharacter(0) | 43 , m_currentCharacter(0) |
45 , m_runWidthSoFar(0) | 44 , m_runWidthSoFar(0) |
46 , m_isAfterExpansion(!run.allowsLeadingExpansion()) | 45 , m_isAfterExpansion(!run.allowsLeadingExpansion()) |
47 , m_fallbackFonts(fallbackFonts) | 46 , m_fallbackFonts(fallbackFonts) |
48 , m_maxGlyphBoundingBoxY(numeric_limits<float>::min()) | 47 , m_maxGlyphBoundingBoxY(std::numeric_limits<float>::min()) |
49 , m_minGlyphBoundingBoxY(numeric_limits<float>::max()) | 48 , m_minGlyphBoundingBoxY(std::numeric_limits<float>::max()) |
50 , m_firstGlyphOverflow(0) | 49 , m_firstGlyphOverflow(0) |
51 , m_lastGlyphOverflow(0) | 50 , m_lastGlyphOverflow(0) |
52 , m_accountForGlyphBounds(accountForGlyphBounds) | 51 , m_accountForGlyphBounds(accountForGlyphBounds) |
53 , m_forTextEmphasis(forTextEmphasis) | 52 , m_forTextEmphasis(forTextEmphasis) |
54 { | 53 { |
55 // If the padding is non-zero, count the number of spaces in the run | 54 // If the padding is non-zero, count the number of spaces in the run |
56 // and divide that by the padding for per space addition. | 55 // and divide that by the padding for per space addition. |
57 m_expansion = m_run.expansion(); | 56 m_expansion = m_run.expansion(); |
58 if (!m_expansion) | 57 if (!m_expansion) |
59 m_expansionPerOpportunity = 0; | 58 m_expansionPerOpportunity = 0; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 171 |
173 return width; | 172 return width; |
174 } | 173 } |
175 | 174 |
176 void WidthIterator::updateGlyphBounds(const GlyphData& glyphData, float width, b
ool firstCharacter) | 175 void WidthIterator::updateGlyphBounds(const GlyphData& glyphData, float width, b
ool firstCharacter) |
177 { | 176 { |
178 ASSERT(glyphData.fontData); | 177 ASSERT(glyphData.fontData); |
179 FloatRect bounds = glyphData.fontData->boundsForGlyph(glyphData.glyph); | 178 FloatRect bounds = glyphData.fontData->boundsForGlyph(glyphData.glyph); |
180 | 179 |
181 if (firstCharacter) | 180 if (firstCharacter) |
182 m_firstGlyphOverflow = max<float>(0, -bounds.x()); | 181 m_firstGlyphOverflow = std::max<float>(0, -bounds.x()); |
183 m_lastGlyphOverflow = max<float>(0, bounds.maxX() - width); | 182 m_lastGlyphOverflow = std::max<float>(0, bounds.maxX() - width); |
184 m_maxGlyphBoundingBoxY = max(m_maxGlyphBoundingBoxY, bounds.maxY()); | 183 m_maxGlyphBoundingBoxY = std::max(m_maxGlyphBoundingBoxY, bounds.maxY()); |
185 m_minGlyphBoundingBoxY = min(m_minGlyphBoundingBoxY, bounds.y()); | 184 m_minGlyphBoundingBoxY = std::min(m_minGlyphBoundingBoxY, bounds.y()); |
186 } | 185 } |
187 | 186 |
188 template <typename TextIterator> | 187 template <typename TextIterator> |
189 unsigned WidthIterator::advanceInternal(TextIterator& textIterator, GlyphBuffer*
glyphBuffer) | 188 unsigned WidthIterator::advanceInternal(TextIterator& textIterator, GlyphBuffer*
glyphBuffer) |
190 { | 189 { |
191 bool hasExtraSpacing = (m_font->fontDescription().letterSpacing() || m_font-
>fontDescription().wordSpacing() || m_expansion) | 190 bool hasExtraSpacing = (m_font->fontDescription().letterSpacing() || m_font-
>fontDescription().wordSpacing() || m_expansion) |
192 && !m_run.spacingDisabled(); | 191 && !m_run.spacingDisabled(); |
193 | 192 |
194 const SimpleFontData* primaryFont = m_font->primaryFont(); | 193 const SimpleFontData* primaryFont = m_font->primaryFont(); |
195 const SimpleFontData* lastFontData = primaryFont; | 194 const SimpleFontData* lastFontData = primaryFont; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 float initialWidth = m_runWidthSoFar; | 257 float initialWidth = m_runWidthSoFar; |
259 | 258 |
260 if (!advance(m_currentCharacter + 1)) | 259 if (!advance(m_currentCharacter + 1)) |
261 return false; | 260 return false; |
262 | 261 |
263 width = m_runWidthSoFar - initialWidth; | 262 width = m_runWidthSoFar - initialWidth; |
264 return true; | 263 return true; |
265 } | 264 } |
266 | 265 |
267 } // namespace blink | 266 } // namespace blink |
OLD | NEW |