/* * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef FontToolUtils_DEFINED #define FontToolUtils_DEFINED #include "include/core/SkColor.h" #include "include/core/SkFontStyle.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" #include "include/core/SkTypeface.h" class SkBitmap; class SkImage; class SkFont; class SkFontMgr; class SkFontScanner; namespace ToolUtils { /** * Returns a font that has a non-empty typeface. This could change, so don't depend on things like * how it looks, font metrics, etc. */ SkFont DefaultPortableFont(); sk_sp DefaultPortableTypeface(); /** * Returns a platform-independent text renderer. */ sk_sp CreatePortableTypeface(const char* name, SkFontStyle style); /* Return a color emoji typeface with planets to scale if available. */ sk_sp PlanetTypeface(); enum class EmojiFontFormat { Cbdt, Sbix, ColrV0, Test, Svg }; struct EmojiTestSample { sk_sp typeface = nullptr; const char* sampleText = ""; }; /** Return a color emoji typeface if available. */ EmojiTestSample EmojiSample(); /** Return a color emoji typeface of a specific color font format if available. */ EmojiTestSample EmojiSample(EmojiFontFormat format); /** Return a string representation of the requeste format. Useful for suffixing test names. */ SkString NameForFontFormat(EmojiFontFormat format); /** A simple SkUserTypeface for testing. */ sk_sp SampleUserTypeface(); SkBitmap CreateStringBitmap(int w, int h, SkColor c, int x, int y, int textSize, const char* str); sk_sp CreateStringImage(int w, int h, SkColor c, int x, int y, int textSize, const char* str); // This returns the SkFontMgr that has been compiled in and configured (e.g. via CLI flag) sk_sp TestFontMgr(); // this returns the SkFontScanner that has been compiled in and configured (e.g. via CLI flag) std::unique_ptr TestFontScanner(); // Must be called before the first call to TestFontMgr to have any effect. void UsePortableFontMgr(); // Returns true if this platform is Windows and this binary is being configured to run // with the GDI font manager. bool FontMgrIsGDI(); // This returns the default SkTypeface returned by the TestFontMgr(). If there was no default // Typeface, DefaultPortableTypeface() is returned instead. sk_sp DefaultTypeface(); // Returns a Typeface matching the given criteria as returned by TestFontMgr(). This may be different // on different platforms. sk_sp CreateTestTypeface(const char* name, SkFontStyle style); // Load the resource with the provided name as a Typeface using TestFontMgr(). sk_sp CreateTypefaceFromResource(const char* resource, int ttcIndex = 0); // This returns a font using DefaultTypeface() SkFont DefaultFont(); } // namespace ToolUtils #endif