wdvi

network DVI viewer
Log | Files | Refs

font.h (5412B)


      1 #include <stdio.h>	/* FILE */
      2 
      3 #include <X11/Intrinsic.h>	/* Boolean */
      4 #include <X11/Xlib.h>		/* XImage */
      5 
      6 #include <ft2build.h>
      7 #include FT_SIZES_H	/* FT_Size */
      8 
      9 #include "data.h"	/* struct bitmap, set_char_proc */
     10 
     11 
     12 /*
     13  * Per-character information for virtual fonts
     14  */
     15 struct macro {
     16 	unsigned char *pos;	/* address of first byte of macro */
     17 	unsigned char *end;	/* address of last+1 byte */
     18 	long	dvi_adv;	/* DVI units to move reference point */
     19 	Boolean	free_me;	/* if free(pos) should be called when */
     20 				/* freeing space */
     21 };
     22 
     23 /*
     24  * Per-character information.
     25  * There is one of these for each character in a font (raster fonts only).
     26  * All fields are filled in at font definition time,
     27  * except for the bitmap, which is "faulted in"
     28  * when the character is first referenced.
     29  */
     30 struct glyph {
     31 	long addr;		/* address of bitmap in font file */
     32 	long dvi_adv;		/* DVI units to move reference point */
     33 	short x, y;		/* x and y offset in pixels */
     34 	struct bitmap bitmap;	/* bitmap for character */
     35 	short x2, y2;		/* x and y offset in pixels (shrunken bitmap) */
     36 	struct fgrec *fg;	/* fgrec for which these pixmaps are valid */
     37 	XImage *image2;
     38 	char *pixmap2;
     39 	char *pixmap2_t;
     40 	struct bitmap bitmap2;	/* shrunken bitmap for character */
     41 };
     42 
     43 /*
     44  * The layout of a font information block.
     45  * There is one of these for every loaded font or magnification thereof.
     46  * Duplicates are eliminated:  this is necessary because of possible recursion
     47  * in virtual fonts.
     48  *
     49  * Also note the strange units.  The design size is in 1/2^20 point
     50  * units (also called micro-points), and the individual character widths
     51  * are in the TFM file in 1/2^20 ems units, i.e., relative to the design size.
     52  *
     53  * We then change the sizes to SPELL units (unshrunk pixel / 2^16).
     54  */
     55 
     56 #define	NOMAGSTP (-29999)
     57 
     58 struct font;
     59 
     60 typedef	void (*read_char_proc)(struct font *, unsigned char);
     61 
     62 struct font {
     63 	struct font *next;		/* link to next font info block */
     64 	char *fontname;			/* name of font */
     65 	float fsize;			/* size information (dots per inch) */
     66 	int magstepval;			/* magstep number * two, or NOMAGSTP */
     67 	FILE *file;			/* open font file or NULL */
     68 	const char *filename;		/* name of font file */
     69 	long checksum;			/* checksum */
     70 	unsigned short timestamp;	/* for LRU management of fonts */
     71 	unsigned char flags;		/* flags byte (see values below) */
     72 	unsigned char maxchar;		/* largest character code */
     73 	double dimconv;			/* size conversion factor */
     74 	set_char_proc set_char_p;	/* proc used to set char */
     75 		/* these fields are used by (loaded) non-virtual fonts */
     76 	read_char_proc read_char;	/* function to read bitmap */
     77 	struct glyph *glyph;
     78 		/* these fields are used by (loaded) virtual fonts */
     79 	struct font **vf_table;		/* list of fonts used by this vf */
     80 	struct tn *vf_chain;		/* ditto, if TeXnumber >= VFTABLELEN */
     81 	struct font *first_font;	/* first font defined */
     82 	struct macro *macro;
     83 		/* these fields are used by (loaded) FreeType fonts */
     84 	struct ftfont	*ft;		/* master record for font (all sizes) */
     85 	double		spsize;		/* scaled size of font in spell units */
     86 	FT_Size		size;
     87 	struct font	*next_size;	/* next font from same face */
     88 		/* I suppose the above could be put into a union, but we */
     89 		/* wouldn't save all that much space. */
     90 };
     91 
     92 #define	FONT_IN_USE	1	/* used for housekeeping */
     93 #define	FONT_LOADED	2	/* if font file has been read */
     94 #define	FONT_VIRTUAL	4	/* if font is virtual */
     95 
     96 #define	TNTABLELEN	30	/* length of TeXnumber array (dvi file) */
     97 #define	VFTABLELEN	5	/* length of TeXnumber array (virtual fonts) */
     98 
     99 struct tn {
    100 	struct tn *next;		/* link to next TeXnumber info block */
    101 	int TeXnumber;			/* font number (in DVI file) */
    102 	struct font *fontp;		/* pointer to the rest of the info */
    103 };
    104 
    105 struct font	*tn_table[TNTABLELEN];
    106 struct font	*font_head	= NULL;
    107 struct tn	*tn_head	= NULL;
    108 unsigned char	maxchar;
    109 unsigned short	current_timestamp = 0;
    110 
    111 	/* Data structure for Type 1 fonts -- contents of psfonts.map */
    112 struct avl_t1 {
    113 	AVL_COMMON;
    114 	const char	*psname;	/* PS name of font */
    115 	const char	*fontfile;	/* (short) name of pfa/pfb file */
    116 	const char	*encname;	/* (short) name of encoding file */
    117 	const char	*addinfo;	/* additional PS instructions */
    118 	Boolean		bad;		/* if later found to be unloadable */
    119 	struct ftfont	*ft;		/* pointer to FreeType record */
    120 };
    121 
    122 
    123 
    124 struct ftfont {		/* info for FreeType font (Type 1 or TrueType) */
    125 	FT_Face		face;		/* NULL means not loaded yet */
    126 	struct font	*first_size;
    127 	struct avl_t1	*t1;
    128 	/* struct avl_tt *tt; */
    129 	struct FT_StreamRec_ stream;
    130 	struct avl_enc	*enc;		/* pointer to encoding record */
    131 	double		expn;		/* expansion factor */
    132 };
    133 
    134 
    135 struct avl_enc {
    136 	AVL_COMMON;
    137 	Boolean		valid;
    138 	const char	*vec[256];
    139 };
    140 
    141 
    142 
    143 Boolean	 font_open(struct font *, char **, int *);
    144 Boolean	 load_ft_font(struct font *);
    145 void	 read_PK_index(struct font *, Boolean);
    146 void	 read_VF_index(struct font *, Boolean);
    147 
    148 struct font *define_font(FILE *, unsigned char,
    149 			struct font *, struct font **, unsigned int,
    150 			struct tn **, long);
    151 
    152 FILE	*open_t1_font(struct avl_t1 *, const char **);
    153 
    154 void	 realloc_font(struct font *, unsigned char);
    155 void	 realloc_virtual_font(struct font *, unsigned char);
    156 Boolean	 load_font(struct font *);
    157 void	 open_font_file(struct font *);
    158 void	 read_encoding(struct avl_enc *);
    159 
    160 long	 set_char(unsigned char);
    161 long	 load_n_set_char(unsigned char);
    162 long	 set_vf_char(unsigned char);
    163 long	 set_ft_char(unsigned char);