1 /*
    2  * << Haru Free PDF Library >> -- hpdf_font.h
    3  *
    4  * URL: http://libharu.org
    5  *
    6  * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
    7  * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
    8  *
    9  * Permission to use, copy, modify, distribute and sell this software
   10  * and its documentation for any purpose is hereby granted without fee,
   11  * provided that the above copyright notice appear in all copies and
   12  * that both that copyright notice and this permission notice appear
   13  * in supporting documentation.
   14  * It is provided "as is" without express or implied warranty.
   15  *
   16  */
   17 
   18 #ifndef _HPDF_FONT_H
   19 #define _HPDF_FONT_H
   20 
   21 #include "hpdf_fontdef.h"
   22 
   23 #ifdef __cplusplus
   24 extern "C" {
   25 #endif
   26 
   27 
   28 /*----------------------------------------------------------------------------*/
   29 /*----- Writing Mode ---------------------------------------------------------*/
   30 
   31 typedef enum _HPDF_FontType {
   32     HPDF_FONT_TYPE1 = 0,
   33     HPDF_FONT_TRUETYPE,
   34     HPDF_FONT_TYPE3,
   35     HPDF_FONT_TYPE0_CID,
   36     HPDF_FONT_TYPE0_TT,
   37     HPDF_FONT_CID_TYPE0,
   38     HPDF_FONT_CID_TYPE2,
   39     HPDF_FONT_MMTYPE1
   40 } HPDF_FontType;
   41 
   42 
   43 typedef HPDF_Dict HPDF_Font;
   44 
   45 
   46 typedef HPDF_TextWidth
   47 (*HPDF_Font_TextWidths_Func)  (HPDF_Font        font,
   48                              const HPDF_BYTE  *text,
   49                              HPDF_UINT        len);
   50 
   51 
   52 typedef HPDF_UINT
   53 (*HPDF_Font_MeasureText_Func)  (HPDF_Font        font,
   54                               const HPDF_BYTE  *text,
   55                               HPDF_UINT        len,
   56                               HPDF_REAL        width,
   57                               HPDF_REAL        fontsize,
   58                               HPDF_REAL        charspace,
   59                               HPDF_REAL        wordspace,
   60                               HPDF_BOOL        wordwrap,
   61                               HPDF_REAL        *real_width);
   62 
   63 
   64 typedef struct _HPDF_FontAttr_Rec  *HPDF_FontAttr;
   65 
   66 typedef struct _HPDF_FontAttr_Rec {
   67     HPDF_FontType               type;
   68     HPDF_WritingMode            writing_mode;
   69     HPDF_Font_TextWidths_Func   text_width_fn;
   70     HPDF_Font_MeasureText_Func  measure_text_fn;
   71     HPDF_FontDef                fontdef;
   72     HPDF_Encoder                encoder;
   73 
   74     /* if the encoding-type is HPDF_ENCODER_TYPE_SINGLE_BYTE, the width of
   75      * each charactors are cashed in 'widths'.
   76      * when HPDF_ENCODER_TYPE_DOUBLE_BYTE the width is calculate each time.
   77      */
   78     HPDF_INT16*                 widths;
   79     HPDF_BYTE*                  used;
   80 
   81     HPDF_Xref                   xref;
   82     HPDF_Font                   descendant_font;
   83     HPDF_Dict                   map_stream;
   84     HPDF_Dict                   cmap_stream;
   85 } HPDF_FontAttr_Rec;
   86 
   87 
   88 HPDF_Font
   89 HPDF_Type1Font_New  (HPDF_MMgr        mmgr,
   90                      HPDF_FontDef     fontdef,
   91                      HPDF_Encoder     encoder,
   92                      HPDF_Xref        xref);
   93 
   94 HPDF_Font
   95 HPDF_TTFont_New  (HPDF_MMgr        mmgr,
   96                   HPDF_FontDef     fontdef,
   97                   HPDF_Encoder     encoder,
   98                   HPDF_Xref        xref);
   99 
  100 HPDF_Font
  101 HPDF_Type0Font_New  (HPDF_MMgr        mmgr,
  102                      HPDF_FontDef     fontdef,
  103                      HPDF_Encoder     encoder,
  104                      HPDF_Xref        xref);
  105 
  106 
  107 HPDF_BOOL
  108 HPDF_Font_Validate  (HPDF_Font font);
  109 
  110 #ifdef __cplusplus
  111 }
  112 #endif /* __cplusplus */
  113 
  114 #endif /* _HPDF_FONT_H */
  115