Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkFontConfigInterface.h
Go to the documentation of this file.
1/*
2 * Copyright 2013 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 SkFontConfigInterface_DEFINED
9#define SkFontConfigInterface_DEFINED
10
15
16class SkFontMgr;
17
18/**
19 * \class SkFontConfigInterface
20 *
21 * A simple interface for remotable font management.
22 * The global instance can be found with RefGlobal().
23 */
25public:
26
27 /**
28 * Returns the global SkFontConfigInterface instance. If it is not
29 * nullptr, calls ref() on it. The caller must balance this with a call to
30 * unref(). The default SkFontConfigInterface is the result of calling
31 * GetSingletonDirectInterface.
32 */
33 static sk_sp<SkFontConfigInterface> RefGlobal();
34
35 /**
36 * Replace the current global instance with the specified one.
37 */
38 static void SetGlobal(sk_sp<SkFontConfigInterface> fc);
39
40 /**
41 * This should be treated as private to the impl of SkFontConfigInterface.
42 * Callers should not change or expect any particular values. It is meant
43 * to be a union of possible storage types to aid the impl.
44 */
45 struct FontIdentity {
46 FontIdentity() : fID(0), fTTCIndex(0) {}
47
48 bool operator==(const FontIdentity& other) const {
49 return fID == other.fID &&
50 fTTCIndex == other.fTTCIndex &&
51 fString == other.fString;
52 }
53 bool operator!=(const FontIdentity& other) const {
54 return !(*this == other);
55 }
56
57 uint32_t fID;
58 int32_t fTTCIndex;
61
62 // If buffer is NULL, just return the number of bytes that would have
63 // been written. Will pad contents to a multiple of 4.
64 size_t writeToMemory(void* buffer = nullptr) const;
65
66 // Recreate from a flattened buffer, returning the number of bytes read.
67 size_t readFromMemory(const void* buffer, size_t length);
68 };
69
70 /**
71 * Given a familyName and style, find the best match.
72 *
73 * If a match is found, return true and set its outFontIdentifier.
74 * If outFamilyName is not null, assign the found familyName to it
75 * (which may differ from the requested familyName).
76 * If outStyle is not null, assign the found style to it
77 * (which may differ from the requested style).
78 *
79 * If a match is not found, return false, and ignore all out parameters.
80 */
81 virtual bool matchFamilyName(const char familyName[],
82 SkFontStyle requested,
83 FontIdentity* outFontIdentifier,
84 SkString* outFamilyName,
85 SkFontStyle* outStyle) = 0;
86
87 /**
88 * Given a FontRef, open a stream to access its data, or return null
89 * if the FontRef's data is not available. The caller is responsible for
90 * deleting the stream when it is done accessing the data.
91 */
93
94 /**
95 * Return an SkTypeface for the given FontIdentity.
96 *
97 * The default implementation simply returns a new typeface built using data obtained from
98 * openStream() using the provided SkFontMgr, but derived classes may implement more
99 * complex caching schemes.
100 */
101 virtual sk_sp<SkTypeface> makeTypeface(const FontIdentity& identity, sk_sp<SkFontMgr> mgr);
102
103 /**
104 * Return a singleton instance of a direct subclass that calls into
105 * libfontconfig. This does not affect the refcnt of the returned instance.
106 */
107 static SkFontConfigInterface* GetSingletonDirectInterface();
108
110};
111
112#endif
#define SK_API
Definition SkAPI.h:35
virtual SkStreamAsset * openStream(const FontIdentity &)=0
virtual bool matchFamilyName(const char familyName[], SkFontStyle requested, FontIdentity *outFontIdentifier, SkString *outFamilyName, SkFontStyle *outStyle)=0
static const uint8_t buffer[]
size_t length
bool operator==(const FontIdentity &other) const
bool operator!=(const FontIdentity &other) const