Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
SkFontStream.cpp File Reference
#include "include/core/SkStream.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkMalloc.h"
#include "src/base/SkAutoMalloc.h"
#include "src/base/SkEndian.h"
#include "src/core/SkFontStream.h"
#include <cstdint>

Go to the source code of this file.

Classes

struct  SkSFNTHeader
 
struct  SkTTCFHeader
 
union  SkSharedTTHeader
 
struct  SkSFNTDirEntry
 
struct  SfntHeader
 

Functions

static bool read (SkStream *stream, void *buffer, size_t amount)
 
static bool skip (SkStream *stream, size_t amount)
 
static int count_tables (SkStream *stream, int ttcIndex, size_t *offsetToDir)
 

Function Documentation

◆ count_tables()

static int count_tables ( SkStream stream,
int  ttcIndex,
size_t *  offsetToDir 
)
static

Return the number of tables, or if this is a TTC (collection), return the number of tables in the first element of the collection. In either case, if offsetToDir is not-null, set it to the offset to the beginning of the table headers (SkSFNTDirEntry), relative to the start of the stream.

On an error, return 0 for number of tables, and ignore offsetToDir

Definition at line 59 of file SkFontStream.cpp.

59 {
60 SkASSERT(ttcIndex >= 0);
61
63 SkSharedTTHeader* header = (SkSharedTTHeader*)storage.get();
64
65 if (!read(stream, header, sizeof(SkSharedTTHeader))) {
66 return 0;
67 }
68
69 // by default, SkSFNTHeader is at the start of the stream
70 size_t offset = 0;
71
72 // if we're really a collection, the first 4-bytes will be 'ttcf'
73 uint32_t tag = SkEndian_SwapBE32(header->fCollection.fTag);
74 if (SkSetFourByteTag('t', 't', 'c', 'f') == tag) {
75 unsigned count = SkEndian_SwapBE32(header->fCollection.fNumOffsets);
76 if ((unsigned)ttcIndex >= count) {
77 return 0;
78 }
79
80 if (ttcIndex > 0) { // need to read more of the shared header
81 stream->rewind();
82 size_t amount = sizeof(SkSharedTTHeader) + ttcIndex * sizeof(uint32_t);
83 header = (SkSharedTTHeader*)storage.reset(amount);
84 if (!read(stream, header, amount)) {
85 return 0;
86 }
87 }
88 // this is the offset to the local SkSFNTHeader
89 offset = SkEndian_SwapBE32((&header->fCollection.fOffset0)[ttcIndex]);
90 stream->rewind();
91 if (!skip(stream, offset)) {
92 return 0;
93 }
94 if (!read(stream, header, sizeof(SkSFNTHeader))) {
95 return 0;
96 }
97 }
98
99 if (offsetToDir) {
100 // add the size of the header, so we will point to the DirEntries
101 *offsetToDir = offset + sizeof(SkSFNTHeader);
102 }
103 return SkEndian_SwapBE16(header->fSingle.fNumTables);
104}
int count
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkEndian_SwapBE32(n)
Definition SkEndian.h:136
#define SkEndian_SwapBE16(n)
Definition SkEndian.h:135
static bool read(SkStream *stream, void *buffer, size_t amount)
static bool skip(SkStream *stream, size_t amount)
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition SkTypes.h:167
static const char header[]
Definition skpbench.cpp:88
Point offset

◆ read()

static bool read ( SkStream stream,
void *  buffer,
size_t  amount 
)
static

Definition at line 44 of file SkFontStream.cpp.

44 {
45 return stream->read(buffer, amount) == amount;
46}
static const uint8_t buffer[]

◆ skip()

static bool skip ( SkStream stream,
size_t  amount 
)
static

Definition at line 48 of file SkFontStream.cpp.

48 {
49 return stream->skip(amount) == amount;
50}