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 GetHardSpacingLength(
const PdfTextState&
state)
const;
202 double GetSpaceCharLength(
const PdfTextState&
state)
const;
229 bool HasCIDSubset()
const;
234 double GetCIDWidth(
unsigned cid)
const;
239 double GetLineSpacing(
const PdfTextState&
state)
const;
245 double GetUnderlineThickness(
const PdfTextState&
state)
const;
251 double GetUnderlinePosition(
const PdfTextState&
state)
const;
257 double GetStrikeThroughPosition(
const PdfTextState&
state)
const;
263 double GetStrikeThroughThickness(
const PdfTextState&
state)
const;
272 double GetAscent(
const PdfTextState&
state)
const;
282 double GetDescent(
const PdfTextState&
state)
const;
284 virtual bool SupportsSubsetting()
const;
286 bool IsStandard14Font()
const;
288 bool IsStandard14Font(PdfStandard14FontType&
std14Font)
const;
290 static std::string_view GetStandard14FontName(PdfStandard14FontType
stdFont);
307 bool IsCIDFont()
const;
312 virtual bool IsObjectLoaded()
const;
321 inline bool IsEmbeddingEnabled()
const {
return m_EmbeddingEnabled; }
327 inline std::string_view GetSubsetPrefix()
const;
346 inline const std::string&
GetName()
const {
return m_Name; }
350 inline bool IsProxy()
const {
return m_IsProxy; }
364 bool tryMapCIDToGIDLoadedMetrics(
unsigned cid,
unsigned&
gid)
const;
368 bool tryMapCIDToGIDNormal(
unsigned cid,
unsigned&
gid)
const;
379 bool TryGetSubstituteCIDEncoding(std::unique_ptr<PdfEncodingMap>&
cidEncodingMap)
const;
381 PdfCIDSystemInfo GetCIDSystemInfo()
const;
385 std::vector<PdfCharGIDInfo> GetCharGIDInfos()
const;
387 virtual PdfObject* getDescendantFontObject();
391 virtual void initImported();
393 virtual void embedFont();
395 virtual void embedFontSubset();
440 PdfCharCodeList Codes;
443 using CIDSubsetMap = std::map<unsigned, CIDSubsetInfo>;
445 bool tryConvertToGIDs(
const std::string_view& utf8Str, PdfGlyphAccess access, std::vector<unsigned>& gids)
const;
446 bool tryAddSubsetGID(
unsigned gid,
const unicodeview& codePoints, PdfCID& cid);
448 void initBase(
const PdfEncoding& encoding);
450 double getStringLength(
const std::vector<PdfCID>& cids,
const PdfTextState& state)
const;
452 void embedFontFileData(PdfDictionary& descriptor,
const PdfName& fontFileName,
453 const std::function<
void(PdfDictionary& dict)>& dictWriter,
const bufferview& data)
const;
455 static std::unique_ptr<PdfFont> createFontForType(PdfDocument& doc, PdfFontMetricsConstPtr&& metrics,
456 const PdfEncoding& encoding,
bool preferNonCID);
458 void initSpacingDescriptors();
460 void initSpaceCharLength();
462 void pushSubsetInfo(
unsigned cid,
const PdfGID& gid,
const PdfCharCode& code);
466 std::string m_SubsetPrefix;
468 bool m_EmbeddingEnabled;
470 bool m_SubsettingEnabled;
472 std::unique_ptr<CIDSubsetMap> m_subsetCIDMap;
473 std::unique_ptr<std::unordered_map<unsigned, unsigned>> m_subsetGIDToCIDMap;
474 const PdfCIDToGIDMap* m_fontProgCIDToGIDMap;
475 double m_WordSpacingLengthRaw;
476 double m_SpaceCharLengthRaw;
479 PdfFontMetricsConstPtr m_Metrics;
480 std::unique_ptr<PdfEncoding> m_Encoding;
481 std::shared_ptr<PdfCharCodeMap> m_DynamicCIDMap;
482 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:58
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:346
const PdfFontMetrics & GetMetrics() const
Returns a handle to the fontmetrics object of this font.
Definition PdfFont.h:339
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:332
bool IsSubsettingEnabled() const
Check if this is a subsetting font.
Definition PdfFont.h:319
bool IsProxy() const
True if the font is substitute for embedding.
Definition PdfFont.h:350
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