Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
modules
skottie
include
TextShaper.h
Go to the documentation of this file.
1
/*
2
* Copyright 2019 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#ifndef SkottieTextShaper_DEFINED
9
#define SkottieTextShaper_DEFINED
10
11
#include "
include/core/SkFont.h
"
12
#include "
include/core/SkPoint.h
"
13
#include "
include/core/SkRefCnt.h
"
14
#include "
include/core/SkScalar.h
"
15
#include "
include/core/SkTypes.h
"
16
#include "
include/private/base/SkTypeTraits.h
"
17
#include "
include/utils/SkTextUtils.h
"
18
19
#include <cstddef>
20
#include <cstdint>
21
#include <type_traits>
22
#include <vector>
23
24
class
SkCanvas
;
25
class
SkFontMgr
;
26
class
SkPaint
;
27
class
SkString
;
28
class
SkTypeface
;
29
struct
SkRect
;
30
31
namespace
SkShapers
{
class
Factory
; }
32
33
namespace
skottie
{
34
35
// Helper implementing After Effects text shaping semantics on top of SkShaper.
36
37
class
Shaper
final {
38
public
:
39
struct
RunRec
{
40
SkFont
fFont
;
41
size_t
fSize
;
42
43
static_assert
(
::sk_is_trivially_relocatable
<
decltype
(
fFont
)>::value);
44
45
using
sk_is_trivially_relocatable
= std::true_type;
46
};
47
48
struct
ShapedGlyphs
{
49
std::vector<RunRec>
fRuns
;
50
51
// Consolidated storage for all runs.
52
std::vector<SkGlyphID>
fGlyphIDs
;
53
std::vector<SkPoint>
fGlyphPos
;
54
55
// fClusters[i] is an input string index, pointing to the start of the UTF sequence
56
// associated with fGlyphs[i]. The number of entries matches the number of glyphs.
57
// Only available with Flags::kClusters.
58
std::vector<size_t>
fClusters
;
59
60
enum class
BoundsType
{
kConservative
,
kTight
};
61
SkRect
computeBounds
(
BoundsType
)
const
;
62
63
void
draw
(
SkCanvas
*,
const
SkPoint
& origin,
const
SkPaint
&)
const
;
64
};
65
66
struct
Fragment
{
67
ShapedGlyphs
fGlyphs
;
68
SkPoint
fOrigin
;
69
70
// Only valid for kFragmentGlyphs
71
float
fAdvance
,
72
fAscent
;
73
uint32_t
fLineIndex
;
// 0-based index for the line this fragment belongs to.
74
bool
fIsWhitespace
;
// True if the first code point in the corresponding
75
// cluster is whitespace.
76
};
77
78
struct
Result
{
79
std::vector<Fragment>
fFragments
;
80
size_t
fMissingGlyphCount
= 0;
81
// Relative text size scale, when using an auto-scaling ResizePolicy
82
// (otherwise 1.0). This is informative of the final text size, and is
83
// not required to render the Result.
84
float
fScale
= 1.0f;
85
86
SkRect
computeVisualBounds
()
const
;
87
};
88
89
enum class
VAlign
: uint8_t {
90
// Align the first line typographical top with the text box top (AE box text).
91
kTop
,
92
// Align the first line typographical baseline with the text box top (AE point text).
93
kTopBaseline
,
94
95
// Skottie vertical alignment extensions
96
97
// These are based on a hybrid extent box defined (in Y) as
98
//
99
// ------------------------------------------------------
100
// MIN(visual_top_extent , typographical_top_extent )
101
//
102
// ...
103
//
104
// MAX(visual_bottom_extent, typographical_bottom_extent)
105
// ------------------------------------------------------
106
kHybridTop
,
// extent box top -> text box top
107
kHybridCenter
,
// extent box center -> text box center
108
kHybridBottom
,
// extent box bottom -> text box bottom
109
110
// Visual alignement modes -- these are using tight visual bounds for the paragraph.
111
kVisualTop
,
// visual top -> text box top
112
kVisualCenter
,
// visual center -> text box center
113
kVisualBottom
,
// visual bottom -> text box bottom
114
};
115
116
enum class
ResizePolicy
: uint8_t {
117
// Use the specified text size.
118
kNone
,
119
// Resize the text such that the extent box fits (snuggly) in the text box,
120
// both horizontally and vertically.
121
kScaleToFit
,
122
// Same kScaleToFit if the text doesn't fit at the specified font size.
123
// Otherwise, same as kNone.
124
kDownscaleToFit
,
125
};
126
127
enum class
LinebreakPolicy
: uint8_t {
128
// Break lines such that they fit in a non-empty paragraph box, horizontally.
129
kParagraph
,
130
// Only break lines when requested explicitly (\r), regardless of paragraph box dimensions.
131
kExplicit
,
132
};
133
134
// Initial text direction.
135
enum class
Direction
: uint8_t {
kLTR
,
kRTL
};
136
137
enum class
Capitalization
{
138
kNone
,
139
kUpperCase
,
140
};
141
142
enum
Flags
: uint32_t {
143
kNone
= 0x00,
144
145
// Split out individual glyphs into separate Fragments
146
// (useful when the caller intends to manipulate glyphs independently).
147
kFragmentGlyphs
= 0x01,
148
149
// Compute the advance and ascent for each fragment.
150
kTrackFragmentAdvanceAscent
= 0x02,
151
152
// Return cluster information.
153
kClusters
= 0x04,
154
};
155
156
struct
TextDesc
{
157
const
sk_sp<SkTypeface>
&
fTypeface
;
158
SkScalar
fTextSize
= 0,
159
fMinTextSize
= 0,
// when auto-sizing
160
fMaxTextSize
= 0,
// when auto-sizing
161
fLineHeight
= 0,
162
fLineShift
= 0,
163
fAscent
= 0;
164
SkTextUtils::Align
fHAlign
=
SkTextUtils::kLeft_Align
;
165
VAlign
fVAlign
=
Shaper::VAlign::kTop
;
166
ResizePolicy
fResize
=
Shaper::ResizePolicy::kNone
;
167
LinebreakPolicy
fLinebreak
=
Shaper::LinebreakPolicy::kExplicit
;
168
Direction
fDirection
=
Shaper::Direction::kLTR
;
169
Capitalization
fCapitalization
=
Shaper::Capitalization::kNone
;
170
size_t
fMaxLines
= 0;
// when auto-sizing, 0 -> no max
171
uint32_t
fFlags
= 0;
172
const
char
*
fLocale
=
nullptr
;
173
const
char
*
fFontFamily
=
nullptr
;
174
};
175
176
// Performs text layout along an infinite horizontal line, starting at |point|.
177
// Only explicit line breaks (\r) are observed.
178
static
Result
Shape
(
const
SkString
&
text
,
const
TextDesc
& desc,
const
SkPoint
& point,
179
const
sk_sp<SkFontMgr>
&,
const
sk_sp<SkShapers::Factory>
&);
180
181
// Performs text layout within |box|, injecting line breaks as needed to ensure
182
// horizontal fitting. The result is *not* guaranteed to fit vertically (it may extend
183
// below the box bottom).
184
static
Result
Shape
(
const
SkString
&
text
,
const
TextDesc
& desc,
const
SkRect
& box,
185
const
sk_sp<SkFontMgr>
&,
const
sk_sp<SkShapers::Factory>
&);
186
187
#if !defined(SK_DISABLE_LEGACY_SHAPER_FACTORY)
188
static
Result
Shape
(
const
SkString
&
text
,
const
TextDesc
& desc,
const
SkPoint
& point,
189
const
sk_sp<SkFontMgr>
&);
190
static
Result
Shape
(
const
SkString
&
text
,
const
TextDesc
& desc,
const
SkRect
& box,
191
const
sk_sp<SkFontMgr>
&);
192
#endif
193
194
private
:
195
Shaper
() =
delete
;
196
};
197
198
}
// namespace skottie
199
200
#endif
// SkottieTextShaper_DEFINED
SkFont.h
SkPoint.h
SkRefCnt.h
SkScalar.h
SkTextUtils.h
SkTypeTraits.h
SkTypes.h
Shape
Shape
Definition
aaxfermodes.cpp:46
SkCanvas
Definition
SkCanvas.h:106
SkFontMgr
Definition
SkFontMgr.h:36
SkFont
Definition
SkFont.h:35
SkPaint
Definition
SkPaint.h:44
SkString
Definition
SkString.h:118
SkTextUtils::Align
Align
Definition
SkTextUtils.h:25
SkTextUtils::kLeft_Align
@ kLeft_Align
Definition
SkTextUtils.h:26
SkTypeface
Definition
SkTypeface.h:52
sk_sp
Definition
SkRefCnt.h:220
skottie::Shaper
Definition
TextShaper.h:37
skottie::Shaper::Direction
Direction
Definition
TextShaper.h:135
skottie::Shaper::Direction::kRTL
@ kRTL
skottie::Shaper::Direction::kLTR
@ kLTR
skottie::Shaper::ResizePolicy
ResizePolicy
Definition
TextShaper.h:116
skottie::Shaper::ResizePolicy::kDownscaleToFit
@ kDownscaleToFit
skottie::Shaper::ResizePolicy::kNone
@ kNone
skottie::Shaper::ResizePolicy::kScaleToFit
@ kScaleToFit
skottie::Shaper::VAlign
VAlign
Definition
TextShaper.h:89
skottie::Shaper::VAlign::kTopBaseline
@ kTopBaseline
skottie::Shaper::VAlign::kVisualBottom
@ kVisualBottom
skottie::Shaper::VAlign::kHybridTop
@ kHybridTop
skottie::Shaper::VAlign::kVisualTop
@ kVisualTop
skottie::Shaper::VAlign::kHybridBottom
@ kHybridBottom
skottie::Shaper::VAlign::kTop
@ kTop
skottie::Shaper::VAlign::kHybridCenter
@ kHybridCenter
skottie::Shaper::VAlign::kVisualCenter
@ kVisualCenter
skottie::Shaper::Capitalization
Capitalization
Definition
TextShaper.h:137
skottie::Shaper::Capitalization::kNone
@ kNone
skottie::Shaper::Capitalization::kUpperCase
@ kUpperCase
skottie::Shaper::LinebreakPolicy
LinebreakPolicy
Definition
TextShaper.h:127
skottie::Shaper::LinebreakPolicy::kParagraph
@ kParagraph
skottie::Shaper::LinebreakPolicy::kExplicit
@ kExplicit
skottie::Shaper::Flags
Flags
Definition
TextShaper.h:142
skottie::Shaper::kFragmentGlyphs
@ kFragmentGlyphs
Definition
TextShaper.h:147
skottie::Shaper::kClusters
@ kClusters
Definition
TextShaper.h:153
skottie::Shaper::kNone
@ kNone
Definition
TextShaper.h:143
skottie::Shaper::kTrackFragmentAdvanceAscent
@ kTrackFragmentAdvanceAscent
Definition
TextShaper.h:150
SkScalar
float SkScalar
Definition
extension.cpp:12
text
std::u16string text
Definition
keyboard_unittests.cc:332
SkShapers::Primitive::Factory
SKSHAPER_API sk_sp< Factory > Factory()
Definition
SkShaper_factory.cpp:32
SkShapers
Definition
Skottie.h:39
skottie
Definition
ExternalLayer.h:16
SkPoint
Definition
SkPoint_impl.h:163
SkRect
Definition
extension.cpp:13
sk_is_trivially_relocatable
Definition
SkTypeTraits.h:23
skottie::Shaper::Fragment
Definition
TextShaper.h:66
skottie::Shaper::Fragment::fOrigin
SkPoint fOrigin
Definition
TextShaper.h:68
skottie::Shaper::Fragment::fGlyphs
ShapedGlyphs fGlyphs
Definition
TextShaper.h:67
skottie::Shaper::Fragment::fAdvance
float fAdvance
Definition
TextShaper.h:71
skottie::Shaper::Fragment::fAscent
float fAscent
Definition
TextShaper.h:72
skottie::Shaper::Fragment::fIsWhitespace
bool fIsWhitespace
Definition
TextShaper.h:74
skottie::Shaper::Fragment::fLineIndex
uint32_t fLineIndex
Definition
TextShaper.h:73
skottie::Shaper::Result
Definition
TextShaper.h:78
skottie::Shaper::Result::fScale
float fScale
Definition
TextShaper.h:84
skottie::Shaper::Result::fFragments
std::vector< Fragment > fFragments
Definition
TextShaper.h:79
skottie::Shaper::Result::fMissingGlyphCount
size_t fMissingGlyphCount
Definition
TextShaper.h:80
skottie::Shaper::Result::computeVisualBounds
SkRect computeVisualBounds() const
Definition
TextShaper.cpp:736
skottie::Shaper::RunRec
Definition
TextShaper.h:39
skottie::Shaper::RunRec::fFont
SkFont fFont
Definition
TextShaper.h:40
skottie::Shaper::RunRec::sk_is_trivially_relocatable
std::true_type sk_is_trivially_relocatable
Definition
TextShaper.h:45
skottie::Shaper::RunRec::fSize
size_t fSize
Definition
TextShaper.h:41
skottie::Shaper::ShapedGlyphs
Definition
TextShaper.h:48
skottie::Shaper::ShapedGlyphs::fGlyphIDs
std::vector< SkGlyphID > fGlyphIDs
Definition
TextShaper.h:52
skottie::Shaper::ShapedGlyphs::BoundsType
BoundsType
Definition
TextShaper.h:60
skottie::Shaper::ShapedGlyphs::BoundsType::kTight
@ kTight
skottie::Shaper::ShapedGlyphs::BoundsType::kConservative
@ kConservative
skottie::Shaper::ShapedGlyphs::computeBounds
SkRect computeBounds(BoundsType) const
Definition
TextShaper.cpp:676
skottie::Shaper::ShapedGlyphs::fGlyphPos
std::vector< SkPoint > fGlyphPos
Definition
TextShaper.h:53
skottie::Shaper::ShapedGlyphs::fClusters
std::vector< size_t > fClusters
Definition
TextShaper.h:58
skottie::Shaper::ShapedGlyphs::fRuns
std::vector< RunRec > fRuns
Definition
TextShaper.h:49
skottie::Shaper::ShapedGlyphs::draw
void draw(SkCanvas *, const SkPoint &origin, const SkPaint &) const
Definition
TextShaper.cpp:721
skottie::Shaper::TextDesc
Definition
TextShaper.h:156
skottie::Shaper::TextDesc::fMaxLines
size_t fMaxLines
Definition
TextShaper.h:170
skottie::Shaper::TextDesc::fFlags
uint32_t fFlags
Definition
TextShaper.h:171
skottie::Shaper::TextDesc::fLineHeight
SkScalar fLineHeight
Definition
TextShaper.h:161
skottie::Shaper::TextDesc::fLinebreak
LinebreakPolicy fLinebreak
Definition
TextShaper.h:167
skottie::Shaper::TextDesc::fHAlign
SkTextUtils::Align fHAlign
Definition
TextShaper.h:164
skottie::Shaper::TextDesc::fLocale
const char * fLocale
Definition
TextShaper.h:172
skottie::Shaper::TextDesc::fDirection
Direction fDirection
Definition
TextShaper.h:168
skottie::Shaper::TextDesc::fTypeface
const sk_sp< SkTypeface > & fTypeface
Definition
TextShaper.h:157
skottie::Shaper::TextDesc::fResize
ResizePolicy fResize
Definition
TextShaper.h:166
skottie::Shaper::TextDesc::fMaxTextSize
SkScalar fMaxTextSize
Definition
TextShaper.h:160
skottie::Shaper::TextDesc::fTextSize
SkScalar fTextSize
Definition
TextShaper.h:158
skottie::Shaper::TextDesc::fCapitalization
Capitalization fCapitalization
Definition
TextShaper.h:169
skottie::Shaper::TextDesc::fMinTextSize
SkScalar fMinTextSize
Definition
TextShaper.h:159
skottie::Shaper::TextDesc::fFontFamily
const char * fFontFamily
Definition
TextShaper.h:173
skottie::Shaper::TextDesc::fLineShift
SkScalar fLineShift
Definition
TextShaper.h:162
skottie::Shaper::TextDesc::fAscent
SkScalar fAscent
Definition
TextShaper.h:163
skottie::Shaper::TextDesc::fVAlign
VAlign fVAlign
Definition
TextShaper.h:165
Generated on Fri Apr 26 2024 06:16:17 for Flutter Engine by
1.9.8