Loading...
Searching...
No Matches
Font.h
Go to the documentation of this file.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5#ifndef PDFTRON_H_CPPPDFFont
6#define PDFTRON_H_CPPPDFFont
7
8#include <Common/Matrix2D.h>
9#include <Common/UString.h>
10#include <Common/Iterator.h>
11#include <PDF/Rect.h>
12#include <PDF/PathData.h>
13#include <PDF/ShapedText.h>
14#include <C/PDF/TRN_Font.h>
15#include <C/SDF/TRN_SDFDoc.h>
16#include <vector>
17
18 namespace pdftron {
19 namespace PDF {
20
55 class Font
56{
57 public:
58
59 enum StandardType1Font
60 {
61 e_times_roman = 0,
62 e_times_bold,
63 e_times_italic,
64 e_times_bold_italic,
65 e_helvetica,
66 e_helvetica_bold,
67 e_helvetica_oblique,
68 e_helvetica_bold_oblique,
69 e_courier,
70 e_courier_bold,
71 e_courier_oblique,
72 e_courier_bold_oblique,
73 e_symbol,
74 e_zapf_dingbats,
75 e_null // not a standard font
76 };
77
83 Font (SDF::Obj font_dict = 0);
84
88 static Font Create(SDF::SDFDoc& doc, StandardType1Font type, bool embed = false );
89
104 static Font CreateTrueTypeFont(SDF::SDFDoc& doc, const UString& font_path,
105 bool embed=true, bool subset=true);
106
121 #ifdef _WIN32
122 static Font CreateTrueTypeFont2(SDF::SDFDoc& doc, const void* logfont,
123 bool embed=true, bool subset=true);
124 #endif
125
126
127 enum Encoding
128 {
129 e_IdentityH=0,
130 e_Indices
131 };
132
151 static Font CreateCIDTrueTypeFont(SDF::SDFDoc& doc, const UString& font_path,
152 bool embed = true, bool subset = true,
153 Encoding encoding=e_IdentityH,
154 UInt32 ttc_font_index=0);
155
172 #ifdef _WIN32
173 static Font CreateCIDTrueTypeFont2(SDF::SDFDoc& doc, const void* logfonta,
174 bool embed = true, bool subset = true,
175 Encoding encoding=e_IdentityH);
176 #endif
177
194#ifdef _WIN32
195 static Font CreateCIDTrueTypeFont2Unicode(SDF::SDFDoc& doc, const void* logfontw,
196 bool embed = true, bool subset = true,
197 Encoding encoding = e_IdentityH);
198#endif
199
214 static Font Create(SDF::SDFDoc& doc, Font& from, const UString& char_set);
215
230 static Font Create(SDF::SDFDoc& doc, const char* name, const UString& char_set);
231
240 static Font CreateType1Font(SDF::SDFDoc& doc, const UString& font_path, bool embed = true);
241
242 // Common Font methods ----------------------------------------------------------
243
244 enum Type
245 {
246 e_Type1, // Type 1 PostScript font
247 e_TrueType, // TrueType font
248 e_MMType1, // Type 1 multiple master PostScript font
249 e_Type3, // Type 3 PostScript font
250 e_Type0, // Type 0 PostScript composite (CID) font
251 e_CIDType0, // Type 0 CID font
252 e_CIDType2, // Type 2 CID font
253 };
254
255
256 Font(const Font& c);
257 Font& operator=(const Font& c);
258
262 Type GetType();
263
280 bool IsSimple();
281
282#ifndef SWIG
286 static Type GetType(SDF::Obj font_dict);
287#endif
288
292 SDF::Obj GetSDFObj ();
293
298 SDF::Obj GetDescriptor();
299
305 const char* GetName();
306
312 const char* GetFamilyName();
313
317 bool IsFixedWidth();
318
322 bool IsSerif();
323
327 bool IsSymbolic();
328
332 bool IsItalic();
333
337 bool IsAllCap();
338
342 bool IsForceBold();
343
347 bool IsHorizontalMode();
348
363 double GetWidth(UInt32 char_code) const;
364
368 double GetMaxWidth();
369
374 double GetMissingWidth();
375
380 Common::Iterator<UInt32> GetCharCodeIterator();
381
382
403 PathData GetGlyphPath(UInt32 char_code,
404 bool conics2cubics,
405 Common::Matrix2D* transform = 0);
406
407
429 ShapedText GetShapedText(const UString& text_to_shape);
430
457 UString MapToUnicode(UInt32 char_code);
458
459#ifndef SWIG
460 bool MapToUnicode(UInt32 char_code,
461 Unicode* out_uni_arr, const int in_uni_sz,
462 int &out_chars);
463#endif
464
465#ifndef SWIG
480 const char** GetEncoding();
481#endif
482
489 bool IsEmbedded();
490
495 const char* GetEmbeddedFontName();
496
502 SDF::Obj GetEmbeddedFont();
503
512 int GetEmbeddedFontBufSize();
513
523 UInt16 GetUnitsPerEm();
524
531 Rect GetBBox();
532
542 double GetAscent();
543
553 double GetDescent();
554
555
556 // Type1 specific methods -------------------------------------------------------
557
562 int GetStandardType1FontType();
563
568 bool IsCFF();
569
570 // Type3 specific methods -------------------------------------------------------
571
579 Common::Matrix2D GetType3FontMatrix();
580
588 SDF::Obj GetType3GlyphStream(UInt32 char_code);
589
590
591 // Type0 specific methods -------------------------------------------------------
592
593
611#ifndef SWIG
612 double GetVerticalAdvance(UInt32 char_code, double &out_pos_vect_x, double &out_pos_vect_y);
613#endif
614
615 std::vector<double> GetVerticalAdvance(UInt32 char_code);
616
622 Font GetDescendant();
623
629 UInt32 MapToCID(UInt32 char_code) const;
630
631#ifndef SWIG
646 int MapToCID(const UChar* char_data, int char_data_avail, UInt32& out_charcode, UInt32& out_cid) const;
647#endif
648
652 void Destroy();
653
654// @cond PRIVATE_DOC
655#ifndef SWIGHIDDEN
656 Font(TRN_Font impl);
657 ~Font();
658 TRN_Font mp_font;
659#endif
660// @endcond
661};
662
663
664#include <Impl/Font.inl>
665
666 }; // namespace PDF
667}; // namespace pdftron
668
669#endif // PDFTRON_H_CPPPDFFont
Iterator.h
Matrix2D.h
PathData.h
Rect.h
ShapedText.h
UString.h
pdftron::Common::Iterator
Definition Iterator.h:21
pdftron::Common::Matrix2D
Definition Matrix2D.h:104
pdftron::PDF::Font::GetEmbeddedFontName
const char * GetEmbeddedFontName()
pdftron::PDF::Font::GetEncoding
const char ** GetEncoding()
pdftron::PDF::Font::Create
static Font Create(SDF::SDFDoc &doc, const char *name, const UString &char_set)
pdftron::PDF::Font::IsSymbolic
bool IsSymbolic()
pdftron::PDF::Font::GetMissingWidth
double GetMissingWidth()
pdftron::PDF::Font::IsAllCap
bool IsAllCap()
pdftron::PDF::Font::GetBBox
Rect GetBBox()
pdftron::PDF::Font::MapToCID
int MapToCID(const UChar *char_data, int char_data_avail, UInt32 &out_charcode, UInt32 &out_cid) const
pdftron::PDF::Font::CreateTrueTypeFont
static Font CreateTrueTypeFont(SDF::SDFDoc &doc, const UString &font_path, bool embed=true, bool subset=true)
pdftron::PDF::Font::GetType
Type GetType()
pdftron::PDF::Font::Font
Font(SDF::Obj font_dict=0)
pdftron::PDF::Font::Font
Font(const Font &c)
pdftron::PDF::Font::CreateType1Font
static Font CreateType1Font(SDF::SDFDoc &doc, const UString &font_path, bool embed=true)
pdftron::PDF::Font::GetSDFObj
SDF::Obj GetSDFObj()
pdftron::PDF::Font::Type
Type
Definition Font.h:245
pdftron::PDF::Font::e_CIDType2
@ e_CIDType2
Definition Font.h:252
pdftron::PDF::Font::e_MMType1
@ e_MMType1
Definition Font.h:248
pdftron::PDF::Font::e_TrueType
@ e_TrueType
Definition Font.h:247
pdftron::PDF::Font::e_Type0
@ e_Type0
Definition Font.h:250
pdftron::PDF::Font::e_Type3
@ e_Type3
Definition Font.h:249
pdftron::PDF::Font::e_Type1
@ e_Type1
Definition Font.h:246
pdftron::PDF::Font::e_CIDType0
@ e_CIDType0
Definition Font.h:251
pdftron::PDF::Font::MapToUnicode
UString MapToUnicode(UInt32 char_code)
pdftron::PDF::Font::IsSerif
bool IsSerif()
pdftron::PDF::Font::CreateCIDTrueTypeFont
static Font CreateCIDTrueTypeFont(SDF::SDFDoc &doc, const UString &font_path, bool embed=true, bool subset=true, Encoding encoding=e_IdentityH, UInt32 ttc_font_index=0)
pdftron::PDF::Font::StandardType1Font
StandardType1Font
Definition Font.h:60
pdftron::PDF::Font::e_times_roman
@ e_times_roman
Definition Font.h:61
pdftron::PDF::Font::e_times_bold
@ e_times_bold
Definition Font.h:62
pdftron::PDF::Font::e_helvetica_bold_oblique
@ e_helvetica_bold_oblique
Definition Font.h:68
pdftron::PDF::Font::e_helvetica_oblique
@ e_helvetica_oblique
Definition Font.h:67
pdftron::PDF::Font::e_helvetica
@ e_helvetica
Definition Font.h:65
pdftron::PDF::Font::e_courier_bold_oblique
@ e_courier_bold_oblique
Definition Font.h:72
pdftron::PDF::Font::e_courier
@ e_courier
Definition Font.h:69
pdftron::PDF::Font::e_null
@ e_null
Definition Font.h:75
pdftron::PDF::Font::e_times_bold_italic
@ e_times_bold_italic
Definition Font.h:64
pdftron::PDF::Font::e_helvetica_bold
@ e_helvetica_bold
Definition Font.h:66
pdftron::PDF::Font::e_zapf_dingbats
@ e_zapf_dingbats
Definition Font.h:74
pdftron::PDF::Font::e_courier_oblique
@ e_courier_oblique
Definition Font.h:71
pdftron::PDF::Font::e_courier_bold
@ e_courier_bold
Definition Font.h:70
pdftron::PDF::Font::e_symbol
@ e_symbol
Definition Font.h:73
pdftron::PDF::Font::e_times_italic
@ e_times_italic
Definition Font.h:63
pdftron::PDF::Font::GetDescendant
Font GetDescendant()
pdftron::PDF::Font::GetFamilyName
const char * GetFamilyName()
pdftron::PDF::Font::IsCFF
bool IsCFF()
pdftron::PDF::Font::GetType
static Type GetType(SDF::Obj font_dict)
pdftron::PDF::Font::GetEmbeddedFont
SDF::Obj GetEmbeddedFont()
pdftron::PDF::Font::Encoding
Encoding
Definition Font.h:128
pdftron::PDF::Font::e_IdentityH
@ e_IdentityH
Definition Font.h:129
pdftron::PDF::Font::e_Indices
@ e_Indices
Definition Font.h:130
pdftron::PDF::Font::GetAscent
double GetAscent()
pdftron::PDF::Font::GetMaxWidth
double GetMaxWidth()
pdftron::PDF::Font::IsHorizontalMode
bool IsHorizontalMode()
pdftron::PDF::Font::GetVerticalAdvance
std::vector< double > GetVerticalAdvance(UInt32 char_code)
pdftron::PDF::Font::GetEmbeddedFontBufSize
int GetEmbeddedFontBufSize()
pdftron::PDF::Font::GetUnitsPerEm
UInt16 GetUnitsPerEm()
pdftron::PDF::Font::IsItalic
bool IsItalic()
pdftron::PDF::Font::GetVerticalAdvance
double GetVerticalAdvance(UInt32 char_code, double &out_pos_vect_x, double &out_pos_vect_y)
pdftron::PDF::Font::MapToUnicode
bool MapToUnicode(UInt32 char_code, Unicode *out_uni_arr, const int in_uni_sz, int &out_chars)
pdftron::PDF::Font::GetCharCodeIterator
Common::Iterator< UInt32 > GetCharCodeIterator()
pdftron::PDF::Font::MapToCID
UInt32 MapToCID(UInt32 char_code) const
pdftron::PDF::Font::GetShapedText
ShapedText GetShapedText(const UString &text_to_shape)
pdftron::PDF::Font::GetWidth
double GetWidth(UInt32 char_code) const
pdftron::PDF::Font::GetDescriptor
SDF::Obj GetDescriptor()
pdftron::PDF::Font::Create
static Font Create(SDF::SDFDoc &doc, Font &from, const UString &char_set)
pdftron::PDF::Font::IsSimple
bool IsSimple()
pdftron::PDF::Font::Create
static Font Create(SDF::SDFDoc &doc, StandardType1Font type, bool embed=false)
pdftron::PDF::Font::operator=
Font & operator=(const Font &c)
pdftron::PDF::Font::Destroy
void Destroy()
pdftron::PDF::Font::GetDescent
double GetDescent()
pdftron::PDF::Font::GetGlyphPath
PathData GetGlyphPath(UInt32 char_code, bool conics2cubics, Common::Matrix2D *transform=0)
pdftron::PDF::Font::IsForceBold
bool IsForceBold()
pdftron::PDF::Font::GetStandardType1FontType
int GetStandardType1FontType()
pdftron::PDF::Font::GetType3FontMatrix
Common::Matrix2D GetType3FontMatrix()
pdftron::PDF::Font::IsFixedWidth
bool IsFixedWidth()
pdftron::PDF::Font::GetType3GlyphStream
SDF::Obj GetType3GlyphStream(UInt32 char_code)
pdftron::PDF::Font::IsEmbedded
bool IsEmbedded()
pdftron::PDF::Font::GetName
const char * GetName()
pdftron::PDF::PathData
Definition PathData.h:20
pdftron::PDF::Rect
Definition Rect.h:29
pdftron::PDF::ShapedText
Definition ShapedText.h:24
pdftron::SDF::Obj
Definition Obj.h:41
pdftron::SDF::SDFDoc
Definition SDFDoc.h:68
pdftron::UString
Definition UString.h:28
pdftron::PDF
Definition Action.h:15
pdftron
Definition BasicTypes.h:10
pdftron::UInt32
TRN_UInt32 UInt32
Definition BasicTypes.h:13
pdftron::UChar
TRN_UChar UChar
Definition BasicTypes.h:12
pdftron::UInt16
TRN_UInt16 UInt16
Definition BasicTypes.h:14
pdftron::Unicode
TRN_Unicode Unicode
Definition BasicTypes.h:22