7 #ifndef PDF_FONT_CACHE_H
8 #define PDF_FONT_CACHE_H
13 #include "PdfEncodingFactory.h"
15 #ifdef PODOFO_HAVE_FONTCONFIG
16 #include "PdfFontConfigWrapper.h"
19 #if defined(_WIN32) && defined(PODOFO_HAVE_WIN32GDI)
21 typedef struct HFONT__* HFONT;
28 struct PODOFO_API PdfFontSearchParams final
30 nullable<PdfFontStyle> Style;
34 std::string FontFamilyPattern;
37 std::function<PdfFont* (
const std::vector<PdfFont*>)> FontSelector;
59 friend class PdfCommon;
73 const PdfFontSearchParams& searchParams = { },
const PdfFontCreateParams& createParams = { });
75 PdfFont* SearchFont(
const std::string_view& fontPattern,
const PdfFontCreateParams& createParams);
77 PdfFont& GetStandard14Font(PdfStandard14FontType stdFont,
78 const PdfFontCreateParams& params = { });
80 PdfFont& GetOrCreateFont(
const std::string_view& fontPath,
unsigned faceIndex,
81 const PdfFontCreateParams& params = { });
83 PdfFont& GetOrCreateFontFromBuffer(
const bufferview& buffer,
unsigned faceIndex,
84 const PdfFontCreateParams& params = { });
86 PdfFont& GetOrCreateFont(
const std::string_view& fontPath,
87 const PdfFontCreateParams& params = { });
89 PdfFont& GetOrCreateFontFromBuffer(
const bufferview& buffer,
90 const PdfFontCreateParams& params = { });
93 const PdfFontCreateParams& params = { });
98 PdfFont* GetCachedFont(
const PdfReference& ref);
105 const PdfFontSearchParams& params = { });
107 #if defined(_WIN32) && defined(PODOFO_HAVE_WIN32GDI)
108 PdfFont& GetOrCreateFont(HFONT font,
const PdfFontCreateParams& params = { });
111 #ifdef PODOFO_HAVE_FONTCONFIG
119 static void SetFontConfigWrapper(
const std::shared_ptr<PdfFontConfigWrapper>& fontConfig);
121 static PdfFontConfigWrapper& GetFontConfigWrapper();
130 PdfFontManager(PdfDocument& doc);
133 const PdfFont* GetLoadedFont(
const PdfResources& resources,
const std::string_view& name);
142 PdfFont* AddImported(std::unique_ptr<PdfFont>&& font);
146 std::string GenerateSubsetPrefix();
148 static void AddFontDirectory(
const std::string_view& path);
155 Descriptor(
const std::string_view& name, PdfStandard14FontType stdType,
156 const PdfEncoding& encoding,
bool hasFontStyle,
PdfFontStyle style);
158 Descriptor(
const Descriptor& rhs) =
default;
160 const std::string
Name;
161 const PdfStandard14FontType StdType;
162 const unsigned EncodingId;
163 const bool HasFontStyle;
167 struct PathDescriptor
169 PathDescriptor(
const std::string_view& filepath,
unsigned faceIndex,
const PdfEncoding& encoding);
171 PathDescriptor(
const PathDescriptor& rhs) =
default;
173 const std::string FilePath;
174 const unsigned FaceIndex;
175 const unsigned EncodingId;
180 size_t operator()(
const Descriptor& elem)
const;
181 size_t operator()(
const PathDescriptor& elem)
const;
186 bool operator()(
const Descriptor& lhs,
const Descriptor& rhs)
const;
187 bool operator()(
const PathDescriptor& lhs,
const PathDescriptor& rhs)
const;
190 using CachedPaths = std::unordered_map<PathDescriptor, PdfFont*, HashElement, EqualElement>;
191 using CachedQueries = std::unordered_map<Descriptor, std::vector<PdfFont*>, HashElement, EqualElement>;
196 std::unique_ptr<PdfFont> Font;
199 using FontMap = std::unordered_map<PdfReference, Storage>;
202 static std::unique_ptr<const PdfFontMetrics> getFontMetrics(
const std::string_view& fontName,
203 const PdfFontSearchParams& params);
204 PdfFont* getImportedFont(
const std::string_view& pattern,
205 const PdfFontSearchParams& searchParams,
const PdfFontCreateParams& createParams);
206 PdfFont* addImported(std::vector<PdfFont*>& fonts, std::unique_ptr<PdfFont>&& font);
209 #if defined(_WIN32) && defined(PODOFO_HAVE_WIN32GDI)
210 static std::unique_ptr<charbuff> getWin32FontData(
const std::string_view& fontName,
211 const PdfFontSearchParams& params);
215 PdfFontManager(
const PdfFontManager&) =
delete;
216 PdfFontManager& operator=(
const PdfFontManager&) =
delete;
220 std::string m_currentPrefix;
223 CachedQueries m_cachedQueries;
226 CachedPaths m_cachedPaths;
232 std::unordered_map<std::string, std::unique_ptr<PdfFont>> m_inlineFonts;
234 #ifdef PODOFO_HAVE_FONTCONFIG
235 static std::shared_ptr<PdfFontConfigWrapper> m_fontConfig;
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
PdfDocument is the core interface for working with PDF documents.
Definition: PdfDocument.h:108
This class assists PdfDocument with caching font information.
Definition: PdfFontManager.h:54
PdfFont * SearchFont(const std::string_view &fontPattern, const PdfFontSearchParams &searchParams={ }, const PdfFontCreateParams &createParams={ })
Get a font from the cache.
Before you can draw text on a PDF document, you have to create a font object first.
Definition: PdfFont.h:49
PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk...
Definition: PdfMemDocument.h:39
A interface that provides a wrapper around /Resources.
Definition: PdfResources.h:25
PdfStreamedDocument is the preferred class for creating new PDF documents.
Definition: PdfStreamedDocument.h:50
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition: basetypes.h:16
@ Name
Name datatype. Names are used as keys in dictionary to reference values.
PdfFontAutoSelectBehavior
Flags to control font creation.
Definition: PdfDeclarations.h:302
cspan< char > bufferview
Convenient read-only char buffer span.
Definition: basetypes.h:19
std::shared_ptr< const PdfFontMetrics > PdfFontMetricsConstPtr
Convenience typedef for a const PdfEncoding shared ptr.
Definition: PdfFontMetrics.h:24
PdfFontStyle
Font style flags used during searches.
Definition: PdfDeclarations.h:281
PdfFontMatchBehaviorFlags
Definition: PdfDeclarations.h:319