class FontMgrGM : public skiagm::GM {
public:
+#ifdef SK_LEGACY_FONTMGR_FACTORY
FontMgrGM(SkFontMgr* fontMgr = nullptr) {
SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
fName.append(sk_tool_utils::platform_os_name());
fName.append(sk_tool_utils::platform_extra_config("GDI"));
}
+#else
+ FontMgrGM(sk_sp<SkFontMgr> fontMgr = nullptr) {
+ SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
+
+ fName.set("fontmgr_iter");
+ if (fontMgr) {
+ fName.append("_factory");
+ fFM = std::move(fontMgr);
+ } else {
+ fFM = SkFontMgr::RefDefault();
+ }
+ fName.append(sk_tool_utils::platform_os_name());
+ fName.append(sk_tool_utils::platform_extra_config("GDI"));
+ }
+#endif
protected:
SkString onShortName() override {
}
fName.append(sk_tool_utils::platform_os_name());
fName.append(sk_tool_utils::platform_extra_config("GDI"));
+#ifdef SK_LEGACY_FONTMGR_FACTORY
fFM.reset(SkFontMgr::RefDefault());
+#else
+ fFM = SkFontMgr::RefDefault();
+#endif
}
static void show_bounds(SkCanvas* canvas, const SkPaint& paint, SkScalar x, SkScalar y,
SkTypeface* legacyCreateTypeface(const char familyName[], SkFontStyle style) const;
- /**
- * Return a ref to the default fontmgr. The caller must call unref() on
- * the returned object.
- */
+ /** Return the default fontmgr. */
+#ifdef SK_LEGACY_FONTMGR_FACTORY
static SkFontMgr* RefDefault();
+#else
+ static sk_sp<SkFontMgr> RefDefault();
+#endif
protected:
virtual int onCountFamilies() const = 0;
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const = 0;
private:
- static SkFontMgr* Factory(); // implemented by porting layer
+
+ /** Implemented by porting layer to return the default factory. */
+#ifdef SK_LEGACY_FONTMGR_FACTORY
+ static SkFontMgr* Factory();
+#else
+ static sk_sp<SkFontMgr> Factory();
+#endif
typedef SkRefCnt INHERITED;
};
class SkFontConfigInterface;
/** Creates a SkFontMgr which wraps a SkFontConfigInterface. */
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_FCI(sk_sp<SkFontConfigInterface> fci);
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_FCI(sk_sp<SkFontConfigInterface> fci);
+#endif
#endif // #ifndef SkFontMgr_FontConfigInterface_DEFINED
};
/** Create a font manager for Android. If 'custom' is NULL, use only system fonts. */
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom);
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom);
+#endif
#endif // SkFontMgr_android_DEFINED
class SkFontMgr;
/** Create a custom font manager which scans a given directory for font files. */
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_Custom_Directory(const char* dir);
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_Custom_Directory(const char* dir);
+#endif
/** Create a custom font manager that contains no built-in fonts. */
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_Custom_Empty();
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_Custom_Empty();
+#endif
#endif // SkFontMgr_custom_DEFINED
* If 'fc' is NULL, will use a new default config.
* Takes ownership of 'fc' and will call FcConfigDestroy on it.
*/
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc);
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_FontConfig(FcConfig* fc);
+#endif
#endif // #ifndef SkFontMgr_fontconfig_DEFINED
struct IDWriteFontCollection;
struct IDWriteFontFallback;
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_GDI();
SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL,
IDWriteFontCollection* collection = NULL);
* If DirectWrite could not be initialized, will return NULL.
*/
SK_API SkRemotableFontMgr* SkRemotableFontMgr_New_DirectWrite();
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_GDI();
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL,
+ IDWriteFontCollection* collection = NULL);
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_DirectWrite(IDWriteFactory* factory,
+ IDWriteFontCollection* collection,
+ IDWriteFontFallback* fallback);
+
+/**
+ * Creates an SkFontMgr which renders using DirectWrite and obtains its data
+ * from the SkRemotableFontMgr.
+ *
+ * If DirectWrite could not be initialized, will return NULL.
+ */
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_DirectWriteRenderer(sk_sp<SkRemotableFontMgr>);
+
+/**
+ * Creates an SkRemotableFontMgr backed by DirectWrite using the default
+ * system font collection in the current locale.
+ *
+ * If DirectWrite could not be initialized, will return NULL.
+ */
+SK_API sk_sp<SkRemotableFontMgr> SkRemotableFontMgr_New_DirectWrite();
+#endif
#endif // SK_BUILD_FOR_WIN
#endif // SkTypeface_win_DEFINED
return this->onLegacyCreateTypeface(familyName, style);
}
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::RefDefault() {
static SkOnce once;
static SkFontMgr* singleton;
});
return SkRef(singleton);
}
+#else
+sk_sp<SkFontMgr> SkFontMgr::RefDefault() {
+ static SkOnce once;
+ static sk_sp<SkFontMgr> singleton;
+
+ once([]{
+ sk_sp<SkFontMgr> fm = SkFontMgr::Factory();
+ singleton = fm ? std::move(fm) : sk_make_sp<SkEmptyFontMgr>();
+ });
+ return singleton;
+}
+#endif
/**
* Width has the greatest priority.
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; }
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() { return sk_make_sp<SkFontMgr_Mac>(); }
+#endif
#endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr_New_GDI() { return new SkFontMgrGDI; }
+#else
+sk_sp<SkFontMgr> SkFontMgr_New_GDI() { return sk_make_sp<SkFontMgrGDI>(); }
+#endif
#endif//defined(SK_BUILD_FOR_WIN32)
}
};
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_FCI(sk_sp<SkFontConfigInterface> fci) {
SkASSERT(fci);
return new SkFontMgr_FCI(std::move(fci));
}
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_FCI(sk_sp<SkFontConfigInterface> fci) {
+ SkASSERT(fci);
+ return sk_make_sp<SkFontMgr_FCI>(std::move(fci));
+}
+#endif
#include "SkFontMgr.h"
#include "SkFontMgr_FontConfigInterface.h"
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() {
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() {
+#endif
sk_sp<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal());
if (!fci) {
return nullptr;
"OnlyCustom", "PreferCustom", "PreferSystem"
};
#endif
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) {
+#else
+sk_sp<SkFontMgr> SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) {
+#endif
if (custom) {
SkASSERT(0 <= custom->fSystemFontUse);
SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings));
custom->fFontsXml,
custom->fFallbackFontsXml));
}
-
+#ifdef SK_LEGACY_FONTMGR_FACTORY
return new SkFontMgr_Android(custom);
+#else
+ return sk_make_sp<SkFontMgr_Android>(custom);
+#endif
}
gTestBasePath, gTestFontsXml, gTestFallbackFontsXml));
}
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() {
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() {
+#endif
// These globals exist so that Chromium can override the environment.
// TODO: these globals need to be removed, and Chromium use SkFontMgr_New_Android instead.
if ((gTestFontsXml || gTestFallbackFontsXml) && gTestBasePath) {
SkString fBaseDirectory;
};
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_Custom_Directory(const char* dir) {
return new SkFontMgr_Custom(DirectorySystemFontLoader(dir));
}
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_Custom_Directory(const char* dir) {
+ return sk_make_sp<SkFontMgr_Custom>(DirectorySystemFontLoader(dir));
+}
+#endif
///////////////////////////////////////////////////////////////////////////////
const SkEmbeddedResourceHeader* fHeader;
};
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) {
return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header));
}
+#else
+sk_sp<SkFontMgr> SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) {
+ return sk_make_sp<SkFontMgr_Custom>(EmbeddedSystemFontLoader(header));
+}
+#endif
///////////////////////////////////////////////////////////////////////////////
};
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_Custom_Empty() {
return new SkFontMgr_Custom(EmptyFontLoader());
}
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_Custom_Empty() {
+ return sk_make_sp<SkFontMgr_Custom>(EmptyFontLoader());
+}
+#endif
# define SK_FONT_FILE_PREFIX "/usr/share/fonts/"
#endif
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() {
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() {
+#endif
return SkFontMgr_New_Custom_Directory(SK_FONT_FILE_PREFIX);
}
struct SkEmbeddedResource { const uint8_t* data; size_t size; };
struct SkEmbeddedResourceHeader { const SkEmbeddedResource* entries; int count; };
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header);
+#else
+sk_sp<SkFontMgr> SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header);
+#endif
extern "C" const SkEmbeddedResourceHeader SK_EMBEDDED_FONTS;
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() {
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() {
+#endif
return SkFontMgr_New_Custom_Embedded(&SK_EMBEDDED_FONTS);
}
#include "SkFontMgr.h"
#include "SkFontMgr_custom.h"
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() {
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() {
+#endif
return SkFontMgr_New_Custom_Empty();
}
#include "SkFontMgr.h"
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() {
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() {
+#endif
// Always return nullptr, an empty SkFontMgr will be used.
return nullptr;
}
}
};
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) {
return new SkFontMgr_fontconfig(fc);
}
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_FontConfig(FcConfig* fc) {
+ return sk_make_sp<SkFontMgr_fontconfig>(fc);
+}
+#endif
#include "SkFontMgr_fontconfig.h"
#include "SkTypes.h"
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() {
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() {
+#endif
return SkFontMgr_New_FontConfig(nullptr);
}
////////////////////////////////////////////////////////////////////////////////
#include "SkTypeface_win.h"
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory,
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_DirectWrite(IDWriteFactory* factory,
+#endif
IDWriteFontCollection* collection) {
return SkFontMgr_New_DirectWrite(factory, collection, nullptr);
}
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory,
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_DirectWrite(IDWriteFactory* factory,
+#endif
IDWriteFontCollection* collection,
IDWriteFontFallback* fallback) {
if (nullptr == factory) {
};
}
+#ifdef SK_LEGACY_FONTMGR_FACTORY
return new SkFontMgr_DirectWrite(factory, collection, fallback, localeName, localeNameLen);
+#else
+ return sk_make_sp<SkFontMgr_DirectWrite>(factory, collection, fallback,
+ localeName, localeNameLen);
+#endif
}
#include "SkFontMgr_indirect.h"
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(sk_sp<SkRemotableFontMgr> proxy) {
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_DirectWriteRenderer(sk_sp<SkRemotableFontMgr> proxy) {
+#endif
sk_sp<SkFontMgr> impl(SkFontMgr_New_DirectWrite());
if (!impl) {
return nullptr;
}
+#ifdef SK_LEGACY_FONTMGR_FACTORY
return new SkFontMgr_Indirect(std::move(impl), std::move(proxy));
+#else
+ return sk_make_sp<SkFontMgr_Indirect>(std::move(impl), std::move(proxy));
+#endif
}
#endif//defined(SK_BUILD_FOR_WIN32)
#include "SkFontMgr.h"
#include "SkTypeface_win.h"
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() {
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() {
+#endif
return SkFontMgr_New_DirectWrite();
}
#include "SkFontMgr.h"
#include "SkTypeface_win.h"
+#ifdef SK_LEGACY_FONTMGR_FACTORY
SkFontMgr* SkFontMgr::Factory() {
+#else
+sk_sp<SkFontMgr> SkFontMgr::Factory() {
+#endif
return SkFontMgr_New_GDI();
}