3 // <groff_src_dir>/src/libs/libdriver/printer.cc
5 /* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002
6 Free Software Foundation, Inc.
7 Written by James Clark (jjc@jclark.com)
9 Last update: 12 Apr 2002
11 This file is part of groff.
13 groff is free software; you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
18 groff is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with groff; see the file COPYING. If not, write to the Free
25 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
33 font_pointer_list::font_pointer_list(font *f, font_pointer_list *fp)
39 : font_list(0), font_table(0), nfonts(0)
47 font_pointer_list *tem = font_list;
48 font_list = font_list->next;
52 if (ferror(stdout) || fflush(stdout) < 0)
53 fatal("output error");
56 void printer::load_font(int n, const char *nm)
64 font_table = new font *[nfonts];
65 for (int i = 0; i < nfonts; i++)
69 font **old_font_table = font_table;
70 int old_nfonts = nfonts;
74 font_table = new font *[nfonts];
76 for (i = 0; i < old_nfonts; i++)
77 font_table[i] = old_font_table[i];
78 for (i = old_nfonts; i < nfonts; i++)
80 a_delete old_font_table;
83 font *f = find_font(nm);
87 font *printer::find_font(const char *nm)
89 for (font_pointer_list *p = font_list; p; p = p->next)
90 if (strcmp(p->p->get_name(), nm) == 0)
92 font *f = make_font(nm);
94 fatal("sorry, I can't continue");
95 font_list = new font_pointer_list(f, font_list);
99 font *printer::make_font(const char *nm)
101 return font::load_font(nm);
104 void printer::end_of_line()
108 void printer::special(char *, const environment *, char)
112 void printer::draw(int, int *, int, const environment *)
116 void printer::change_color(const environment *)
120 void printer::change_fill_color(const environment *)
124 void printer::set_ascii_char(unsigned char c, const environment *env,
134 int i = set_char_and_width(buf, env, &w, &f);
135 set_char(i, f, env, w, 0);
141 void printer::set_special_char(const char *nm, const environment *env,
146 int i = set_char_and_width(nm, env, &w, &f);
148 set_char(i, f, env, w, nm);
154 int printer::set_char_and_width(const char *nm, const environment *env,
155 int *widthp, font **f)
157 int i = font::name_to_index(nm);
158 int fn = env->fontno;
159 if (fn < 0 || fn >= nfonts) {
160 error("bad font position `%1'", fn);
165 error("no font mounted at `%1'", fn);
168 if (!(*f)->contains(i)) {
169 if (nm[0] != '\0' && nm[1] == '\0')
170 error("font `%1' does not contain ascii character `%2'",
174 error("font `%1' does not contain special character `%2'",
179 int w = (*f)->get_width(i, env->size);
185 void printer::set_numbered_char(int num, const environment *env, int *widthp)
187 int i = font::number_to_index(num);
188 int fn = env->fontno;
189 if (fn < 0 || fn >= nfonts) {
190 error("bad font position `%1'", fn);
193 font *f = font_table[fn];
195 error("no font mounted at `%1'", fn);
198 if (!f->contains(i)) {
199 error("font `%1' does not contain numbered character %2",
204 int w = f->get_width(i, env->size);
207 set_char(i, f, env, w, 0);
210 font *printer::get_font_from_index(int fontno)
212 if ((fontno >= 0) && (fontno < nfonts))
213 return(font_table[fontno]);