| Flutter Impeller |

paragraph_builder.cc
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 #include "impeller/toolkit/interop/paragraph_builder.h"
6
7 #include "flutter/txt/src/skia/paragraph_builder_skia.h"
8 #include "impeller/base/validation.h"
9 #include "impeller/toolkit/interop/paragraph.h"
10
11 namespace impeller::interop {
12
13 ParagraphBuilder::ParagraphBuilder(ScopedObject<TypographyContext> context)
14 : context_(std::move(context)) {}
15
16 ParagraphBuilder::~ParagraphBuilder() = default;
17
18 bool ParagraphBuilder::IsValid() const {
19 return !!context_;
20 }
21
22 void ParagraphBuilder::PushStyle(const ParagraphStyle& style) {
23 GetBuilder(style.GetParagraphStyle())->PushStyle(style.CreateTextStyle());
24 }
25
26 void ParagraphBuilder::PopStyle() {
27 GetBuilder()->Pop();
28 }
29
30 void ParagraphBuilder::AddText(const uint8_t* data, size_t byte_length) {
31 GetBuilder()->AddText(data, byte_length);
32 }
33
34 ScopedObject<Paragraph> ParagraphBuilder::Build(Scalar width) const {
35 auto txt_paragraph = GetBuilder()->Build();
36 if (!txt_paragraph) {
37 return nullptr;
38 }
39 txt_paragraph->Layout(width);
40 return Create<Paragraph>(std::move(txt_paragraph));
41 }
42
43 const std::unique_ptr<txt::ParagraphBuilder>& ParagraphBuilder::GetBuilder(
44 const txt::ParagraphStyle& style) const {
45 if (lazy_builder_) {
46 return lazy_builder_;
47 }
48 lazy_builder_ = std::make_unique<txt::ParagraphBuilderSkia>(
49 style, //
50 context_->GetFontCollection(), //
51 true // is impeller enabled
52 );
53 return lazy_builder_;
54 }
55
56 const std::unique_ptr<txt::ParagraphBuilder>& ParagraphBuilder::GetBuilder()
57 const {
58 static txt::ParagraphStyle kDefaultStyle;
59 return GetBuilder(kDefaultStyle);
60 }
61
62 } // namespace impeller::interop
impeller::interop::ParagraphBuilder::ParagraphBuilder
ParagraphBuilder(ScopedObject< TypographyContext > context)
Definition: paragraph_builder.cc:13
impeller::interop::ParagraphBuilder::PopStyle
void PopStyle()
Definition: paragraph_builder.cc:26
impeller::interop::ParagraphBuilder::~ParagraphBuilder
~ParagraphBuilder() override
impeller::interop::ParagraphBuilder::IsValid
bool IsValid() const
Definition: paragraph_builder.cc:18
impeller::interop::ParagraphBuilder::Build
ScopedObject< Paragraph > Build(Scalar width) const
Definition: paragraph_builder.cc:34
impeller::interop::ParagraphBuilder::PushStyle
void PushStyle(const ParagraphStyle &style)
Definition: paragraph_builder.cc:22
impeller::interop::ParagraphBuilder::AddText
void AddText(const uint8_t *data, size_t byte_length)
Definition: paragraph_builder.cc:30
impeller::interop::ParagraphStyle
Definition: paragraph_style.h:17
impeller::interop::ParagraphStyle::CreateTextStyle
txt::TextStyle CreateTextStyle() const
Definition: paragraph_style.cc:58
impeller::interop::ParagraphStyle::GetParagraphStyle
const txt::ParagraphStyle & GetParagraphStyle() const
Definition: paragraph_style.cc:70
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop
Definition: context_gles.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:18
std
Definition: comparable.h:95
paragraph.h
paragraph_builder.h
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:67
validation.h