• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "flutter/lib/ui/text/paragraph.h"
6 
7 #include "flutter/common/settings.h"
8 #include "flutter/common/task_runners.h"
9 #include "flutter/fml/logging.h"
10 #include "flutter/fml/task_runner.h"
11 
12 namespace flutter {
13 
14 IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph);
15 
16 #define FOR_EACH_BINDING(V)             \
17   V(Paragraph, width)                   \
18   V(Paragraph, height)                  \
19   V(Paragraph, longestLine)             \
20   V(Paragraph, minIntrinsicWidth)       \
21   V(Paragraph, maxIntrinsicWidth)       \
22   V(Paragraph, alphabeticBaseline)      \
23   V(Paragraph, ideographicBaseline)     \
24   V(Paragraph, didExceedMaxLines)       \
25   V(Paragraph, layout)                  \
26   V(Paragraph, paint)                   \
27   V(Paragraph, getWordBoundary)         \
28   V(Paragraph, getRectsForRange)        \
29   V(Paragraph, getRectsForPlaceholders) \
30   V(Paragraph, getPositionForOffset)
31 
DART_BIND_ALL(Paragraph,FOR_EACH_BINDING)32 DART_BIND_ALL(Paragraph, FOR_EACH_BINDING)
33 
34 Paragraph::Paragraph(std::unique_ptr<txt::Paragraph> paragraph)
35     : m_paragraph(std::move(paragraph)) {}
36 
37 Paragraph::~Paragraph() = default;
38 
GetAllocationSize()39 size_t Paragraph::GetAllocationSize() {
40   // We don't have an accurate accounting of the paragraph's memory consumption,
41   // so return a fixed size to indicate that its impact is more than the size
42   // of the Paragraph class.
43   return 2000;
44 }
45 
width()46 double Paragraph::width() {
47   return m_paragraph->GetMaxWidth();
48 }
49 
height()50 double Paragraph::height() {
51   return m_paragraph->GetHeight();
52 }
53 
longestLine()54 double Paragraph::longestLine() {
55   return m_paragraph->GetLongestLine();
56 }
57 
minIntrinsicWidth()58 double Paragraph::minIntrinsicWidth() {
59   return m_paragraph->GetMinIntrinsicWidth();
60 }
61 
maxIntrinsicWidth()62 double Paragraph::maxIntrinsicWidth() {
63   return m_paragraph->GetMaxIntrinsicWidth();
64 }
65 
alphabeticBaseline()66 double Paragraph::alphabeticBaseline() {
67   return m_paragraph->GetAlphabeticBaseline();
68 }
69 
ideographicBaseline()70 double Paragraph::ideographicBaseline() {
71   return m_paragraph->GetIdeographicBaseline();
72 }
73 
didExceedMaxLines()74 bool Paragraph::didExceedMaxLines() {
75   return m_paragraph->DidExceedMaxLines();
76 }
77 
layout(double width)78 void Paragraph::layout(double width) {
79   m_paragraph->Layout(width);
80 }
81 
paint(Canvas * canvas,double x,double y)82 void Paragraph::paint(Canvas* canvas, double x, double y) {
83   SkCanvas* sk_canvas = canvas->canvas();
84   if (!sk_canvas)
85     return;
86   m_paragraph->Paint(sk_canvas, x, y);
87 }
88 
getRectsForRange(unsigned start,unsigned end,unsigned boxHeightStyle,unsigned boxWidthStyle)89 std::vector<TextBox> Paragraph::getRectsForRange(unsigned start,
90                                                  unsigned end,
91                                                  unsigned boxHeightStyle,
92                                                  unsigned boxWidthStyle) {
93   std::vector<TextBox> result;
94   std::vector<txt::Paragraph::TextBox> boxes = m_paragraph->GetRectsForRange(
95       start, end, static_cast<txt::Paragraph::RectHeightStyle>(boxHeightStyle),
96       static_cast<txt::Paragraph::RectWidthStyle>(boxWidthStyle));
97   for (const txt::Paragraph::TextBox& box : boxes) {
98     result.emplace_back(box.rect, static_cast<TextDirection>(box.direction));
99   }
100   return result;
101 }
102 
getRectsForPlaceholders()103 std::vector<TextBox> Paragraph::getRectsForPlaceholders() {
104   std::vector<TextBox> result;
105   std::vector<txt::Paragraph::TextBox> boxes =
106       m_paragraph->GetRectsForPlaceholders();
107   for (const txt::Paragraph::TextBox& box : boxes) {
108     result.emplace_back(box.rect, static_cast<TextDirection>(box.direction));
109   }
110   return result;
111 }
112 
getPositionForOffset(double dx,double dy)113 Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) {
114   return nullptr;
115 }
116 
getWordBoundary(unsigned offset)117 Dart_Handle Paragraph::getWordBoundary(unsigned offset) {
118   return nullptr;
119 }
120 
121 }  // namespace flutter
122