xref: /trueos/contrib/groff/src/include/font.h (revision 513cdf04e173130783343fe42786eef6b8294c6e)
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2002, 2004
3    Free Software Foundation, Inc.
4      Written by James Clark (jjc@jclark.com)
5 
6 This file is part of groff.
7 
8 groff is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12 
13 groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License along
19 with groff; see the file COPYING.  If not, write to the Free Software
20 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21 
22 typedef void (*FONT_COMMAND_HANDLER)(const char *, const char *,
23 				     const char *, int);
24 
25 struct font_kern_list;
26 struct font_char_metric;
27 struct font_widths_cache;
28 
29 class font {
30 public:
31   enum {
32     LIG_ff = 1,
33     LIG_fi = 2,
34     LIG_fl = 4,
35     LIG_ffi = 8,
36     LIG_ffl = 16
37     };
38 
39   virtual ~font();
40   int contains(int index);
41   int is_special();
42   int get_width(int index, int point_size);
43   int get_height(int index, int point_size);
44   int get_depth(int index, int point_size);
45   int get_space_width(int point_size);
46   int get_character_type(int index);
47   int get_kern(int index1, int index2, int point_size);
48   int get_skew(int index, int point_size, int slant);
49   int has_ligature(int);
50   int get_italic_correction(int index, int point_size);
51   int get_left_italic_correction(int index, int point_size);
52   int get_subscript_correction(int index, int point_size);
53   int get_code(int i);
54   const char *get_special_device_encoding(int index);
55   const char *get_name();
56   const char *get_internal_name();
57   const char *get_image_generator();
58 
59   static int scan_papersize(const char *, const char **, double *, double *);
60 
61   static font *load_font(const char *, int * = 0, int = 0);
62   static void command_line_font_dir(const char *path);
63   static FILE *open_file(const char *name, char **pathp);
64   static int load_desc();
65   static int name_to_index(const char *);
66   static int number_to_index(int);
67   static FONT_COMMAND_HANDLER
68     set_unknown_desc_command_handler(FONT_COMMAND_HANDLER);
69 
70   static int res;
71   static int hor;
72   static int vert;
73   static int unitwidth;
74   static int paperwidth;
75   static int paperlength;
76   static const char *papersize;
77   static int biggestfont;
78   static int spare2;
79   static int sizescale;
80   static int tcommand;
81   static int unscaled_charwidths;
82   static int pass_filenames;
83   static int use_charnames_in_special;
84   static const char *image_generator;
85 
86   static const char **font_name_table;
87   static const char **style_table;
88   static const char *family;
89   static int *sizes;
90 private:
91   unsigned ligatures;
92   font_kern_list **kern_hash_table;
93   int space_width;
94   int *ch_index;
95   int nindices;
96   font_char_metric *ch;
97   int ch_used;
98   int ch_size;
99   int special;
100   char *name;
101   char *internalname;
102   double slant;
103   font_widths_cache *widths_cache;
104   static FONT_COMMAND_HANDLER unknown_desc_command_handler;
105 
106   enum { KERN_HASH_TABLE_SIZE = 503 };
107 
108   void add_entry(int index, const font_char_metric &);
109   void copy_entry(int new_index, int old_index);
110   void add_kern(int index1, int index2, int amount);
111   static int hash_kern(int i1, int i2);
112   void alloc_ch_index(int);
113   void extend_ch();
114   void compact();
115 
116   static int scale(int w, int pointsize);
117   static int unit_scale(double *value, char unit);
118   virtual void handle_unknown_font_command(const char *command,
119 					   const char *arg,
120 					   const char *file, int lineno);
121 protected:
122   font(const char *);
123   int load(int * = 0, int = 0);
124 };
125