| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ShapingLineBreaker_h | 5 #ifndef ShapingLineBreaker_h |
| 6 #define ShapingLineBreaker_h | 6 #define ShapingLineBreaker_h |
| 7 | 7 |
| 8 #include "platform/LayoutUnit.h" | 8 #include "platform/LayoutUnit.h" |
| 9 #include "platform/PlatformExport.h" | 9 #include "platform/PlatformExport.h" |
| 10 #include "platform/wtf/text/AtomicString.h" | 10 #include "platform/wtf/text/AtomicString.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class Font; | 14 class Font; |
| 15 class ShapeResult; | 15 class ShapeResult; |
| 16 class HarfBuzzShaper; | 16 class HarfBuzzShaper; |
| 17 class LazyLineBreakIterator; | |
| 18 enum class LineBreakType; | 17 enum class LineBreakType; |
| 19 | 18 |
| 20 // Shapes a line of text by finding the ideal break position as indicated by the | 19 // Shapes a line of text by finding the ideal break position as indicated by the |
| 21 // available space and the shape results for the entire paragraph. Once an ideal | 20 // available space and the shape results for the entire paragraph. Once an ideal |
| 22 // break position has been found the text is scanned backwards until a valid and | 21 // break position has been found the text is scanned backwards until a valid and |
| 23 // and appropriate break opportunity is identified. Unless the break opportunity | 22 // and appropriate break opportunity is identified. Unless the break opportunity |
| 24 // is at a safe-to-break boundary (as identified by HarfBuzz) the beginning and/ | 23 // is at a safe-to-break boundary (as identified by HarfBuzz) the beginning and/ |
| 25 // or end of the line is reshaped to account for differences caused by breaking. | 24 // or end of the line is reshaped to account for differences caused by breaking. |
| 26 // | 25 // |
| 27 // This allows for significantly faster and more efficient line breaking by only | 26 // This allows for significantly faster and more efficient line breaking by only |
| 28 // reshaping when absolutely necessarily and by only evaluating likely candidate | 27 // reshaping when absolutely necessarily and by only evaluating likely candidate |
| 29 // break opportunities instead of measuring and evaluating all possible options. | 28 // break opportunities instead of measuring and evaluating all possible options. |
| 30 class PLATFORM_EXPORT ShapingLineBreaker final { | 29 class PLATFORM_EXPORT ShapingLineBreaker final { |
| 31 public: | 30 public: |
| 32 ShapingLineBreaker(const HarfBuzzShaper*, | 31 ShapingLineBreaker(const HarfBuzzShaper*, |
| 33 const Font*, | 32 const Font*, |
| 34 const ShapeResult*, | 33 const ShapeResult*, |
| 35 const AtomicString, | 34 const AtomicString, |
| 36 LineBreakType); | 35 LineBreakType); |
| 37 ~ShapingLineBreaker() {} | 36 ~ShapingLineBreaker() {} |
| 38 | 37 |
| 39 // Shapes a line of text by finding a valid and appropriate break opportunity | 38 // Shapes a line of text by finding a valid and appropriate break opportunity |
| 40 // based on the shaping results for the entire paragraph. | 39 // based on the shaping results for the entire paragraph. |
| 41 // The output parameter breakOffset indicates the resulting break offset. | 40 // The output parameter breakOffset indicates the resulting break offset. |
| 42 PassRefPtr<ShapeResult> ShapeLine(unsigned start_offset, | 41 PassRefPtr<ShapeResult> ShapeLine(unsigned start_offset, |
| 43 LayoutUnit available_space, | 42 LayoutUnit available_space, |
| 44 unsigned* break_offset); | 43 unsigned* break_offset); |
| 45 | 44 |
| 46 private: | 45 private: |
| 47 unsigned PreviousBreakOpportunity(LazyLineBreakIterator*, | |
| 48 unsigned start, | |
| 49 unsigned offset); | |
| 50 unsigned NextBreakOpportunity(LazyLineBreakIterator*, unsigned offset); | |
| 51 | 46 |
| 52 const HarfBuzzShaper* shaper_; | 47 const HarfBuzzShaper* shaper_; |
| 53 const Font* font_; | 48 const Font* font_; |
| 54 const ShapeResult* result_; | 49 const ShapeResult* result_; |
| 55 const AtomicString locale_; | 50 const AtomicString locale_; |
| 56 LineBreakType break_type_; | 51 LineBreakType break_type_; |
| 57 String text_; | 52 String text_; |
| 58 }; | 53 }; |
| 59 | 54 |
| 60 } // namespace blink | 55 } // namespace blink |
| 61 | 56 |
| 62 #endif // ShapingLineBreaker_h | 57 #endif // ShapingLineBreaker_h |
| OLD | NEW |