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 
6 
7 #include "flutter/txt/src/skia/paragraph_builder_skia.h"
10 
11 namespace impeller::interop {
12 
14  : context_(std::move(context)) {}
15 
17 
19  return !!context_;
20 }
21 
23  GetBuilder(style.GetParagraphStyle())->PushStyle(style.CreateTextStyle());
24 }
25 
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 
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
ParagraphBuilder(ScopedObject< TypographyContext > context)
ScopedObject< Paragraph > Build(Scalar width) const
void PushStyle(const ParagraphStyle &style)
void AddText(const uint8_t *data, size_t byte_length)
txt::TextStyle CreateTextStyle() const
const txt::ParagraphStyle & GetParagraphStyle() const
float Scalar
Definition: scalar.h:19
Definition: comparable.h:95
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:68