xref: /aosp_15_r20/external/skia/src/ports/SkFontConfigInterface_direct.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2009-2015 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 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */
9 #ifndef SKFONTCONFIGINTERFACE_DIRECT_H_
10 #define SKFONTCONFIGINTERFACE_DIRECT_H_
11 
12 #include "include/ports/SkFontConfigInterface.h"
13 
14 #include <fontconfig/fontconfig.h>
15 
16 class SkFontConfigInterfaceDirect : public SkFontConfigInterface {
17 public:
18     /** Create around a FontConfig instance.
19      *  If 'fc' is nullptr, each method call will use the current config.
20      *  Takes ownership of 'fc' and will call FcConfigDestroy on it.
21      */
22     SkFontConfigInterfaceDirect(FcConfig* fc);
23     ~SkFontConfigInterfaceDirect() override;
24 
25     bool matchFamilyName(const char familyName[],
26                          SkFontStyle requested,
27                          FontIdentity* outFontIdentifier,
28                          SkString* outFamilyName,
29                          SkFontStyle* outStyle) override;
30 
31     SkStreamAsset* openStream(const FontIdentity&) override;
32 
33 protected:
34     virtual bool isAccessible(const char* filename);
35 
36 private:
37     FcConfig * const fFC;
38     bool isValidPattern(FcPattern* pattern);
39     FcPattern* MatchFont(FcFontSet* font_set, const char* post_config_family,
40                          const SkString& family);
41     using INHERITED = SkFontConfigInterface;
42 };
43 
44 #endif
45