Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
SkFontMgr_custom_embedded.cpp File Reference
#include "include/core/SkRefCnt.h"
#include "include/core/SkStream.h"
#include "include/ports/SkFontMgr_data.h"
#include "src/core/SkFontDescriptor.h"
#include "src/core/SkFontScanner.h"
#include "src/ports/SkFontMgr_custom.h"

Go to the source code of this file.

Classes

struct  SkEmbeddedResource
 
struct  SkEmbeddedResourceHeader
 
class  EmbeddedSystemFontLoader
 
class  DataFontLoader
 

Functions

static void load_font_from_data (const SkFontScanner *scanner, std::unique_ptr< SkMemoryStream > stream, int index, SkFontMgr_Custom::Families *families)
 
static SkFontStyleSet_Customfind_family (SkFontMgr_Custom::Families &families, const char familyName[])
 
sk_sp< SkFontMgrSkFontMgr_New_Custom_Embedded (const SkEmbeddedResourceHeader *header)
 
sk_sp< SkFontMgrSkFontMgr_New_Custom_Data (SkSpan< sk_sp< SkData > > datas)
 

Function Documentation

◆ find_family()

static SkFontStyleSet_Custom * find_family ( SkFontMgr_Custom::Families families,
const char  familyName[] 
)
static

Definition at line 68 of file SkFontMgr_custom_embedded.cpp.

70{
71 for (int i = 0; i < families.size(); ++i) {
72 if (families[i]->getFamilyName().equals(familyName)) {
73 return families[i].get();
74 }
75 }
76 return nullptr;
77}
static bool equals(T *a, T *b)
int size() const
Definition SkTArray.h:416

◆ load_font_from_data()

static void load_font_from_data ( const SkFontScanner scanner,
std::unique_ptr< SkMemoryStream stream,
int  index,
SkFontMgr_Custom::Families families 
)
static

Definition at line 79 of file SkFontMgr_custom_embedded.cpp.

82 {
83 int numFaces;
84 if (!scanner->scanFile(stream.get(), &numFaces)) {
85 SkDebugf("---- failed to open <%d> as a font\n", index);
86 return;
87 }
88 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) {
89 int numInstances;
90 if (!scanner->scanFace(stream.get(), faceIndex, &numInstances)) {
91 SkDebugf("---- failed to open <%d> <%d> as a face\n", index, faceIndex);
92 continue;
93 }
94
95 for (int instanceIndex = 0; instanceIndex <= numInstances; ++instanceIndex) {
96 bool isFixedPitch;
97 SkString realname;
98 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning
99 if (!scanner->scanInstance(stream.get(),
100 faceIndex,
101 instanceIndex,
102 &realname,
103 &style,
104 &isFixedPitch,
105 nullptr)) {
106 SkDebugf("---- failed to open <%d> <%d> <%d> as an instance\n",
107 index,
108 faceIndex,
109 instanceIndex);
110 return;
111 }
112
113 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str());
114 if (nullptr == addTo) {
115 addTo = new SkFontStyleSet_Custom(realname);
116 families->push_back().reset(addTo);
117 }
118 auto data = std::make_unique<SkFontData>(
119 stream->duplicate(), faceIndex, 0, nullptr, 0, nullptr, 0);
120 addTo->appendTypeface(sk_make_sp<SkTypeface_FreeTypeStream>(
121 std::move(data), realname, style, isFixedPitch));
122 }
123 }
124}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkFontStyleSet_Custom * find_family(SkFontMgr_Custom::Families &families, const char familyName[])
virtual bool scanFace(SkStreamAsset *stream, int faceIndex, int *numInstances) const =0
virtual bool scanInstance(SkStreamAsset *stream, int faceIndex, int instanceIndex, SkString *name, SkFontStyle *style, bool *isFixedPitch, AxisDefinitions *axes) const =0
virtual bool scanFile(SkStreamAsset *stream, int *numFaces) const =0
void appendTypeface(sk_sp< SkTypeface > typeface)
const char * c_str() const
Definition SkString.h:133
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ SkFontMgr_New_Custom_Data()

sk_sp< SkFontMgr > SkFontMgr_New_Custom_Data ( SkSpan< sk_sp< SkData > >  datas)

Create a custom font manager which wraps a collection of SkData-stored fonts. This font manager uses FreeType for rendering.

Definition at line 130 of file SkFontMgr_custom_embedded.cpp.

130 {
131 SkASSERT(!datas.empty());
132 return sk_make_sp<SkFontMgr_Custom>(DataFontLoader(datas.data(), datas.size()));
133}
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr T * data() const
Definition SkSpan_impl.h:94
constexpr bool empty() const
Definition SkSpan_impl.h:96
constexpr size_t size() const
Definition SkSpan_impl.h:95

◆ SkFontMgr_New_Custom_Embedded()

sk_sp< SkFontMgr > SkFontMgr_New_Custom_Embedded ( const SkEmbeddedResourceHeader header)

Definition at line 126 of file SkFontMgr_custom_embedded.cpp.

126 {
127 return sk_make_sp<SkFontMgr_Custom>(EmbeddedSystemFontLoader(header));
128}
static const char header[]
Definition skpbench.cpp:88