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_BUILDER_H_ 6 #define FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_H_ 7 8 #include <memory> 9 10 #include "flutter/lib/ui/dart_wrapper.h" 11 #include "flutter/lib/ui/painting/paint.h" 12 #include "flutter/lib/ui/text/paragraph.h" 13 #include "flutter/third_party/txt/src/txt/paragraph_builder.h" 14 15 namespace tonic { 16 class DartLibraryNatives; 17 } // namespace tonic 18 19 namespace flutter { 20 21 class Paragraph; 22 23 class ParagraphBuilder : public RefCountedDartWrappable<ParagraphBuilder> { 24 DEFINE_WRAPPERTYPEINFO(); 25 FML_FRIEND_MAKE_REF_COUNTED(ParagraphBuilder); 26 27 public: 28 static fml::RefPtr<ParagraphBuilder> create( 29 tonic::Int32List& encoded, 30 Dart_Handle strutData, 31 const std::string& fontFamily, 32 const std::vector<std::string>& strutFontFamilies, 33 double fontSize, 34 double height, 35 const std::u16string& ellipsis, 36 const std::string& locale); 37 38 ~ParagraphBuilder() override; 39 40 void pushStyle(tonic::Int32List& encoded, 41 const std::vector<std::string>& fontFamilies, 42 double fontSize, 43 double letterSpacing, 44 double wordSpacing, 45 double height, 46 double decorationThickness, 47 const std::string& locale, 48 Dart_Handle background_objects, 49 Dart_Handle background_data, 50 Dart_Handle foreground_objects, 51 Dart_Handle foreground_data, 52 Dart_Handle shadows_data, 53 Dart_Handle font_features_data); 54 55 void pop(); 56 57 Dart_Handle addText(const std::u16string& text); 58 59 // Pushes the information requried to leave an open space, where Flutter may 60 // draw a custom placeholder into. 61 // 62 // Internally, this method adds a single object replacement character (0xFFFC) 63 // and emplaces a new PlaceholderRun instance to the vector of inline 64 // placeholders. 65 Dart_Handle addPlaceholder(double width, 66 double height, 67 unsigned alignment, 68 double baseline_offset, 69 unsigned baseline); 70 71 fml::RefPtr<Paragraph> build(); 72 73 static void RegisterNatives(tonic::DartLibraryNatives* natives); 74 75 private: 76 explicit ParagraphBuilder(tonic::Int32List& encoded, 77 Dart_Handle strutData, 78 const std::string& fontFamily, 79 const std::vector<std::string>& strutFontFamilies, 80 double fontSize, 81 double height, 82 const std::u16string& ellipsis, 83 const std::string& locale); 84 85 std::unique_ptr<txt::ParagraphBuilder> m_paragraphBuilder; 86 }; 87 88 } // namespace flutter 89 90 #endif // FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_H_ 91