Back to index

tetex-bin  3.0
t1lib.h
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------------
00002   ----- File:        t1lib.h
00003   ----- Author:      Rainer Menzner (Rainer.Menzner@web.de)
00004   ----- Date:        2004-02-04
00005   ----- Description: This file is part of the t1-library. It must be
00006                      included by the user of the t1lib. It contains
00007                    function declarations and some basic data types, the
00008                    user must deal with.
00009   ----- Copyright:   t1lib is copyrighted (c) Rainer Menzner, 1996-2004.
00010                      As of version 0.5, t1lib is distributed under the
00011                    GNU General Public Library Lincense. The
00012                    conditions can be found in the files LICENSE and
00013                    LGPL, which should reside in the toplevel
00014                    directory of the distribution.  Please note that 
00015                    there are parts of t1lib that are subject to
00016                    other licenses:
00017                    The parseAFM-package is copyrighted by Adobe Systems
00018                    Inc.
00019                    The type1 rasterizer is copyrighted by IBM and the
00020                    X11-consortium.
00021   ----- Warranties:  Of course, there's NO WARRANTY OF ANY KIND :-)
00022   ----- Credits:     I want to thank IBM and the X11-consortium for making
00023                      their rasterizer freely available.
00024                    Also thanks to Piet Tutelaers for his ps2pk, from
00025                    which I took the rasterizer sources in a format
00026                    independent from X11.
00027                      Thanks to all people who make free software living!
00028 --------------------------------------------------------------------------*/
00029 
00030 
00031 #ifndef T1LIB_H_INCLUDED
00032 
00033 #define T1LIB_H_INCLUDED
00034 
00035 /* type definitions, needed by the user: */
00036 
00037 #if defined(__cplusplus) || defined(c_plusplus)
00038 extern "C" {
00039 #endif
00040 
00041 /* Version information filled in by configure */
00042 #define T1LIB_VERSION            5
00043 #define T1LIB_REVISION           0
00044 #define T1LIB_PATCHLEVEL         1
00045 #define T1LIB_VERSIONSTRING      "5.0.1"
00046 
00047 
00048 /* the data structure which contains the character bitmap description */
00049 typedef struct
00050 {
00051   char *bits;           /* A pointer to the characters local bitmap */
00052   struct                /* A struct containing diverse metric information */
00053   {
00054     int ascent;
00055     int descent;
00056     int leftSideBearing;
00057     int rightSideBearing;
00058     int advanceX;
00059     int advanceY;
00060   } metrics;
00061   void *pFontCacheInfo;
00062   unsigned long bpp;
00063 } GLYPH;
00064 
00065 
00066 /* A structure representing a matrix */
00067 typedef struct
00068 {
00069   double cxx;
00070   double cyx;
00071   double cxy;
00072   double cyy;
00073 } T1_TMATRIX;
00074 
00075 
00076 /* the bounding box data structure: */
00077 typedef struct
00078 { 
00079    int llx;   /* lower left x-position  */
00080    int lly;   /* lower left y-position  */
00081    int urx;   /* upper right x-position */
00082    int ury;   /* upper right y-position */
00083 } BBox;
00084 
00085 
00086 /* A data that makes most important information available to user. */
00087 typedef struct
00088 {
00089   int      width;       /* The glyph's width */
00090   BBox     bbox;        /* The glyph's bounding box */
00091   int      numchars;    /* The number of characters in the glyph (string) */
00092   int      *charpos;    /* A pointer to an integer array were the horizontal
00093                         positions in (afm units) of the individual
00094                         characters in the string are stored */
00095 } METRICSINFO;
00096 
00097 
00098 #define  PAD(bits, pad)  (((bits)+(pad)-1)&-(pad))
00099 
00100 
00101 /* def's for T1_InitLib() */
00102 #define NO_LOGFILE          0x0
00103 #define LOGFILE             0x1
00104 #define IGNORE_FONTDATABASE 0x2  /* Default is to read database */
00105 #define IGNORE_CONFIGFILE   0x4  /* Default is to read config file */
00106 #define T1_AA_CACHING       0x8  /* Cache aa-bytes */
00107 #define T1_NO_AFM           0x10 /* Do not load or generate AFM data */
00108 
00109 
00110 
00111 /* common 'yes'/'no' */
00112 #define T1_YES              0x1
00113 #define T1_NO               0x0
00114 
00115 
00116 /* logfile levels: */
00117 #define T1LOG_ERROR     1
00118 #define T1LOG_WARNING   2
00119 #define T1LOG_STATISTIC 3
00120 #define T1LOG_DEBUG     4
00121 
00122 
00123 /* #define's for manipulating searchpaths */
00124 #define T1_PFAB_PATH        0x01
00125 #define T1_AFM_PATH         0x02
00126 #define T1_ENC_PATH         0x04
00127 #define T1_FDB_PATH         0x08
00128 #define T1_APPEND_PATH      0x00
00129 #define T1_PREPEND_PATH     0x01
00130 
00131 
00132 /* #define's for character/string properties (not all implemented) */
00133 #define T1_DEFAULT             0x0000
00134 #define T1_UNDERLINE           0x0001
00135 #define T1_OVERLINE            0x0002
00136 #define T1_OVERSTRIKE          0x0004
00137 #define T1_DOUBLEOVERSTRIKE    0x0008
00138 #define T1_RIGHT_TO_LEFT       0x0010
00139 #define T1_SUBSCRIPT           0x0100
00140 #define T1_SUPERSCRIPT         0x0200
00141 #define T1_STROKED             0x1000
00142 #define T1_KERNING             0x2000
00143 
00144 
00145 /* Setting the subsampling value */
00146 #define T1_AA_NONE  1
00147 #define T1_AA_LOW   2
00148 #define T1_AA_HIGH  4
00149 
00150 
00151 /* Error handling: */
00152 extern int T1_errno;
00153 
00154 /* These are from scanning a font file */
00155 #define T1ERR_SCAN_FONT_FORMAT       -5
00156 #define T1ERR_SCAN_FILE_OPEN_ERR     -4
00157 #define T1ERR_SCAN_OUT_OF_MEMORY     -3
00158 #define T1ERR_SCAN_ERROR             -2
00159 #define T1ERR_SCAN_FILE_EOF          -1
00160 /* These are from generating paths */
00161 #define T1ERR_PATH_ERROR              1
00162 #define T1ERR_PARSE_ERROR             2
00163 #define T1ERR_TYPE1_ABORT             3
00164 /* These are from t1lib */
00165 #define T1ERR_INVALID_FONTID          10
00166 #define T1ERR_INVALID_PARAMETER       11
00167 #define T1ERR_OP_NOT_PERMITTED        12
00168 #define T1ERR_ALLOC_MEM               13
00169 #define T1ERR_FILE_OPEN_ERR           14
00170 #define T1ERR_UNSPECIFIED             15
00171 #define T1ERR_NO_AFM_DATA             16
00172 #define T1ERR_X11                     17
00173 #define T1ERR_COMPOSITE_CHAR          18
00174 #define T1ERR_SCAN_ENCODING           19
00175 
00176 
00177 /* Flags to control the rasterizer */
00178 #define T1_IGNORE_FORCEBOLD           0x0001
00179 #define T1_IGNORE_FAMILYALIGNMENT     0x0002
00180 #define T1_IGNORE_HINTING             0x0004
00181 
00182 #define T1_DEBUG_LINE                 0x0100
00183 #define T1_DEBUG_REGION               0x0200
00184 #define T1_DEBUG_PATH                 0x0400
00185 #define T1_DEBUG_FONT                 0x0800
00186 #define T1_DEBUG_HINT                 0x1000
00187 
00188 
00189 /* definitions for outline handling */
00190 #define   FRACTBITS     16   /* number of fractional bits in 'fractpel'      */
00191 /* From/to conversion of pels/fractpels */
00192 #define   T1_TOPATHPOINT(p)      (((long)p)<<FRACTBITS)
00193 #define   PPHALF                 (1<<(FRACTBITS-1))
00194 #define   T1_NEARESTPOINT(fp)    (((fp)+PPHALF)>>FRACTBITS)
00195 
00196 /* A fractional point */
00197 typedef struct {
00198   long x;
00199   long y;
00200 } T1_PATHPOINT;
00201 
00202 
00203 /* A straight outline segment, stroked or not stroked */
00204 typedef struct pathsegment {  
00205   char type;                /* type of segment (line or move) */
00206   unsigned char flag;       /* type1 rasterizer internal stuff */
00207   short references;         /* type1 rasterizer internal stuff */
00208   unsigned char size;       /* size of the structure */
00209   unsigned char context;    /* index to device context */
00210   struct pathsegment *link; /* pointer to next structure in linked list */
00211   struct pathsegment *last; /* pointer to last structure in list */
00212   T1_PATHPOINT    dest;     /* relative ending location of path segment */
00213 } T1_PATHSEGMENT;
00214 
00215 /* A third order bezier segment */
00216 typedef struct bezierpathsegment {
00217   char type;                /* type of segment (bezier) */
00218   unsigned char flag;     /* type1 rasterizer internal stuff */
00219   short references;       /* type1 rasterizer internal stuff */
00220   unsigned char size;     /* as with any 'segment' type */
00221   unsigned char context;  /* as with any 'segment' type */
00222   T1_PATHSEGMENT *link;   /* as with any 'segment' type */
00223   T1_PATHSEGMENT *last;   /* as with any 'segment' type */
00224   T1_PATHPOINT    dest;   /* ending point (D) */
00225   T1_PATHPOINT    B;      /* control point B */
00226   T1_PATHPOINT    C;      /* control point C */
00227 } T1_BEZIERSEGMENT;
00228 
00229 typedef T1_PATHSEGMENT  T1_OUTLINE;
00230 
00231 #define   T1_PATHTYPE_LINE           0x10
00232 #define   T1_PATHTYPE_BEZIER         0x12
00233 #define   T1_PATHTYPE_MOVE           0x15
00234 
00235 
00236 /* Definitions for font subsetting */
00237 #define T1_SUBSET_DEFAULT            0x00
00238 #define T1_SUBSET_FORCE_REENCODE     0x01
00239 #define T1_SUBSET_SKIP_REENCODE      0x02
00240 #define T1_SUBSET_ENCRYPT_BINARY     0x04
00241 /* This is only for debugging, it does not produce valid font-files!
00242    This flag is not in the documented API!. */
00243 #define T1_SUBSET_ENCRYPT_NONE       0x08
00244 
00245 
00246 /* Two structures for handling composite character data */
00247 /* One structure for each symbol of the composite character */
00248 typedef struct
00249 {
00250   int piece;               /* the index of the current symbol */
00251   int deltax;              /* horizontal displacement of current symbol in CS */ 
00252   int deltay;              /* vertical displacement of current symbol in CS */ 
00253 } T1_COMP_PIECE;
00254 
00255 /* This one defines the composite character, the number of pieces and how to
00256    access their data. */
00257 typedef struct 
00258 {
00259   int compchar;             /* the base character in the current encoding */
00260   int numPieces;            /* the number of defined pieces including the base char */
00261   T1_COMP_PIECE *pieces;   /* a pointer to the pieces' information */
00262 } T1_COMP_CHAR_INFO;
00263 
00264 
00265 
00266 /* function declarations: */
00267 
00268 /* from t1base.c */
00269 extern void *T1_InitLib( int log);
00270 extern int T1_CloseLib( void);
00271 extern int T1_AddFont( char *fontfilename);
00272 extern void T1_PrintLog( char *func_ident, char *msg_txt, int level, ...);
00273 extern void T1_SetLogLevel( int level);
00274 extern int T1_CheckForInit(void);
00275 extern int T1_CheckForFontID( int FontID);
00276 extern char *T1_GetFontFileName( int FontID);
00277 extern int  T1_GetNoFonts(void);
00278 extern int T1_SetDeviceResolutions( float x_res, float y_res);
00279 extern int T1_CopyFont( int FontID);
00280 extern int T1_QueryX11Support( void);
00281 extern int T1_CheckEndian(void);
00282 extern int T1_SetBitmapPad( int pad);
00283 extern int T1_GetBitmapPad( void);
00284 extern char *T1_GetLibIdent( void);
00285 extern void T1_SetRasterFlags( int flags);
00286 extern char *T1_GetAfmFileName( int FontID);
00287 extern int T1_SetAfmFileName( int FontId, char *afm_name);
00288 extern char *T1_GetFontFilePath( int FontID);
00289 extern char *T1_GetAfmFilePath( int FontID);
00290 extern const char *T1_StrError( int t1err);
00291 
00292 /* from t1delete.c */
00293 extern int T1_DeleteSize( int FontID, float size);
00294 extern int T1_DeleteAllSizes( int FontID);
00295 extern int T1_FreeGlyph( GLYPH *glyph);
00296 extern int T1_FreeCompCharData( T1_COMP_CHAR_INFO *cci);
00297 extern int T1_DeleteFont( int FontID);
00298 
00299 /* from t1enc.c */
00300 extern char **T1_LoadEncoding( char *FileName);
00301 extern int T1_DeleteEncoding( char **encoding);
00302 extern int T1_ReencodeFont( int FontID, char **Encoding);
00303 extern int T1_SetDefaultEncoding( char **encoding);
00304 extern char *T1_GetEncodingScheme( int FontID);
00305 
00306 /* from t1env.c */
00307 extern int T1_SetFileSearchPath( int type, char *pathname);
00308 extern int T1_AddToFileSearchPath( int pathtype, int mode, char *pathname);
00309 extern char *T1_GetFileSearchPath( int type);
00310 extern int T1_SetFontDataBase( char *filename);
00311 extern int T1_AddFontDataBase( int mode, char *filename);
00312 
00313 /* from t1finfo.c */
00314 extern int T1_GetKerning( int FontID, char char1,
00315                        char char2);
00316 extern int T1_GetCharWidth( int FontID, char char1);
00317 extern BBox T1_GetCharBBox( int FontID, char char1);
00318 extern float T1_GetUnderlinePosition( int FontID);
00319 extern float T1_GetUnderlineThickness( int FontID);
00320 extern float T1_GetItalicAngle( int FontID);
00321 extern int T1_GetIsFixedPitch( int FontID);
00322 extern char *T1_GetFontName( int FontID);
00323 extern char *T1_GetFullName( int FontID);
00324 extern char *T1_GetFamilyName( int FontID);
00325 extern char *T1_GetWeight( int FontID);
00326 extern char *T1_GetVersion( int FontID);
00327 extern char *T1_GetNotice( int FontID);
00328 extern char *T1_GetCharName( int FontID, char char1);
00329 extern int T1_QueryLigs( int FontID,
00330                       char char1,
00331                       char **successors,
00332                       char **ligatures);
00333 extern int T1_GetEncodingIndex( int FontID, char *char1);
00334 extern int *T1_GetEncodingIndices( int FontID, char *char1);
00335 extern int T1_GetStringWidth( int FontID, char *string,
00336                            int len,  long spaceoff, int kerning);
00337 extern BBox T1_GetStringBBox( int FontID, char *string,
00338                            int len,  long spaceoff, int kerning);
00339 extern METRICSINFO T1_GetMetricsInfo( int FontID, char *string,
00340                                   int len,  long spaceoff, int kerning);
00341 extern BBox T1_GetFontBBox( int FontID);
00342 extern char **T1_GetAllCharNames( int FontID);
00343 extern int T1_GetNoKernPairs( int FontID);
00344 extern int T1_GetNoCompositeChars( int FontID);
00345 extern int T1_QueryCompositeChar( int FontID, char char1);
00346 extern T1_COMP_CHAR_INFO *T1_GetCompCharData( int FontID, char char1);
00347 extern T1_COMP_CHAR_INFO *T1_GetCompCharDataByIndex( int FontID, int index);
00348 extern int T1_IsInternalChar( int FontID, char char1);
00349 
00350 /* from t1load.c */
00351 extern int T1_LoadFont( int FontID);
00352 extern void *T1_QueryFontSize( int FontID, float size, int aa);
00353 
00354 /* from t1set.c */
00355 extern GLYPH *T1_SetChar( int FontID, char charcode, 
00356                        float size, T1_TMATRIX *transform);
00357 extern GLYPH *T1_SetString( int FontID, char *string, int len,
00358                          long spaceoff, int modflag,
00359                          float size, T1_TMATRIX *transform);
00360 extern GLYPH* T1_SetRect( int FontID, float size,
00361                        float width, float height,
00362                        T1_TMATRIX *transform);
00363 extern GLYPH *T1_CopyGlyph(GLYPH *glyph);
00364 extern void T1_DumpGlyph( GLYPH *glyph);
00365 extern GLYPH *T1_ConcatGlyphs( GLYPH *glyph1, GLYPH *glyph2,
00366                             int x_off, int y_off, int modflag);
00367 extern void T1_DumpPixmap( GLYPH *glyph);
00368 extern GLYPH *T1_FillOutline( T1_OUTLINE *path, int modflag);
00369 
00370 /* from t1trans.c */
00371 extern int T1_ExtendFont( int FontID, double extend);
00372 extern int T1_SlantFont( int FontID, double slant);
00373 extern int T1_TransformFont( int FontID, T1_TMATRIX *matrix);
00374 extern double T1_GetExtend( int FontID);
00375 extern double T1_GetSlant( int FontID);
00376 extern T1_TMATRIX T1_GetTransform( int FontID);
00377 extern int T1_SetLinePosition( int FontID, int linetype, float value);
00378 extern int T1_SetLineThickness( int FontID, int linetype, float value);
00379 extern float T1_GetLinePosition( int FontID, int linetype);
00380 extern float T1_GetLineThickness( int FontID, int linetype);
00381 extern T1_TMATRIX *T1_RotateMatrix( T1_TMATRIX *matrix, double angle);
00382 extern T1_TMATRIX *T1_MirrorHMatrix( T1_TMATRIX *matrix);
00383 extern T1_TMATRIX *T1_MirrorVMatrix( T1_TMATRIX *matrix);
00384 extern T1_TMATRIX *T1_ShearHMatrix( T1_TMATRIX *matrix, double shear);
00385 extern T1_TMATRIX *T1_ShearVMatrix( T1_TMATRIX *matrix, double shear);
00386 extern T1_TMATRIX *T1_ExtendHMatrix( T1_TMATRIX *matrix, double extent);
00387 extern T1_TMATRIX *T1_ExtendVMatrix( T1_TMATRIX *matrix, double extent);
00388 extern T1_TMATRIX *T1_TransformMatrix( T1_TMATRIX *matrix,
00389                                    double cxx, double cyx,
00390                                    double cxy, double cyy);
00391 extern int T1_StrokeFont( int FontID, int dostroke);
00392 extern int T1_SetStrokeFlag( int FontID);
00393 extern int T1_ClearStrokeFlag( int FontID);
00394 extern int T1_GetStrokeMode( int FontID);
00395 extern int T1_SetStrokeWidth( int FontID, float strokewidth);
00396 extern float T1_GetStrokeWidth( int FontID);
00397 
00398 
00399 /* from t1aaset.c */
00400 extern GLYPH *T1_AASetChar( int FontID, char charcode, 
00401                          float size, T1_TMATRIX *transform);
00402 extern GLYPH *T1_AASetString( int FontID, char *string, int len,
00403                            long spaceoff, int modflag,
00404                            float size, T1_TMATRIX *transform);
00405 extern GLYPH* T1_AASetRect( int FontID, float size,
00406                          float width, float height,
00407                          T1_TMATRIX *transform);
00408 extern int T1_AASetGrayValues(unsigned long white,
00409                            unsigned long gray75,
00410                            unsigned long gray50,
00411                            unsigned long gray25,
00412                            unsigned long black);
00413 extern int T1_AAHSetGrayValues( unsigned long *grayvals);
00414 extern int T1_AANSetGrayValues( unsigned long bg, unsigned long fg);
00415 extern int T1_AAGetGrayValues( long *pgrayvals);
00416 extern int T1_AAHGetGrayValues( long *pgrayvals);
00417 extern int T1_AANGetGrayValues( long *pgrayvals);
00418 extern int T1_AASetBitsPerPixel( int bpp);
00419 extern int T1_AAGetBitsPerPixel( void);
00420 extern int T1_AASetLevel( int level);
00421 extern int T1_AAGetLevel( void);
00422 extern GLYPH *T1_AAFillOutline( T1_OUTLINE *path, int modflag);
00423 extern int T1_AASetSmartLimits( float limit1, float limit2);
00424 extern int T1_AASetSmartMode( int smart);
00425 
00426 
00427 /* from t1afmtool.c */
00428 extern int      T1_WriteAFMFallbackFile( int FontID);
00429 
00430 /* from t1outline.c */
00431 extern T1_OUTLINE *T1_GetCharOutline( int FontID, char charcode,
00432                                   float size, T1_TMATRIX *transform);
00433 extern T1_OUTLINE *T1_GetStringOutline( int FontID, char *string, int len, 
00434                                    long spaceoff, int modflag,
00435                                    float size, T1_TMATRIX *transform);
00436 extern T1_OUTLINE *T1_ConcatOutlines( T1_OUTLINE *path1,
00437                                   T1_OUTLINE *path2);
00438 extern T1_OUTLINE *T1_ScaleOutline( T1_OUTLINE *path, float scale);
00439 extern T1_OUTLINE *T1_GetMoveOutline( int FontID, int deltax, int deltay, int modflag,
00440                                   float size, T1_TMATRIX *transform);
00441 extern void T1_DumpPath( T1_OUTLINE *path);
00442 extern void T1_AbsolutePath( T1_OUTLINE *rpath);
00443 extern void T1_RelativePath( T1_OUTLINE *apath);
00444 extern void T1_ManipulatePath( T1_OUTLINE *path,
00445                             void (*manipulate)(long *x,long *y,int type));
00446 extern T1_OUTLINE *T1_CopyOutline( T1_OUTLINE *path);
00447 extern void T1_FreeOutline( T1_OUTLINE *path);
00448 
00449 
00450 /* from t1subset.c */
00451 extern char *T1_SubsetFont( int FontID,
00452                          char *mask,
00453                          unsigned int flags,
00454                          int linewidth,
00455                          unsigned long maxblocksize,
00456                          unsigned long *bufsize);
00457 extern char *T1_GetCharString( int FontID, char *charname, int *len);
00458 extern int T1_GetlenIV( int FontID);
00459 
00460 
00461 #if defined(__cplusplus) || defined(c_plusplus)
00462 }
00463 #endif
00464 
00465 #endif /* T1LIB_H_INCLUDED */