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