3 // <groff_src_dir>/src/libs/libdriver/printer.cpp
5 /* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003
6 Free Software Foundation, Inc.
7 Written by James Clark (jjc@jclark.com)
9 Last update: 04 Apr 2003
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
31 font_pointer_list::font_pointer_list(font *f, font_pointer_list *fp)
37 : font_list(0), font_table(0), nfonts(0)
45 font_pointer_list *tem = font_list;
46 font_list = font_list->next;
50 if (ferror(stdout) || fflush(stdout) < 0)
51 fatal("output error");
54 void printer::load_font(int n, const char *nm)
62 font_table = new font *[nfonts];
63 for (int i = 0; i < nfonts; i++)
67 font **old_font_table = font_table;
68 int old_nfonts = nfonts;
72 font_table = new font *[nfonts];
74 for (i = 0; i < old_nfonts; i++)
75 font_table[i] = old_font_table[i];
76 for (i = old_nfonts; i < nfonts; i++)
78 a_delete old_font_table;
81 font *f = find_font(nm);
85 font *printer::find_font(const char *nm)
87 for (font_pointer_list *p = font_list; p; p = p->next)
88 if (strcmp(p->p->get_name(), nm) == 0)
90 font *f = make_font(nm);
92 fatal("sorry, I can't continue");
93 font_list = new font_pointer_list(f, font_list);
97 font *printer::make_font(const char *nm)
99 return font::load_font(nm);
102 void printer::end_of_line()
106 void printer::special(char *, const environment *, char)
110 void printer::draw(int, int *, int, const environment *)
114 void printer::change_color(const environment * const)
118 void printer::change_fill_color(const environment * const)
122 void printer::set_ascii_char(unsigned char c, const environment *env,
132 int i = set_char_and_width(buf, env, &w, &f);
133 set_char(i, f, env, w, 0);
139 void printer::set_special_char(const char *nm, const environment *env,
144 int i = set_char_and_width(nm, env, &w, &f);
146 set_char(i, f, env, w, nm);
152 int printer::set_char_and_width(const char *nm, const environment *env,
153 int *widthp, font **f)
155 int i = font::name_to_index(nm);
156 int fn = env->fontno;
157 if (fn < 0 || fn >= nfonts) {
158 error("bad font position `%1'", fn);
163 error("no font mounted at `%1'", fn);
166 if (!(*f)->contains(i)) {
167 if (nm[0] != '\0' && nm[1] == '\0')
168 error("font `%1' does not contain ascii character `%2'",
172 error("font `%1' does not contain special character `%2'",
177 int w = (*f)->get_width(i, env->size);
183 void printer::set_numbered_char(int num, const environment *env, int *widthp)
185 int i = font::number_to_index(num);
186 int fn = env->fontno;
187 if (fn < 0 || fn >= nfonts) {
188 error("bad font position `%1'", fn);
191 font *f = font_table[fn];
193 error("no font mounted at `%1'", fn);
196 if (!f->contains(i)) {
197 error("font `%1' does not contain numbered character %2",
202 int w = f->get_width(i, env->size);
205 set_char(i, f, env, w, 0);
208 font *printer::get_font_from_index(int fontno)
210 if ((fontno >= 0) && (fontno < nfonts))
211 return(font_table[fontno]);