font.h revision 104862
12Sjlaskey// -*- C++ -*-
26Sjlaskey/* Copyright (C) 1989, 1990, 1991, 1992, 2002 Free Software Foundation, Inc.
32Sjlaskey     Written by James Clark (jjc@jclark.com)
4877Sattila
52SjlaskeyThis file is part of groff.
62Sjlaskey
72Sjlaskeygroff is free software; you can redistribute it and/or modify it under
8877Sattilathe terms of the GNU General Public License as published by the Free
92SjlaskeySoftware Foundation; either version 2, or (at your option) any later
102Sjlaskeyversion.
112Sjlaskey
122Sjlaskeygroff is distributed in the hope that it will be useful, but WITHOUT ANY
132SjlaskeyWARRANTY; without even the implied warranty of MERCHANTABILITY or
14877SattilaFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
152Sjlaskeyfor more details.
162Sjlaskey
172SjlaskeyYou should have received a copy of the GNU General Public License along
18877Sattilawith groff; see the file COPYING.  If not, write to the Free Software
192SjlaskeyFoundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
202Sjlaskey
212Sjlaskeytypedef void (*FONT_COMMAND_HANDLER)(const char *, const char *,
222Sjlaskey				     const char *, int);
232Sjlaskey
242Sjlaskeystruct font_kern_list;
252Sjlaskeystruct font_char_metric;
262Sjlaskeystruct font_widths_cache;
272Sjlaskey
282Sjlaskeyclass font {
292Sjlaskeypublic:
302Sjlaskey  enum {
312Sjlaskey    LIG_ff = 1,
322Sjlaskey    LIG_fi = 2,
332Sjlaskey    LIG_fl = 4,
342Sjlaskey    LIG_ffi = 8,
352Sjlaskey    LIG_ffl = 16
362Sjlaskey    };
372Sjlaskey
382Sjlaskey  virtual ~font();
392Sjlaskey  int contains(int index);
402Sjlaskey  int is_special();
412Sjlaskey  int get_width(int index, int point_size);
42  int get_height(int index, int point_size);
43  int get_depth(int index, int point_size);
44  int get_space_width(int point_size);
45  int get_character_type(int index);
46  int get_kern(int index1, int index2, int point_size);
47  int get_skew(int index, int point_size, int slant);
48  int has_ligature(int);
49  int get_italic_correction(int index, int point_size);
50  int get_left_italic_correction(int index, int point_size);
51  int get_subscript_correction(int index, int point_size);
52  int get_code(int i);
53  const char *get_special_device_encoding(int index);
54  const char *get_name();
55  const char *get_internal_name();
56
57  static int scan_papersize(const char *, const char **, double *, double *);
58
59  static font *load_font(const char *, int *not_found = 0);
60  static void command_line_font_dir(const char *path);
61  static FILE *open_file(const char *name, char **pathp);
62  static int load_desc();
63  static int name_to_index(const char *);
64  static int number_to_index(int);
65  static FONT_COMMAND_HANDLER
66    set_unknown_desc_command_handler(FONT_COMMAND_HANDLER);
67
68  static int res;
69  static int hor;
70  static int vert;
71  static int unitwidth;
72  static int paperwidth;
73  static int paperlength;
74  static const char *papersize;
75  static int biggestfont;
76  static int spare2;
77  static int sizescale;
78  static int tcommand;
79  static int pass_filenames;
80  static int use_charnames_in_special;
81
82  static const char **font_name_table;
83  static const char **style_table;
84  static const char *family;
85  static int *sizes;
86private:
87  unsigned ligatures;
88  font_kern_list **kern_hash_table;
89  int space_width;
90  short *ch_index;
91  int nindices;
92  font_char_metric *ch;
93  int ch_used;
94  int ch_size;
95  int special;
96  char *name;
97  char *internalname;
98  double slant;
99  font_widths_cache *widths_cache;
100  static FONT_COMMAND_HANDLER unknown_desc_command_handler;
101
102  enum { KERN_HASH_TABLE_SIZE = 503 };
103
104  void add_entry(int index, const font_char_metric &);
105  void copy_entry(int new_index, int old_index);
106  void add_kern(int index1, int index2, int amount);
107  static int hash_kern(int i1, int i2);
108  void alloc_ch_index(int);
109  void extend_ch();
110  void compact();
111
112  static int scale(int w, int pointsize);
113  static int unit_scale(double *value, char unit);
114  virtual void handle_unknown_font_command(const char *command,
115					   const char *arg,
116					   const char *file, int lineno);
117protected:
118  font(const char *);
119  int load(int *not_found = 0);
120};
121