| Flutter Impeller |

paragraph_style.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_style.h"
6
7 #include "flutter/fml/string_conversion.h"
8
9 namespace impeller::interop {
10
11 ParagraphStyle::ParagraphStyle() = default;
12
13 ParagraphStyle::~ParagraphStyle() = default;
14
15 void ParagraphStyle::SetFontWeight(int weight) {
16 style_.font_weight = weight;
17 }
18
19 void ParagraphStyle::SetFontStyle(txt::FontStyle style) {
20 style_.font_style = style;
21 }
22
23 void ParagraphStyle::SetFontFamily(std::string family) {
24 style_.font_family = std::move(family);
25 }
26
27 void ParagraphStyle::SetFontSize(double size) {
28 style_.font_size = size;
29 }
30
31 void ParagraphStyle::SetHeight(double height) {
32 style_.height = height;
33 style_.has_height_override = (height != 0.0);
34 }
35
36 void ParagraphStyle::SetTextAlignment(txt::TextAlign alignment) {
37 style_.text_align = alignment;
38 }
39
40 void ParagraphStyle::SetTextDirection(txt::TextDirection direction) {
41 style_.text_direction = direction;
42 }
43
44 void ParagraphStyle::SetMaxLines(size_t max_lines) {
45 style_.max_lines = max_lines;
46 }
47
48 void ParagraphStyle::SetLocale(std::string locale) {
49 style_.locale = std::move(locale);
50 }
51
52 void ParagraphStyle::SetForeground(ScopedObject<Paint> paint) {
53 foreground_ = std::move(paint);
54 }
55
56 void ParagraphStyle::SetBackground(ScopedObject<Paint> paint) {
57 background_ = std::move(paint);
58 }
59
60 txt::TextStyle ParagraphStyle::CreateTextStyle() const {
61 auto style = style_.GetTextStyle();
62
63 if (foreground_) {
64 style.foreground = foreground_->GetPaint();
65 }
66 if (background_) {
67 style.background = background_->GetPaint();
68 }
69 if (decoration_.has_value()) {
70 const auto& decoration = decoration_.value();
71 style.decoration = decoration.types;
72 style.decoration_color = ToSkiaType(decoration.color);
73 style.decoration_style = ToTxtType(decoration.style);
74 style.decoration_thickness_multiplier = decoration.thickness_multiplier;
75 }
76
77 return style;
78 }
79
80 const txt::ParagraphStyle& ParagraphStyle::GetParagraphStyle() const {
81 return style_;
82 }
83
84 void ParagraphStyle::SetTextDecoration(
85 const ImpellerTextDecoration& decoration) {
86 decoration_ = decoration;
87 }
88
89 void ParagraphStyle::SetEllipsis(const std::string& string) {
90 if (string.empty()) {
91 style_.ellipsis = {};
92 return;
93 }
94 style_.ellipsis = fml::Utf8ToUtf16(string);
95 }
96
97 } // namespace impeller::interop
impeller::interop::ParagraphStyle::~ParagraphStyle
~ParagraphStyle() override
impeller::interop::ParagraphStyle::SetFontFamily
void SetFontFamily(std::string family)
Definition: paragraph_style.cc:23
impeller::interop::ParagraphStyle::SetTextDecoration
void SetTextDecoration(const ImpellerTextDecoration &decoration)
Definition: paragraph_style.cc:84
impeller::interop::ParagraphStyle::SetTextDirection
void SetTextDirection(txt::TextDirection direction)
Definition: paragraph_style.cc:40
impeller::interop::ParagraphStyle::SetHeight
void SetHeight(double height)
Definition: paragraph_style.cc:31
impeller::interop::ParagraphStyle::SetBackground
void SetBackground(ScopedObject< Paint > paint)
Definition: paragraph_style.cc:56
impeller::interop::ParagraphStyle::SetForeground
void SetForeground(ScopedObject< Paint > paint)
Definition: paragraph_style.cc:52
impeller::interop::ParagraphStyle::CreateTextStyle
txt::TextStyle CreateTextStyle() const
Definition: paragraph_style.cc:60
impeller::interop::ParagraphStyle::SetFontWeight
void SetFontWeight(int weight)
Definition: paragraph_style.cc:15
impeller::interop::ParagraphStyle::SetLocale
void SetLocale(std::string locale)
Definition: paragraph_style.cc:48
impeller::interop::ParagraphStyle::ParagraphStyle
ParagraphStyle()
impeller::interop::ParagraphStyle::SetFontSize
void SetFontSize(double size)
Definition: paragraph_style.cc:27
impeller::interop::ParagraphStyle::SetFontStyle
void SetFontStyle(txt::FontStyle style)
Definition: paragraph_style.cc:19
impeller::interop::ParagraphStyle::SetEllipsis
void SetEllipsis(const std::string &string)
Definition: paragraph_style.cc:89
impeller::interop::ParagraphStyle::GetParagraphStyle
const txt::ParagraphStyle & GetParagraphStyle() const
Definition: paragraph_style.cc:80
impeller::interop::ParagraphStyle::SetMaxLines
void SetMaxLines(size_t max_lines)
Definition: paragraph_style.cc:44
impeller::interop::ParagraphStyle::SetTextAlignment
void SetTextAlignment(txt::TextAlign alignment)
Definition: paragraph_style.cc:36
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop
Definition: context_gles.cc:12
impeller::interop::ToTxtType
constexpr txt::TextDecorationStyle ToTxtType(ImpellerTextDecorationStyle style)
Definition: formats.h:442
impeller::interop::ToSkiaType
constexpr std::optional< SkRect > ToSkiaType(const ImpellerRect *rect)
Definition: formats.h:30
paragraph_style.h
ImpellerTextDecoration
Definition: impeller.h:646