Flutter Engine
The Flutter Engine
text_style.cpp
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 "../export.h"
6#include "../wrappers.h"
8
9const double kTextHeightNone = 0.0;
10
11using namespace skia::textlayout;
12using namespace Skwasm;
13
15 auto style = new TextStyle();
16
17 // Default color in flutter is black.
18 style->setColor(SK_ColorBLACK);
19 return style;
20}
21
23 return new TextStyle(*style);
24}
25
27 delete style;
28}
29
31 style->setColor(color);
32}
33
35 TextDecoration decoration) {
36 style->setDecoration(decoration);
37}
38
40 SkColor color) {
42}
43
45 TextStyle* style,
46 TextDecorationStyle decorationStyle) {
47 style->setDecorationStyle(decorationStyle);
48}
49
51 SkScalar thickness) {
52 style->setDecorationThicknessMultiplier(thickness);
53}
54
56 int weight,
57 SkFontStyle::Slant slant) {
59}
60
62 TextBaseline baseline) {
63 style->setTextBaseline(baseline);
64}
65
67 style->setFontFamilies({});
68}
69
71 SkString** fontFamilies,
72 int count) {
73 const std::vector<SkString>& currentFamilies = style->getFontFamilies();
74 std::vector<SkString> newFamilies;
75 newFamilies.reserve(currentFamilies.size() + count);
76 for (int i = 0; i < count; i++) {
77 newFamilies.push_back(*fontFamilies[i]);
78 }
79 for (const auto& family : currentFamilies) {
80 newFamilies.push_back(family);
81 }
82 style->setFontFamilies(std::move(newFamilies));
83}
84
86 style->setFontSize(size);
87}
88
90 SkScalar letterSpacing) {
91 style->setLetterSpacing(letterSpacing);
92}
93
95 SkScalar wordSpacing) {
96 style->setWordSpacing(wordSpacing);
97}
98
100 style->setHeight(height);
102}
103
105 bool halfLeading) {
106 style->setHalfLeading(halfLeading);
107}
108
110 style->setLocale(*locale);
111}
112
114 style->setBackgroundColor(*paint);
115}
116
118 style->setForegroundColor(*paint);
119}
120
125 SkScalar blurSigma) {
126 style->addShadow(TextShadow(color, {offsetX, offsetY}, blurSigma));
127}
128
130 SkString* featureName,
131 int value) {
132 style->addFontFeature(*featureName, value);
133}
134
136 SkFourByteTag* axes,
137 float* values,
138 int count) {
139 std::vector<SkFontArguments::VariationPosition::Coordinate> coordinates;
140 for (int i = 0; i < count; i++) {
141 coordinates.push_back({axes[i], values[i]});
142 }
144 coordinates.data(), static_cast<int>(coordinates.size())};
145 style->setFontArguments(
147}
int count
Definition: FontMgrTest.cpp:50
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
uint32_t SkFourByteTag
Definition: SkTypes.h:166
void setDecorationStyle(TextDecorationStyle style)
Definition: TextStyle.h:222
void addShadow(TextShadow shadow)
Definition: TextStyle.h:233
void setFontFamilies(std::vector< SkString > families)
Definition: TextStyle.h:253
void setHeight(SkScalar height)
Definition: TextStyle.h:260
void setLetterSpacing(SkScalar letterSpacing)
Definition: TextStyle.h:269
void setWordSpacing(SkScalar wordSpacing)
Definition: TextStyle.h:272
const std::vector< SkString > & getFontFamilies() const
Definition: TextStyle.h:252
void setColor(SkColor color)
Definition: TextStyle.h:166
void setHeightOverride(bool heightOverride)
Definition: TextStyle.h:263
void setTextBaseline(TextBaseline baseline)
Definition: TextStyle.h:283
void setFontStyle(SkFontStyle fontStyle)
Definition: TextStyle.h:228
void setBackgroundColor(SkPaint paint)
Definition: TextStyle.h:204
void setLocale(const SkString &locale)
Definition: TextStyle.h:280
void setHalfLeading(bool halfLeading)
Definition: TextStyle.h:266
void setFontSize(SkScalar size)
Definition: TextStyle.h:250
void setFontArguments(const std::optional< SkFontArguments > &args)
void setForegroundColor(SkPaint paint)
Definition: TextStyle.h:181
void addFontFeature(const SkString &fontFeature, int value)
Definition: TextStyle.h:239
void setDecorationColor(SkColor color)
Definition: TextStyle.h:223
void setDecoration(TextDecoration decoration)
Definition: TextStyle.h:220
void setDecorationThicknessMultiplier(SkScalar m)
Definition: TextStyle.h:224
const Paint & paint
Definition: color_source.cc:38
DlColor color
float SkScalar
Definition: extension.cpp:12
uint8_t value
Definition: helpers.h:12
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkScalar offsetX
SkScalar offsetY
int32_t height
SkFontArguments & setVariationDesignPosition(VariationPosition position)
SKWASM_EXPORT void textStyle_setDecorationColor(TextStyle *style, SkColor color)
Definition: text_style.cpp:39
SKWASM_EXPORT void textStyle_setDecorationThickness(TextStyle *style, SkScalar thickness)
Definition: text_style.cpp:50
SKWASM_EXPORT void textStyle_setForeground(TextStyle *style, SkPaint *paint)
Definition: text_style.cpp:117
SKWASM_EXPORT TextStyle * textStyle_create()
Definition: text_style.cpp:14
SKWASM_EXPORT TextStyle * textStyle_copy(TextStyle *style)
Definition: text_style.cpp:22
SKWASM_EXPORT void textStyle_setLetterSpacing(TextStyle *style, SkScalar letterSpacing)
Definition: text_style.cpp:89
SKWASM_EXPORT void textStyle_setLocale(TextStyle *style, SkString *locale)
Definition: text_style.cpp:109
SKWASM_EXPORT void textStyle_setDecorationStyle(TextStyle *style, TextDecorationStyle decorationStyle)
Definition: text_style.cpp:44
SKWASM_EXPORT void textStyle_addFontFamilies(TextStyle *style, SkString **fontFamilies, int count)
Definition: text_style.cpp:70
SKWASM_EXPORT void textStyle_setColor(TextStyle *style, SkColor color)
Definition: text_style.cpp:30
SKWASM_EXPORT void textStyle_addFontFeature(TextStyle *style, SkString *featureName, int value)
Definition: text_style.cpp:129
SKWASM_EXPORT void textStyle_setDecoration(TextStyle *style, TextDecoration decoration)
Definition: text_style.cpp:34
SKWASM_EXPORT void textStyle_setBackground(TextStyle *style, SkPaint *paint)
Definition: text_style.cpp:113
SKWASM_EXPORT void textStyle_setHalfLeading(TextStyle *style, bool halfLeading)
Definition: text_style.cpp:104
SKWASM_EXPORT void textStyle_setFontSize(TextStyle *style, SkScalar size)
Definition: text_style.cpp:85
SKWASM_EXPORT void textStyle_setFontStyle(TextStyle *style, int weight, SkFontStyle::Slant slant)
Definition: text_style.cpp:55
SKWASM_EXPORT void textStyle_setHeight(TextStyle *style, SkScalar height)
Definition: text_style.cpp:99
SKWASM_EXPORT void textStyle_dispose(TextStyle *style)
Definition: text_style.cpp:26
SKWASM_EXPORT void textStyle_setTextBaseline(TextStyle *style, TextBaseline baseline)
Definition: text_style.cpp:61
SKWASM_EXPORT void textStyle_clearFontFamilies(TextStyle *style)
Definition: text_style.cpp:66
const double kTextHeightNone
Definition: text_style.cpp:9
SKWASM_EXPORT void textStyle_addShadow(TextStyle *style, SkColor color, SkScalar offsetX, SkScalar offsetY, SkScalar blurSigma)
Definition: text_style.cpp:121
SKWASM_EXPORT void textStyle_setWordSpacing(TextStyle *style, SkScalar wordSpacing)
Definition: text_style.cpp:94
SKWASM_EXPORT void textStyle_setFontVariations(TextStyle *style, SkFourByteTag *axes, float *values, int count)
Definition: text_style.cpp:135
#define SKWASM_EXPORT
Definition: export.h:10