PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
font.h
1// Copyright (c) 2009-2025 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_PDF_FONT_H_INCLUDED_
4#define PDFSDK_CXX_PDF_FONT_H_INCLUDED_
5
6#include <functional>
7#include <memory>
8#include <optional>
9#include <string>
10#include <string_view>
11#include <vector>
12
13#include <pdfsdk/core/content.h>
14#include <pdfsdk/cxx/bytes.h>
15#include <pdfsdk/cxx/math.h>
16#include <pdfsdk/cxx/read_stream.h>
17
18#include "forward_declarations.h"
19#include "wrapper_base.h"
20
21namespace PDF {
22
24
30class Font : public detail::RefCountedHandle<PDEFont> {
31public:
38 static Font CreateFromPdfObject(const Object& object);
39
45
57
62 PDAtom GetName() const;
63
76
90
104
123 bool IsEmbedded() const;
124
135
145
154 std::vector<Byte> GetFontFileData() const;
155
164 size_t GetFontFileSize() const;
165
174
180 PDEType3GlyphInfo GetType3GlyphInfo(uint8_t charcode) const;
181
194 Content GetType3CharProc(uint8_t charcode) const;
195
202 void SetType3CharProc(uint8_t charcode, const PDEType3GlyphInfo& glyphInfo, const Content& content);
203
204#ifndef SWIG
217 void EnumCharOutline(const char* codepoint, size_t codepointLen, OutlineEnumMonitor& mon) const;
218#endif
219
229 void EnumCharOutline(const std::string& codepoint, OutlineEnumMonitor& mon) const;
230
231#ifndef SWIG
246 int16_t GetCharWidth(const char* codepoint, size_t codepointLen) const;
247#endif
248
261 int16_t GetCharWidth(const std::string& codepoint) const;
262
263#ifndef SWIG
276 bool IsGlyphPresent(const char* codepoint, size_t codepointLen) const;
277#endif
278
285 bool IsGlyphPresent(const std::string& codepoint) const;
286
287#ifndef SWIG
297 PDEGlyphVertMetric GetCharVertMetric(const char* codepoint, size_t codepointLen) const;
298#endif
299
307 PDEGlyphVertMetric GetCharVertMetric(const std::string& codepoint) const;
308
314
320
321 PDECIDSystemInfo GetCIDSystemInfo() const;
322
333 PDAtom GetEncodingName() const;
334
345 bool CanTypeUnicode(const std::wstring& unicode) const;
346
354 bool IsFauxed() const;
355
364
376 std::optional<PDFontInfo> FindSubstFontInfo(bool forceBold = false, bool forceItalic = false) const;
377
389 bool HasValidToUnicodeMap(PDEFontToUnicodeCheckFlags checkFlags = 0) const;
390
406 void CreateToUnicodeMap(PDF::Document document, PDEFontToUnicodeCreateFlags createFlags = kPDEFontToUnicodeCreateDefault);
407
417 bool HasValidWidths() const;
418
436
448 bool HasValidCIDSet() const;
449
460
469
480 bool HasValidCharSet() const;
481
498
499#ifndef SWIG
508 std::wstring CharToUnicode(const char* codepoint, size_t codepointLen, bool useOnlyToUnicode = false) const;
509#endif
510
518 std::wstring CharToUnicode(const std::string& codepoint, bool useOnlyToUnicode = false) const;
519
520#ifndef SWIG
527 std::string UnicodeToChar(const UnicodeChar* unicode, size_t unicodeLen) const;
528#endif
529
535 std::string UnicodeToChar(const std::wstring& unicode) const;
536
548
549 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(Font, PDEFont)
550};
551
553public:
554 virtual ~OutlineEnumMonitor() = default;
555 virtual void MoveTo(const PDPointF& to) = 0;
556 virtual void LineTo(const PDPointF& to) = 0;
557 virtual void ConicCurveTo(const PDPointF& c, const PDPointF& to) = 0;
558 virtual void CubicCurveTo(const PDPointF& c1, const PDPointF& c2, const PDPointF& to) = 0;
559};
560
564using FontSubstitutionID = uint32_t;
565
576FontSubstitutionID AddFontNameSubstitution(PDAtom pdfFontName, PDAtom familyName, PDFontStyle style = kPDFontStyleRegular);
577
583bool RemoveFontNameSubstitution(FontSubstitutionID id);
584
597FontSubstitutionID AddCIDFontSubstitution(const PDECIDSystemInfo& cidSystemInfo, PDAtom familyName, PDFontStyle style = kPDFontStyleRegular);
598
604bool RemoveCIDFontSubstitution(FontSubstitutionID id);
605
606} // namespace PDF
607
608#include "font_impl.inl"
609
610#endif // PDFSDK_CXX_PDF_FONT_H_INCLUDED_
Represents a content array.
Definition content.h:29
Represents a PDF document.
Definition document.h:27
Matrix GetFontMatrix() const
Get the font transformation matrix.
bool HasValidWidths() const
std::string UnicodeToChar(const std::wstring &unicode) const
Convert the specified Unicode value to its character code equivalent.
Object GetPdfObject() const
Get the PDF object associated with this Font object.
RectF GetType3GlyphsBBox() const
Get the bounding box of the Type 3 glyphs.
ReadStream OpenFontFileStream() const
Open the embedded font program as a read stream.
PDAtom GetName() const
Get the name of the font.
std::wstring CharToUnicode(const std::string &codepoint, bool useOnlyToUnicode=false) const
Convert the specified character code to its Unicode equivalent.
bool HasValidToUnicodeMap(PDEFontToUnicodeCheckFlags checkFlags=0) const
PDEType3GlyphInfo GetType3GlyphInfo(uint8_t charcode) const
PDEFontMetrics GetMetrics() const
Get the metrics of the font.
void EnumCharOutline(const std::string &codepoint, OutlineEnumMonitor &mon) const
Enumerate the outline of a character by specifying its character code.
bool HasRenderableGlyphs() const
void SetType3CharProc(uint8_t charcode, const PDEType3GlyphInfo &glyphInfo, const Content &content)
bool IsEmbedded() const
Check if the font has an embedded font program.
RectF GetFontBBox() const
Get the font bounding box.
bool CanTypeUnicode(const std::wstring &unicode) const
Check if the font can type the specified Unicode string.
static Font CreateFromPdfObject(const Object &object)
Creates a font from the specified PDF object.
void CreateCIDSet(PDF::Document document)
PDFontStyle GetStyle() const
Get the style of the font.
PDEGlyphVertMetric GetCharVertMetric(const std::string &codepoint) const
Get the vertical metrics of the character represented by the character code.
std::string UnicodeToChar(const UnicodeChar *unicode, size_t unicodeLen) const
Convert the specified Unicode value to its character code equivalent.
bool HasValidCharSet() const
void CreateWidths(PDF::Document document)
PDEWritingMode GetWritingMode() const
Get the writing mode of the font.
PDFontInfo GetFauxFontInfo() const
Get the substitute faux font info.
size_t GetFontFileSize() const
Get the size, in bytes, of the decoded embedded font program.
PDEFontFileFormat GetFontFileFormat() const
Get the format of the embedded font program.
PDFontInfo GetFontInfo() const
Get the font info.
std::wstring CharToUnicode(const char *codepoint, size_t codepointLen, bool useOnlyToUnicode=false) const
Convert the specified character code to its Unicode equivalent.
PDAtom GetEncodingName() const
Get the encoding name of the font.
PDEGlyphVertMetric GetCharVertMetric(const char *codepoint, size_t codepointLen) const
Get the vertical metrics of the character represented by the character code and the number of bytes u...
void EnumCharOutline(const char *codepoint, size_t codepointLen, OutlineEnumMonitor &mon) const
Enumerate the outline of a character by specifying its character code and number of bytes used to rep...
bool HasValidCIDSet() const
std::optional< PDFontInfo > FindSubstFontInfo(bool forceBold=false, bool forceItalic=false) const
Finds the system font that would be substituted for this font.
std::vector< Byte > GetFontFileData() const
Get the embedded font program bytes.
bool IsGlyphPresent(const std::string &codepoint) const
int16_t GetCharWidth(const char *codepoint, size_t codepointLen) const
Get the width of the character represented by the specified character code and the number of bytes us...
void CreateCharSet(PDF::Document document)
void CreateToUnicodeMap(PDF::Document document, PDEFontToUnicodeCreateFlags createFlags=kPDEFontToUnicodeCreateDefault)
bool IsFauxed() const
Check if the font is fauxed.
bool IsGlyphPresent(const char *codepoint, size_t codepointLen) const
PDEFontSubtype GetSubtype() const
Get the subtype of the font.
Content GetType3CharProc(uint8_t charcode) const
Retrieves the glyph description for a character code.
int16_t GetCharWidth(const std::string &codepoint) const
Get the width of the character represented by the specified character code.
Represents a PDF object.
Definition object.h:25
Definition font.h:552
Represents a read stream for reading data from PDF objects.
Definition read_stream.h:19
Content API.
PDEFontFileFormat
Identifies the format of an embedded font program.
Definition content.h:662
PDEWritingMode
Specifies the writing orientation of any CIDFont. This is the WMode key from the CMap stream dictiona...
Definition content.h:775
PDEFontSubtype
Specifies the font subtype or type (if there is no subtype).
Definition content.h:640
@ kPDEFontToUnicodeCreateDefault
Definition content.h:295
PDFontStyle
Specifies the styling to apply to a font.
Definition fonts.h:24
@ kPDFontStyleRegular
Definition fonts.h:25
Specifies the CIDSystemInfo dictionary.
Definition content.h:750
Definition content.h:703
Specifies the vertical metrics of CIDFonts.
Definition content.h:761
Specifies the glyph information for Type3 fonts extracted from d0 and d1 operators in the content str...
Definition content.h:722
Definition math.h:1276
Definition math.h:752
Specifies the font information.
Definition fonts.h:36
Definition math_types.h:12