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_BUILDER_SKIA_H_ |
18 | #define LIB_TXT_SRC_PARAGRAPH_BUILDER_SKIA_H_ |
19 | |
20 | #include "txt/paragraph_builder.h" |
21 | |
22 | #include "flutter/display_list/dl_paint.h" |
23 | #include "third_party/skia/modules/skparagraph/include/ParagraphBuilder.h" |
24 | |
25 | namespace txt { |
26 | |
27 | // Implementation of ParagraphBuilder based on Skia's text layout module. |
28 | class ParagraphBuilderSkia : public ParagraphBuilder { |
29 | public: |
30 | ParagraphBuilderSkia(const ParagraphStyle& style, |
31 | std::shared_ptr<FontCollection> font_collection); |
32 | |
33 | virtual ~ParagraphBuilderSkia(); |
34 | |
35 | virtual void PushStyle(const TextStyle& style) override; |
36 | virtual void Pop() override; |
37 | virtual const TextStyle& PeekStyle() override; |
38 | virtual void AddText(const std::u16string& text) override; |
39 | virtual void AddPlaceholder(PlaceholderRun& span) override; |
40 | virtual std::unique_ptr<Paragraph> Build() override; |
41 | |
42 | private: |
43 | skia::textlayout::ParagraphPainter::PaintID CreatePaintID( |
44 | const flutter::DlPaint& dl_paint); |
45 | skia::textlayout::ParagraphStyle TxtToSkia(const ParagraphStyle& txt); |
46 | skia::textlayout::TextStyle TxtToSkia(const TextStyle& txt); |
47 | |
48 | std::shared_ptr<skia::textlayout::ParagraphBuilder> builder_; |
49 | TextStyle base_style_; |
50 | std::stack<TextStyle> txt_style_stack_; |
51 | std::vector<flutter::DlPaint> dl_paints_; |
52 | }; |
53 | |
54 | } // namespace txt |
55 | |
56 | #endif // LIB_TXT_SRC_PARAGRAPH_BUILDER_SKIA_H_ |
57 | |