summaryrefslogtreecommitdiff
path: root/src/include/font.h
blob: 3d46138e7cdabdd3d083061de8e9c41603101425 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// -*- C++ -*-
/* Copyright (C) 1989, 1990, 1991, 1992, 2002, 2004
   Free Software Foundation, Inc.
     Written by James Clark (jjc@jclark.com)

This file is part of groff.

groff is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.

groff is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with groff; see the file COPYING.  If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

typedef void (*FONT_COMMAND_HANDLER)(const char *, const char *,
				     const char *, int);

struct font_kern_list;
struct font_char_metric;
struct font_widths_cache;

class font {
public:
  enum {
    LIG_ff = 1,
    LIG_fi = 2,
    LIG_fl = 4,
    LIG_ffi = 8,
    LIG_ffl = 16
    };

  virtual ~font();
  int contains(int index);
  int is_special();
  int get_width(int index, int point_size);
  int get_height(int index, int point_size);
  int get_depth(int index, int point_size);
  int get_space_width(int point_size);
  int get_character_type(int index);
  int get_kern(int index1, int index2, int point_size);
  int get_skew(int index, int point_size, int slant);
  int has_ligature(int);
  int get_italic_correction(int index, int point_size);
  int get_left_italic_correction(int index, int point_size);
  int get_subscript_correction(int index, int point_size);
  int get_code(int i);
  const char *get_special_device_encoding(int index);
  const char *get_name();
  const char *get_internal_name();

  static int scan_papersize(const char *, const char **, double *, double *);

  static font *load_font(const char *, int *not_found = 0);
  static void command_line_font_dir(const char *path);
  static FILE *open_file(const char *name, char **pathp);
  static int load_desc();
  static int name_to_index(const char *);
  static int number_to_index(int);
  static FONT_COMMAND_HANDLER
    set_unknown_desc_command_handler(FONT_COMMAND_HANDLER);

  static int res;
  static int hor;
  static int vert;
  static int unitwidth;
  static int paperwidth;
  static int paperlength;
  static const char *papersize;
  static int biggestfont;
  static int spare2;
  static int sizescale;
  static int tcommand;
  static int pass_filenames;
  static int use_charnames_in_special;

  static const char **font_name_table;
  static const char **style_table;
  static const char *family;
  static int *sizes;
private:
  unsigned ligatures;
  font_kern_list **kern_hash_table;
  int space_width;
  int *ch_index;
  int nindices;
  font_char_metric *ch;
  int ch_used;
  int ch_size;
  int special;
  char *name;
  char *internalname;
  double slant;
  font_widths_cache *widths_cache;
  static FONT_COMMAND_HANDLER unknown_desc_command_handler;

  enum { KERN_HASH_TABLE_SIZE = 503 };

  void add_entry(int index, const font_char_metric &);
  void copy_entry(int new_index, int old_index);
  void add_kern(int index1, int index2, int amount);
  static int hash_kern(int i1, int i2);
  void alloc_ch_index(int);
  void extend_ch();
  void compact();

  static int scale(int w, int pointsize);
  static int unit_scale(double *value, char unit);
  virtual void handle_unknown_font_command(const char *command,
					   const char *arg,
					   const char *file, int lineno);
protected:
  font(const char *);
  int load(int *not_found = 0);
};