Flutter Engine
paragraph_skia.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 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_PARAGRAPH_SKIA_H_
18 #define LIB_TXT_SRC_PARAGRAPH_SKIA_H_
19 
20 #include <optional>
21 
22 #include "txt/paragraph.h"
23 
24 #include "third_party/skia/modules/skparagraph/include/Paragraph.h"
25 
26 namespace txt {
27 
28 // Implementation of Paragraph based on Skia's text layout module.
29 class ParagraphSkia : public Paragraph {
30  public:
31  ParagraphSkia(std::unique_ptr<skia::textlayout::Paragraph> paragraph);
32 
33  virtual ~ParagraphSkia() = default;
34 
35  double GetMaxWidth() override;
36 
37  double GetHeight() override;
38 
39  double GetLongestLine() override;
40 
41  double GetMinIntrinsicWidth() override;
42 
43  double GetMaxIntrinsicWidth() override;
44 
45  double GetAlphabeticBaseline() override;
46 
47  double GetIdeographicBaseline() override;
48 
49  std::vector<LineMetrics>& GetLineMetrics() override;
50 
51  bool DidExceedMaxLines() override;
52 
53  void Layout(double width) override;
54 
55  void Paint(SkCanvas* canvas, double x, double y) override;
56 
57  std::vector<TextBox> GetRectsForRange(
58  size_t start,
59  size_t end,
60  RectHeightStyle rect_height_style,
61  RectWidthStyle rect_width_style) override;
62 
63  std::vector<TextBox> GetRectsForPlaceholders() override;
64 
66  double dy) override;
67 
68  Range<size_t> GetWordBoundary(size_t offset) override;
69 
70  private:
71  std::unique_ptr<skia::textlayout::Paragraph> paragraph_;
72  std::optional<std::vector<LineMetrics>> line_metrics_;
73  std::vector<TextStyle> line_metrics_styles_;
74 };
75 
76 } // namespace txt
77 
78 #endif // LIB_TXT_SRC_PARAGRAPH_SKIA_H_
Range< size_t > GetWordBoundary(size_t offset) override
double GetMaxIntrinsicWidth() override
bool DidExceedMaxLines() override
virtual ~ParagraphSkia()=default
double GetLongestLine() override
std::vector< TextBox > GetRectsForRange(size_t start, size_t end, RectHeightStyle rect_height_style, RectWidthStyle rect_width_style) override
std::vector< TextBox > GetRectsForPlaceholders() override
int32_t width
void Layout(double width) override
double GetHeight() override
double GetMaxWidth() override
double GetAlphabeticBaseline() override
double GetIdeographicBaseline() override
PositionWithAffinity GetGlyphPositionAtCoordinate(double dx, double dy) override
void Paint(SkCanvas *canvas, double x, double y) override
std::vector< LineMetrics > & GetLineMetrics() override
ParagraphSkia(std::unique_ptr< skia::textlayout::Paragraph > paragraph)
double GetMinIntrinsicWidth() override