• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FXGE_FX_FREETYPE_H_
8 #define CORE_FXGE_FX_FREETYPE_H_
9 
10 #include <ft2build.h>
11 
12 #include <memory>
13 
14 #include FT_FREETYPE_H
15 #include FT_GLYPH_H
16 #include FT_LCD_FILTER_H
17 #include FT_MULTIPLE_MASTERS_H
18 #include FT_OUTLINE_H
19 #include FT_TRUETYPE_TABLES_H
20 
21 using FXFT_LibraryRec = struct FT_LibraryRec_;
22 using FXFT_FaceRec = struct FT_FaceRec_;
23 using FXFT_StreamRec = struct FT_StreamRec_;
24 using FXFT_MM_VarPtr = FT_MM_Var*;
25 
26 struct FXFTFaceRecDeleter {
operatorFXFTFaceRecDeleter27   inline void operator()(FXFT_FaceRec* pRec) {
28     if (pRec)
29       FT_Done_Face(pRec);
30   }
31 };
32 
33 struct FXFTLibraryRecDeleter {
operatorFXFTLibraryRecDeleter34   inline void operator()(FXFT_LibraryRec* pRec) {
35     if (pRec)
36       FT_Done_FreeType(pRec);
37   }
38 };
39 
40 using ScopedFXFTFaceRec = std::unique_ptr<FXFT_FaceRec, FXFTFaceRecDeleter>;
41 using ScopedFXFTLibraryRec =
42     std::unique_ptr<FXFT_LibraryRec, FXFTLibraryRecDeleter>;
43 
44 #define FXFT_Select_Charmap(face, encoding) \
45   FT_Select_Charmap(face, static_cast<FT_Encoding>(encoding))
46 #define FXFT_Get_Name_Index(face, name) \
47   FT_Get_Name_Index(face, const_cast<char*>(name))
48 #define FXFT_Get_Glyph_Outline(face) &((face)->glyph->outline)
49 #define FXFT_Render_Glyph(face, mode) \
50   FT_Render_Glyph((face)->glyph, static_cast<enum FT_Render_Mode_>(mode))
51 
52 #define FXFT_Has_Glyph_Names(face) \
53   (((face)->face_flags) & FT_FACE_FLAG_GLYPH_NAMES)
54 #define FXFT_Clear_Face_External_Stream(face) \
55   ((face)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM)
56 #define FXFT_Get_Face_External_Stream(face) \
57   (((face)->face_flags) & FT_FACE_FLAG_EXTERNAL_STREAM)
58 #define FXFT_Is_Face_TT_OT(face) (((face)->face_flags) & FT_FACE_FLAG_SFNT)
59 #define FXFT_Is_Face_Tricky(face) (((face)->face_flags) & FT_FACE_FLAG_TRICKY)
60 #define FXFT_Is_Face_fixedwidth(face) \
61   (((face)->face_flags) & FT_FACE_FLAG_FIXED_WIDTH)
62 #define FXFT_Get_Face_Stream_Base(face) (face)->stream->base
63 #define FXFT_Get_Face_Stream_Size(face) (face)->stream->size
64 #define FXFT_Get_Face_Family_Name(face) (face)->family_name
65 #define FXFT_Get_Face_Style_Name(face) (face)->style_name
66 #define FXFT_Is_Face_Italic(face) (((face)->style_flags) & FT_STYLE_FLAG_ITALIC)
67 #define FXFT_Is_Face_Bold(face) (((face)->style_flags) & FT_STYLE_FLAG_BOLD)
68 #define FXFT_Get_Face_Charmaps(face) (face)->charmaps
69 #define FXFT_Get_Glyph_HoriBearingX(face) (face)->glyph->metrics.horiBearingX
70 #define FXFT_Get_Glyph_HoriBearingY(face) (face)->glyph->metrics.horiBearingY
71 #define FXFT_Get_Glyph_Width(face) (face)->glyph->metrics.width
72 #define FXFT_Get_Glyph_Height(face) (face)->glyph->metrics.height
73 #define FXFT_Get_Face_CharmapCount(face) (face)->num_charmaps
74 #define FXFT_Get_Charmap_Encoding(charmap) (charmap)->encoding
75 #define FXFT_Get_Face_Charmap(face) (face)->charmap
76 #define FXFT_Get_Charmap_PlatformID(charmap) (charmap)->platform_id
77 #define FXFT_Get_Charmap_EncodingID(charmap) (charmap)->encoding_id
78 #define FXFT_Get_Face_UnitsPerEM(face) (face)->units_per_EM
79 #define FXFT_Get_Face_xMin(face) (face)->bbox.xMin
80 #define FXFT_Get_Face_xMax(face) (face)->bbox.xMax
81 #define FXFT_Get_Face_yMin(face) (face)->bbox.yMin
82 #define FXFT_Get_Face_yMax(face) (face)->bbox.yMax
83 #define FXFT_Get_Face_Height(face) (face)->height
84 #define FXFT_Get_Face_Ascender(face) (face)->ascender
85 #define FXFT_Get_Face_Descender(face) (face)->descender
86 #define FXFT_Get_Glyph_HoriAdvance(face) (face)->glyph->metrics.horiAdvance
87 #define FXFT_Get_MM_Axis(var, index) (var)->axis[index]
88 #define FXFT_Get_MM_Axis_Min(axis) (axis).minimum
89 #define FXFT_Get_MM_Axis_Max(axis) (axis).maximum
90 #define FXFT_Get_MM_Axis_Def(axis) (axis).def
91 #define FXFT_Free(face, p) (face)->memory->free((face)->memory, p)
92 #define FXFT_Get_Glyph_Outline(face) &((face)->glyph->outline)
93 #define FXFT_Get_Glyph_Bitmap(face) (face)->glyph->bitmap
94 #define FXFT_Get_Bitmap_Width(bitmap) (bitmap).width
95 #define FXFT_Get_Bitmap_Rows(bitmap) (bitmap).rows
96 #define FXFT_Get_Bitmap_PixelMode(bitmap) (bitmap).pixel_mode
97 #define FXFT_Get_Bitmap_Pitch(bitmap) (bitmap).pitch
98 #define FXFT_Get_Bitmap_Buffer(bitmap) (bitmap).buffer
99 #define FXFT_Get_Glyph_BitmapLeft(face) (face)->glyph->bitmap_left
100 #define FXFT_Get_Glyph_BitmapTop(face) (face)->glyph->bitmap_top
101 
102 int FXFT_unicode_from_adobe_name(const char* glyph_name);
103 void FXFT_adobe_name_from_unicode(char* name, wchar_t unicode);
104 
105 #endif  // CORE_FXGE_FX_FREETYPE_H_
106