14 #include "PdfTextState.h"
16 #include "PdfEncoding.h"
17 #include "PdfElement.h"
18 #include "PdfFontMetrics.h"
24 using UsedGIDsMap = std::map<unsigned, PdfCID>;
26 struct PODOFO_API PdfFontCreateParams final
32 struct PODOFO_API PdfSplittedString final
35 bool IsSeparator =
false;
48 class PODOFO_API
PdfFont :
public PdfDictionaryElement
52 friend class PdfFontFactory;
53 friend class PdfFontObject;
87 static bool TryCreateFromObject(
const PdfObject& obj, std::unique_ptr<const PdfFont>& font);
103 const PdfFontCreateParams& createParams);
117 static std::unique_ptr<PdfFont> CreateStandard14(
PdfDocument& doc, PdfStandard14FontType std14Font,
118 const PdfFontCreateParams& createParams);
124 bool TryCreateSubstituteFont(
PdfFont*& substFont)
const;
136 void WriteStringToStream(
OutputStream& stream,
const std::string_view& str)
const;
145 bool TryGetGID(char32_t codePoint,
PdfGlyphAccess access,
unsigned& gid)
const;
153 double GetStringLength(
const std::string_view& str,
const PdfTextState& state)
const;
159 bool TryGetStringLength(
const std::string_view& str,
const PdfTextState& state,
double& width)
const;
167 double GetEncodedStringLength(
const PdfString& encodedStr,
const PdfTextState& state)
const;
172 bool TryGetEncodedStringLength(
const PdfString& encodedStr,
const PdfTextState& state,
double& length)
const;
179 bool TryScanEncodedString(
const PdfString& encodedStr,
const PdfTextState& state, std::string& utf8str,
180 std::vector<double>& lengths, std::vector<unsigned>& positions)
const;
188 double GetWordSpacingLength(
const PdfTextState& state)
const;
196 double GetSpaceCharLength(
const PdfTextState& state)
const;
201 double GetCharLength(char32_t codePoint,
const PdfTextState& state,
bool ignoreCharSpacing =
false)
const;
203 bool TryGetCharLength(char32_t codePoint,
const PdfTextState& state,
bool ignoreCharSpacing,
double& width)
const;
205 bool TryGetCharLength(char32_t codePoint,
const PdfTextState& state,
double& width)
const;
207 double GetDefaultCharLength(
const PdfTextState& state,
bool ignoreCharSpacing =
false)
const;
219 void AddSubsetGIDs(
const PdfString& encodedStr);
224 double GetLineSpacing(
const PdfTextState& state)
const;
230 double GetUnderlineThickness(
const PdfTextState& state)
const;
236 double GetUnderlinePosition(
const PdfTextState& state)
const;
242 double GetStrikeThroughPosition(
const PdfTextState& state)
const;
248 double GetStrikeThroughThickness(
const PdfTextState& state)
const;
257 double GetAscent(
const PdfTextState& state)
const;
267 double GetDescent(
const PdfTextState& state)
const;
269 virtual bool SupportsSubsetting()
const;
273 bool IsStandard14Font()
const;
275 bool IsStandard14Font(PdfStandard14FontType& std14Font)
const;
277 static std::string_view GetStandard14FontName(PdfStandard14FontType stdFont);
284 static bool IsStandard14Font(
const std::string_view& fontName, PdfStandard14FontType& stdFont);
289 static bool IsStandard14Font(
const std::string_view& fontName,
bool useAltNames, PdfStandard14FontType& stdFont);
294 bool IsCIDKeyed()
const;
299 virtual bool IsObjectLoaded()
const;
306 inline bool IsEmbeddingEnabled()
const {
return m_EmbeddingEnabled; }
331 inline const std::string&
GetName()
const {
return m_Name; }
333 const UsedGIDsMap& GetUsedGIDs()
const {
return m_SubsetGIDs; }
335 PdfObject& GetDescendantFontObject();
338 void EmbedFontFile(PdfObject& descriptor);
339 void EmbedFontFileType1(PdfObject& descriptor,
const bufferview& data,
340 unsigned length1,
unsigned length2,
unsigned length3);
341 void EmbedFontFileCFF(PdfObject& descriptor,
const bufferview& data);
342 void EmbedFontFileTrueType(PdfObject& descriptor,
const bufferview& data);
343 void EmbedFontFileOpenType(PdfObject& descriptor,
const bufferview& data);
345 virtual bool tryMapCIDToGID(
unsigned cid,
unsigned& gid)
const;
350 double GetCIDLengthRaw(
unsigned cid)
const;
352 void GetBoundingBox(PdfArray& arr)
const;
356 void FillDescriptor(PdfDictionary& dict)
const;
358 virtual PdfObject* getDescendantFontObject();
362 virtual void initImported();
364 virtual void embedFont();
366 virtual void embedFontSubset();
369 PdfFont(
const PdfFont& rhs) =
delete;
380 void InitImported(
bool wantEmbed,
bool wantSubset);
390 PdfCID AddSubsetGIDSafe(
unsigned gid,
const unicodeview& codePoints);
396 PdfCharCode AddCharCodeSafe(
unsigned gid,
const unicodeview& codePoints);
402 bool TryMapCIDToGID(
unsigned cid,
PdfGlyphAccess access,
unsigned& gid)
const;
405 bool tryConvertToGIDs(
const std::string_view& utf8Str,
PdfGlyphAccess access, std::vector<unsigned>& gids)
const;
406 bool tryAddSubsetGID(
unsigned gid,
const unicodeview& codePoints, PdfCID& cid);
408 void initBase(
const PdfEncoding& encoding);
410 double getStringLength(
const std::vector<PdfCID>& cids,
const PdfTextState& state)
const;
412 void embedFontFileData(PdfObject& descriptor,
const PdfName& fontFileName,
413 const std::function<
void(PdfDictionary& dict)>& dictWriter,
const bufferview& data);
415 static std::unique_ptr<PdfFont> createFontForType(PdfDocument& doc,
const PdfFontMetricsConstPtr& metrics,
418 void initSpaceDescriptors();
422 std::string m_SubsetPrefix;
423 bool m_EmbeddingEnabled;
425 bool m_SubsettingEnabled;
426 UsedGIDsMap m_SubsetGIDs;
427 PdfCIDToGIDMapConstPtr m_cidToGidMap;
428 double m_WordSpacingLengthRaw;
429 double m_SpaceCharLengthRaw;
433 std::unique_ptr<PdfEncoding> m_Encoding;
434 std::shared_ptr<PdfCharCodeMap> m_DynamicCIDMap;
435 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
PdfDocument is the core interface for working with PDF documents.
Definition: PdfDocument.h:108
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:33
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:49
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:331
static bool TryCreateFromObject(PdfObject &obj, std::unique_ptr< PdfFont > &font)
Create a new PdfFont from an existing font in a PDF file.
bool IsSubsettingEnabled() const
Check if this is a subsetting font.
Definition: PdfFont.h:304
const PdfFontMetrics & GetMetrics() const
Returns a handle to the fontmetrics object of this font.
Definition: PdfFont.h:324
const std::string & GetSubsetPrefix() const
Definition: PdfFont.h:312
static bool IsStandard14Font(const std::string_view &fontName, PdfStandard14FontType &stdFont)
Determine if font name is a Standard14 font.
const PdfEncoding & GetEncoding() const
Returns a reference to the fonts encoding.
Definition: PdfFont.h:317
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
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 width or to index i...
Definition: PdfDeclarations.h:294
PdfFontFileType
Definition: PdfDeclarations.h:267
@ 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:311
@ None
No special settings.
std::shared_ptr< const PdfFontMetrics > PdfFontMetricsConstPtr
Convenience typedef for a const PdfEncoding shared ptr.
Definition: PdfFontMetrics.h:24
PdfFontType
Enum specifying the type of the font.
Definition: PdfDeclarations.h:257