From 2439471a2388c92b9256987e649d5e91df2e1711 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 20 Feb 2024 19:11:42 -0300 Subject: [PATCH] Add EmptyFontMgr when LAF_BACKEND=none --- text/CMakeLists.txt | 3 ++ text/empty_font_mgr.cpp | 72 +++++++++++++++++++++++++++++++++++++++++ text/font_mgr.h | 6 ++-- text/font_style_set.h | 9 ++---- text/skia_font_mgr.cpp | 6 ++-- text/skia_font_mgr.h | 4 +-- 6 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 text/empty_font_mgr.cpp diff --git a/text/CMakeLists.txt b/text/CMakeLists.txt index 7a10cfe9f..2cae2d627 100644 --- a/text/CMakeLists.txt +++ b/text/CMakeLists.txt @@ -25,6 +25,9 @@ if(LAF_BACKEND STREQUAL "skia") skia_font_mgr.cpp) target_link_libraries(laf-text skia skshaper skunicode) +else() + target_sources(laf-text PRIVATE + empty_font_mgr.cpp) endif() if(LAF_WITH_TESTS) diff --git a/text/empty_font_mgr.cpp b/text/empty_font_mgr.cpp new file mode 100644 index 000000000..02e007c53 --- /dev/null +++ b/text/empty_font_mgr.cpp @@ -0,0 +1,72 @@ +// LAF Text Library +// Copyright (c) 2024 Igara Studio S.A. +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#include "text/font_mgr.h" + +#include "text/font.h" +#include "text/font_style.h" +#include "text/font_style_set.h" +#include "text/typeface.h" + +namespace text { + +class EmptyTypeface : public Typeface { +public: + EmptyTypeface() { } + FontStyle fontStyle() const override { return FontStyle(); } +}; + +class EmptyFont : public Font { +public: + EmptyFont() { } + FontType type() override { return FontType::Unknown; } + int height() const override { return 0; } + int textLength(const std::string& str) const override { return 0; }; + bool isScalable() const override { return false; } + void setSize(int size) override { } + void setAntialias(bool antialias) override { } + bool hasCodePoint(int codepoint) const override { return false; } +}; + +class EmptyFontStyleSet : public FontStyleSet { +public: + EmptyFontStyleSet() { } + int count() override { return 0; } + void getStyle(int index, + FontStyle& style, + std::string& name) override { } + TypefaceRef typeface(int index) override { + return base::make_ref(); + } + TypefaceRef matchStyle(const FontStyle& style) override { + return base::make_ref(); + } +}; + +class EmptyFontMgr : public FontMgr { +public: + EmptyFontMgr() { } + ~EmptyFontMgr() { } + FontRef defaultFont(float size) const override { + return base::make_ref(); + } + int countFamilies() const override { return 0; } + std::string familyName(int i) const override { return std::string(); } + FontStyleSetRef familyStyleSet(int i) const override { + return base::make_ref(); + } + FontStyleSetRef matchFamily(const std::string& familyName) const override { + return base::make_ref(); + } +}; + +// static +FontMgrRef FontMgr::Make() +{ + return base::make_ref(); +} + +} // namespace text diff --git a/text/font_mgr.h b/text/font_mgr.h index 1067618df..0822bd538 100644 --- a/text/font_mgr.h +++ b/text/font_mgr.h @@ -20,7 +20,7 @@ namespace text { class FontMgr : public base::RefCount { public: - static base::Ref Make(); + static FontMgrRef Make(); FontRef loadSpriteSheetFont(const char* filename, int scale); FontRef loadTrueTypeFont(const char* filename, int height); @@ -28,8 +28,8 @@ namespace text { virtual FontRef defaultFont(float size = 12) const = 0; virtual int countFamilies() const = 0; virtual std::string familyName(int index) const = 0; - virtual base::Ref familyStyleSet(int index) const = 0; - virtual base::Ref matchFamily(const std::string& familyName) const = 0; + virtual FontStyleSetRef familyStyleSet(int index) const = 0; + virtual FontStyleSetRef matchFamily(const std::string& familyName) const = 0; protected: FontMgr(); diff --git a/text/font_style_set.h b/text/font_style_set.h index 2147ad78a..2ba2f0efe 100644 --- a/text/font_style_set.h +++ b/text/font_style_set.h @@ -8,13 +8,10 @@ #define LAF_TEXT_FONT_STYLE_SET_H_INCLUDED #pragma once -#include "base/ref.h" -#include "text/typeface.h" +#include "text/fwd.h" namespace text { - class FontStyle; - class FontStyleSet : public base::RefCount { protected: virtual ~FontStyleSet() { } @@ -23,8 +20,8 @@ namespace text { virtual void getStyle(int index, FontStyle& style, std::string& name) = 0; - virtual base::Ref typeface(int index) = 0; - virtual base::Ref matchStyle(const FontStyle& style) = 0; + virtual TypefaceRef typeface(int index) = 0; + virtual TypefaceRef matchStyle(const FontStyle& style) = 0; }; } // namespace text diff --git a/text/skia_font_mgr.cpp b/text/skia_font_mgr.cpp index 114621521..258cd1510 100644 --- a/text/skia_font_mgr.cpp +++ b/text/skia_font_mgr.cpp @@ -80,7 +80,7 @@ TypefaceRef SkiaFontStyleSet::matchStyle(const FontStyle& style) // SkiaFontMgr // static -base::Ref FontMgr::Make() +FontMgrRef FontMgr::Make() { return base::make_ref(); } @@ -123,12 +123,12 @@ std::string SkiaFontMgr::familyName(int i) const return std::string(name.c_str()); } -base::Ref SkiaFontMgr::familyStyleSet(int i) const +FontStyleSetRef SkiaFontMgr::familyStyleSet(int i) const { return base::make_ref(m_skFontMgr->createStyleSet(i)); } -base::Ref SkiaFontMgr::matchFamily(const std::string& familyName) const +FontStyleSetRef SkiaFontMgr::matchFamily(const std::string& familyName) const { return base::make_ref(m_skFontMgr->matchFamily(familyName.c_str())); } diff --git a/text/skia_font_mgr.h b/text/skia_font_mgr.h index 328c8d185..9e317d596 100644 --- a/text/skia_font_mgr.h +++ b/text/skia_font_mgr.h @@ -52,8 +52,8 @@ class SkiaFontMgr : public FontMgr { int countFamilies() const override; std::string familyName(int i) const override; - base::Ref familyStyleSet(int i) const override; - base::Ref matchFamily(const std::string& familyName) const override; + FontStyleSetRef familyStyleSet(int i) const override; + FontStyleSetRef matchFamily(const std::string& familyName) const override; sk_sp skFontMgr() const { return m_skFontMgr; }