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_INCLUDE_FXGE_FX_FREETYPE_H_
8 #define CORE_INCLUDE_FXGE_FX_FREETYPE_H_
9 
10 #include <ft2build.h>
11 #include <freetype.h>
12 #include <ftglyph.h>
13 #include <ftlcdfil.h>
14 #include <ftmm.h>
15 #include <ftoutln.h>
16 #include <tttables.h>
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 #define FXFT_ENCODING_UNICODE FT_ENCODING_UNICODE
21 #define FXFT_ENCODING_ADOBE_STANDARD FT_ENCODING_ADOBE_STANDARD
22 #define FXFT_ENCODING_ADOBE_EXPERT FT_ENCODING_ADOBE_EXPERT
23 #define FXFT_ENCODING_ADOBE_LATIN_1 FT_ENCODING_ADOBE_LATIN_1
24 #define FXFT_ENCODING_APPLE_ROMAN FT_ENCODING_APPLE_ROMAN
25 #define FXFT_ENCODING_ADOBE_CUSTOM FT_ENCODING_ADOBE_CUSTOM
26 #define FXFT_ENCODING_MS_SYMBOL FT_ENCODING_MS_SYMBOL
27 #define FXFT_ENCODING_GB2312 FT_ENCODING_GB2312
28 #define FXFT_ENCODING_BIG5 FT_ENCODING_BIG5
29 #define FXFT_ENCODING_SJIS FT_ENCODING_SJIS
30 #define FXFT_ENCODING_JOHAB FT_ENCODING_JOHAB
31 #define FXFT_ENCODING_WANSUNG FT_ENCODING_WANSUNG
32 #define FXFT_LOAD_NO_SCALE FT_LOAD_NO_SCALE
33 #define FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
34 #define FXFT_RENDER_MODE_LCD FT_RENDER_MODE_LCD
35 #define FXFT_RENDER_MODE_MONO FT_RENDER_MODE_MONO
36 #define FXFT_RENDER_MODE_NORMAL FT_RENDER_MODE_NORMAL
37 #define FXFT_LOAD_IGNORE_TRANSFORM FT_LOAD_IGNORE_TRANSFORM
38 #define FXFT_LOAD_NO_BITMAP FT_LOAD_NO_BITMAP
39 #define FXFT_LOAD_NO_HINTING FT_LOAD_NO_HINTING
40 #define FXFT_PIXEL_MODE_MONO FT_PIXEL_MODE_MONO
41 #define FXFT_STYLE_FLAG_ITALIC FT_STYLE_FLAG_ITALIC
42 #define FXFT_STYLE_FLAG_BOLD FT_STYLE_FLAG_BOLD
43 #define FXFT_FACE_FLAG_SFNT FT_FACE_FLAG_SFNT
44 #define FXFT_FACE_FLAG_TRICKY ( 1L << 13 )
45 typedef FT_MM_Var*		FXFT_MM_Var;
46 typedef FT_Bitmap*		FXFT_Bitmap;
47 #define FXFT_Matrix		FT_Matrix
48 #define FXFT_Vector		FT_Vector
49 #define FXFT_Outline_Funcs FT_Outline_Funcs
50 typedef FT_Open_Args	FXFT_Open_Args;
51 typedef FT_StreamRec	FXFT_StreamRec;
52 typedef FT_StreamRec*	FXFT_Stream;
53 typedef FT_BBox			FXFT_BBox;
54 typedef FT_Glyph		FXFT_Glyph;
55 typedef FT_CharMap		FXFT_CharMap;
56 #define FXFT_GLYPH_BBOX_PIXELS	FT_GLYPH_BBOX_PIXELS
57 #define FXFT_Open_Face(library, args, index, face) \
58     FT_Open_Face((FT_Library)(library), args, index, (FT_Face*)(face))
59 #define FXFT_Done_Face(face) FT_Done_Face((FT_Face)(face))
60 #define FXFT_Done_FreeType(library) FT_Done_FreeType((FT_Library)(library))
61 #define FXFT_Init_FreeType(library) FT_Init_FreeType((FT_Library*)(library))
62 #define FXFT_New_Memory_Face(library, base, size, index, face) \
63     FT_New_Memory_Face((FT_Library)(library), base, size, index, (FT_Face*)(face))
64 #define FXFT_New_Face(library, filename, index, face) \
65     FT_New_Face((FT_Library)(library), filename, index, (FT_Face*)(face))
66 #define FXFT_Get_Face_FreeType(face) ((FT_Face)face)->driver->root.library
67 #define FXFT_Select_Charmap(face, encoding) FT_Select_Charmap((FT_Face)face, (FT_Encoding)encoding)
68 #define FXFT_Set_Charmap(face, charmap) FT_Set_Charmap((FT_Face)face, (FT_CharMap)charmap)
69 #define FXFT_Load_Glyph(face, glyph_index, flags) FT_Load_Glyph((FT_Face)face, glyph_index, flags)
70 #define FXFT_Get_Char_Index(face, code) FT_Get_Char_Index((FT_Face)face, code)
71 #define FXFT_Get_Glyph_Name(face, index, buffer, size) FT_Get_Glyph_Name((FT_Face)face, index, buffer, size)
72 #define FXFT_Get_Name_Index(face, name) FT_Get_Name_Index((FT_Face)face, name)
73 #define FXFT_Has_Glyph_Names(face)  (((FT_Face)face)->face_flags & FT_FACE_FLAG_GLYPH_NAMES)
74 #define FXFT_Get_Postscript_Name(face) FT_Get_Postscript_Name((FT_Face)face)
75 #define FXFT_Load_Sfnt_Table(face, tag, offset, buffer, length) \
76     FT_Load_Sfnt_Table((FT_Face)face, tag, offset, buffer, length)
77 #define FXFT_Get_First_Char(face, glyph_index) FT_Get_First_Char((FT_Face)face, glyph_index)
78 #define FXFT_Get_Next_Char(face, code, glyph_index) FT_Get_Next_Char((FT_Face)face, code, glyph_index)
79 #define FXFT_Clear_Face_External_Stream(face) (((FT_Face)face)->face_flags&=~FT_FACE_FLAG_EXTERNAL_STREAM)
80 #define FXFT_Get_Face_External_Stream(face) (((FT_Face)face)->face_flags&FT_FACE_FLAG_EXTERNAL_STREAM)
81 #define FXFT_Is_Face_TT_OT(face) (((FT_Face)face)->face_flags&FT_FACE_FLAG_SFNT)
82 #define FXFT_Is_Face_Tricky(face) (((FT_Face)face)->face_flags&FXFT_FACE_FLAG_TRICKY)
83 #define FXFT_Is_Face_fixedwidth(face) (((FT_Face)face)->face_flags & FT_FACE_FLAG_FIXED_WIDTH)
84 #define FXFT_Get_Face_Stream_Base(face) ((FT_Face)face)->stream->base
85 #define FXFT_Get_Face_Stream_Size(face) ((FT_Face)face)->stream->size
86 #define FXFT_Get_Face_Family_Name(face) ((FT_Face)face)->family_name
87 #define FXFT_Get_Face_Style_Name(face) ((FT_Face)face)->style_name
88 #define FXFT_Get_Face_Numfaces(face) ((FT_Face)face)->num_faces
89 #define FXFT_Get_Face_Faceindex(face) ((FT_Face)face)->face_index
90 #define FXFT_Is_Face_Italic(face) (((FT_Face)face)->style_flags&FT_STYLE_FLAG_ITALIC)
91 #define FXFT_Is_Face_Bold(face) (((FT_Face)face)->style_flags&FT_STYLE_FLAG_BOLD)
92 #define FXFT_Get_Face_Charmaps(face) ((FT_Face)face)->charmaps
93 #define FXFT_Get_Glyph_HoriBearingX(face) ((FT_Face)face)->glyph->metrics.horiBearingX
94 #define FXFT_Get_Glyph_HoriBearingY(face) ((FT_Face)face)->glyph->metrics.horiBearingY
95 #define FXFT_Get_Glyph_Width(face) ((FT_Face)face)->glyph->metrics.width
96 #define FXFT_Get_Glyph_Height(face) ((FT_Face)face)->glyph->metrics.height
97 #define FXFT_Get_Face_CharmapCount(face) ((FT_Face)face)->num_charmaps
98 #define FXFT_Get_Charmap_Encoding(charmap) ((FT_CharMap)charmap)->encoding
99 #define FXFT_Get_Face_Charmap(face) ((FT_Face)face)->charmap
100 #define FXFT_Get_Charmap_PlatformID(charmap) ((FT_CharMap)charmap)->platform_id
101 #define FXFT_Get_Charmap_EncodingID(charmap) ((FT_CharMap)charmap)->encoding_id
102 #define FXFT_Get_Face_UnitsPerEM(face) ((FT_Face)face)->units_per_EM
103 #define FXFT_Get_Face_xMin(face) ((FT_Face)face)->bbox.xMin
104 #define FXFT_Get_Face_xMax(face) ((FT_Face)face)->bbox.xMax
105 #define FXFT_Get_Face_yMin(face) ((FT_Face)face)->bbox.yMin
106 #define FXFT_Get_Face_yMax(face) ((FT_Face)face)->bbox.yMax
107 #define FXFT_Get_Face_Height(face) ((FT_Face)face)->height
108 #define FXFT_Get_Face_UnderLineThickness(face) ((FT_Face)face)->underline_thickness
109 #define FXFT_Get_Face_UnderLinePosition(face) ((FT_Face)face)->underline_position
110 #define FXFT_Get_Face_MaxAdvanceWidth(face) ((FT_Face)face)->max_advance_width
111 #define FXFT_Get_Face_Ascender(face) ((FT_Face)face)->ascender
112 #define FXFT_Get_Face_Descender(face) ((FT_Face)face)->descender
113 #define FXFT_Get_Glyph_HoriAdvance(face) ((FT_Face)face)->glyph->metrics.horiAdvance
114 #define FXFT_Get_MM_Axis(var, index) &((FT_MM_Var*)var)->axis[index]
115 #define FXFT_Get_MM_Axis_Min(axis) ((FT_Var_Axis*)axis)->minimum
116 #define FXFT_Get_MM_Axis_Max(axis) ((FT_Var_Axis*)axis)->maximum
117 #define FXFT_Get_MM_Axis_Def(axis) ((FT_Var_Axis*)axis)->def
118 #define FXFT_Alloc(library, size) ((FT_Library)library)->memory->alloc(((FT_Library)library)->memory, size)
119 #define FXFT_Free(face, p) ((FT_Face)face)->memory->free(((FT_Face)face)->memory, p)
120 #define FXFT_Get_Glyph_Outline(face) &((FT_Face)face)->glyph->outline
121 #define FXFT_Get_Outline_Bbox(outline, cbox)  FT_Outline_Get_CBox(outline, cbox)
122 #define FXFT_Render_Glyph(face, mode) FT_Render_Glyph(((FT_Face)face)->glyph, (enum FT_Render_Mode_)mode)
123 #define FXFT_Get_MM_Var(face, p) FT_Get_MM_Var((FT_Face)face, p)
124 #define FXFT_Set_MM_Design_Coordinates(face, n, p) FT_Set_MM_Design_Coordinates((FT_Face)face, n, p)
125 #define FXFT_Set_Pixel_Sizes(face, w, h) FT_Set_Pixel_Sizes((FT_Face)face, w, h)
126 #define FXFT_Set_Transform(face, m, d) FT_Set_Transform((FT_Face)face, m, d)
127 #define FXFT_Outline_Embolden(outline, s) FT_Outline_Embolden(outline, s)
128 #define FXFT_Get_Glyph_Bitmap(face) &((FT_Face)face)->glyph->bitmap
129 #define FXFT_Get_Bitmap_Width(bitmap) ((FT_Bitmap*)bitmap)->width
130 #define FXFT_Get_Bitmap_Rows(bitmap) ((FT_Bitmap*)bitmap)->rows
131 #define FXFT_Get_Bitmap_PixelMode(bitmap) ((FT_Bitmap*)bitmap)->pixel_mode
132 #define FXFT_Get_Bitmap_Pitch(bitmap) ((FT_Bitmap*)bitmap)->pitch
133 #define FXFT_Get_Bitmap_Buffer(bitmap) ((FT_Bitmap*)bitmap)->buffer
134 #define FXFT_Get_Glyph_BitmapLeft(face) ((FT_Face)face)->glyph->bitmap_left
135 #define FXFT_Get_Glyph_BitmapTop(face) ((FT_Face)face)->glyph->bitmap_top
136 #define FXFT_Outline_Decompose(outline, funcs, params) FT_Outline_Decompose(outline, funcs, params)
137 #define FXFT_Set_Char_Size(face, char_width, char_height, horz_resolution, vert_resolution) FT_Set_Char_Size(face, char_width, char_height, horz_resolution, vert_resolution)
138 #define FXFT_Get_Glyph(slot, aglyph) FT_Get_Glyph(slot, aglyph)
139 #define FXFT_Glyph_Get_CBox(glyph, bbox_mode, acbox) FT_Glyph_Get_CBox(glyph, bbox_mode, acbox)
140 #define FXFT_Done_Glyph(glyph)	FT_Done_Glyph(glyph)
141 #define FXFT_Library_SetLcdFilter(library, filter) FT_Library_SetLcdFilter((FT_Library)(library), filter)
142 int FXFT_unicode_from_adobe_name(const char*  glyph_name);
143 void FXFT_adobe_name_from_unicode(char* name, wchar_t unicode);
144 #ifdef __cplusplus
145 };
146 #endif
147 
148 #endif  // CORE_INCLUDE_FXGE_FX_FREETYPE_H_
149