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/third_party/txt/src/skia/paragraph_builder_skia.h"
10 
11 namespace impeller::interop {
12 
14  if (!context.IsValid()) {
15  VALIDATION_LOG << "Invalid typography context.";
16  return;
17  }
18 
19  static txt::ParagraphStyle kBaseStyle;
20 
21  builder_ = std::make_unique<txt::ParagraphBuilderSkia>(
22  kBaseStyle, //
23  context.GetFontCollection(), //
24  true // is impeller enabled
25  );
26 }
27 
29 
31  return !!builder_;
32 }
33 
35  builder_->PushStyle(style.CreateTextStyle());
36 }
37 
39  builder_->Pop();
40 }
41 
42 void ParagraphBuilder::AddText(const uint8_t* data, size_t byte_length) {
43  builder_->AddText(data, byte_length);
44 }
45 
47  auto txt_paragraph = builder_->Build();
48  if (!txt_paragraph) {
49  return nullptr;
50  }
51  txt_paragraph->Layout(width);
52  return Create<Paragraph>(std::move(txt_paragraph));
53 }
54 
55 } // namespace impeller::interop
paragraph.h
impeller::interop::ParagraphBuilder::~ParagraphBuilder
~ParagraphBuilder() override
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::interop::ParagraphBuilder::AddText
void AddText(const uint8_t *data, size_t byte_length)
Definition: paragraph_builder.cc:42
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop::TypographyContext::IsValid
bool IsValid() const
Definition: typography_context.cc:27
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
impeller::interop::ParagraphBuilder::Build
ScopedObject< Paragraph > Build(Scalar width) const
Definition: paragraph_builder.cc:46
impeller::interop
Definition: color_filter.cc:7
validation.h
impeller::interop::ParagraphBuilder::ParagraphBuilder
ParagraphBuilder(const TypographyContext &context)
Definition: paragraph_builder.cc:13
paragraph_builder.h
impeller::interop::ParagraphStyle::CreateTextStyle
txt::TextStyle CreateTextStyle() const
Definition: paragraph_style.cc:57
impeller::interop::ParagraphBuilder::IsValid
bool IsValid() const
Definition: paragraph_builder.cc:30
impeller::interop::ParagraphStyle
Definition: paragraph_style.h:15
impeller::interop::TypographyContext
Definition: typography_context.h:16
impeller::interop::ParagraphBuilder::PushStyle
void PushStyle(const ParagraphStyle &style)
Definition: paragraph_builder.cc:34
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
impeller::interop::TypographyContext::GetFontCollection
const std::shared_ptr< txt::FontCollection > & GetFontCollection() const
Definition: typography_context.cc:32
impeller::interop::ParagraphBuilder::PopStyle
void PopStyle()
Definition: paragraph_builder.cc:38