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 
6 
7 #include "flutter/fml/string_conversion.h"
8 
9 namespace impeller::interop {
10 
12 
14 
15 void ParagraphStyle::SetFontWeight(txt::FontWeight 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 
53  foreground_ = std::move(paint);
54 }
55 
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 
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
void SetFontWeight(txt::FontWeight weight)
void SetFontFamily(std::string family)
void SetTextDecoration(const ImpellerTextDecoration &decoration)
void SetTextDirection(txt::TextDirection direction)
void SetBackground(ScopedObject< Paint > paint)
void SetForeground(ScopedObject< Paint > paint)
txt::TextStyle CreateTextStyle() const
void SetLocale(std::string locale)
void SetFontStyle(txt::FontStyle style)
void SetEllipsis(const std::string &string)
const txt::ParagraphStyle & GetParagraphStyle() const
void SetMaxLines(size_t max_lines)
void SetTextAlignment(txt::TextAlign alignment)
constexpr txt::TextDecorationStyle ToTxtType(ImpellerTextDecorationStyle style)
Definition: formats.h:442
constexpr std::optional< SkRect > ToSkiaType(const ImpellerRect *rect)
Definition: formats.h:30