All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Font.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2021 by PDFTron Systems 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 
60  {
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  {
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
283 
286  static Type GetType(SDF::Obj font_dict);
287 #endif
288 
292  SDF::Obj GetSDFObj ();
293 
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 
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
466 
480  const char** GetEncoding();
481 #endif
482 
489  bool IsEmbedded();
490 
495  const char* GetEmbeddedFontName();
496 
503 
513 
524 
531  Rect GetBBox();
532 
542  double GetAscent();
543 
553  double GetDescent();
554 
555 
556  // Type1 specific methods -------------------------------------------------------
557 
563 
568  bool IsCFF();
569 
570  // Type3 specific methods -------------------------------------------------------
571 
580 
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 
623 
629  UInt32 MapToCID(UInt32 char_code) const;
630 
631 #ifndef SWIG
632 
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
UInt16 GetUnitsPerEm()
PathData GetGlyphPath(UInt32 char_code, bool conics2cubics, Common::Matrix2D *transform=0)
const char * GetFamilyName()
TRN_UInt16 UInt16
Definition: BasicTypes.h:14
static Font CreateTrueTypeFont2(SDF::SDFDoc &doc, const void *logfont, bool embed=true, bool subset=true)
Common::Iterator< UInt32 > GetCharCodeIterator()
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)
UString MapToUnicode(UInt32 char_code)
const char * GetName()
Font & operator=(const Font &c)
TRN_Unicode Unicode
Definition: BasicTypes.h:22
ShapedText GetShapedText(const UString &text_to_shape)
static Font CreateType1Font(SDF::SDFDoc &doc, const UString &font_path, bool embed=true)
int GetStandardType1FontType()
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
static Font CreateTrueTypeFont(SDF::SDFDoc &doc, const UString &font_path, bool embed=true, bool subset=true)
double GetWidth(UInt32 char_code) const
Common::Matrix2D GetType3FontMatrix()
TRN_UChar UChar
Definition: BasicTypes.h:12
double GetMissingWidth()
SDF::Obj GetSDFObj()
static Font Create(SDF::SDFDoc &doc, StandardType1Font type, bool embed=false)
SDF::Obj GetDescriptor()
double GetVerticalAdvance(UInt32 char_code, double &out_pos_vect_x, double &out_pos_vect_y)
SDF::Obj GetEmbeddedFont()
static Font CreateCIDTrueTypeFont2(SDF::SDFDoc &doc, const void *logfonta, bool embed=true, bool subset=true, Encoding encoding=e_IdentityH)
UInt32 MapToCID(UInt32 char_code) const
const char * GetEmbeddedFontName()
const char ** GetEncoding()
int GetEmbeddedFontBufSize()
SDF::Obj GetType3GlyphStream(UInt32 char_code)
static Font CreateCIDTrueTypeFont2Unicode(SDF::SDFDoc &doc, const void *logfontw, bool embed=true, bool subset=true, Encoding encoding=e_IdentityH)
Font(SDF::Obj font_dict=0)