Debian Codegraph @

tools/fonts/FontToolUtils.h

raw
1 /*
2 * Copyright 2023 Google LLC
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 FontToolUtils_DEFINED
9 #define FontToolUtils_DEFINED
10
11 #include "include/core/SkColor.h"
12 #include "include/core/SkFontStyle.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkString.h"
15 #include "include/core/SkTypeface.h"
16
17 class SkBitmap;
18 class SkImage;
19 class SkFont;
20 class SkFontMgr;
21 class SkFontScanner;
22
23 namespace ToolUtils {
24 /**
25 * Returns a font that has a non-empty typeface. This could change, so don't depend on things like
26 * how it looks, font metrics, etc.
27 */
28 SkFont DefaultPortableFont();
29
30 sk_sp<SkTypeface> DefaultPortableTypeface();
31
32 /**
33 * Returns a platform-independent text renderer.
34 */
35 sk_sp<SkTypeface> CreatePortableTypeface(const char* name, SkFontStyle style);
36
37 /* Return a color emoji typeface with planets to scale if available. */
38 sk_sp<SkTypeface> PlanetTypeface();
39
40 enum class EmojiFontFormat {
41 Cbdt,
42 Sbix,
43 ColrV0,
44 Test,
45 Svg
46 };
47
48 struct EmojiTestSample {
49 sk_sp<SkTypeface> typeface = nullptr;
50 const char* sampleText = "";
51 };
52
53 /** Return a color emoji typeface if available. */
54 EmojiTestSample EmojiSample();
55
56 /** Return a color emoji typeface of a specific color font format if available. */
57 EmojiTestSample EmojiSample(EmojiFontFormat format);
58
59 /** Return a string representation of the requeste format. Useful for suffixing test names. */
60 SkString NameForFontFormat(EmojiFontFormat format);
61
62 /** A simple SkUserTypeface for testing. */
63 sk_sp<SkTypeface> SampleUserTypeface();
64
65 SkBitmap CreateStringBitmap(int w, int h, SkColor c, int x, int y, int textSize, const char* str);
66 sk_sp<SkImage> CreateStringImage(int w, int h, SkColor c, int x, int y, int textSize, const char* str);
67
68 // This returns the SkFontMgr that has been compiled in and configured (e.g. via CLI flag)
69 sk_sp<SkFontMgr> TestFontMgr();
70
71 // this returns the SkFontScanner that has been compiled in and configured (e.g. via CLI flag)
72 std::unique_ptr<SkFontScanner> TestFontScanner();
73
74 // Must be called before the first call to TestFontMgr to have any effect.
75 void UsePortableFontMgr();
76
77 // Returns true if this platform is Windows and this binary is being configured to run
78 // with the GDI font manager.
79 bool FontMgrIsGDI();
80
81 // This returns the default SkTypeface returned by the TestFontMgr(). If there was no default
82 // Typeface, DefaultPortableTypeface() is returned instead.
83 sk_sp<SkTypeface> DefaultTypeface();
84
85 // Returns a Typeface matching the given criteria as returned by TestFontMgr(). This may be different
86 // on different platforms.
87 sk_sp<SkTypeface> CreateTestTypeface(const char* name, SkFontStyle style);
88
89 // Load the resource with the provided name as a Typeface using TestFontMgr().
90 sk_sp<SkTypeface> CreateTypefaceFromResource(const char* resource, int ttcIndex = 0);
91
92 // This returns a font using DefaultTypeface()
93 SkFont DefaultFont();
94
95 void RegisterAvailableTypefaceFactories();
96
97 } // namespace ToolUtils
98
99 #endif