AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AFontManager.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include "AUI/Common/SharedPtr.h"
   15#include "AUI/Util/Manager.h"
   16#include "AUI/Font/AFontFamily.h"
   17#include "AUI/Font/AFont.h"
   18
   19class API_AUI_VIEWS AFontManager {
   20public:
   21    AFontManager();
   22    AFontManager(const AFontManager&) = delete;
   23    virtual ~AFontManager();
   24
   25    static AFontManager& inst();
   26
   27    [[nodiscard]] _<AFontFamily> getDefaultFamily() {
   28        return mDefaultFamily;
   29    }
   30    [[nodiscard]] _<AFont> getDefaultFont() {
   31        return mDefaultFont;
   32    }
   33
   34    [[nodiscard]]
   35    _<AFontFamily> getFontFamily(const AString& name) const {
   36        if (auto c = mFamilies.contains(name)) {
   37            return c->second;
   38        }
   39        return nullptr;
   40    }
   41    [[nodiscard]]
   42    _<AFont> getFont(const AUrl& url) {
   43        if (auto c = mLoadedFont.contains(url)) {
   44            return c->second;
   45        }
   46        return mLoadedFont[url] = loadFont(url);
   47    }
   48private:
   49    AMap<AUrl, _<AFont>> mLoadedFont;
   50    AMap<AString, _<AFontFamily>> mFamilies;
   51    _<FreeType> mFreeType;
   52    _<AFontFamily> mDefaultFamily;
   53    _<AFont> mDefaultFont;
   54
   55    AString getPathToFont(const AString& family);
   56
   57    _<AFont> loadFont(const AUrl& url);
   58
   59
   60    friend class AFont;
   61};
A std::map with AUI extensions.
Definition AMap.h:218
Represents a Unicode character string.
Definition AString.h:38
Uniform Resource Locator implementation.
Definition AUrl.h:31
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179