Flutter Engine
The Flutter Engine
SkFontDescriptor.h
Go to the documentation of this file.
1/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkFontDescriptor_DEFINED
9#define SkFontDescriptor_DEFINED
10
20
21#include <memory>
22#include <utility>
23
25public:
26 /** Makes a copy of the data in 'axis'. */
27 SkFontData(std::unique_ptr<SkStreamAsset> stream, int index, int paletteIndex,
28 const SkFixed* axis, int axisCount,
29 const SkFontArguments::Palette::Override* paletteOverrides, int paletteOverrideCount)
30 : fStream(std::move(stream))
31 , fIndex(index)
32 , fPaletteIndex(paletteIndex)
33 , fAxisCount(axisCount)
34 , fPaletteOverrideCount(paletteOverrideCount)
35 , fAxis(fAxisCount)
36 , fPaletteOverrides(fPaletteOverrideCount)
37 {
38 for (int i = 0; i < fAxisCount; ++i) {
39 fAxis[i] = axis[i];
40 }
41 for (int i = 0; i < fPaletteOverrideCount; ++i) {
42 fPaletteOverrides[i] = paletteOverrides[i];
43 }
44 }
45
47 : fStream(that.fStream->duplicate())
48 , fIndex(that.fIndex)
49 , fPaletteIndex(that.fPaletteIndex)
50 , fAxisCount(that.fAxisCount)
51 , fPaletteOverrideCount(that.fPaletteOverrideCount)
52 , fAxis(fAxisCount)
53 , fPaletteOverrides(fPaletteOverrideCount)
54 {
55 for (int i = 0; i < fAxisCount; ++i) {
56 fAxis[i] = that.fAxis[i];
57 }
58 for (int i = 0; i < fPaletteOverrideCount; ++i) {
59 fPaletteOverrides[i] = that.fPaletteOverrides[i];
60 }
61 }
62 bool hasStream() const { return fStream != nullptr; }
63 std::unique_ptr<SkStreamAsset> detachStream() { return std::move(fStream); }
64 SkStreamAsset* getStream() { return fStream.get(); }
65 SkStreamAsset const* getStream() const { return fStream.get(); }
66 int getIndex() const { return fIndex; }
67 int getAxisCount() const { return fAxisCount; }
68 const SkFixed* getAxis() const { return fAxis.get(); }
69 int getPaletteIndex() const { return fPaletteIndex; }
70 int getPaletteOverrideCount() const { return fPaletteOverrideCount; }
72 return fPaletteOverrides.get();
73 }
74
75private:
76 std::unique_ptr<SkStreamAsset> fStream;
77 int fIndex;
78 int fPaletteIndex;
79 int fAxisCount;
80 int fPaletteOverrideCount;
83};
84
86public:
88 // Does not affect ownership of SkStream.
90
91 void serialize(SkWStream*) const;
92
93 SkFontStyle getStyle() const { return fStyle; }
94 void setStyle(SkFontStyle style) { fStyle = style; }
95
96 const char* getFamilyName() const { return fFamilyName.c_str(); }
97 const char* getFullName() const { return fFullName.c_str(); }
98 const char* getPostscriptName() const { return fPostscriptName.c_str(); }
99
100 void setFamilyName(const char* name) { fFamilyName.set(name); }
101 void setFullName(const char* name) { fFullName.set(name); }
102 void setPostscriptName(const char* name) { fPostscriptName.set(name); }
103
104 bool hasStream() const { return bool(fStream); }
105 std::unique_ptr<SkStreamAsset> dupStream() const { return fStream->duplicate(); }
106 int getCollectionIndex() const { return fCollectionIndex; }
107 int getPaletteIndex() const { return fPaletteIndex; }
108 int getVariationCoordinateCount() const { return fCoordinateCount; }
110 return fVariation.get();
111 }
112 int getPaletteEntryOverrideCount() const { return fPaletteEntryOverrideCount; }
114 return fPaletteEntryOverrides.get();
115 }
117 return fFactoryId;
118 }
119
120 std::unique_ptr<SkStreamAsset> detachStream() { return std::move(fStream); }
121 void setStream(std::unique_ptr<SkStreamAsset> stream) { fStream = std::move(stream); }
122 void setCollectionIndex(int collectionIndex) { fCollectionIndex = collectionIndex; }
123 void setPaletteIndex(int paletteIndex) { fPaletteIndex = paletteIndex; }
125 fCoordinateCount = coordinateCount;
126 return fVariation.reset(coordinateCount);
127 }
129 fPaletteEntryOverrideCount = paletteEntryOverrideCount;
130 return fPaletteEntryOverrides.reset(paletteEntryOverrideCount);
131 }
133 fFactoryId = factoryId;
134 }
135
137 return SkFontArguments()
140 .setPalette({this->getPaletteIndex(),
143 }
145
146private:
147 SkString fFamilyName;
148 SkString fFullName;
149 SkString fPostscriptName;
150 SkFontStyle fStyle;
151
152 std::unique_ptr<SkStreamAsset> fStream;
153 int fCollectionIndex = 0;
154 using Coordinates =
156 int fCoordinateCount = 0;
157 Coordinates fVariation;
158 int fPaletteIndex = 0;
159 int fPaletteEntryOverrideCount = 0;
161 SkTypeface::FactoryId fFactoryId = 0;
162};
163
164#endif // SkFontDescriptor_DEFINED
int32_t SkFixed
Definition: SkFixed.h:25
SkStreamAsset * getStream()
const SkFontArguments::Palette::Override * getPaletteOverrides() const
int getPaletteIndex() const
int getPaletteOverrideCount() const
int getIndex() const
SkStreamAsset const * getStream() const
const SkFixed * getAxis() const
bool hasStream() const
SkFontData(const SkFontData &that)
int getAxisCount() const
std::unique_ptr< SkStreamAsset > detachStream()
SkFontData(std::unique_ptr< SkStreamAsset > stream, int index, int paletteIndex, const SkFixed *axis, int axisCount, const SkFontArguments::Palette::Override *paletteOverrides, int paletteOverrideCount)
const SkFontArguments::Palette::Override * getPaletteEntryOverrides() const
void setFullName(const char *name)
SkFontArguments::Palette::Override * setPaletteEntryOverrides(int paletteEntryOverrideCount)
static SkFontStyle::Width SkFontStyleWidthForWidthAxisValue(SkScalar width)
SkFontArguments::VariationPosition::Coordinate * setVariationCoordinates(int coordinateCount)
const char * getPostscriptName() const
void setFamilyName(const char *name)
void setStyle(SkFontStyle style)
int getCollectionIndex() const
SkFontStyle getStyle() const
void serialize(SkWStream *) const
std::unique_ptr< SkStreamAsset > dupStream() const
void setStream(std::unique_ptr< SkStreamAsset > stream)
void setPaletteIndex(int paletteIndex)
const SkFontArguments::VariationPosition::Coordinate * getVariation() const
void setFactoryId(SkTypeface::FactoryId factoryId)
const char * getFamilyName() const
bool hasStream() const
static bool Deserialize(SkStream *, SkFontDescriptor *result)
std::unique_ptr< SkStreamAsset > detachStream()
void setCollectionIndex(int collectionIndex)
void setPostscriptName(const char *name)
int getVariationCoordinateCount() const
const char * getFullName() const
int getPaletteIndex() const
int getPaletteEntryOverrideCount() const
SkTypeface::FactoryId getFactoryId()
SkFontArguments getFontArguments() const
void set(const SkString &src)
Definition: SkString.h:186
const char * c_str() const
Definition: SkString.h:133
SkFourByteTag FactoryId
Definition: SkTypeface.h:335
T * reset(size_t count)
Definition: SkTemplates.h:356
T * reset(size_t count=0)
Definition: SkTemplates.h:296
float SkScalar
Definition: extension.cpp:12
GAsyncResult * result
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Definition: ref_ptr.h:256
int32_t width
SkFontArguments & setCollectionIndex(int collectionIndex)
SkFontArguments & setVariationDesignPosition(VariationPosition position)