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-2020 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 
203  static Font Create(SDF::SDFDoc& doc, Font& from, const UString& char_set);
204  static Font Create(SDF::SDFDoc& doc, const char* name, const UString& char_set);
205 
214  static Font CreateType1Font(SDF::SDFDoc& doc, const UString& font_path, bool embed = true);
215 
216  // Common Font methods ----------------------------------------------------------
217 
218  enum Type
219  {
220  e_Type1, // Type 1 PostScript font
221  e_TrueType, // TrueType font
222  e_MMType1, // Type 1 multiple master PostScript font
223  e_Type3, // Type 3 PostScript font
224  e_Type0, // Type 0 PostScript composite (CID) font
225  e_CIDType0, // Type 0 CID font
226  e_CIDType2, // Type 2 CID font
227  };
228 
229 
230  Font(const Font& c);
231  Font& operator=(const Font& c);
232 
236  Type GetType();
237 
254  bool IsSimple();
255 
256 #ifndef SWIG
257 
260  static Type GetType(SDF::Obj font_dict);
261 #endif
262 
266  SDF::Obj GetSDFObj ();
267 
273 
279  const char* GetName();
280 
286  const char* GetFamilyName();
287 
291  bool IsFixedWidth();
292 
296  bool IsSerif();
297 
301  bool IsSymbolic();
302 
306  bool IsItalic();
307 
311  bool IsAllCap();
312 
316  bool IsForceBold();
317 
321  bool IsHorizontalMode();
322 
337  double GetWidth(UInt32 char_code) const;
338 
342  double GetMaxWidth();
343 
348  double GetMissingWidth();
349 
355 
356 
377  PathData GetGlyphPath(UInt32 char_code,
378  bool conics2cubics,
379  Common::Matrix2D* transform = 0);
380 
381 
403  ShapedText GetShapedText(const UString& text_to_shape);
404 
431  UString MapToUnicode(UInt32 char_code);
432 
433 #ifndef SWIG
434  bool MapToUnicode(UInt32 char_code,
435  Unicode* out_uni_arr, const int in_uni_sz,
436  int &out_chars);
437 #endif
438 
439 #ifndef SWIG
440 
454  const char** GetEncoding();
455 #endif
456 
463  bool IsEmbedded();
464 
469  const char* GetEmbeddedFontName();
470 
477 
487 
498 
505  Rect GetBBox();
506 
516  double GetAscent();
517 
527  double GetDescent();
528 
529 
530  // Type1 specific methods -------------------------------------------------------
531 
537 
542  bool IsCFF();
543 
544  // Type3 specific methods -------------------------------------------------------
545 
554 
563 
564 
565  // Type0 specific methods -------------------------------------------------------
566 
567 
585 #ifndef SWIG
586  double GetVerticalAdvance(UInt32 char_code, double &out_pos_vect_x, double &out_pos_vect_y);
587 #endif
588 
589  std::vector<double> GetVerticalAdvance(UInt32 char_code);
590 
597 
603  UInt32 MapToCID(UInt32 char_code) const;
604 
605 #ifndef SWIG
606 
620  int MapToCID(const UChar* char_data, int char_data_avail, UInt32& out_charcode, UInt32& out_cid) const;
621 #endif
622 
626  void Destroy();
627 
628 // @cond PRIVATE_DOC
629 #ifndef SWIGHIDDEN
630  Font(TRN_Font impl);
631  ~Font();
632  TRN_Font mp_font;
633 #endif
634 // @endcond
635 };
636 
637 
638 #include <Impl/Font.inl>
639 
640  }; // namespace PDF
641 }; // namespace pdftron
642 
643 #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
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()
UInt32 MapToCID(UInt32 char_code) const
const char * GetEmbeddedFontName()
const char ** GetEncoding()
int GetEmbeddedFontBufSize()
SDF::Obj GetType3GlyphStream(UInt32 char_code)
Font(SDF::Obj font_dict=0)