Flutter Engine
The Flutter Engine
SkTypeface_FreeType.h
Go to the documentation of this file.
1/*
2 * Copyright 2006-2012 The Android Open Source Project
3 * Copyright 2012 Mozilla Foundation
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef SkTypeface_Freetype_DEFINED
10#define SkTypeface_Freetype_DEFINED
11
12#include "include/core/SkSpan.h"
22
23class SkFontData;
24
25// These are forward declared to avoid pimpl but also hide the FreeType implementation.
26typedef struct FT_LibraryRec_* FT_Library;
27typedef struct FT_FaceRec_* FT_Face;
28typedef struct FT_StreamRec_* FT_Stream;
29typedef signed long FT_Pos;
30typedef struct FT_BBox_ FT_BBox;
31
33public:
34 /** Fetch units/EM from "head" table if needed (ie for bitmap fonts) */
35 static int GetUnitsPerEm(FT_Face face);
36
37 /** Return the font data, or nullptr on failure. */
38 std::unique_ptr<SkFontData> makeFontData() const;
39 class FaceRec;
40 FaceRec* getFaceRec() const;
41
42 static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('f','r','e','e');
43 static sk_sp<SkTypeface> MakeFromStream(std::unique_ptr<SkStreamAsset>, const SkFontArguments&);
44
45protected:
47 ~SkTypeface_FreeType() override;
48
49 std::unique_ptr<SkFontData> cloneFontData(const SkFontArguments&, SkFontStyle* style) const;
50 std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects&,
51 const SkDescriptor*) const override;
52 void onFilterRec(SkScalerContextRec*) const override;
53 void getGlyphToUnicodeMap(SkUnichar*) const override;
54 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
55 void getPostScriptGlyphNames(SkString* dstArray) const override;
56 bool onGetPostScriptName(SkString*) const override;
57 int onGetUPEM() const override;
58 bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
59 int32_t adjustments[]) const override;
60 void onCharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const override;
61 int onCountGlyphs() const override;
62
64
65 bool onGlyphMaskNeedsCurrentColor() const override;
67 int coordinateCount) const override;
69 int parameterCount) const override;
70 int onGetTableTags(SkFontTableTag tags[]) const override;
72 size_t length, void* data) const override;
74
75 virtual std::unique_ptr<SkFontData> onMakeFontData() const = 0;
76 /** Utility to fill out the SkFontDescriptor palette information from the SkFontData. */
78
79private:
80 mutable SkOnce fFTFaceOnce;
81 mutable std::unique_ptr<FaceRec> fFaceRec;
82
83 mutable SkSharedMutex fC2GCacheMutex;
84 mutable SkCharToGlyphCache fC2GCache;
85
86 mutable SkOnce fGlyphMasksMayNeedCurrentColorOnce;
87 mutable bool fGlyphMasksMayNeedCurrentColor;
88
89 using INHERITED = SkTypeface;
90};
91
93public:
94 SkTypeface_FreeTypeStream(std::unique_ptr<SkFontData> fontData, const SkString familyName,
95 const SkFontStyle& style, bool isFixedPitch);
97
98protected:
99 void onGetFamilyName(SkString* familyName) const override;
100 void onGetFontDescriptor(SkFontDescriptor*, bool* serialize) const override;
101 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
102 std::unique_ptr<SkFontData> onMakeFontData() const override;
103 sk_sp<SkTypeface> onMakeClone(const SkFontArguments&) const override;
104
105private:
106 const SkString fFamilyName;
107 const std::unique_ptr<const SkFontData> fData;
108};
109
111public:
113 ~SkFontScanner_FreeType() override;
114
115 bool scanFile(SkStreamAsset* stream, int* numFaces) const override;
116 bool scanFace(SkStreamAsset* stream, int faceIndex, int* numInstances) const override;
118 int faceIndex,
119 int instanceIndex,
120 SkString* name,
121 SkFontStyle* style,
122 bool* isFixedPitch,
123 AxisDefinitions* axes) const override;
124 static void computeAxisValues(
125 AxisDefinitions axisDefinitions,
127 SkFixed* axisValues,
128 const SkString& name,
129 SkFontStyle* style,
130 const SkFontArguments::VariationPosition::Coordinate* currentPosition = nullptr);
131 static bool GetAxes(FT_Face face, AxisDefinitions* axes);
132private:
133 FT_Face openFace(SkStreamAsset* stream, int ttcIndex, FT_Stream ftStream) const;
134 FT_Library fLibrary;
135 mutable SkMutex fLibraryMutex;
136};
137
138#endif // SkTypeface_Freetype_DEFINED
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
int count
Definition: FontMgrTest.cpp:50
int32_t SkFixed
Definition: SkFixed.h:25
struct FT_FaceRec_ * FT_Face
uint32_t SkFontTableTag
Definition: SkTypeface.h:41
struct FT_BBox_ FT_BBox
signed long FT_Pos
struct FT_StreamRec_ * FT_Stream
struct FT_FaceRec_ * FT_Face
struct FT_LibraryRec_ * FT_Library
int32_t SkUnichar
Definition: SkTypes.h:175
uint16_t SkGlyphID
Definition: SkTypes.h:179
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
static bool GetAxes(FT_Face face, AxisDefinitions *axes)
bool scanFace(SkStreamAsset *stream, int faceIndex, int *numInstances) const override
static void computeAxisValues(AxisDefinitions axisDefinitions, const SkFontArguments::VariationPosition position, SkFixed *axisValues, const SkString &name, SkFontStyle *style, const SkFontArguments::VariationPosition::Coordinate *currentPosition=nullptr)
bool scanInstance(SkStreamAsset *stream, int faceIndex, int instanceIndex, SkString *name, SkFontStyle *style, bool *isFixedPitch, AxisDefinitions *axes) const override
bool scanFile(SkStreamAsset *stream, int *numFaces) const override
Definition: SkOnce.h:22
sk_sp< SkTypeface > onMakeClone(const SkFontArguments &) const override
void onGetFamilyName(SkString *familyName) const override
void onGetFontDescriptor(SkFontDescriptor *, bool *serialize) const override
SkTypeface_FreeTypeStream(std::unique_ptr< SkFontData > fontData, const SkString familyName, const SkFontStyle &style, bool isFixedPitch)
std::unique_ptr< SkStreamAsset > onOpenStream(int *ttcIndex) const override
std::unique_ptr< SkFontData > onMakeFontData() const override
void getPostScriptGlyphNames(SkString *dstArray) const override
sk_sp< SkData > onCopyTableData(SkFontTableTag) const override
std::unique_ptr< SkAdvancedTypefaceMetrics > onGetAdvancedMetrics() const override
void onCharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const override
std::unique_ptr< SkScalerContext > onCreateScalerContext(const SkScalerContextEffects &, const SkDescriptor *) const override
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const override
bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count, int32_t adjustments[]) const override
int onGetUPEM() const override
int onGetTableTags(SkFontTableTag tags[]) const override
bool onGlyphMaskNeedsCurrentColor() const override
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], int parameterCount) const override
std::unique_ptr< SkFontData > makeFontData() const
std::unique_ptr< SkFontData > cloneFontData(const SkFontArguments &, SkFontStyle *style) const
virtual std::unique_ptr< SkFontData > onMakeFontData() const =0
size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void *data) const override
void onFilterRec(SkScalerContextRec *) const override
int onCountGlyphs() const override
SkTypeface_FreeType(const SkFontStyle &style, bool isFixedPitch)
LocalizedStrings * onCreateFamilyNameIterator() const override
FaceRec * getFaceRec() const
static sk_sp< SkTypeface > MakeFromStream(std::unique_ptr< SkStreamAsset >, const SkFontArguments &)
static void FontDataPaletteToDescriptorPalette(const SkFontData &, SkFontDescriptor *)
static int GetUnitsPerEm(FT_Face face)
void getGlyphToUnicodeMap(SkUnichar *) const override
bool onGetPostScriptName(SkString *) const override
void serialize(SkWStream *, SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
Definition: SkTypeface.cpp:202
bool isFixedPitch() const
Definition: SkTypeface.h:68
SkFourByteTag FactoryId
Definition: SkTypeface.h:335
SkTypeface(const SkFontStyle &style, bool isFixedPitch=false)
Definition: SkTypeface.cpp:56
size_t length
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
SeparatedVector2 offset
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63