| 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 // Creates a new RunInfo instance representing a subset of the current run. |
| 102 RunInfo* createSubRun(unsigned start, unsigned end) { |
| 103 DCHECK(end > start); |
| 104 unsigned numberOfCharacters = std::min(end - start, m_numCharacters); |
| 105 |
| 106 // This ends up looping over the glyphs twice if we don't know the glyph |
| 107 // count up front. Once to count the number of glyphs and allocate the new |
| 108 // RunInfo object and then a second time to copy the glyphs over. |
| 109 // TODO: Compared to the cost of allocation and copying the extra loop is |
| 110 // probably fine but we might want to try to eliminate it if we can. |
| 111 unsigned numberOfGlyphs; |
| 112 if (start == 0 && end == m_numCharacters) { |
| 113 numberOfGlyphs = m_glyphData.size(); |
| 114 } else { |
| 115 numberOfGlyphs = 0; |
| 116 forEachGlyphInRange( |
| 117 0, m_startIndex + start, m_startIndex + end, 0, |
| 118 [&](const HarfBuzzRunGlyphData&, float, uint16_t) -> bool { |
| 119 numberOfGlyphs++; |
| 120 return true; |
| 121 }); |
| 122 } |
| 123 |
| 124 RunInfo* run = |
| 125 new RunInfo(m_fontData.get(), m_direction, m_script, |
| 126 m_startIndex + start, numberOfGlyphs, numberOfCharacters); |
| 127 |
| 128 unsigned subGlyphIndex = 0; |
| 129 float totalAdvance = 0; |
| 130 forEachGlyphInRange( |
| 131 0, m_startIndex + start, m_startIndex + end, 0, |
| 132 [&](const HarfBuzzRunGlyphData& glyphData, float, uint16_t) -> bool { |
| 133 HarfBuzzRunGlyphData& subGlyph = run->m_glyphData[subGlyphIndex++]; |
| 134 subGlyph.glyph = glyphData.glyph; |
| 135 subGlyph.characterIndex = glyphData.characterIndex - start; |
| 136 subGlyph.advance = glyphData.advance; |
| 137 subGlyph.offset = glyphData.offset; |
| 138 totalAdvance += glyphData.advance; |
| 139 return true; |
| 140 }); |
| 141 |
| 142 run->m_width = totalAdvance; |
| 143 run->m_numCharacters = numberOfCharacters; |
| 144 return run; |
| 145 } |
| 146 |
| 101 // Iterates over, and applies the functor to all the glyphs in this run. | 147 // Iterates over, and applies the functor to all the glyphs in this run. |
| 102 // Also tracks (and returns) a seeded total advance. | 148 // Also tracks (and returns) a seeded total advance. |
| 103 // | 149 // |
| 104 // Functor signature: | 150 // Functor signature: |
| 105 // | 151 // |
| 106 // bool func(const HarfBuzzRunGlyphData& glyphData, float totalAdvance) | 152 // bool func(const HarfBuzzRunGlyphData& glyphData, float totalAdvance) |
| 107 // | 153 // |
| 108 // where the returned bool signals whether iteration should continue (true) | 154 // where the returned bool signals whether iteration should continue (true) |
| 109 // or stop (false). | 155 // or stop (false). |
| 110 template <typename Func> | 156 template <typename Func> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 hb_script_t m_script; | 202 hb_script_t m_script; |
| 157 Vector<HarfBuzzRunGlyphData> m_glyphData; | 203 Vector<HarfBuzzRunGlyphData> m_glyphData; |
| 158 unsigned m_startIndex; | 204 unsigned m_startIndex; |
| 159 unsigned m_numCharacters; | 205 unsigned m_numCharacters; |
| 160 float m_width; | 206 float m_width; |
| 161 }; | 207 }; |
| 162 | 208 |
| 163 } // namespace blink | 209 } // namespace blink |
| 164 | 210 |
| 165 #endif // ShapeResultInlineHeaders_h | 211 #endif // ShapeResultInlineHeaders_h |
| OLD | NEW |