175584Sru// -*- C++ -*-
2151497Sru/* Copyright (C) 1989, 1990, 1991, 1992, 2002, 2004
3151497Sru   Free Software Foundation, Inc.
475584Sru     Written by James Clark (jjc@jclark.com)
575584Sru
675584SruThis file is part of groff.
775584Sru
875584Srugroff is free software; you can redistribute it and/or modify it under
975584Sruthe terms of the GNU General Public License as published by the Free
1075584SruSoftware Foundation; either version 2, or (at your option) any later
1175584Sruversion.
1275584Sru
1375584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY
1475584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or
1575584SruFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1675584Srufor more details.
1775584Sru
1875584SruYou should have received a copy of the GNU General Public License along
1975584Sruwith groff; see the file COPYING.  If not, write to the Free Software
20151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
2175584Sru
2275584Srutypedef void (*FONT_COMMAND_HANDLER)(const char *, const char *,
2375584Sru				     const char *, int);
2475584Sru
2575584Srustruct font_kern_list;
2675584Srustruct font_char_metric;
2775584Srustruct font_widths_cache;
2875584Sru
2975584Sruclass font {
3075584Srupublic:
3175584Sru  enum {
3275584Sru    LIG_ff = 1,
3375584Sru    LIG_fi = 2,
3475584Sru    LIG_fl = 4,
3575584Sru    LIG_ffi = 8,
3675584Sru    LIG_ffl = 16
3775584Sru    };
3875584Sru
3975584Sru  virtual ~font();
4075584Sru  int contains(int index);
4175584Sru  int is_special();
4275584Sru  int get_width(int index, int point_size);
4375584Sru  int get_height(int index, int point_size);
4475584Sru  int get_depth(int index, int point_size);
4575584Sru  int get_space_width(int point_size);
4675584Sru  int get_character_type(int index);
4775584Sru  int get_kern(int index1, int index2, int point_size);
4875584Sru  int get_skew(int index, int point_size, int slant);
4975584Sru  int has_ligature(int);
5075584Sru  int get_italic_correction(int index, int point_size);
5175584Sru  int get_left_italic_correction(int index, int point_size);
5275584Sru  int get_subscript_correction(int index, int point_size);
5375584Sru  int get_code(int i);
5475584Sru  const char *get_special_device_encoding(int index);
5575584Sru  const char *get_name();
5675584Sru  const char *get_internal_name();
57151497Sru  const char *get_image_generator();
5875584Sru
59104862Sru  static int scan_papersize(const char *, const char **, double *, double *);
60104862Sru
61151497Sru  static font *load_font(const char *, int * = 0, int = 0);
6275584Sru  static void command_line_font_dir(const char *path);
6375584Sru  static FILE *open_file(const char *name, char **pathp);
6475584Sru  static int load_desc();
6575584Sru  static int name_to_index(const char *);
6675584Sru  static int number_to_index(int);
6775584Sru  static FONT_COMMAND_HANDLER
6875584Sru    set_unknown_desc_command_handler(FONT_COMMAND_HANDLER);
6975584Sru
7075584Sru  static int res;
7175584Sru  static int hor;
7275584Sru  static int vert;
7375584Sru  static int unitwidth;
7475584Sru  static int paperwidth;
7575584Sru  static int paperlength;
76104862Sru  static const char *papersize;
7775584Sru  static int biggestfont;
7875584Sru  static int spare2;
7975584Sru  static int sizescale;
8075584Sru  static int tcommand;
81151497Sru  static int unscaled_charwidths;
8275584Sru  static int pass_filenames;
8375584Sru  static int use_charnames_in_special;
84151497Sru  static const char *image_generator;
8575584Sru
8675584Sru  static const char **font_name_table;
8775584Sru  static const char **style_table;
8875584Sru  static const char *family;
8975584Sru  static int *sizes;
9075584Sruprivate:
9175584Sru  unsigned ligatures;
9275584Sru  font_kern_list **kern_hash_table;
9375584Sru  int space_width;
94151497Sru  int *ch_index;
9575584Sru  int nindices;
9675584Sru  font_char_metric *ch;
9775584Sru  int ch_used;
9875584Sru  int ch_size;
9975584Sru  int special;
10075584Sru  char *name;
10175584Sru  char *internalname;
10275584Sru  double slant;
10375584Sru  font_widths_cache *widths_cache;
10475584Sru  static FONT_COMMAND_HANDLER unknown_desc_command_handler;
10575584Sru
10675584Sru  enum { KERN_HASH_TABLE_SIZE = 503 };
10775584Sru
10875584Sru  void add_entry(int index, const font_char_metric &);
10975584Sru  void copy_entry(int new_index, int old_index);
11075584Sru  void add_kern(int index1, int index2, int amount);
11175584Sru  static int hash_kern(int i1, int i2);
11275584Sru  void alloc_ch_index(int);
11375584Sru  void extend_ch();
11475584Sru  void compact();
11575584Sru
11675584Sru  static int scale(int w, int pointsize);
117104862Sru  static int unit_scale(double *value, char unit);
11875584Sru  virtual void handle_unknown_font_command(const char *command,
11975584Sru					   const char *arg,
12075584Sru					   const char *file, int lineno);
12175584Sruprotected:
12275584Sru  font(const char *);
123151497Sru  int load(int * = 0, int = 0);
12475584Sru};
125