wxMaxima
Loading...
Searching...
No Matches
FontVariantCache.h
Go to the documentation of this file.
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2023 Gunter Königsmann <wxMaxima@peterpall.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// SPDX-License-Identifier: GPL-2.0+
21
22#ifndef FONTVARIANTCACHE_H
23#define FONTVARIANTCACHE_H
24
25#include "precomp.h"
26#include <memory>
27#include <wx/font.h>
28#include <functional>
29#include <list>
30#include <utility>
31#include <unordered_map>
32
43{
44 FontVariantCache(const FontVariantCache &) = delete;
45 FontVariantCache &operator=(const FontVariantCache &) = delete;
46public:
48 explicit FontVariantCache(const wxString &fontName);
51 void ClearCache() const;
55 std::shared_ptr<wxFont> GetFont (double size,
56 bool isItalic,
57 bool isBold,
58 bool isUnderlined,
59 bool isSlanted,
60 bool isStrikeThrough
61 );
63 const wxString& GetFaceName() const {return m_fontName;}
64private:
66 static int GetIndex (
67 bool isItalic,
68 bool isBold,
69 bool isUnderlined,
70 bool isSlanted,
71 bool isStrikeThrough
72 )
73 {
74 int result =0;
75 if(isItalic)
76 result++;
77 if(isBold)
78 result += 2;
79 if(isUnderlined)
80 result +=4;
81 if(isSlanted)
82 result +=8;
83 if(isStrikeThrough)
84 result +=16;
85 return result;
86 }
87
89 mutable std::unordered_map<double, std::shared_ptr<wxFont>> m_fontCaches[32];
91 wxString m_fontName;
92};
93
94#endif // FONTVARIANTCACHE_H
Definition: FontVariantCache.h:43
std::shared_ptr< wxFont > GetFont(double size, bool isItalic, bool isBold, bool isUnderlined, bool isSlanted, bool isStrikeThrough)
Returns a font with the requested attributes.
Definition: FontVariantCache.cpp:46
void ClearCache() const
Clear this font variant cache.
Definition: FontVariantCache.cpp:32
const wxString & GetFaceName() const
Get the name of the fonts this font variant cache is responsible for.
Definition: FontVariantCache.h:63