Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
paragraph_builder.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_PARAGRAPH_BUILDER_H_
18#define LIB_TXT_SRC_PARAGRAPH_BUILDER_H_
19
20#include <memory>
21#include <string>
22
23#include "flutter/fml/macros.h"
24#include "font_collection.h"
25#include "paragraph.h"
26#include "paragraph_style.h"
27#include "placeholder_run.h"
28#include "text_style.h"
29
30namespace txt {
31
33 public:
34 static std::unique_ptr<ParagraphBuilder> CreateSkiaBuilder(
35 const ParagraphStyle& style,
36 std::shared_ptr<FontCollection> font_collection,
37 const bool impeller_enabled);
38
39 virtual ~ParagraphBuilder() = default;
40
41 // Push a style to the stack. The corresponding text added with AddText will
42 // use the top-most style.
43 virtual void PushStyle(const TextStyle& style) = 0;
44
45 // Remove a style from the stack. Useful to apply different styles to chunks
46 // of text such as bolding.
47 // Example:
48 // builder.PushStyle(normal_style);
49 // builder.AddText("Hello this is normal. ");
50 //
51 // builder.PushStyle(bold_style);
52 // builder.AddText("And this is BOLD. ");
53 //
54 // builder.Pop();
55 // builder.AddText(" Back to normal again.");
56 virtual void Pop() = 0;
57
58 // Returns the last TextStyle on the stack.
59 virtual const TextStyle& PeekStyle() = 0;
60
61 // Adds text to the builder. Forms the proper runs to use the upper-most style
62 // on the style_stack_;
63 virtual void AddText(const std::u16string& text) = 0;
64
65 // Pushes the information required to leave an open space, where Flutter may
66 // draw a custom placeholder into.
67 //
68 // Internally, this method adds a single object replacement character (0xFFFC)
69 // and emplaces a new PlaceholderRun instance to the vector of inline
70 // placeholders.
71 virtual void AddPlaceholder(PlaceholderRun& span) = 0;
72
73 // Constructs a Paragraph object that can be used to layout and paint the text
74 // to a SkCanvas.
75 virtual std::unique_ptr<Paragraph> Build() = 0;
76
77 protected:
78 ParagraphBuilder() = default;
79
80 private:
82};
83
84} // namespace txt
85
86#endif // LIB_TXT_SRC_PARAGRAPH_BUILDER_H_
virtual std::unique_ptr< Paragraph > Build()=0
virtual void AddText(const std::u16string &text)=0
virtual void AddPlaceholder(PlaceholderRun &span)=0
virtual void Pop()=0
virtual void PushStyle(const TextStyle &style)=0
ParagraphBuilder()=default
static std::unique_ptr< ParagraphBuilder > CreateSkiaBuilder(const ParagraphStyle &style, std::shared_ptr< FontCollection > font_collection, const bool impeller_enabled)
Creates a |ParagraphBuilder| based on Skia's text layout module.
virtual const TextStyle & PeekStyle()=0
virtual ~ParagraphBuilder()=default
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::u16string text