12#include "PdfTextState.h"
14#include "PdfEncoding.h"
15#include "PdfElement.h"
16#include "PdfFontMetrics.h"
22struct PODOFO_API PdfFontCreateParams final
28struct PODOFO_API PdfSplittedString final
31 bool IsSeparator =
false;
44class PODOFO_API
PdfFont :
public PdfDictionaryElement
48 friend class PdfFontFactory;
49 friend class PdfFontObject;
83 static bool TryCreateFromObject(
const PdfObject&
obj, std::unique_ptr<const PdfFont>&
font);
151 double GetStringLength(
const std::string_view&
str,
const PdfTextState&
state)
const;
157 bool TryGetStringLength(
const std::string_view&
str,
const PdfTextState&
state,
double&
width)
const;
186 double GetWordSpacingLength(
const PdfTextState&
state)
const;
194 double GetSpaceCharLength(
const PdfTextState&
state)
const;
221 bool HasCIDSubset()
const;
226 double GetCIDWidth(
unsigned cid)
const;
231 double GetLineSpacing(
const PdfTextState&
state)
const;
237 double GetUnderlineThickness(
const PdfTextState&
state)
const;
243 double GetUnderlinePosition(
const PdfTextState&
state)
const;
249 double GetStrikeThroughPosition(
const PdfTextState&
state)
const;
255 double GetStrikeThroughThickness(
const PdfTextState&
state)
const;
264 double GetAscent(
const PdfTextState&
state)
const;
274 double GetDescent(
const PdfTextState&
state)
const;
276 virtual bool SupportsSubsetting()
const;
280 bool IsStandard14Font()
const;
282 bool IsStandard14Font(PdfStandard14FontType&
std14Font)
const;
284 static std::string_view GetStandard14FontName(PdfStandard14FontType
stdFont);
301 bool IsCIDFont()
const;
306 virtual bool IsObjectLoaded()
const;
313 inline bool IsEmbeddingEnabled()
const {
return m_EmbeddingEnabled; }
319 inline std::string_view GetSubsetPrefix()
const;
338 inline const std::string&
GetName()
const {
return m_Name; }
342 inline bool IsProxy()
const {
return m_IsProxy; }
356 bool tryMapCIDToGIDLoadedMetrics(
unsigned cid,
unsigned&
gid)
const;
360 bool tryMapCIDToGIDUnicode(
unsigned cid,
unsigned&
gid)
const;
371 bool TryGetSubstituteCIDEncoding(std::unique_ptr<PdfEncodingMap>&
cidEncodingMap)
const;
373 PdfCIDSystemInfo GetCIDSystemInfo()
const;
377 std::vector<PdfCharGIDInfo> GetCharGIDInfos();
379 virtual PdfObject* getDescendantFontObject();
383 virtual void initImported();
385 virtual void embedFont();
387 virtual void embedFontSubset();
432 PdfCharCodeList Codes;
435 using CIDSubsetMap = std::map<unsigned, CIDSubsetInfo>;
437 bool tryConvertToGIDs(
const std::string_view& utf8Str, PdfGlyphAccess access, std::vector<unsigned>& gids)
const;
438 bool tryAddSubsetGID(
unsigned gid,
const unicodeview& codePoints, PdfCID& cid);
440 void initBase(
const PdfEncoding& encoding);
442 double getStringLength(
const std::vector<PdfCID>& cids,
const PdfTextState& state)
const;
444 void embedFontFileData(PdfObject& descriptor,
const PdfName& fontFileName,
445 const std::function<
void(PdfDictionary& dict)>& dictWriter,
const bufferview& data);
447 static std::unique_ptr<PdfFont> createFontForType(PdfDocument& doc,
const PdfFontMetricsConstPtr& metrics,
448 const PdfEncoding& encoding, PdfFontFileType type,
bool preferNonCID);
450 void initSpaceDescriptors();
452 void pushSubsetInfo(
unsigned cid,
const PdfGID& gid,
const PdfCharCode& code);
456 std::string m_SubsetPrefix;
457 bool m_EmbeddingEnabled;
459 bool m_SubsettingEnabled;
461 std::unique_ptr<CIDSubsetMap> m_subsetCIDMap;
462 std::unique_ptr<std::unordered_map<unsigned, unsigned>> m_subsetGIDToCIDMap;
463 PdfCIDToGIDMapConstPtr m_fontProgCIDToGIDMap;
464 double m_WordSpacingLengthRaw;
465 double m_SpaceCharLengthRaw;
468 PdfFontMetricsConstPtr m_Metrics;
469 std::unique_ptr<PdfEncoding> m_Encoding;
470 std::shared_ptr<PdfCharCodeMap> m_DynamicCIDMap;
471 std::shared_ptr<PdfCharCodeMap> m_DynamicToUnicodeMap;
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
An interface for writing blocks of data to a data source.
Definition OutputStream.h:18
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:81
The PDF dictionary data type of PoDoFo (inherits from PdfDataContainer, the base class for such repre...
Definition PdfDictionary.h:82
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:111
A PdfEncoding is in PdfFont to transform a text string into a representation so that it can be displa...
Definition PdfEncoding.h:55
A PdfFont that represents a CID-keyed font.
Definition PdfFontCID.h:17
This class assists PdfDocument with caching font information.
Definition PdfFontManager.h:54
This abstract class provides access to font metrics information.
Definition PdfFontMetrics.h:36
This is a common base class for simple, non CID-keyed fonts like Type1, TrueType and Type3.
Definition PdfFontSimple.h:20
Before you can draw text on a PDF document, you have to create a font object first.
Definition PdfFont.h:45
static bool IsStandard14Font(const std::string_view &fontName, bool useAltNames, PdfStandard14FontType &stdFont)
Determine if font name is a Standard14 font.
const std::string & GetName() const
Get the base font name of this font.
Definition PdfFont.h:338
const PdfFontMetrics & GetMetrics() const
Returns a handle to the fontmetrics object of this font.
Definition PdfFont.h:331
static bool TryCreateFromObject(PdfObject &obj, std::unique_ptr< PdfFont > &font)
Create a new PdfFont from an existing font in a PDF file.
const PdfEncoding & GetEncoding() const
Returns a reference to the fonts encoding.
Definition PdfFont.h:324
bool IsSubsettingEnabled() const
Check if this is a subsetting font.
Definition PdfFont.h:311
bool IsProxy() const
True if the font is substitute for embedding.
Definition PdfFont.h:342
static bool IsStandard14Font(const std::string_view &fontName, PdfStandard14FontType &stdFont)
Determine if font name is a Standard14 font.
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:35
A string that can be written to a PDF document.
Definition PdfString.h:24
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
cspan< char32_t > unicodeview
Unicode code point view.
Definition basetypes.h:27
PdfGlyphAccess
When accessing a glyph, there may be a difference in the glyph ID to retrieve the widths or to index ...
Definition PdfDeclarations.h:323
@ String
String datatype in PDF file. Strings have the form (Hallo World!) in PDF files.
@ Create
Create a new file or truncate existing one for writing/reading.
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:19
PdfFontCreateFlags
Font init flags.
Definition PdfDeclarations.h:340
std::shared_ptr< const PdfFontMetrics > PdfFontMetricsConstPtr
Convenience typedef for a const PdfEncoding shared ptr.
Definition PdfFontMetrics.h:27
PdfFontType
Enum specifying the type of the font.
Definition PdfDeclarations.h:286
Represent a CID (Character ID) with full code unit information.
Definition PdfEncodingCommon.h:52
A character code unit.
Definition PdfEncodingCommon.h:20
Represents a GID (Glyph ID) with PDF metrics identifier.
Definition PdfEncodingCommon.h:74