| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
|---|---|
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef FLUTTER_LIB_UI_TEXT_PARAGRAPH_H_ |
| 6 | #define FLUTTER_LIB_UI_TEXT_PARAGRAPH_H_ |
| 7 | |
| 8 | #include "flutter/fml/message_loop.h" |
| 9 | #include "flutter/lib/ui/dart_wrapper.h" |
| 10 | #include "flutter/lib/ui/painting/canvas.h" |
| 11 | #include "flutter/lib/ui/text/line_metrics.h" |
| 12 | #include "flutter/lib/ui/text/text_box.h" |
| 13 | #include "flutter/third_party/txt/src/txt/paragraph.h" |
| 14 | |
| 15 | namespace flutter { |
| 16 | |
| 17 | class Paragraph : public RefCountedDartWrappable<Paragraph> { |
| 18 | DEFINE_WRAPPERTYPEINFO(); |
| 19 | FML_FRIEND_MAKE_REF_COUNTED(Paragraph); |
| 20 | |
| 21 | public: |
| 22 | static void Create(Dart_Handle paragraph_handle, |
| 23 | std::unique_ptr<txt::Paragraph> txt_paragraph) { |
| 24 | auto paragraph = fml::MakeRefCounted<Paragraph>(args: std::move(txt_paragraph)); |
| 25 | paragraph->AssociateWithDartWrapper(wrappable: paragraph_handle); |
| 26 | } |
| 27 | |
| 28 | ~Paragraph() override; |
| 29 | |
| 30 | double width(); |
| 31 | double height(); |
| 32 | double longestLine(); |
| 33 | double minIntrinsicWidth(); |
| 34 | double maxIntrinsicWidth(); |
| 35 | double alphabeticBaseline(); |
| 36 | double ideographicBaseline(); |
| 37 | bool didExceedMaxLines(); |
| 38 | |
| 39 | void layout(double width); |
| 40 | void paint(Canvas* canvas, double x, double y); |
| 41 | |
| 42 | tonic::Float32List getRectsForRange(unsigned start, |
| 43 | unsigned end, |
| 44 | unsigned boxHeightStyle, |
| 45 | unsigned boxWidthStyle); |
| 46 | tonic::Float32List getRectsForPlaceholders(); |
| 47 | Dart_Handle getPositionForOffset(double dx, double dy); |
| 48 | Dart_Handle getWordBoundary(unsigned offset); |
| 49 | Dart_Handle getLineBoundary(unsigned offset); |
| 50 | tonic::Float64List computeLineMetrics(); |
| 51 | |
| 52 | void dispose(); |
| 53 | |
| 54 | private: |
| 55 | std::unique_ptr<txt::Paragraph> m_paragraph; |
| 56 | |
| 57 | explicit Paragraph(std::unique_ptr<txt::Paragraph> paragraph); |
| 58 | }; |
| 59 | |
| 60 | } // namespace flutter |
| 61 | |
| 62 | #endif // FLUTTER_LIB_UI_TEXT_PARAGRAPH_H_ |
| 63 |
