| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. | 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 size_t glyphToCharacterIndex(size_t i) const { | 92 size_t glyphToCharacterIndex(size_t i) const { |
| 93 return m_startIndex + m_glyphData[i].characterIndex; | 93 return m_startIndex + m_glyphData[i].characterIndex; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // For memory reporting. | 96 // For memory reporting. |
| 97 size_t byteSize() const { | 97 size_t byteSize() const { |
| 98 return sizeof(this) + m_glyphData.size() * sizeof(HarfBuzzRunGlyphData); | 98 return sizeof(this) + m_glyphData.size() * sizeof(HarfBuzzRunGlyphData); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Iterates over, and applies the functor to all the glyphs in this run. |
| 102 // Also tracks (and returns) a seeded total advance. |
| 103 // |
| 104 // Functor signature: |
| 105 // |
| 106 // bool func(const HarfBuzzRunGlyphData& glyphData, float totalAdvance) |
| 107 // |
| 108 // where the returned bool signals whether iteration should continue (true) |
| 109 // or stop (false). |
| 110 template <typename Func> |
| 111 float forEachGlyph(float initialAdvance, Func func) const { |
| 112 float totalAdvance = initialAdvance; |
| 113 |
| 114 for (const auto& glyphData : m_glyphData) { |
| 115 if (!func(glyphData, totalAdvance)) |
| 116 break; |
| 117 totalAdvance += glyphData.advance; |
| 118 } |
| 119 |
| 120 return totalAdvance; |
| 121 } |
| 122 |
| 123 // Same as the above, except it only applies the functor to glyphs in the |
| 124 // specified range, and stops after the range. |
| 125 template <typename Func> |
| 126 float forEachGlyphInRange(float initialAdvance, |
| 127 unsigned from, |
| 128 unsigned to, |
| 129 unsigned indexOffset, |
| 130 Func func) const { |
| 131 return forEachGlyph( |
| 132 initialAdvance, |
| 133 [&](const HarfBuzzRunGlyphData& glyphData, float totalAdvance) -> bool { |
| 134 const uint16_t characterIndex = |
| 135 m_startIndex + glyphData.characterIndex + indexOffset; |
| 136 |
| 137 if (characterIndex < from) { |
| 138 // Glyph out-of-range; before the range (and must continue |
| 139 // accumulating advance) in LTR. |
| 140 return !rtl(); |
| 141 } |
| 142 |
| 143 if (characterIndex >= to) { |
| 144 // Glyph out-of-range; before the range (and must continue |
| 145 // accumulating advance) in RTL. |
| 146 return rtl(); |
| 147 } |
| 148 |
| 149 // Glyph in range; apply functor. |
| 150 return func(glyphData, totalAdvance, characterIndex); |
| 151 }); |
| 152 } |
| 153 |
| 101 RefPtr<SimpleFontData> m_fontData; | 154 RefPtr<SimpleFontData> m_fontData; |
| 102 hb_direction_t m_direction; | 155 hb_direction_t m_direction; |
| 103 hb_script_t m_script; | 156 hb_script_t m_script; |
| 104 Vector<HarfBuzzRunGlyphData> m_glyphData; | 157 Vector<HarfBuzzRunGlyphData> m_glyphData; |
| 105 unsigned m_startIndex; | 158 unsigned m_startIndex; |
| 106 unsigned m_numCharacters; | 159 unsigned m_numCharacters; |
| 107 float m_width; | 160 float m_width; |
| 108 }; | 161 }; |
| 109 | 162 |
| 110 } // namespace blink | 163 } // namespace blink |
| 111 | 164 |
| 112 #endif // ShapeResultInlineHeaders_h | 165 #endif // ShapeResultInlineHeaders_h |
| OLD | NEW |