Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
SkFontStream Class Reference

#include <SkFontStream.h>

Static Public Member Functions

static int CountTTCEntries (SkStream *)
 
static int GetTableTags (SkStream *, int ttcIndex, SkFontTableTag tags[])
 
static size_t GetTableData (SkStream *, int ttcIndex, SkFontTableTag tag, size_t offset, size_t length, void *data)
 
static size_t GetTableSize (SkStream *stream, int ttcIndex, SkFontTableTag tag)
 

Detailed Description

Definition at line 17 of file SkFontStream.h.

Member Function Documentation

◆ CountTTCEntries()

int SkFontStream::CountTTCEntries ( SkStream stream)
static

Return the number of shared directories inside a TTC sfnt, or return 1 if the stream is a normal sfnt (ttf). If there is an error or no directory is found, return 0.

Note: the stream is rewound initially, but is returned at an arbitrary read offset.

Definition at line 143 of file SkFontStream.cpp.

143 {
144 stream->rewind();
145
146 SkSharedTTHeader shared;
147 if (!read(stream, &shared, sizeof(shared))) {
148 return 0;
149 }
150
151 // if we're really a collection, the first 4-bytes will be 'ttcf'
152 uint32_t tag = SkEndian_SwapBE32(shared.fCollection.fTag);
153 if (SkSetFourByteTag('t', 't', 'c', 'f') == tag) {
155 } else {
156 return 1; // normal 'sfnt' has 1 dir entry
157 }
158}
#define SkEndian_SwapBE32(n)
Definition SkEndian.h:136
static bool read(SkStream *stream, void *buffer, size_t amount)
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition SkTypes.h:167
uint32_t fNumOffsets
SkTTCFHeader fCollection

◆ GetTableData()

size_t SkFontStream::GetTableData ( SkStream stream,
int  ttcIndex,
SkFontTableTag  tag,
size_t  offset,
size_t  length,
void *  data 
)
static
Parameters
ttcIndex0 for normal sfnts, or the index within a TTC sfnt.

Note: the stream is rewound initially, but is returned at an arbitrary read offset.

Definition at line 175 of file SkFontStream.cpp.

177 {
179 if (!header.init(stream, ttcIndex)) {
180 return 0;
181 }
182
183 for (int i = 0; i < header.fCount; i++) {
184 if (SkEndian_SwapBE32(header.fDir[i].fTag) == tag) {
185 size_t realOffset = SkEndian_SwapBE32(header.fDir[i].fOffset);
186 size_t realLength = SkEndian_SwapBE32(header.fDir[i].fLength);
187 if (offset >= realLength) {
188 // invalid
189 return 0;
190 }
191 // if the caller is trusting the length from the file, then a
192 // hostile file might choose a value which would overflow offset +
193 // length.
194 if (offset + length < offset) {
195 return 0;
196 }
197 if (length > realLength - offset) {
198 length = realLength - offset;
199 }
200 if (data) {
201 // skip the stream to the part of the table we want to copy from
202 stream->rewind();
203 size_t bytesToSkip = realOffset + offset;
204 if (!skip(stream, bytesToSkip)) {
205 return 0;
206 }
207 if (!read(stream, data, length)) {
208 return 0;
209 }
210 }
211 return length;
212 }
213 }
214 return 0;
215}
static bool skip(SkStream *stream, size_t amount)
size_t length
static const char header[]
Definition skpbench.cpp:88
Point offset

◆ GetTableSize()

static size_t SkFontStream::GetTableSize ( SkStream stream,
int  ttcIndex,
SkFontTableTag  tag 
)
inlinestatic

Definition at line 46 of file SkFontStream.h.

46 {
47 return GetTableData(stream, ttcIndex, tag, 0, ~0U, nullptr);
48 }
static size_t GetTableData(SkStream *, int ttcIndex, SkFontTableTag tag, size_t offset, size_t length, void *data)

◆ GetTableTags()

int SkFontStream::GetTableTags ( SkStream stream,
int  ttcIndex,
SkFontTableTag  tags[] 
)
static
Parameters
ttcIndex0 for normal sfnts, or the index within a TTC sfnt.

Note: the stream is rewound initially, but is returned at an arbitrary read offset.

Definition at line 160 of file SkFontStream.cpp.

161 {
163 if (!header.init(stream, ttcIndex)) {
164 return 0;
165 }
166
167 if (tags) {
168 for (int i = 0; i < header.fCount; i++) {
169 tags[i] = SkEndian_SwapBE32(header.fDir[i].fTag);
170 }
171 }
172 return header.fCount;
173}

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