Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
SkFontDescriptor Class Reference

#include <SkFontDescriptor.h>

Inheritance diagram for SkFontDescriptor:
SkNoncopyable

Public Member Functions

 SkFontDescriptor ()
 
void serialize (SkWStream *) const
 
SkFontStyle getStyle () const
 
void setStyle (SkFontStyle style)
 
const char * getFamilyName () const
 
const char * getFullName () const
 
const char * getPostscriptName () const
 
void setFamilyName (const char *name)
 
void setFullName (const char *name)
 
void setPostscriptName (const char *name)
 
bool hasStream () const
 
std::unique_ptr< SkStreamAssetdupStream () const
 
int getCollectionIndex () const
 
int getPaletteIndex () const
 
int getVariationCoordinateCount () const
 
const SkFontArguments::VariationPosition::CoordinategetVariation () const
 
int getPaletteEntryOverrideCount () const
 
const SkFontArguments::Palette::OverridegetPaletteEntryOverrides () const
 
SkTypeface::FactoryId getFactoryId ()
 
std::unique_ptr< SkStreamAssetdetachStream ()
 
void setStream (std::unique_ptr< SkStreamAsset > stream)
 
void setCollectionIndex (int collectionIndex)
 
void setPaletteIndex (int paletteIndex)
 
SkFontArguments::VariationPosition::CoordinatesetVariationCoordinates (int coordinateCount)
 
SkFontArguments::Palette::OverridesetPaletteEntryOverrides (int paletteEntryOverrideCount)
 
void setFactoryId (SkTypeface::FactoryId factoryId)
 
SkFontArguments getFontArguments () const
 

Static Public Member Functions

static bool Deserialize (SkStream *, SkFontDescriptor *result)
 
static SkFontStyle::Width SkFontStyleWidthForWidthAxisValue (SkScalar width)
 

Detailed Description

Definition at line 85 of file SkFontDescriptor.h.

Constructor & Destructor Documentation

◆ SkFontDescriptor()

SkFontDescriptor::SkFontDescriptor ( )

Definition at line 43 of file SkFontDescriptor.cpp.

43{ }

Member Function Documentation

◆ Deserialize()

bool SkFontDescriptor::Deserialize ( SkStream stream,
SkFontDescriptor result 
)
static

Definition at line 90 of file SkFontDescriptor.cpp.

90 {
91 size_t factoryId;
92 using FactoryIdType = decltype(result->fFactoryId);
93
94 size_t coordinateCount;
95 using CoordinateCountType = decltype(result->fCoordinateCount);
96
97 size_t index;
98 using CollectionIndexType = decltype(result->fCollectionIndex);
99
100 size_t paletteIndex;
101 using PaletteIndexType = decltype(result->fPaletteIndex);
102
103 size_t paletteEntryOverrideCount;
104 using PaletteEntryOverrideCountType = decltype(result->fPaletteEntryOverrideCount);
105
106 size_t paletteEntryOverrideIndex;
107 using PaletteEntryOverrideIndexType = decltype(result->fPaletteEntryOverrides[0].index);
108
111 SkScalar slant = 0;
112 SkScalar italic = 0;
113
114 size_t styleBits;
115 if (!stream->readPackedUInt(&styleBits)) { return false; }
116 weight = ((styleBits >> 16) & 0xFFFF);
117 width = ((styleBits >> 8) & 0x000F)[width_for_usWidth];
118 slant = ((styleBits >> 0) & 0x000F) != SkFontStyle::kUpright_Slant ? 14 : 0;
119 italic = ((styleBits >> 0) & 0x000F) == SkFontStyle::kItalic_Slant ? 1 : 0;
120
121 for (size_t id; (id = read_id(stream)) != kSentinel;) {
122 switch (id) {
123 case kFontFamilyName:
124 if (!read_string(stream, &result->fFamilyName)) { return false; }
125 break;
126 case kFullName:
127 if (!read_string(stream, &result->fFullName)) { return false; }
128 break;
129 case kPostscriptName:
130 if (!read_string(stream, &result->fPostscriptName)) { return false; }
131 break;
132 case kWeight:
133 if (!stream->readScalar(&weight)) { return false; }
134 break;
135 case kWidth:
136 if (!stream->readScalar(&width)) { return false; }
137 break;
138 case kSlant:
139 if (!stream->readScalar(&slant)) { return false; }
140 break;
141 case kItalic:
142 if (!stream->readScalar(&italic)) { return false; }
143 break;
144 case kFontVariation:
145 if (!stream->readPackedUInt(&coordinateCount)) { return false; }
146 if (!SkTFitsIn<CoordinateCountType>(coordinateCount)) { return false; }
147 if (StreamRemainingLengthIsBelow(stream, coordinateCount)) {
148 return false;
149 }
150 result->fCoordinateCount = SkTo<CoordinateCountType>(coordinateCount);
151
152 result->fVariation.reset(coordinateCount);
153 for (size_t i = 0; i < coordinateCount; ++i) {
154 if (!stream->readU32(&result->fVariation[i].axis)) { return false; }
155 if (!stream->readScalar(&result->fVariation[i].value)) { return false; }
156 }
157 break;
158 case kFontIndex:
159 if (!stream->readPackedUInt(&index)) { return false; }
160 if (!SkTFitsIn<CollectionIndexType>(index)) { return false; }
161 result->fCollectionIndex = SkTo<CollectionIndexType>(index);
162 break;
163 case kPaletteIndex:
164 if (!stream->readPackedUInt(&paletteIndex)) { return false; }
165 if (!SkTFitsIn<PaletteIndexType>(paletteIndex)) { return false; }
166 result->fPaletteIndex = SkTo<PaletteIndexType>(paletteIndex);
167 break;
169 if (!stream->readPackedUInt(&paletteEntryOverrideCount)) { return false; }
170 if (!SkTFitsIn<PaletteEntryOverrideCountType>(paletteEntryOverrideCount)) {
171 return false;
172 }
173 if (StreamRemainingLengthIsBelow(stream, paletteEntryOverrideCount)) {
174 return false;
175 }
176 result->fPaletteEntryOverrideCount =
177 SkTo<PaletteEntryOverrideCountType>(paletteEntryOverrideCount);
178
179 result->fPaletteEntryOverrides.reset(paletteEntryOverrideCount);
180 for (size_t i = 0; i < paletteEntryOverrideCount; ++i) {
181 if (!stream->readPackedUInt(&paletteEntryOverrideIndex)) { return false; }
182 if (!SkTFitsIn<PaletteEntryOverrideIndexType>(paletteEntryOverrideIndex)) {
183 return false;
184 }
185 result->fPaletteEntryOverrides[i].index =
186 SkTo<PaletteEntryOverrideIndexType>(paletteEntryOverrideIndex);
187 if (!stream->readU32(&result->fPaletteEntryOverrides[i].color)) {
188 return false;
189 }
190 }
191 break;
192 case kFactoryId:
193 if (!stream->readPackedUInt(&factoryId)) { return false; }
194 if (!SkTFitsIn<FactoryIdType>(factoryId)) { return false; }
195 result->fFactoryId = SkTo<FactoryIdType>(factoryId);
196 break;
197 default:
198 SkDEBUGFAIL("Unknown id used by a font descriptor");
199 return false;
200 }
201 }
202
204 if (slant != 0) { slantEnum = SkFontStyle::kOblique_Slant; }
205 if (0 < italic) { slantEnum = SkFontStyle::kItalic_Slant; }
207 result->fStyle = SkFontStyle(SkScalarRoundToInt(weight), widthEnum, slantEnum);
208
209 size_t length;
210 if (!stream->readPackedUInt(&length)) { return false; }
211 if (length > 0) {
213 return false;
214 }
216 if (stream->read(data->writable_data(), length) != length) {
217 SkDEBUGFAIL("Could not read font data");
218 return false;
219 }
220 result->fStream = SkMemoryStream::Make(std::move(data));
221 }
222 return true;
223}
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
static size_t read_id(SkStream *stream)
static constexpr SkScalar width_for_usWidth[0x10]
static bool read_string(SkStream *stream, SkString *string)
@ kPaletteEntryOverrides
@ kFullName
@ kSlant
@ kWeight
@ kItalic
@ kFontFamilyName
@ kPaletteIndex
@ kFontVariation
@ kFontIndex
@ kPostscriptName
@ kFactoryId
@ kSentinel
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
bool StreamRemainingLengthIsBelow(SkStream *stream, size_t len)
Definition: SkStream.cpp:976
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
static SkFontStyle::Width SkFontStyleWidthForWidthAxisValue(SkScalar width)
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
Definition: SkStream.cpp:314
float SkScalar
Definition: extension.cpp:12
GAsyncResult * result
size_t length
int32_t width
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ detachStream()

std::unique_ptr< SkStreamAsset > SkFontDescriptor::detachStream ( )
inline

Definition at line 120 of file SkFontDescriptor.h.

120{ return std::move(fStream); }

◆ dupStream()

std::unique_ptr< SkStreamAsset > SkFontDescriptor::dupStream ( ) const
inline

Definition at line 105 of file SkFontDescriptor.h.

105{ return fStream->duplicate(); }

◆ getCollectionIndex()

int SkFontDescriptor::getCollectionIndex ( ) const
inline

Definition at line 106 of file SkFontDescriptor.h.

106{ return fCollectionIndex; }

◆ getFactoryId()

SkTypeface::FactoryId SkFontDescriptor::getFactoryId ( )
inline

Definition at line 116 of file SkFontDescriptor.h.

116 {
117 return fFactoryId;
118 }

◆ getFamilyName()

const char * SkFontDescriptor::getFamilyName ( ) const
inline

Definition at line 96 of file SkFontDescriptor.h.

96{ return fFamilyName.c_str(); }
const char * c_str() const
Definition: SkString.h:133

◆ getFontArguments()

SkFontArguments SkFontDescriptor::getFontArguments ( ) const
inline

Definition at line 136 of file SkFontDescriptor.h.

136 {
137 return SkFontArguments()
140 .setPalette({this->getPaletteIndex(),
143 }
const SkFontArguments::Palette::Override * getPaletteEntryOverrides() const
int getCollectionIndex() const
const SkFontArguments::VariationPosition::Coordinate * getVariation() const
int getVariationCoordinateCount() const
int getPaletteIndex() const
int getPaletteEntryOverrideCount() const
SkFontArguments & setCollectionIndex(int collectionIndex)
SkFontArguments & setVariationDesignPosition(VariationPosition position)

◆ getFullName()

const char * SkFontDescriptor::getFullName ( ) const
inline

Definition at line 97 of file SkFontDescriptor.h.

97{ return fFullName.c_str(); }

◆ getPaletteEntryOverrideCount()

int SkFontDescriptor::getPaletteEntryOverrideCount ( ) const
inline

Definition at line 112 of file SkFontDescriptor.h.

112{ return fPaletteEntryOverrideCount; }

◆ getPaletteEntryOverrides()

const SkFontArguments::Palette::Override * SkFontDescriptor::getPaletteEntryOverrides ( ) const
inline

Definition at line 113 of file SkFontDescriptor.h.

113 {
114 return fPaletteEntryOverrides.get();
115 }

◆ getPaletteIndex()

int SkFontDescriptor::getPaletteIndex ( ) const
inline

Definition at line 107 of file SkFontDescriptor.h.

107{ return fPaletteIndex; }

◆ getPostscriptName()

const char * SkFontDescriptor::getPostscriptName ( ) const
inline

Definition at line 98 of file SkFontDescriptor.h.

98{ return fPostscriptName.c_str(); }

◆ getStyle()

SkFontStyle SkFontDescriptor::getStyle ( ) const
inline

Definition at line 93 of file SkFontDescriptor.h.

93{ return fStyle; }

◆ getVariation()

const SkFontArguments::VariationPosition::Coordinate * SkFontDescriptor::getVariation ( ) const
inline

Definition at line 109 of file SkFontDescriptor.h.

109 {
110 return fVariation.get();
111 }

◆ getVariationCoordinateCount()

int SkFontDescriptor::getVariationCoordinateCount ( ) const
inline

Definition at line 108 of file SkFontDescriptor.h.

108{ return fCoordinateCount; }

◆ hasStream()

bool SkFontDescriptor::hasStream ( ) const
inline

Definition at line 104 of file SkFontDescriptor.h.

104{ return bool(fStream); }

◆ serialize()

void SkFontDescriptor::serialize ( SkWStream stream) const

Definition at line 225 of file SkFontDescriptor.cpp.

225 {
226 uint32_t styleBits = (fStyle.weight() << 16) | (fStyle.width() << 8) | (fStyle.slant());
227 stream->writePackedUInt(styleBits);
228
229 write_string(stream, fFamilyName, kFontFamilyName);
230 write_string(stream, fFullName, kFullName);
231 write_string(stream, fPostscriptName, kPostscriptName);
232
233 write_scalar(stream, fStyle.weight(), kWeight);
237
238 if (fCollectionIndex > 0) {
239 write_uint(stream, fCollectionIndex, kFontIndex);
240 }
241 if (fPaletteIndex > 0) {
242 write_uint(stream, fPaletteIndex, kPaletteIndex);
243 }
244 if (fCoordinateCount > 0) {
245 write_uint(stream, fCoordinateCount, kFontVariation);
246 for (int i = 0; i < fCoordinateCount; ++i) {
247 stream->write32(fVariation[i].axis);
248 stream->writeScalar(fVariation[i].value);
249 }
250 }
251 if (fPaletteEntryOverrideCount > 0) {
252 write_uint(stream, fPaletteEntryOverrideCount, kPaletteEntryOverrides);
253 for (int i = 0; i < fPaletteEntryOverrideCount; ++i) {
254 stream->writePackedUInt(fPaletteEntryOverrides[i].index);
255 stream->write32(fPaletteEntryOverrides[i].color);
256 }
257 }
258
259 write_uint(stream, fFactoryId, kFactoryId);
260
261 stream->writePackedUInt(kSentinel);
262
263 if (fStream) {
264 std::unique_ptr<SkStreamAsset> fontStream = fStream->duplicate();
265 size_t length = fontStream->getLength();
266 stream->writePackedUInt(length);
267 stream->writeStream(fontStream.get(), length);
268 } else {
269 stream->writePackedUInt(0);
270 }
271}
static bool write_scalar(SkWStream *stream, SkScalar n, uint32_t id)
static bool write_string(SkWStream *stream, const SkString &string, uint32_t id)
static bool write_uint(SkWStream *stream, size_t n, uint32_t id)
Slant slant() const
Definition: SkFontStyle.h:64
int width() const
Definition: SkFontStyle.h:63
int weight() const
Definition: SkFontStyle.h:62
DlColor color
uint8_t value

◆ setCollectionIndex()

void SkFontDescriptor::setCollectionIndex ( int  collectionIndex)
inline

Definition at line 122 of file SkFontDescriptor.h.

122{ fCollectionIndex = collectionIndex; }

◆ setFactoryId()

void SkFontDescriptor::setFactoryId ( SkTypeface::FactoryId  factoryId)
inline

Definition at line 132 of file SkFontDescriptor.h.

132 {
133 fFactoryId = factoryId;
134 }

◆ setFamilyName()

void SkFontDescriptor::setFamilyName ( const char *  name)
inline

Definition at line 100 of file SkFontDescriptor.h.

100{ fFamilyName.set(name); }
void set(const SkString &src)
Definition: SkString.h:186
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ setFullName()

void SkFontDescriptor::setFullName ( const char *  name)
inline

Definition at line 101 of file SkFontDescriptor.h.

101{ fFullName.set(name); }

◆ setPaletteEntryOverrides()

SkFontArguments::Palette::Override * SkFontDescriptor::setPaletteEntryOverrides ( int  paletteEntryOverrideCount)
inline

Definition at line 128 of file SkFontDescriptor.h.

128 {
129 fPaletteEntryOverrideCount = paletteEntryOverrideCount;
130 return fPaletteEntryOverrides.reset(paletteEntryOverrideCount);
131 }
T * reset(size_t count=0)
Definition: SkTemplates.h:296

◆ setPaletteIndex()

void SkFontDescriptor::setPaletteIndex ( int  paletteIndex)
inline

Definition at line 123 of file SkFontDescriptor.h.

123{ fPaletteIndex = paletteIndex; }

◆ setPostscriptName()

void SkFontDescriptor::setPostscriptName ( const char *  name)
inline

Definition at line 102 of file SkFontDescriptor.h.

102{ fPostscriptName.set(name); }

◆ setStream()

void SkFontDescriptor::setStream ( std::unique_ptr< SkStreamAsset stream)
inline

Definition at line 121 of file SkFontDescriptor.h.

121{ fStream = std::move(stream); }

◆ setStyle()

void SkFontDescriptor::setStyle ( SkFontStyle  style)
inline

Definition at line 94 of file SkFontDescriptor.h.

94{ fStyle = style; }

◆ setVariationCoordinates()

SkFontArguments::VariationPosition::Coordinate * SkFontDescriptor::setVariationCoordinates ( int  coordinateCount)
inline

Definition at line 124 of file SkFontDescriptor.h.

124 {
125 fCoordinateCount = coordinateCount;
126 return fVariation.reset(coordinateCount);
127 }
T * reset(size_t count)
Definition: SkTemplates.h:356

◆ SkFontStyleWidthForWidthAxisValue()

SkFontStyle::Width SkFontDescriptor::SkFontStyleWidthForWidthAxisValue ( SkScalar  width)
static

Definition at line 273 of file SkFontDescriptor.cpp.

273 {
275 return static_cast<SkFontStyle::Width>(usWidth);
276}
static constexpr SkScalar usWidths[9]
SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[], const SkScalar values[], int length)
Definition: SkScalar.cpp:11

The documentation for this class was generated from the following files: