Flutter Engine
The Flutter Engine
third_party
skia
src
ports
SkFontMgr_android_parser.h
Go to the documentation of this file.
1
/*
2
* Copyright 2011 The Android Open Source Project
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 SkFontMgr_android_parser_DEFINED
9
#define SkFontMgr_android_parser_DEFINED
10
11
#include "
include/core/SkFontArguments.h
"
12
#include "
include/core/SkFontMgr.h
"
13
#include "
include/core/SkString.h
"
14
#include "
include/core/SkTypes.h
"
15
#include "
include/private/base/SkTArray.h
"
16
#include "
include/private/base/SkTDArray.h
"
17
#include "
src/core/SkTHash.h
"
18
19
#include <climits>
20
#include <limits>
21
22
/** \class SkLanguage
23
24
The SkLanguage class represents a human written language, and is used by
25
text draw operations to determine which glyph to draw when drawing
26
characters with variants (ie Han-derived characters).
27
*/
28
class
SkLanguage
{
29
public
:
30
SkLanguage
() { }
31
SkLanguage
(
const
SkString
& tag) : fTag(tag) { }
32
SkLanguage
(
const
char
* tag) : fTag(tag) { }
33
SkLanguage
(
const
char
* tag,
size_t
len
) : fTag(tag,
len
) { }
34
SkLanguage
(
const
SkLanguage
&) =
default
;
35
SkLanguage
&
operator=
(
const
SkLanguage
&) =
default
;
36
37
/** Gets a BCP 47 language identifier for this SkLanguage.
38
@return a BCP 47 language identifier representing this language
39
*/
40
const
SkString
&
getTag
()
const
{
return
fTag; }
41
42
/** Performs BCP 47 fallback to return an SkLanguage one step more general.
43
@return an SkLanguage one step more general
44
*/
45
SkLanguage
getParent
()
const
;
46
47
bool
operator==
(
const
SkLanguage
&
b
)
const
{
48
return
fTag ==
b
.fTag;
49
}
50
bool
operator!=
(
const
SkLanguage
&
b
)
const
{
51
return
fTag !=
b
.fTag;
52
}
53
54
private
:
55
//! BCP 47 language identifier
56
SkString
fTag;
57
};
58
59
enum
FontVariants
{
60
kDefault_FontVariant
= 0x01,
61
kCompact_FontVariant
= 0x02,
62
kElegant_FontVariant
= 0x04,
63
kLast_FontVariant
=
kElegant_FontVariant
,
64
};
65
typedef
uint32_t
FontVariant
;
66
67
// Must remain trivially movable (can be memmoved).
68
struct
FontFileInfo
{
69
FontFileInfo
() :
fIndex
(0),
fWeight
(0),
fStyle
(
Style
::kAuto) { }
70
71
SkString
fFileName
;
72
int
fIndex
;
73
int
fWeight
;
74
enum class
Style
{ kAuto,
kNormal
,
kItalic
}
fStyle
;
75
skia_private::TArray<SkFontArguments::VariationPosition::Coordinate, true>
76
fVariationDesignPosition
;
77
};
78
79
/**
80
* A font family provides one or more names for a collection of fonts, each of
81
* which has a different style (normal, italic) or weight (thin, light, bold,
82
* etc).
83
* Some fonts may occur in compact variants for use in the user interface.
84
* Android distinguishes "fallback" fonts to support non-ASCII character sets.
85
*/
86
struct
FontFamily
{
87
FontFamily
(
const
SkString
& basePath,
bool
isFallbackFont)
88
:
fVariant
(
kDefault_FontVariant
)
89
,
fOrder
(-1)
90
,
fIsFallbackFont
(isFallbackFont)
91
,
fBasePath
(basePath)
92
{ }
93
94
skia_private::TArray<SkString, true>
fNames
;
95
skia_private::TArray<FontFileInfo, true>
fFonts
;
96
skia_private::TArray<SkLanguage, true>
fLanguages
;
97
skia_private::THashMap<SkString, std::unique_ptr<FontFamily>
>
fallbackFamilies
;
98
FontVariant
fVariant
;
99
int
fOrder
;
// internal to the parser, not useful to users.
100
bool
fIsFallbackFont
;
101
SkString
fFallbackFor
;
102
const
SkString
fBasePath
;
103
};
104
105
namespace
SkFontMgr_Android_Parser
{
106
107
/** Parses system font configuration files and appends result to fontFamilies. */
108
void
GetSystemFontFamilies
(
SkTDArray<FontFamily*>
& fontFamilies);
109
110
/** Parses font configuration files and appends result to fontFamilies. */
111
void
GetCustomFontFamilies
(
SkTDArray<FontFamily*>
& fontFamilies,
112
const
SkString
& basePath,
113
const
char
* fontsXml,
114
const
char
* fallbackFontsXml,
115
const
char
* langFallbackFontsDir =
nullptr
);
116
117
}
// namespace SkFontMgr_Android_Parser
118
119
120
/** Parses a null terminated string into an integer type, checking for overflow.
121
* http://www.w3.org/TR/html-markup/datatypes.html#common.data.integer.non-negative-def
122
*
123
* If the string cannot be parsed into 'value', returns false and does not change 'value'.
124
*/
125
template
<
typename
T>
bool
parse_non_negative_integer
(
const
char
*
s
,
T
*
value
) {
126
static_assert
(
std::numeric_limits<T>::is_integer
,
"T_must_be_integer"
);
127
128
if
(*
s
==
'\0'
) {
129
return
false
;
130
}
131
132
const
T
nMax =
std::numeric_limits<T>::max
() / 10;
133
const
T
dMax =
std::numeric_limits<T>::max
() - (nMax * 10);
134
T
n = 0;
135
for
(; *
s
; ++
s
) {
136
// Check if digit
137
if
(*
s
<
'0'
||
'9'
< *
s
) {
138
return
false
;
139
}
140
T
d
= *
s
-
'0'
;
141
// Check for overflow
142
if
(n > nMax || (n == nMax &&
d
> dMax)) {
143
return
false
;
144
}
145
n = (n * 10) +
d
;
146
}
147
*
value
= n;
148
return
true
;
149
}
150
151
/** Parses a null terminated string into a signed fixed point value with bias N.
152
*
153
* Like http://www.w3.org/TR/html-markup/datatypes.html#common.data.float-def ,
154
* but may start with '.' and does not support 'e'. '-?((:digit:+(.:digit:+)?)|(.:digit:+))'
155
*
156
* Checks for overflow.
157
* Low bit rounding is not defined (is currently truncate).
158
* Bias (N) required to allow for the sign bit and 4 bits of integer.
159
*
160
* If the string cannot be parsed into 'value', returns false and does not change 'value'.
161
*/
162
template
<
int
N,
typename
T>
bool
parse_fixed
(
const
char
*
s
,
T
*
value
) {
163
static_assert
(
std::numeric_limits<T>::is_integer
,
"T_must_be_integer"
);
164
static_assert
(
std::numeric_limits<T>::is_signed
,
"T_must_be_signed"
);
165
static_assert
(
sizeof
(
T
) * CHAR_BIT -
N
>= 5,
"N_must_leave_four_bits_plus_sign"
);
166
167
bool
negate =
false
;
168
if
(*
s
==
'-'
) {
169
++
s
;
170
negate =
true
;
171
}
172
if
(*
s
==
'\0'
) {
173
return
false
;
174
}
175
176
const
T
nMax = (
std::numeric_limits<T>::max
() >>
N
) / 10;
177
const
T
dMax = (
std::numeric_limits<T>::max
() >>
N
) - (nMax * 10);
178
T
n = 0;
179
T
frac = 0;
180
for
(; *
s
; ++
s
) {
181
// Check if digit
182
if
(*
s
<
'0'
||
'9'
< *
s
) {
183
// If it wasn't a digit, check if it is a '.' followed by something.
184
if
(*
s
!=
'.'
||
s
[1] ==
'\0'
) {
185
return
false
;
186
}
187
// Find the end, verify digits.
188
for
(++
s
; *
s
; ++
s
) {
189
if
(*
s
<
'0'
||
'9'
< *
s
) {
190
return
false
;
191
}
192
}
193
// Read back toward the '.'.
194
for
(--
s
; *
s
!=
'.'
; --
s
) {
195
T
d
= *
s
-
'0'
;
196
frac = (frac + (
d
<<
N
)) / 10;
// This requires four bits overhead.
197
}
198
break
;
199
}
200
T
d
= *
s
-
'0'
;
201
// Check for overflow
202
if
(n > nMax || (n == nMax &&
d
> dMax)) {
203
return
false
;
204
}
205
n = (n * 10) +
d
;
206
}
207
if
(negate) {
208
n = -n;
209
frac = -frac;
210
}
211
*
value
=
SkLeftShift
(n,
N
) + frac;
212
return
true
;
213
}
214
215
#endif
/* SkFontMgr_android_parser_DEFINED */
SkFontArguments.h
kItalic
@ kItalic
Definition:
SkFontDescriptor.cpp:30
SkFontMgr.h
parse_non_negative_integer
bool parse_non_negative_integer(const char *s, T *value)
Definition:
SkFontMgr_android_parser.h:125
parse_fixed
bool parse_fixed(const char *s, T *value)
Definition:
SkFontMgr_android_parser.h:162
FontVariant
uint32_t FontVariant
Definition:
SkFontMgr_android_parser.h:65
FontVariants
FontVariants
Definition:
SkFontMgr_android_parser.h:59
kDefault_FontVariant
@ kDefault_FontVariant
Definition:
SkFontMgr_android_parser.h:60
kCompact_FontVariant
@ kCompact_FontVariant
Definition:
SkFontMgr_android_parser.h:61
kLast_FontVariant
@ kLast_FontVariant
Definition:
SkFontMgr_android_parser.h:63
kElegant_FontVariant
@ kElegant_FontVariant
Definition:
SkFontMgr_android_parser.h:62
SkLeftShift
static constexpr int32_t SkLeftShift(int32_t value, int32_t shift)
Definition:
SkMath.h:37
is_integer
static bool is_integer(SkScalar x)
Definition:
SkPDFDevice.cpp:1506
SkString.h
SkTArray.h
SkTDArray.h
SkTHash.h
SkTypes.h
N
#define N
Definition:
beziers.cpp:19
SkLanguage
Definition:
SkFontMgr_android_parser.h:28
SkLanguage::SkLanguage
SkLanguage()
Definition:
SkFontMgr_android_parser.h:30
SkLanguage::getParent
SkLanguage getParent() const
Definition:
SkFontMgr_android_parser.cpp:837
SkLanguage::operator=
SkLanguage & operator=(const SkLanguage &)=default
SkLanguage::getTag
const SkString & getTag() const
Definition:
SkFontMgr_android_parser.h:40
SkLanguage::SkLanguage
SkLanguage(const char *tag)
Definition:
SkFontMgr_android_parser.h:32
SkLanguage::operator!=
bool operator!=(const SkLanguage &b) const
Definition:
SkFontMgr_android_parser.h:50
SkLanguage::SkLanguage
SkLanguage(const char *tag, size_t len)
Definition:
SkFontMgr_android_parser.h:33
SkLanguage::operator==
bool operator==(const SkLanguage &b) const
Definition:
SkFontMgr_android_parser.h:47
SkLanguage::SkLanguage
SkLanguage(const SkString &tag)
Definition:
SkFontMgr_android_parser.h:31
SkLanguage::SkLanguage
SkLanguage(const SkLanguage &)=default
SkString
Definition:
SkString.h:118
SkTDArray< FontFamily * >
skia_private::TArray< SkFontArguments::VariationPosition::Coordinate, true >
skia_private::THashMap
Definition:
SkTHash.h:442
kNormal
@ kNormal
Default priority level.
Definition:
embedder.h:262
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition:
main.cc:19
b
static bool b
Definition:
ffi_native_test_module.c:74
s
struct MyStruct s
value
uint8_t value
Definition:
fl_standard_message_codec.cc:36
max
static float max(float r, float g, float b)
Definition:
hsl.cpp:49
SkFontMgr_Android_Parser
Definition:
SkFontMgr_android_parser.h:105
SkFontMgr_Android_Parser::GetCustomFontFamilies
void GetCustomFontFamilies(SkTDArray< FontFamily * > &fontFamilies, const SkString &basePath, const char *fontsXml, const char *fallbackFontsXml, const char *langFallbackFontsDir=nullptr)
Definition:
SkFontMgr_android_parser.cpp:818
SkFontMgr_Android_Parser::GetSystemFontFamilies
void GetSystemFontFamilies(SkTDArray< FontFamily * > &fontFamilies)
Definition:
SkFontMgr_android_parser.cpp:802
SkSL::is_signed
static bool is_signed(const Type &type)
Definition:
SkSLSPIRVCodeGenerator.cpp:919
gn.find_headers.len
len
Definition:
find_headers.py:30
T
#define T
Definition:
precompiler.cc:65
FontFamily
Definition:
SkFontMgr_android_parser.h:86
FontFamily::fFallbackFor
SkString fFallbackFor
Definition:
SkFontMgr_android_parser.h:101
FontFamily::fNames
skia_private::TArray< SkString, true > fNames
Definition:
SkFontMgr_android_parser.h:94
FontFamily::FontFamily
FontFamily(const SkString &basePath, bool isFallbackFont)
Definition:
SkFontMgr_android_parser.h:87
FontFamily::fBasePath
const SkString fBasePath
Definition:
SkFontMgr_android_parser.h:102
FontFamily::fallbackFamilies
skia_private::THashMap< SkString, std::unique_ptr< FontFamily > > fallbackFamilies
Definition:
SkFontMgr_android_parser.h:97
FontFamily::fLanguages
skia_private::TArray< SkLanguage, true > fLanguages
Definition:
SkFontMgr_android_parser.h:96
FontFamily::fOrder
int fOrder
Definition:
SkFontMgr_android_parser.h:99
FontFamily::fFonts
skia_private::TArray< FontFileInfo, true > fFonts
Definition:
SkFontMgr_android_parser.h:95
FontFamily::fVariant
FontVariant fVariant
Definition:
SkFontMgr_android_parser.h:98
FontFamily::fIsFallbackFont
bool fIsFallbackFont
Definition:
SkFontMgr_android_parser.h:100
FontFileInfo
Definition:
SkFontMgr_android_parser.h:68
FontFileInfo::fStyle
enum FontFileInfo::Style fStyle
FontFileInfo::fWeight
int fWeight
Definition:
SkFontMgr_android_parser.h:73
FontFileInfo::fFileName
SkString fFileName
Definition:
SkFontMgr_android_parser.h:71
FontFileInfo::Style
Style
Definition:
SkFontMgr_android_parser.h:74
FontFileInfo::fVariationDesignPosition
skia_private::TArray< SkFontArguments::VariationPosition::Coordinate, true > fVariationDesignPosition
Definition:
SkFontMgr_android_parser.h:76
FontFileInfo::fIndex
int fIndex
Definition:
SkFontMgr_android_parser.h:72
FontFileInfo::FontFileInfo
FontFileInfo()
Definition:
SkFontMgr_android_parser.h:69
Generated on Sun Jun 23 2024 21:56:31 for Flutter Engine by
1.9.4