Flutter Engine
The Flutter Engine
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
Definition: FontMgrTest.cpp:50
#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
SeparatedVector2 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}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ 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}