Flutter Engine
paint_record.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIB_TXT_SRC_PAINT_RECORD_H_
18 #define LIB_TXT_SRC_PAINT_RECORD_H_
19 
20 #include "flutter/fml/logging.h"
21 #include "flutter/fml/macros.h"
22 #include "placeholder_run.h"
23 #include "text_style.h"
24 #include "third_party/skia/include/core/SkFontMetrics.h"
25 #include "third_party/skia/include/core/SkTextBlob.h"
26 
27 namespace txt {
28 
29 // PaintRecord holds the layout data after Paragraph::Layout() is called. This
30 // stores all necessary offsets, blobs, metrics, and more for Skia to draw the
31 // text.
32 class PaintRecord {
33  public:
34  PaintRecord() = delete;
35 
36  ~PaintRecord();
37 
39  SkPoint offset,
40  sk_sp<SkTextBlob> text,
41  SkFontMetrics metrics,
42  size_t line,
43  double x_start,
44  double x_end,
45  bool is_ghost);
46 
47  PaintRecord(TextStyle style,
48  SkPoint offset,
49  sk_sp<SkTextBlob> text,
50  SkFontMetrics metrics,
51  size_t line,
52  double x_start,
53  double x_end,
54  bool is_ghost,
55  PlaceholderRun* placeholder_run);
56 
57  PaintRecord(TextStyle style,
58  sk_sp<SkTextBlob> text,
59  SkFontMetrics metrics,
60  size_t line,
61  double x_start,
62  double x_end,
63  bool is_ghost);
64 
65  PaintRecord(PaintRecord&& other);
66 
68 
69  SkPoint offset() const { return offset_; }
70 
71  void SetOffset(SkPoint pt);
72 
73  SkTextBlob* text() const { return text_.get(); }
74 
75  const SkFontMetrics& metrics() const { return metrics_; }
76 
77  const TextStyle& style() const { return style_; }
78 
79  size_t line() const { return line_; }
80 
81  double x_start() const { return x_start_; }
82  double x_end() const { return x_end_; }
83  double GetRunWidth() const { return x_end_ - x_start_; }
84 
85  PlaceholderRun* GetPlaceholderRun() const { return placeholder_run_; }
86 
87  bool isGhost() const { return is_ghost_; }
88 
89  bool isPlaceholder() const { return placeholder_run_ == nullptr; }
90 
91  private:
92  TextStyle style_;
93  // offset_ is the overall offset of the origin of the SkTextBlob.
94  SkPoint offset_;
95  // SkTextBlob stores the glyphs and coordinates to draw them.
96  sk_sp<SkTextBlob> text_;
97  // FontMetrics stores the measurements of the font used.
98  SkFontMetrics metrics_;
99  size_t line_;
100  double x_start_ = 0.0f;
101  double x_end_ = 0.0f;
102  // 'Ghost' runs represent trailing whitespace. 'Ghost' runs should not have
103  // decorations painted on them and do not impact layout of visible glyphs.
104  bool is_ghost_ = false;
105  // Stores the corresponding PlaceholderRun that the record corresponds to.
106  // When this is nullptr, then the record is of normal text and does not
107  // represent an inline placeholder.
108  PlaceholderRun* placeholder_run_ = nullptr;
109 
110  FML_DISALLOW_COPY_AND_ASSIGN(PaintRecord);
111 };
112 
113 } // namespace txt
114 
115 #endif // LIB_TXT_SRC_PAINT_RECORD_H_
bool isGhost() const
Definition: paint_record.h:87
void SetOffset(SkPoint pt)
bool isPlaceholder() const
Definition: paint_record.h:89
double x_end() const
Definition: paint_record.h:82
PaintRecord()=delete
PaintRecord & operator=(PaintRecord &&other)
Definition: paint_record.cc:88
double GetRunWidth() const
Definition: paint_record.h:83
const SkFontMetrics & metrics() const
Definition: paint_record.h:75
size_t line() const
Definition: paint_record.h:79
double x_start() const
Definition: paint_record.h:81
SkPoint offset() const
Definition: paint_record.h:69
SkTextBlob * text() const
Definition: paint_record.h:73
const TextStyle & style() const
Definition: paint_record.h:77
PlaceholderRun * GetPlaceholderRun() const
Definition: paint_record.h:85