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