Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Typedefs | Enumerations | Functions
SkFontMgr_android_parser.h File Reference
#include "include/core/SkFontArguments.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTDArray.h"
#include "src/core/SkTHash.h"
#include <climits>
#include <limits>

Go to the source code of this file.

Classes

class  SkLanguage
 
struct  FontFileInfo
 
struct  FontFamily
 

Namespaces

namespace  SkFontMgr_Android_Parser
 

Typedefs

typedef uint32_t FontVariant
 

Enumerations

enum  FontVariants { kDefault_FontVariant = 0x01 , kCompact_FontVariant = 0x02 , kElegant_FontVariant = 0x04 , kLast_FontVariant = kElegant_FontVariant }
 

Functions

void SkFontMgr_Android_Parser::GetSystemFontFamilies (SkTDArray< FontFamily * > &fontFamilies)
 
void SkFontMgr_Android_Parser::GetCustomFontFamilies (SkTDArray< FontFamily * > &fontFamilies, const SkString &basePath, const char *fontsXml, const char *fallbackFontsXml, const char *langFallbackFontsDir=nullptr)
 
template<typename T >
bool parse_non_negative_integer (const char *s, T *value)
 
template<int N, typename T >
bool parse_fixed (const char *s, T *value)
 

Typedef Documentation

◆ FontVariant

typedef uint32_t FontVariant

Definition at line 65 of file SkFontMgr_android_parser.h.

Enumeration Type Documentation

◆ FontVariants

Enumerator
kDefault_FontVariant 
kCompact_FontVariant 
kElegant_FontVariant 
kLast_FontVariant 

Definition at line 59 of file SkFontMgr_android_parser.h.

Function Documentation

◆ parse_fixed()

template<int N, typename T >
bool parse_fixed ( const char *  s,
T value 
)

Parses a null terminated string into a signed fixed point value with bias N.

Like http://www.w3.org/TR/html-markup/datatypes.html#common.data.float-def , but may start with '.' and does not support 'e'. '-?((:digit:+(.:digit:+)?)|(.:digit:+))'

Checks for overflow. Low bit rounding is not defined (is currently truncate). Bias (N) required to allow for the sign bit and 4 bits of integer.

If the string cannot be parsed into 'value', returns false and does not change 'value'.

Definition at line 162 of file SkFontMgr_android_parser.h.

162 {
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}
static constexpr int32_t SkLeftShift(int32_t value, int32_t shift)
Definition SkMath.h:37
#define N
Definition beziers.cpp:19
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
struct MyStruct s
uint8_t value
#define T

◆ parse_non_negative_integer()

template<typename T >
bool parse_non_negative_integer ( const char *  s,
T value 
)

Parses a null terminated string into an integer type, checking for overflow. http://www.w3.org/TR/html-markup/datatypes.html#common.data.integer.non-negative-def

If the string cannot be parsed into 'value', returns false and does not change 'value'.

Definition at line 125 of file SkFontMgr_android_parser.h.

125 {
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}