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/text_box.h" 12 #include "flutter/third_party/txt/src/txt/paragraph.h" 13 14 namespace tonic { 15 class DartLibraryNatives; 16 } // namespace tonic 17 18 namespace flutter { 19 20 class Paragraph : public RefCountedDartWrappable<Paragraph> { 21 DEFINE_WRAPPERTYPEINFO(); 22 FML_FRIEND_MAKE_REF_COUNTED(Paragraph); 23 24 public: Create(std::unique_ptr<txt::Paragraph> paragraph)25 static fml::RefPtr<Paragraph> Create( 26 std::unique_ptr<txt::Paragraph> paragraph) { 27 return fml::MakeRefCounted<Paragraph>(std::move(paragraph)); 28 } 29 30 ~Paragraph() override; 31 32 double width(); 33 double height(); 34 double longestLine(); 35 double minIntrinsicWidth(); 36 double maxIntrinsicWidth(); 37 double alphabeticBaseline(); 38 double ideographicBaseline(); 39 bool didExceedMaxLines(); 40 41 void layout(double width); 42 void paint(Canvas* canvas, double x, double y); 43 44 std::vector<TextBox> getRectsForRange(unsigned start, 45 unsigned end, 46 unsigned boxHeightStyle, 47 unsigned boxWidthStyle); 48 std::vector<TextBox> getRectsForPlaceholders(); 49 Dart_Handle getPositionForOffset(double dx, double dy); 50 Dart_Handle getWordBoundary(unsigned offset); 51 52 size_t GetAllocationSize() override; 53 54 static void RegisterNatives(tonic::DartLibraryNatives* natives); 55 56 private: 57 std::unique_ptr<txt::Paragraph> m_paragraph; 58 59 explicit Paragraph(std::unique_ptr<txt::Paragraph> paragraph); 60 }; 61 62 } // namespace flutter 63 64 #endif // FLUTTER_LIB_UI_TEXT_PARAGRAPH_H_ 65