2 /* Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.uucp)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 1, or (at your option) any later
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file LICENSE. If not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
30 const char *const FONT_ENV_VAR
= "GROFF_FONT_PATH";
35 int font::unitwidth
= 0;
36 int font::paperwidth
= 0;
37 int font::paperlength
= 0;
38 int font::biggestfont
= 0;
40 int font::sizescale
= 1;
41 int font::tcommand
= 0;
42 const char **font::font_name_table
= 0;
44 char *font::dev_name
= 0;
45 char *font::cl_font_dirs
= 0;
46 const char *font::family
= 0;
47 const char **font::style_table
= 0;
49 void font::command_line_font_dir(const char *dir
)
51 if (cl_font_dirs
== 0) {
52 cl_font_dirs
= new char[strlen(dir
)+1];
53 strcpy(cl_font_dirs
, dir
);
56 int len
= strlen(cl_font_dirs
);
58 if (len
> 0 && cl_font_dirs
[len
-1] != ':')
60 char *old_dirs
= cl_font_dirs
;
61 cl_font_dirs
= new char[len
+ need_colon
+ strlen(dir
) + 1];
62 strcpy(cl_font_dirs
, old_dirs
);
64 strcat(cl_font_dirs
, ":");
65 strcat(cl_font_dirs
, dir
);
70 void font::forget_command_line_font_dirs()
72 a_delete cl_font_dirs
;
76 FILE *font::open_file(const char *name
, char **pathp
)
78 assert(dev_name
!= 0);
79 const char *dir_vec
[3];
80 dir_vec
[0] = cl_font_dirs
;
81 dir_vec
[1] = getenv(FONT_ENV_VAR
);
82 dir_vec
[2] = FONTPATH
;
83 for (int i
= 0; i
< 3; i
++)
84 if (dir_vec
[i
] != 0) {
85 const char *dirs
= dir_vec
[i
];
86 while (*dirs
!= '\0') {
87 const char *p
= strchr(dirs
, ':');
90 p
= strchr(dirs
, '\0');
92 if (p
> dirs
&& p
[-1] != '/')
94 char *path
= new char[(p
- dirs
) + need_slash
+ 3
95 + strlen(dev_name
) + 1
97 memcpy(path
, dirs
, p
- dirs
);
98 path
[p
- dirs
] = '\0';
102 strcat(path
, dev_name
);
106 FILE *fp
= fopen(path
, "r");
121 void font::set_device_name(const char *s
)
123 dev_name
= new char[strlen(s
)+1];
127 const char *font::get_device_name()