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