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

source code of flutter_engine/flutter/lib/ui/text/paragraph_builder.h