Home | History | Annotate | Download | only in fxge
      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 #include FT_FREETYPE_H
     12 #include FT_GLYPH_H
     13 #include FT_LCD_FILTER_H
     14 #include FT_MULTIPLE_MASTERS_H
     15 #include FT_OUTLINE_H
     16 #include FT_TRUETYPE_TABLES_H
     17 
     18 using FXFT_Face = struct FT_FaceRec_*;
     19 using FXFT_Library = void*;
     20 
     21 using FXFT_MM_Var = FT_MM_Var*;
     22 using FXFT_Open_Args = FT_Open_Args;
     23 using FXFT_StreamRec = FT_StreamRec;
     24 using FXFT_Stream = FT_StreamRec*;
     25 using FXFT_BBox = FT_BBox;
     26 using FXFT_Glyph = FT_Glyph;
     27 using FXFT_CharMap = FT_CharMap;
     28 
     29 using FXFT_Matrix = FT_Matrix;
     30 using FXFT_Vector = FT_Vector;
     31 using FXFT_Outline_Funcs = FT_Outline_Funcs;
     32 
     33 #define FXFT_ENCODING_UNICODE FT_ENCODING_UNICODE
     34 #define FXFT_ENCODING_ADOBE_STANDARD FT_ENCODING_ADOBE_STANDARD
     35 #define FXFT_ENCODING_ADOBE_EXPERT FT_ENCODING_ADOBE_EXPERT
     36 #define FXFT_ENCODING_ADOBE_LATIN_1 FT_ENCODING_ADOBE_LATIN_1
     37 #define FXFT_ENCODING_APPLE_ROMAN FT_ENCODING_APPLE_ROMAN
     38 #define FXFT_ENCODING_ADOBE_CUSTOM FT_ENCODING_ADOBE_CUSTOM
     39 #define FXFT_ENCODING_MS_SYMBOL FT_ENCODING_MS_SYMBOL
     40 #define FXFT_ENCODING_GB2312 FT_ENCODING_GB2312
     41 #define FXFT_ENCODING_BIG5 FT_ENCODING_BIG5
     42 #define FXFT_ENCODING_SJIS FT_ENCODING_SJIS
     43 #define FXFT_ENCODING_JOHAB FT_ENCODING_JOHAB
     44 
     45 #define FXFT_LOAD_NO_SCALE FT_LOAD_NO_SCALE
     46 #define FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH \
     47   FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
     48 #define FXFT_LOAD_NO_BITMAP FT_LOAD_NO_BITMAP
     49 
     50 #define FXFT_RENDER_MODE_LCD FT_RENDER_MODE_LCD
     51 #define FXFT_RENDER_MODE_MONO FT_RENDER_MODE_MONO
     52 #define FXFT_RENDER_MODE_NORMAL FT_RENDER_MODE_NORMAL
     53 
     54 #define FXFT_PIXEL_MODE_MONO FT_PIXEL_MODE_MONO
     55 
     56 #define FXFT_STYLE_FLAG_ITALIC FT_STYLE_FLAG_ITALIC
     57 #define FXFT_STYLE_FLAG_BOLD FT_STYLE_FLAG_BOLD
     58 
     59 #define FXFT_FACE_FLAG_SFNT FT_FACE_FLAG_SFNT
     60 #define FXFT_FACE_FLAG_TRICKY (1L << 13)
     61 
     62 #define FXFT_GLYPH_BBOX_PIXELS FT_GLYPH_BBOX_PIXELS
     63 
     64 #define FXFT_Open_Face(library, args, index, face)            \
     65   FT_Open_Face(static_cast<FT_Library>(library), args, index, \
     66                static_cast<FT_Face*>(face))
     67 #define FXFT_Done_Face(face) FT_Done_Face(static_cast<FT_Face>(face))
     68 #define FXFT_Done_FreeType(library) \
     69   FT_Done_FreeType(static_cast<FT_Library>(library))
     70 #define FXFT_Init_FreeType(library) \
     71   FT_Init_FreeType(reinterpret_cast<FT_Library*>(library))
     72 #define FXFT_Library_Version(library, amajor, aminor, apatch)               \
     73   FT_Library_Version(reinterpret_cast<FT_Library>(library), amajor, aminor, \
     74                      apatch)
     75 #define FXFT_New_Memory_Face(library, base, size, index, face)            \
     76   FT_New_Memory_Face(static_cast<FT_Library>(library), base, size, index, \
     77                      static_cast<FT_Face*>(face))
     78 #define FXFT_New_Face(library, filename, index, face)            \
     79   FT_New_Face(static_cast<FT_Library>(library), filename, index, \
     80               static_cast<FT_Face*>(face))
     81 #define FXFT_Select_Charmap(face, encoding)     \
     82   FT_Select_Charmap(static_cast<FT_Face>(face), \
     83                     static_cast<FT_Encoding>(encoding))
     84 #define FXFT_Set_Charmap(face, charmap) \
     85   FT_Set_Charmap(static_cast<FT_Face>(face), static_cast<FT_CharMap>(charmap))
     86 #define FXFT_Load_Glyph(face, glyph_index, flags) \
     87   FT_Load_Glyph(static_cast<FT_Face>(face), glyph_index, flags)
     88 #define FXFT_Get_Char_Index(face, code) \
     89   FT_Get_Char_Index(static_cast<FT_Face>(face), code)
     90 #define FXFT_Get_Glyph_Name(face, index, buffer, size) \
     91   FT_Get_Glyph_Name(static_cast<FT_Face>(face), index, buffer, size)
     92 #define FXFT_Get_Name_Index(face, name) \
     93   FT_Get_Name_Index(static_cast<FT_Face>(face), name)
     94 #define FXFT_Has_Glyph_Names(face) \
     95   (static_cast<FT_Face>(face)->face_flags & FT_FACE_FLAG_GLYPH_NAMES)
     96 #define FXFT_Get_Postscript_Name(face) \
     97   FT_Get_Postscript_Name(static_cast<FT_Face>(face))
     98 #define FXFT_Load_Sfnt_Table(face, tag, offset, buffer, length) \
     99   FT_Load_Sfnt_Table(static_cast<FT_Face>(face), tag, offset, buffer, length)
    100 #define FXFT_Get_First_Char(face, glyph_index) \
    101   FT_Get_First_Char(static_cast<FT_Face>(face), glyph_index)
    102 #define FXFT_Get_Next_Char(face, code, glyph_index) \
    103   FT_Get_Next_Char(static_cast<FT_Face>(face), code, glyph_index)
    104 #define FXFT_Clear_Face_External_Stream(face) \
    105   (static_cast<FT_Face>(face)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM)
    106 #define FXFT_Get_Face_External_Stream(face) \
    107   (static_cast<FT_Face>(face)->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM)
    108 #define FXFT_Is_Face_TT_OT(face) \
    109   (static_cast<FT_Face>(face)->face_flags & FT_FACE_FLAG_SFNT)
    110 #define FXFT_Is_Face_Tricky(face) \
    111   (static_cast<FT_Face>(face)->face_flags & FXFT_FACE_FLAG_TRICKY)
    112 #define FXFT_Is_Face_fixedwidth(face) \
    113   (static_cast<FT_Face>(face)->face_flags & FT_FACE_FLAG_FIXED_WIDTH)
    114 #define FXFT_Get_Face_Stream_Base(face) static_cast<FT_Face>(face)->stream->base
    115 #define FXFT_Get_Face_Stream_Size(face) static_cast<FT_Face>(face)->stream->size
    116 #define FXFT_Get_Face_Family_Name(face) static_cast<FT_Face>(face)->family_name
    117 #define FXFT_Get_Face_Style_Name(face) static_cast<FT_Face>(face)->style_name
    118 #define FXFT_Is_Face_Italic(face) \
    119   (static_cast<FT_Face>(face)->style_flags & FT_STYLE_FLAG_ITALIC)
    120 #define FXFT_Is_Face_Bold(face) \
    121   (static_cast<FT_Face>(face)->style_flags & FT_STYLE_FLAG_BOLD)
    122 #define FXFT_Get_Face_Charmaps(face) static_cast<FT_Face>(face)->charmaps
    123 #define FXFT_Get_Glyph_HoriBearingX(face) \
    124   static_cast<FT_Face>(face)->glyph->metrics.horiBearingX
    125 #define FXFT_Get_Glyph_HoriBearingY(face) \
    126   static_cast<FT_Face>(face)->glyph->metrics.horiBearingY
    127 #define FXFT_Get_Glyph_Width(face) \
    128   static_cast<FT_Face>(face)->glyph->metrics.width
    129 #define FXFT_Get_Glyph_Height(face) \
    130   static_cast<FT_Face>(face)->glyph->metrics.height
    131 #define FXFT_Get_Face_CharmapCount(face) \
    132   static_cast<FT_Face>(face)->num_charmaps
    133 #define FXFT_Get_Charmap_Encoding(charmap) \
    134   static_cast<FT_CharMap>(charmap)->encoding
    135 #define FXFT_Get_Face_Charmap(face) static_cast<FT_Face>(face)->charmap
    136 #define FXFT_Get_Charmap_PlatformID(charmap) \
    137   static_cast<FT_CharMap>(charmap)->platform_id
    138 #define FXFT_Get_Charmap_EncodingID(charmap) \
    139   static_cast<FT_CharMap>(charmap)->encoding_id
    140 #define FXFT_Get_Face_UnitsPerEM(face) static_cast<FT_Face>(face)->units_per_EM
    141 #define FXFT_Get_Face_xMin(face) static_cast<FT_Face>(face)->bbox.xMin
    142 #define FXFT_Get_Face_xMax(face) static_cast<FT_Face>(face)->bbox.xMax
    143 #define FXFT_Get_Face_yMin(face) static_cast<FT_Face>(face)->bbox.yMin
    144 #define FXFT_Get_Face_yMax(face) static_cast<FT_Face>(face)->bbox.yMax
    145 #define FXFT_Get_Face_Height(face) static_cast<FT_Face>(face)->height
    146 #define FXFT_Get_Face_Ascender(face) static_cast<FT_Face>(face)->ascender
    147 #define FXFT_Get_Face_Descender(face) static_cast<FT_Face>(face)->descender
    148 #define FXFT_Get_Glyph_HoriAdvance(face) \
    149   static_cast<FT_Face>(face)->glyph->metrics.horiAdvance
    150 #define FXFT_Get_MM_Axis(var, index) &static_cast<FT_MM_Var*>(var)->axis[index]
    151 #define FXFT_Get_MM_Axis_Min(axis) static_cast<FT_Var_Axis*>(axis)->minimum
    152 #define FXFT_Get_MM_Axis_Max(axis) static_cast<FT_Var_Axis*>(axis)->maximum
    153 #define FXFT_Get_MM_Axis_Def(axis) static_cast<FT_Var_Axis*>(axis)->def
    154 #define FXFT_Free(face, p)                                                     \
    155   static_cast<FT_Face>(face)->memory->free(static_cast<FT_Face>(face)->memory, \
    156                                            p)
    157 #define FXFT_Get_Glyph_Outline(face) &static_cast<FT_Face>(face)->glyph->outline
    158 #define FXFT_Render_Glyph(face, mode)                \
    159   FT_Render_Glyph(static_cast<FT_Face>(face)->glyph, \
    160                   static_cast<enum FT_Render_Mode_>(mode))
    161 #define FXFT_Get_MM_Var(face, p) FT_Get_MM_Var(static_cast<FT_Face>(face), p)
    162 #define FXFT_Set_MM_Design_Coordinates(face, n, p) \
    163   FT_Set_MM_Design_Coordinates(static_cast<FT_Face>(face), n, p)
    164 #define FXFT_Set_Pixel_Sizes(face, w, h) \
    165   FT_Set_Pixel_Sizes(static_cast<FT_Face>(face), w, h)
    166 #define FXFT_Set_Transform(face, m, d) \
    167   FT_Set_Transform(static_cast<FT_Face>(face), m, d)
    168 #define FXFT_Outline_Embolden(outline, s) FT_Outline_Embolden(outline, s)
    169 #define FXFT_Get_Glyph_Bitmap(face) &static_cast<FT_Face>(face)->glyph->bitmap
    170 #define FXFT_Get_Bitmap_Width(bitmap) static_cast<FT_Bitmap*>(bitmap)->width
    171 #define FXFT_Get_Bitmap_Rows(bitmap) static_cast<FT_Bitmap*>(bitmap)->rows
    172 #define FXFT_Get_Bitmap_PixelMode(bitmap) \
    173   static_cast<FT_Bitmap*>(bitmap)->pixel_mode
    174 #define FXFT_Get_Bitmap_Pitch(bitmap) static_cast<FT_Bitmap*>(bitmap)->pitch
    175 #define FXFT_Get_Bitmap_Buffer(bitmap) static_cast<FT_Bitmap*>(bitmap)->buffer
    176 #define FXFT_Get_Glyph_BitmapLeft(face) \
    177   static_cast<FT_Face>(face)->glyph->bitmap_left
    178 #define FXFT_Get_Glyph_BitmapTop(face) \
    179   static_cast<FT_Face>(face)->glyph->bitmap_top
    180 #define FXFT_Outline_Decompose(outline, funcs, params) \
    181   FT_Outline_Decompose(outline, funcs, params)
    182 #define FXFT_Set_Char_Size(face, char_width, char_height, horz_resolution, \
    183                            vert_resolution)                                \
    184   FT_Set_Char_Size(face, char_width, char_height, horz_resolution,         \
    185                    vert_resolution)
    186 #define FXFT_Get_Glyph(slot, aglyph) FT_Get_Glyph(slot, aglyph)
    187 #define FXFT_Glyph_Get_CBox(glyph, bbox_mode, acbox) \
    188   FT_Glyph_Get_CBox(glyph, bbox_mode, acbox)
    189 #define FXFT_Done_Glyph(glyph) FT_Done_Glyph(glyph)
    190 #define FXFT_Library_SetLcdFilter(library, filter) \
    191   FT_Library_SetLcdFilter(static_cast<FT_Library>(library), filter)
    192 
    193 int FXFT_unicode_from_adobe_name(const char* glyph_name);
    194 void FXFT_adobe_name_from_unicode(char* name, wchar_t unicode);
    195 
    196 #endif  // CORE_FXGE_FX_FREETYPE_H_
    197