summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog59
-rw-r--r--src/devices/grodvi/dvi.cpp10
-rw-r--r--src/devices/grohtml/post-html.cpp82
-rw-r--r--src/devices/grolbp/lbp.cpp8
-rw-r--r--src/devices/grolj4/lj4.cpp8
-rw-r--r--src/devices/grops/ps.cpp28
-rw-r--r--src/devices/grotty/tty.cpp8
-rw-r--r--src/include/font.h200
-rw-r--r--src/include/printer.h8
-rw-r--r--src/libs/libdriver/printer.cpp38
-rw-r--r--src/libs/libgroff/font.cpp132
-rw-r--r--src/libs/libgroff/nametoindex.cpp14
-rw-r--r--src/roff/troff/charinfo.h8
-rw-r--r--src/roff/troff/env.cpp3
-rw-r--r--src/roff/troff/input.cpp8
-rw-r--r--src/roff/troff/node.cpp4
16 files changed, 369 insertions, 249 deletions
diff --git a/ChangeLog b/ChangeLog
index 353bd1a4..348543f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,64 @@
2006-02-11 Bruno Haible <bruno@clisp.org>
+ Make the glyph data type abstract.
+ * src/include/font.h (glyph_t): New class.
+ (name_to_index, number_to_index): Change return type to glyph_t.
+ (font::contains, font::get_width, font::get_height, font::get_depth,
+ font::get_character_type, font::get_kern, font::get_skew,
+ font::get_italic_correction, font::get_left_italic_correction,
+ font::get_subscript_correction, font::get_code,
+ font::get_special_device_encoding, font::add_entry, font::copy_entry,
+ font::add_kern, font::hash_kern): Change argument type to glyph_t.
+ * src/libs/libgroff/font.cpp (struct font_kern_list): Change members
+ type and constructor argument types to glyph_t.
+ (font::contains, font::get_width, font::get_height, font::get_depth,
+ font::get_character_type, font::get_kern, font::get_skew,
+ font::get_italic_correction, font::get_left_italic_correction,
+ font::get_subscript_correction, font::get_code,
+ font::get_special_device_encoding, font::add_entry, font::copy_entry,
+ font::add_kern, font::hash_kern): Change argument type to glyph_t.
+ (font::load): Use glyph_t variables.
+ * src/libs/libgroff/nametoindex.cpp (name_to_index, number_to_index):
+ Change return type to glyph_t.
+ * src/roff/troff/charinfo.h (charinfo::index): Change type to glyph_t.
+ (charinfo::get_index): Change return type to glyph_t.
+ * src/roff/troff/env.cpp: Include font.h.
+ * src/roff/troff/node.cpp: Include font.h before charinfo.h.
+ * src/roff/troff/input.cpp: Include font.h before charinfo.h.
+ (charinfo::charinfo): Update.
+ (name_to_index, number_to_index): Change return type to glyph_t.
+ * src/include/printer.h (printer::set_char_and_width): Change return
+ type to glyph_t.
+ * src/libs/libdriver/printer.cpp (printer::set_char_and_width): Change
+ return type to glyph_t.
+ * src/devices/grodvi/dvi.cpp (dvi_printer::set_char): Change argument
+ type to glyph_t.
+ * src/devices/grohtml/post-html.cpp (page::add_and_encode): Update.
+ (html_printer::space_glyph): Renamed from space_char_index.
+ (html_printer::add_to_sbuf, html_printer::sbuf_continuation,
+ html_printer::overstrike, html_printer::set_char): Change argument type
+ to glyph_t.
+ (html_printer::set_char_and_width): Change return type to glyph_t.
+ * src/devices/grolbp/lbp.cpp (lbp_printer::set_char): Change argument
+ type to glyph_t.
+ * src/devices/grolj4/lj4.cpp (lj4_printer::set_char): Change argument
+ type to glyph_t.
+ * src/devices/grops/ps.cpp (ps_printer::space_glyph): Renamed from
+ space_char_index.
+ (ps_printer::set_subencoding, ps_printer::set_char): Change argument
+ type to glyph_t.
+ * src/devices/grotty/tty.cpp (tty_printer::set_char): Change argument
+ type to glyph_t.
+
+2006-02-11 Bruno Haible <bruno@clisp.org>
+
+ * src/roff/troff/input.cpp (font::name_to_index): Never return a
+ negative value.
+ * src/libs/libgroff/font.cpp (font::load): Remove failure tests for
+ font::name_to_index.
+
+2006-02-11 Bruno Haible <bruno@clisp.org>
+
* src/roff/troff/input.cpp (font::name_to_index): Never return a
negative value.
* src/libs/libgroff/font.cpp (font::load): Remove failure tests for
diff --git a/src/devices/grodvi/dvi.cpp b/src/devices/grodvi/dvi.cpp
index 201eb1c4..c7c0dee2 100644
--- a/src/devices/grodvi/dvi.cpp
+++ b/src/devices/grodvi/dvi.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -175,7 +175,7 @@ public:
font *make_font(const char *);
void begin_page(int);
void end_page(int);
- void set_char(int, font *, const environment *, int w, const char *name);
+ void set_char(glyph_t, font *, const environment *, int w, const char *name);
void special(char *arg, const environment *env, char type);
void end_of_line();
void draw(int code, int *p, int np, const environment *env);
@@ -340,12 +340,12 @@ void dvi_printer::set_color(color *col)
do_special(buf);
}
-void dvi_printer::set_char(int idx, font *f, const environment *env,
+void dvi_printer::set_char(glyph_t glyph, font *f, const environment *env,
int w, const char *)
{
if (*env->col != cur_color)
set_color(env->col);
- int code = f->get_code(idx);
+ int code = f->get_code(glyph);
if (env->size != cur_point_size || f != cur_font) {
cur_font = f;
cur_point_size = env->size;
@@ -384,7 +384,7 @@ void dvi_printer::set_char(int idx, font *f, const environment *env,
}
possibly_begin_line();
end_h = env->hpos + w;
- cur_h += scale(f->get_width(idx, UNITWIDTH)/MULTIPLIER,
+ cur_h += scale(f->get_width(glyph, UNITWIDTH)/MULTIPLIER,
cur_point_size*RES_7227);
if (cur_h > max_h)
max_h = cur_h;
diff --git a/src/devices/grohtml/post-html.cpp b/src/devices/grohtml/post-html.cpp
index 9210d3cf..5b065103 100644
--- a/src/devices/grohtml/post-html.cpp
+++ b/src/devices/grohtml/post-html.cpp
@@ -1417,10 +1417,9 @@ void page::add_and_encode (style *s, const string &str,
if (html_glyph)
html_string += html_glyph;
else {
- int idx=s->f->name_to_index((troff_charname + '\0').contents());
-
- if (s->f->contains(idx) && (idx != 0))
- html_string += s->f->get_code(idx);
+ glyph_t glyph = s->f->name_to_index((troff_charname + '\0').contents());
+ if (s->f->contains(glyph))
+ html_string += s->f->get_code(glyph);
}
}
} else
@@ -1939,7 +1938,7 @@ class html_printer : public printer {
files file_list;
simple_output html;
int res;
- int space_char_index;
+ glyph_t space_glyph;
int space_width;
int no_of_printed_pages;
int paper_length;
@@ -2010,9 +2009,9 @@ class html_printer : public printer {
void set_line_thickness (const environment *);
void terminate_current_font (void);
void flush_font (void);
- void add_to_sbuf (int index, const string &s);
+ void add_to_sbuf (glyph_t glyph, const string &s);
void write_title (int in_head);
- int sbuf_continuation (int index, const char *name, const environment *env, int w);
+ int sbuf_continuation (glyph_t glyph, const char *name, const environment *env, int w);
void flush_page (void);
void troff_tag (text_glob *g);
void flush_globs (void);
@@ -2063,7 +2062,7 @@ class html_printer : public printer {
void outstanding_eol (int n);
int is_bold (font *f);
font *make_bold (font *f);
- int overstrike (int index, const char *name, const environment *env, int w);
+ int overstrike (glyph_t glyph, const char *name, const environment *env, int w);
void do_body (void);
int next_horiz_pos (text_glob *g, int nf);
void lookahead_for_tables (void);
@@ -2101,9 +2100,9 @@ class html_printer : public printer {
public:
html_printer ();
~html_printer ();
- void set_char (int i, font *f, const environment *env, int w, const char *name);
+ void set_char (glyph_t glyph, font *f, const environment *env, int w, const char *name);
void set_numbered_char(int num, const environment *env, int *widthp);
- int set_char_and_width(const char *nm, const environment *env,
+ glyph_t set_char_and_width(const char *nm, const environment *env,
int *widthp, font **f);
void draw (int code, int *p, int np, const environment *env);
void begin_page (int);
@@ -4221,7 +4220,7 @@ html_printer::html_printer()
}
res = r;
html.set_fixed_point(point);
- space_char_index = font::name_to_index("space");
+ space_glyph = font::name_to_index("space");
space_width = font::hor;
paper_length = font::paperlength;
linelength = font::res*13/2;
@@ -4235,17 +4234,17 @@ html_printer::html_printer()
* add_to_sbuf - adds character code or name to the sbuf.
*/
-void html_printer::add_to_sbuf (int idx, const string &s)
+void html_printer::add_to_sbuf (glyph_t glyph, const string &s)
{
if (sbuf_style.f == NULL)
return;
const char *html_glyph = NULL;
- unsigned int code = sbuf_style.f->get_code(idx);
+ unsigned int code = sbuf_style.f->get_code(glyph);
if (s.empty()) {
- if (sbuf_style.f->contains(idx))
- html_glyph = get_html_entity(sbuf_style.f->get_code(idx));
+ if (sbuf_style.f->contains(glyph))
+ html_glyph = get_html_entity(sbuf_style.f->get_code(glyph));
else
html_glyph = NULL;
@@ -4261,7 +4260,7 @@ void html_printer::add_to_sbuf (int idx, const string &s)
sbuf += html_glyph;
}
-int html_printer::sbuf_continuation (int idx, const char *name,
+int html_printer::sbuf_continuation (glyph_t glyph, const char *name,
const environment *env, int w)
{
/*
@@ -4271,7 +4270,7 @@ int html_printer::sbuf_continuation (int idx, const char *name,
|| ((sbuf_prev_hpos < sbuf_end_hpos)
&& (env->hpos < sbuf_end_hpos)
&& ((sbuf_end_hpos-env->hpos < env->hpos-sbuf_prev_hpos)))) {
- add_to_sbuf(idx, name);
+ add_to_sbuf(glyph, name);
sbuf_prev_hpos = sbuf_end_hpos;
sbuf_end_hpos += w + sbuf_kern;
return TRUE;
@@ -4283,7 +4282,7 @@ int html_printer::sbuf_continuation (int idx, const char *name,
*/
if (env->hpos-sbuf_end_hpos < space_width) {
- add_to_sbuf(idx, name);
+ add_to_sbuf(glyph, name);
sbuf_prev_hpos = sbuf_end_hpos;
sbuf_end_hpos = env->hpos + w;
return TRUE;
@@ -4300,14 +4299,12 @@ int html_printer::sbuf_continuation (int idx, const char *name,
const char *get_html_translation (font *f, const string &name)
{
- int idx;
-
if ((f == 0) || name.empty())
return NULL;
else {
- idx = f->name_to_index((char *)(name + '\0').contents());
- if (f->contains(idx))
- return get_html_entity(f->get_code(idx));
+ glyph_t glyph = f->name_to_index((char *)(name + '\0').contents());
+ if (f->contains(glyph))
+ return get_html_entity(f->get_code(glyph));
else
return NULL;
}
@@ -4579,7 +4576,7 @@ static const char *get_html_entity (unsigned int code)
* is flushed.
*/
-int html_printer::overstrike(int idx, const char *name, const environment *env, int w)
+int html_printer::overstrike(glyph_t glyph, const char *name, const environment *env, int w)
{
if ((env->hpos < sbuf_end_hpos)
|| ((sbuf_kern != 0) && (sbuf_end_hpos - sbuf_kern < env->hpos))) {
@@ -4589,7 +4586,7 @@ int html_printer::overstrike(int idx, const char *name, const environment *env,
if (overstrike_detected) {
/* already detected, remove previous glyph and use this glyph */
sbuf.set_length(last_sbuf_length);
- add_to_sbuf(idx, name);
+ add_to_sbuf(glyph, name);
sbuf_end_hpos = env->hpos + w;
return TRUE;
} else {
@@ -4598,7 +4595,7 @@ int html_printer::overstrike(int idx, const char *name, const environment *env,
if (! is_bold(sbuf_style.f))
flush_sbuf();
overstrike_detected = TRUE;
- add_to_sbuf(idx, name);
+ add_to_sbuf(glyph, name);
sbuf_end_hpos = env->hpos + w;
return TRUE;
}
@@ -4612,7 +4609,7 @@ int html_printer::overstrike(int idx, const char *name, const environment *env,
* and add character anew.
*/
-void html_printer::set_char(int i, font *f, const environment *env,
+void html_printer::set_char(glyph_t glyph, font *f, const environment *env,
int w, const char *name)
{
style sty(f, env->size, env->height, env->slant, env->fontno, *env->col);
@@ -4623,13 +4620,14 @@ void html_printer::set_char(int i, font *f, const environment *env,
}
}
if (((! sbuf.empty()) && (sty == sbuf_style) && (sbuf_vpos == env->vpos))
- && (sbuf_continuation(i, name, env, w) || overstrike(i, name, env, w)))
+ && (sbuf_continuation(glyph, name, env, w)
+ || overstrike(glyph, name, env, w)))
return;
flush_sbuf();
if (sbuf_style.f == NULL)
sbuf_style = sty;
- add_to_sbuf(i, name);
+ add_to_sbuf(glyph, name);
sbuf_end_hpos = env->hpos + w;
sbuf_start_hpos = env->hpos;
sbuf_prev_hpos = env->hpos;
@@ -4652,7 +4650,7 @@ void html_printer::set_numbered_char(int num, const environment *env,
nbsp_width = -num;
num = 160; // &nbsp;
}
- int i = font::number_to_index(num);
+ glyph_t glyph = font::number_to_index(num);
int fn = env->fontno;
if (fn < 0 || fn >= nfonts) {
error("bad font position `%1'", fn);
@@ -4663,7 +4661,7 @@ void html_printer::set_numbered_char(int num, const environment *env,
error("no font mounted at `%1'", fn);
return;
}
- if (!f->contains(i)) {
+ if (!f->contains(glyph)) {
error("font `%1' does not contain numbered character %2",
f->get_name(),
num);
@@ -4673,28 +4671,28 @@ void html_printer::set_numbered_char(int num, const environment *env,
if (nbsp_width)
w = nbsp_width;
else
- w = f->get_width(i, env->size);
+ w = f->get_width(glyph, env->size);
w = round_width(w);
if (widthp)
*widthp = w;
- set_char(i, f, env, w, 0);
+ set_char(glyph, f, env, w, 0);
}
-int html_printer::set_char_and_width(const char *nm, const environment *env,
- int *widthp, font **f)
+glyph_t html_printer::set_char_and_width(const char *nm, const environment *env,
+ int *widthp, font **f)
{
- int i = font::name_to_index(nm);
+ glyph_t glyph = font::name_to_index(nm);
int fn = env->fontno;
if (fn < 0 || fn >= nfonts) {
error("bad font position `%1'", fn);
- return -1;
+ return UNDEFINED_GLYPH;
}
*f = font_table[fn];
if (*f == 0) {
error("no font mounted at `%1'", fn);
- return -1;
+ return UNDEFINED_GLYPH;
}
- if (!(*f)->contains(i)) {
+ if (!(*f)->contains(glyph)) {
if (nm[0] != '\0' && nm[1] == '\0')
error("font `%1' does not contain ascii character `%2'",
(*f)->get_name(),
@@ -4703,13 +4701,13 @@ int html_printer::set_char_and_width(const char *nm, const environment *env,
error("font `%1' does not contain special character `%2'",
(*f)->get_name(),
nm);
- return -1;
+ return UNDEFINED_GLYPH;
}
- int w = (*f)->get_width(i, env->size);
+ int w = (*f)->get_width(glyph, env->size);
w = round_width(w);
if (widthp)
*widthp = w;
- return i;
+ return glyph;
}
/*
diff --git a/src/devices/grolbp/lbp.cpp b/src/devices/grolbp/lbp.cpp
index 081ab998..f1e63011 100644
--- a/src/devices/grolbp/lbp.cpp
+++ b/src/devices/grolbp/lbp.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1994, 2000, 2001, 2002, 2003, 2004, 2005
+/* Copyright (C) 1994, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Written by Francisco Andrés Verdú <pandres@dragonet.es> with many ideas
taken from the other groff drivers.
@@ -63,7 +63,7 @@ class lbp_printer : public printer {
public:
lbp_printer(int, double, double);
~lbp_printer();
- void set_char(int, font *, const environment *, int, const char *name);
+ void set_char(glyph_t, font *, const environment *, int, const char *name);
void draw(int code, int *p, int np, const environment *env);
void begin_page(int);
void end_page(int page_length);
@@ -277,10 +277,10 @@ char *lbp_printer::font_name(const lbp_font *f, const int siz)
return bfont_name;
}
-void lbp_printer::set_char(int idx, font *f, const environment *env,
+void lbp_printer::set_char(glyph_t glyph, font *f, const environment *env,
int w, const char *)
{
- int code = f->get_code(idx);
+ int code = f->get_code(glyph);
unsigned char ch = code & 0xff;
unsigned short symbol_set = code >> 8;
if (f != cur_font) {
diff --git a/src/devices/grolj4/lj4.cpp b/src/devices/grolj4/lj4.cpp
index 12849542..0f0b69b0 100644
--- a/src/devices/grolj4/lj4.cpp
+++ b/src/devices/grolj4/lj4.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1994, 2000, 2001, 2002, 2003, 2004
+/* Copyright (C) 1994, 2000, 2001, 2002, 2003, 2004, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -163,7 +163,7 @@ class lj4_printer : public printer {
public:
lj4_printer(int);
~lj4_printer();
- void set_char(int, font *, const environment *, int, const char *name);
+ void set_char(glyph_t, font *, const environment *, int, const char *name);
void draw(int code, int *p, int np, const environment *env);
void begin_page(int);
void end_page(int page_length);
@@ -278,10 +278,10 @@ int is_unprintable(unsigned char c)
return c < 32 && (c == 0 || (7 <= c && c <= 15) || c == 27);
}
-void lj4_printer::set_char(int idx, font *f, const environment *env,
+void lj4_printer::set_char(glyph_t glyph, font *f, const environment *env,
int w, const char *)
{
- int code = f->get_code(idx);
+ int code = f->get_code(glyph);
unsigned char ch = code & 0xff;
unsigned short symbol_set = code >> 8;
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index 98feb4bd..39c31b38 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -523,7 +523,7 @@ class ps_printer : public printer {
FILE *tempfp;
ps_output out;
int res;
- int space_char_index;
+ glyph_t space_glyph;
int pages_output;
int paper_length;
int equalise_spaces;
@@ -562,7 +562,7 @@ class ps_printer : public printer {
void set_style(const style &);
void set_space_code(unsigned char c);
int set_encoding_index(ps_font *);
- subencoding *set_subencoding(font *, int, unsigned char *);
+ subencoding *set_subencoding(font *, glyph_t, unsigned char *);
char *get_subfont(subencoding *, const char *);
void do_exec(char *, const environment *);
void do_import(char *, const environment *);
@@ -587,7 +587,7 @@ class ps_printer : public printer {
public:
ps_printer(double);
~ps_printer();
- void set_char(int i, font *f, const environment *env, int w,
+ void set_char(glyph_t glyph, font *f, const environment *env, int w,
const char *name);
void draw(int code, int *p, int np, const environment *env);
void begin_page(int);
@@ -630,7 +630,7 @@ ps_printer::ps_printer(double pl)
}
res = r;
out.set_fixed_point(point);
- space_char_index = font::name_to_index("space");
+ space_glyph = font::name_to_index("space");
if (pl == 0)
paper_length = font::paperlength;
else
@@ -656,9 +656,9 @@ int ps_printer::set_encoding_index(ps_font *f)
return f->encoding_index = next_encoding_index++;
}
-subencoding *ps_printer::set_subencoding(font *f, int i, unsigned char *codep)
+subencoding *ps_printer::set_subencoding(font *f, glyph_t glyph, unsigned char *codep)
{
- unsigned int idx = f->get_code(i);
+ unsigned int idx = f->get_code(glyph);
*codep = idx % 256;
unsigned int num = idx >> 8;
if (num == 0)
@@ -670,7 +670,7 @@ subencoding *ps_printer::set_subencoding(font *f, int i, unsigned char *codep)
if (p == 0)
p = subencodings = new subencoding(f, num, next_subencoding_index++,
subencodings);
- p->glyphs[*codep] = f->get_special_device_encoding(i);
+ p->glyphs[*codep] = f->get_special_device_encoding(glyph);
return p;
}
@@ -685,13 +685,13 @@ char *ps_printer::get_subfont(subencoding *sub, const char *stem)
return sub->subfont;
}
-void ps_printer::set_char(int i, font *f, const environment *env, int w,
+void ps_printer::set_char(glyph_t glyph, font *f, const environment *env, int w,
const char *)
{
- if (i == space_char_index || invis_count > 0)
+ if (glyph == space_glyph || invis_count > 0)
return;
unsigned char code;
- subencoding *sub = set_subencoding(f, i, &code);
+ subencoding *sub = set_subencoding(f, glyph, &code);
style sty(f, sub, env->size, env->height, env->slant);
if (sty.slant != 0) {
if (sty.slant > 80 || sty.slant < -80) {
@@ -720,8 +720,8 @@ void ps_printer::set_char(int i, font *f, const environment *env, int w,
if (sbuf_len < SBUF_SIZE - 1 && env->hpos >= sbuf_end_hpos
&& (sbuf_kern == 0 || sbuf_end_hpos - sbuf_kern != env->hpos)) {
if (sbuf_space_code < 0) {
- if (f->contains(space_char_index)) {
- sbuf_space_code = f->get_code(space_char_index);
+ if (f->contains(space_glyph)) {
+ sbuf_space_code = f->get_code(space_glyph);
sbuf_space_width = env->hpos - sbuf_end_hpos;
sbuf_end_hpos = env->hpos + w + sbuf_kern;
sbuf[sbuf_len++] = sbuf_space_code;
@@ -998,7 +998,7 @@ void ps_printer::flush_sbuf()
}
}
if (sbuf_space_code >= 0) {
- int w = sbuf_style.f->get_width(space_char_index, sbuf_style.point_size);
+ int w = sbuf_style.f->get_width(space_glyph, sbuf_style.point_size);
if (w + sbuf_kern != sbuf_space_width) {
if (sbuf_space_code != output_space_code) {
set_space_code(sbuf_space_code);
diff --git a/src/devices/grotty/tty.cpp b/src/devices/grotty/tty.cpp
index a959461f..81bc7180 100644
--- a/src/devices/grotty/tty.cpp
+++ b/src/devices/grotty/tty.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989-2000, 2001, 2002, 2003, 2004, 2005
+/* Copyright (C) 1989-2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -215,7 +215,7 @@ class tty_printer : public printer {
public:
tty_printer(const char *device);
~tty_printer();
- void set_char(int, font *, const environment *, int, const char *name);
+ void set_char(glyph_t, font *, const environment *, int, const char *name);
void draw(int code, int *p, int np, const environment *env);
void special(char *arg, const environment *env, char type);
void change_color(const environment * const env);
@@ -360,12 +360,12 @@ schar tty_printer::color_to_idx(color *col)
return idx;
}
-void tty_printer::set_char(int i, font *f, const environment *env,
+void tty_printer::set_char(glyph_t gly, font *f, const environment *env,
int w, const char *)
{
if (w % font::hor != 0)
fatal("width of character not a multiple of horizontal resolution");
- add_char(f->get_code(i), w,
+ add_char(f->get_code(gly), w,
env->hpos, env->vpos,
env->col, env->fill,
((tty_font *)f)->get_mode());
diff --git a/src/include/font.h b/src/include/font.h
index 82a7d939..43b95c93 100644
--- a/src/include/font.h
+++ b/src/include/font.h
@@ -26,6 +26,54 @@ typedef void (*FONT_COMMAND_HANDLER)(const char *, // command
const char *, // file
int); // lineno
+// A glyph is represented by a font-independent glyph_t object.
+// The functions font::name_to_index and font::number_to_index return such
+// an object.
+struct glyph_t {
+private:
+ int index; // A font-independent integer value.
+ friend class font;
+ friend class charinfo;
+ glyph_t(int); // Glyph with given index.
+public:
+ glyph_t(); // Uninitialized glyph.
+ static glyph_t undefined_glyph(); // Undefined glyph.
+ int glyph_index();
+ int operator==(const glyph_t&) const;
+ int operator!=(const glyph_t&) const;
+};
+
+inline glyph_t::glyph_t(int idx)
+: index (idx)
+{
+}
+
+inline glyph_t::glyph_t()
+: index (0xdeadbeef)
+{
+}
+
+inline glyph_t glyph_t::undefined_glyph()
+{
+ return glyph_t(-1);
+}
+#define UNDEFINED_GLYPH glyph_t::undefined_glyph()
+
+inline int glyph_t::glyph_index()
+{
+ return index;
+}
+
+inline int glyph_t::operator==(const glyph_t &other) const
+{
+ return index == other.index;
+}
+
+inline int glyph_t::operator!=(const glyph_t &other) const
+{
+ return index != other.index;
+}
+
// Types used in non-public members of `class font'.
struct font_kern_list;
struct font_char_metric;
@@ -34,10 +82,6 @@ struct font_widths_cache;
// A `class font' instance represents the relevant information of a font of
// the given device. This includes the set of glyphs represented by the
// font, and metrics for each glyph.
-//
-// In the member functions a glyph is represented by a font-independent
-// integer value called an `index'; the functions font::name_to_index and
-// font::number_to_index return such an index.
class font {
public:
enum { // The valid argument values of `has_ligature'.
@@ -49,52 +93,51 @@ public:
};
virtual ~font(); // Destructor.
- int contains(int); // Return 1 if this font contains the glyph with the
- // given index, 0 otherwise.
+ int contains(glyph_t); // Return 1 if this font contains the given
+ // glyph, 0 otherwise.
int is_special(); // Return 1 if this font is special, 0 otherwise.
// See section `Special Fonts' in the info file of
// groff. Used by make_glyph_node().
- int get_width(int, int); // A rectangle represents the shape of the
- // glyph with the given index (arg1) at the given
- // point size (arg2). Return the horizontal
- // dimension of this rectangle.
- int get_height(int, int); // A rectangle represents the shape of the
- // glyph with the given index (arg1) at the given
- // point size (arg2). Return the distance between
- // the base line and the top of this rectangle.
+ int get_width(glyph_t, int); // A rectangle represents the shape of the
+ // given glyph (arg1) at the given point size
+ // (arg2). Return the horizontal dimension of this
+ // rectangle.
+ int get_height(glyph_t, int); // A rectangle represents the shape of the
+ // given glyph (arg1) at the given point size
+ // (arg2). Return the distance between the base
+ // line and the top of this rectangle.
// This is often also called the `ascent' of the
// glyph. If the top is above the base line, this
// value is positive.
- int get_depth(int, int); // A rectangle represents the shape of the
- // glyph with the given index (arg1) at the given
- // point size (arg2). Return the distance between
- // the base line and the bottom of this rectangle.
+ int get_depth(glyph_t, int); // A rectangle represents the shape of the
+ // given glyph (arg1) at the given point size
+ // (arg2). Return the distance between the base
+ // line and the bottom of this rectangle.
// This is often also called the `descent' of the
// glyph. If the bottom is below the base line,
// this value is positive.
int get_space_width(int); // Return the normal width of a space at the
// given point size.
- int get_character_type(int); // Return a bit mask describing the shape of
- // the glyph with the given index. Bit 0 is set if
- // the character has a descender. Bit 1 is set if
- // the character has a tall glyph. See groff
- // manual, description of \w and the `ct' register.
- int get_kern(int, int, int); // Return the kerning between the glyphs
- // with given indices (arg1 and the arg2), both at
- // the given point size (arg3).
- int get_skew(int, int, int); // A rectangle represents the shape of the
- // glyph with the given index (arg1) at the given
- // point size (arg2). For slanted fonts like
- // Times-Italic, the optical vertical axis is
- // naturally slanted. The natural slant value
- // (measured in degrees; positive values mean a
- // slant to the right) is specified in the font's
- // description file (see member variable SLANT
- // below). In addition to this, any font can be
- // artificially slanted. This artificial slant
- // value (arg3, measured in degrees; positive values
- // mean a slant to the right) is specified with the
- // \S escape.
+ int get_character_type(glyph_t); // Return a bit mask describing the
+ // shape of the given glyph. Bit 0 is set if the
+ // haracter has a descender. Bit 1 is set if the
+ // character has a tall glyph. See groff manual,
+ // description of \w and the `ct' register.
+ int get_kern(glyph_t, glyph_t, int); // Return the kerning between the
+ // given glyphs (arg1 and arg2), both at the given
+ // point size (arg3).
+ int get_skew(glyph_t, int, int); // A rectangle represents the shape
+ // of the given glyph (arg1) at the given point size
+ // (arg2). For slanted fonts like Times-Italic, the
+ // optical vertical axis is naturally slanted. The
+ // natural slant value (measured in degrees;
+ // positive values mean aslant to the right) is
+ // specified in the font's description file (see
+ // member variable SLANT below). In addition to
+ // this, any font can be artificially slanted. This
+ // artificial slant value (arg3, measured in
+ // degrees; positive values mean a slant to the
+ // right) is specified with the \S escape.
//
// Return the skew value which is the horizontal
// distance between the upper left corner of the
@@ -106,31 +149,29 @@ public:
int has_ligature(int); // Return a non-zero value if this font has
// the given ligature type (one of LIG_ff, LIG_fi,
// etc.), 0 otherwise.
- int get_italic_correction(int, int); // If the glyph with the given index
- // (arg1) at the given point size (arg2) is followed
- // by an unslanted glyph, some horizontal white
+ int get_italic_correction(glyph_t, int); // If the given glyph (arg1)
+ // at the given point size (arg2) is followed by an
+ // unslanted glyph, some horizontal white space may
+ // need to be inserted in between. See the groff
+ // manual, description of \/. Return the amount
+ // (width) of this white space.
+ int get_left_italic_correction(glyph_t, int); // If the given glyph (arg1)
+ // at the given point size (arg2) is preceded by an
+ // unslanted roman glyph, some horizontal white
// space may need to be inserted in between. See
- // the groff manual, description of \/. Return the
+ // the groff manual, description of \,. Return the
// amount (width) of this white space.
- int get_left_italic_correction(int, int); // If the glyph with the
- // given index (arg1) at the given point size (arg2)
- // is preceded by an unslanted roman glyph, some
- // horizontal white space may need to be inserted in
- // between. See the groff manual, description of
- // \,. Return the amount (width) of this white
- // space.
- int get_subscript_correction(int, int); // If the glyph with the
- // given index (arg1) at the given point size (arg2)
- // is followed by a subscript glyph, the horizontal
- // position may need to be advanced by some
- // (possibly negative) amount. See groff manual,
- // description of \w and the `ssc' register. Return
- // this amount.
- int get_code(int); // Return the code point in the physical font of the
- // glyph with the given index.
- const char *get_special_device_encoding(int); // Return special device
- // dependent information about the glyph with the
- // given index. Return NULL if there is no special
+ int get_subscript_correction(glyph_t, int); // If the given glyph (arg1)
+ // at the given point size (arg2)is followed by a
+ // subscript glyph, the horizontal position may need
+ // to be advanced by some (possibly negative)
+ // amount. See groff manual, description of \w and
+ // the `ssc' register. Return this amount.
+ int get_code(glyph_t); // Return the code point in the physical
+ // font of the given glyph.
+ const char *get_special_device_encoding(glyph_t); // Return special
+ // device dependent information about the given
+ // glyph. Return NULL if there is no special
// information.
const char *get_name(); // Return the name of this font.
const char *get_internal_name(); // Return the `internalname'
@@ -168,16 +209,21 @@ public:
static int load_desc(); // Open the DESC file (depending on the
// device) and initialize some static variables with
// info from there.
- static int name_to_index(const char *); // Convert the glyph with
- // the given name (arg1) to a glyph index. This has
+
+ // The next two functions exist in two versions: one in roff/troff/input.cpp
+ // for troff, and one for libs/libgroff/nametoindex.cpp for the preprocessors
+ // and the postprocessors.
+ static glyph_t name_to_index(const char *); // Convert the glyph with
+ // the given name (arg1) to a glyph_t. This has
// the same semantics as the groff escape sequence
- // \C'name'. If such an index does not yet exist, a
+ // \C'name'. If such a glyph_t does not yet exist, a
// new one is allocated.
- static int number_to_index(int); // Convert the font-dependent glyph
- // with the given number (in the font) to a glyph
- // index. This has the same semantics as the groff
- // escape sequence \N'number'. If such an index
- // does not yet exist, a new one is allocated.
+ static glyph_t number_to_index(int); // Convert the font-dependent glyph
+ // with the given number (in the font) to a glyph_t.
+ // This has the same semantics as the groff escape
+ // sequence \N'number'. If such a glyph_t does not
+ // yet exist, a new one is allocated.
+
static FONT_COMMAND_HANDLER
set_unknown_desc_command_handler(FONT_COMMAND_HANDLER); // Register
// a function which defines the semantics of
@@ -249,19 +295,19 @@ private:
// pairs.
// These methods add new characters to the ch_index[] and ch[] arrays.
- void add_entry(int, // index
+ void add_entry(glyph_t, // glyph
const font_char_metric &); // metric
- void copy_entry(int, // new_index
- int); // old_index
+ void copy_entry(glyph_t, // new_glyph
+ glyph_t); // old_glyph
void alloc_ch_index(int); // index
void extend_ch();
void compact();
- void add_kern(int, int, int); // Add to the kerning table a kerning amount
- // (arg3) between two glyphs with given indices
+ void add_kern(glyph_t, glyph_t, int); // Add to the kerning table a
+ // kerning amount (arg3) between two given glyphs
// (arg1 and arg2).
- static int hash_kern(int, int); // Return a hash code for the pair
- // of glyph indices (arg1 and arg2).
+ static int hash_kern(glyph_t, glyph_t); // Return a hash code for
+ // the pair of glyphs (arg1 and arg2).
/* Returns w * pointsize / unitwidth, rounded to the nearest integer. */
static int scale(int w, int pointsize);
diff --git a/src/include/printer.h b/src/include/printer.h
index fb39f489..49df7bfe 100644
--- a/src/include/printer.h
+++ b/src/include/printer.h
@@ -2,7 +2,7 @@
// <groff_src_dir>/src/include/printer.h
-/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004
+/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -69,8 +69,8 @@ public:
int *widthp = 0);
virtual void set_numbered_char(int n, const environment *env,
int *widthp = 0);
- int set_char_and_width(const char *nm, const environment *env,
- int *widthp, font **f);
+ glyph_t set_char_and_width(const char *nm, const environment *env,
+ int *widthp, font **f);
font *get_font_from_index(int fontno);
virtual void draw(int code, int *p, int np, const environment *env);
// perform change of line color (text, outline) in the print-out
@@ -100,7 +100,7 @@ protected:
private:
font *find_font(const char *);
- virtual void set_char(int index, font *f, const environment *env,
+ virtual void set_char(glyph_t glyph, font *f, const environment *env,
int w, const char *name) = 0;
};
diff --git a/src/libs/libdriver/printer.cpp b/src/libs/libdriver/printer.cpp
index fd77d6b5..03d098d4 100644
--- a/src/libs/libdriver/printer.cpp
+++ b/src/libs/libdriver/printer.cpp
@@ -2,7 +2,7 @@
// <groff_src_dir>/src/libs/libdriver/printer.cpp
-/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004, 2005
+/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -182,8 +182,8 @@ void printer::set_ascii_char(unsigned char c, const environment *env,
buf[0] = c;
buf[1] = '\0';
- int i = set_char_and_width(buf, env, &w, &f);
- set_char(i, f, env, w, 0);
+ glyph_t glyph = set_char_and_width(buf, env, &w, &f);
+ set_char(glyph, f, env, w, 0);
if (widthp) {
*widthp = w;
}
@@ -194,29 +194,29 @@ void printer::set_special_char(const char *nm, const environment *env,
{
font *f;
int w;
- int i = set_char_and_width(nm, env, &w, &f);
- if (i != -1) {
- set_char(i, f, env, w, nm);
+ glyph_t glyph = set_char_and_width(nm, env, &w, &f);
+ if (glyph != UNDEFINED_GLYPH) {
+ set_char(glyph, f, env, w, nm);
if (widthp)
*widthp = w;
}
}
-int printer::set_char_and_width(const char *nm, const environment *env,
- int *widthp, font **f)
+glyph_t printer::set_char_and_width(const char *nm, const environment *env,
+ int *widthp, font **f)
{
- int i = font::name_to_index(nm);
+ glyph_t glyph = font::name_to_index(nm);
int fn = env->fontno;
if (fn < 0 || fn >= nfonts) {
error("bad font position `%1'", fn);
- return(-1);
+ return UNDEFINED_GLYPH;
}
*f = font_table[fn];
if (*f == 0) {
error("no font mounted at `%1'", fn);
- return(-1);
+ return UNDEFINED_GLYPH;
}
- if (!(*f)->contains(i)) {
+ if (!(*f)->contains(glyph)) {
if (nm[0] != '\0' && nm[1] == '\0')
error("font `%1' does not contain ascii character `%2'",
(*f)->get_name(),
@@ -225,17 +225,17 @@ int printer::set_char_and_width(const char *nm, const environment *env,
error("font `%1' does not contain special character `%2'",
(*f)->get_name(),
nm);
- return(-1);
+ return UNDEFINED_GLYPH;
}
- int w = (*f)->get_width(i, env->size);
+ int w = (*f)->get_width(glyph, env->size);
if (widthp)
*widthp = w;
- return( i );
+ return glyph;
}
void printer::set_numbered_char(int num, const environment *env, int *widthp)
{
- int i = font::number_to_index(num);
+ glyph_t glyph = font::number_to_index(num);
int fn = env->fontno;
if (fn < 0 || fn >= nfonts) {
error("bad font position `%1'", fn);
@@ -246,16 +246,16 @@ void printer::set_numbered_char(int num, const environment *env, int *widthp)
error("no font mounted at `%1'", fn);
return;
}
- if (!f->contains(i)) {
+ if (!f->contains(glyph)) {
error("font `%1' does not contain numbered character %2",
f->get_name(),
num);
return;
}
- int w = f->get_width(i, env->size);
+ int w = f->get_width(glyph, env->size);
if (widthp)
*widthp = w;
- set_char(i, f, env, w, 0);
+ set_char(glyph, f, env, w, 0);
}
font *printer::get_font_from_index(int fontno)
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index a0358ed0..230fb643 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -47,12 +47,12 @@ struct font_char_metric {
};
struct font_kern_list {
- int i1;
- int i2;
+ glyph_t glyph1;
+ glyph_t glyph2;
int amount;
font_kern_list *next;
- font_kern_list(int, int, int, font_kern_list * = 0);
+ font_kern_list(glyph_t, glyph_t, int, font_kern_list * = 0);
};
struct font_widths_cache {
@@ -239,15 +239,17 @@ int font::unit_scale(double *value, char unit)
return 0;
}
-int font::get_skew(int c, int point_size, int sl)
+int font::get_skew(glyph_t c, int point_size, int sl)
{
int h = get_height(c, point_size);
return int(h*tan((slant+sl)*PI/180.0) + .5);
}
-int font::contains(int c)
+int font::contains(glyph_t c)
{
- return c >= 0 && c < nindices && ch_index[c] >= 0;
+ int idx = c.glyph_index();
+ assert(idx >= 0);
+ return idx < nindices && ch_index[idx] >= 0;
}
int font::is_special()
@@ -269,10 +271,11 @@ font_widths_cache::~font_widths_cache()
a_delete width;
}
-int font::get_width(int c, int point_size)
+int font::get_width(glyph_t c, int point_size)
{
- assert(c >= 0 && c < nindices);
- int i = ch_index[c];
+ int idx = c.glyph_index();
+ assert(idx >= 0 && idx < nindices);
+ int i = ch_index[idx];
assert(i >= 0);
if (point_size == unitwidth || font::unscaled_charwidths)
@@ -300,34 +303,39 @@ int font::get_width(int c, int point_size)
return w;
}
-int font::get_height(int c, int point_size)
+int font::get_height(glyph_t c, int point_size)
{
- assert(c >= 0 && c < nindices && ch_index[c] >= 0);
- return scale(ch[ch_index[c]].height, point_size);
+ int idx = c.glyph_index();
+ assert(idx >= 0 && idx < nindices && ch_index[idx] >= 0);
+ return scale(ch[ch_index[idx]].height, point_size);
}
-int font::get_depth(int c, int point_size)
+int font::get_depth(glyph_t c, int point_size)
{
- assert(c >= 0 && c < nindices && ch_index[c] >= 0);
- return scale(ch[ch_index[c]].depth, point_size);
+ int idx = c.glyph_index();
+ assert(idx >= 0 && idx < nindices && ch_index[idx] >= 0);
+ return scale(ch[ch_index[idx]].depth, point_size);
}
-int font::get_italic_correction(int c, int point_size)
+int font::get_italic_correction(glyph_t c, int point_size)
{
- assert(c >= 0 && c < nindices && ch_index[c] >= 0);
- return scale(ch[ch_index[c]].italic_correction, point_size);
+ int idx = c.glyph_index();
+ assert(idx >= 0 && idx < nindices && ch_index[idx] >= 0);
+ return scale(ch[ch_index[idx]].italic_correction, point_size);
}
-int font::get_left_italic_correction(int c, int point_size)
+int font::get_left_italic_correction(glyph_t c, int point_size)
{
- assert(c >= 0 && c < nindices && ch_index[c] >= 0);
- return scale(ch[ch_index[c]].pre_math_space, point_size);
+ int idx = c.glyph_index();
+ assert(idx >= 0 && idx < nindices && ch_index[idx] >= 0);
+ return scale(ch[ch_index[idx]].pre_math_space, point_size);
}
-int font::get_subscript_correction(int c, int point_size)
+int font::get_subscript_correction(glyph_t c, int point_size)
{
- assert(c >= 0 && c < nindices && ch_index[c] >= 0);
- return scale(ch[ch_index[c]].subscript_correction, point_size);
+ int idx = c.glyph_index();
+ assert(idx >= 0 && idx < nindices && ch_index[idx] >= 0);
+ return scale(ch[ch_index[idx]].subscript_correction, point_size);
}
int font::get_space_width(int point_size)
@@ -335,33 +343,33 @@ int font::get_space_width(int point_size)
return scale(space_width, point_size);
}
-font_kern_list::font_kern_list(int c1, int c2, int n, font_kern_list *p)
-: i1(c1), i2(c2), amount(n), next(p)
+font_kern_list::font_kern_list(glyph_t c1, glyph_t c2, int n, font_kern_list *p)
+: glyph1(c1), glyph2(c2), amount(n), next(p)
{
}
-inline int font::hash_kern(int i1, int i2)
+inline int font::hash_kern(glyph_t glyph1, glyph_t glyph2)
{
- int n = ((i1 << 10) + i2) % KERN_HASH_TABLE_SIZE;
+ int n = ((glyph1.glyph_index() << 10) + glyph2.glyph_index()) % KERN_HASH_TABLE_SIZE;
return n < 0 ? -n : n;
}
-void font::add_kern(int i1, int i2, int amount)
+void font::add_kern(glyph_t glyph1, glyph_t glyph2, int amount)
{
if (!kern_hash_table) {
kern_hash_table = new font_kern_list *[int(KERN_HASH_TABLE_SIZE)];
for (int i = 0; i < KERN_HASH_TABLE_SIZE; i++)
kern_hash_table[i] = 0;
}
- font_kern_list **p = kern_hash_table + hash_kern(i1, i2);
- *p = new font_kern_list(i1, i2, amount, *p);
+ font_kern_list **p = kern_hash_table + hash_kern(glyph1, glyph2);
+ *p = new font_kern_list(glyph1, glyph2, amount, *p);
}
-int font::get_kern(int i1, int i2, int point_size)
+int font::get_kern(glyph_t glyph1, glyph_t glyph2, int point_size)
{
if (kern_hash_table) {
- for (font_kern_list *p = kern_hash_table[hash_kern(i1, i2)]; p; p = p->next)
- if (i1 == p->i1 && i2 == p->i2)
+ for (font_kern_list *p = kern_hash_table[hash_kern(glyph1, glyph2)]; p; p = p->next)
+ if (glyph1 == p->glyph1 && glyph2 == p->glyph2)
return scale(p->amount, point_size);
}
return 0;
@@ -372,16 +380,18 @@ int font::has_ligature(int mask)
return mask & ligatures;
}
-int font::get_character_type(int c)
+int font::get_character_type(glyph_t c)
{
- assert(c >= 0 && c < nindices && ch_index[c] >= 0);
- return ch[ch_index[c]].type;
+ int idx = c.glyph_index();
+ assert(idx >= 0 && idx < nindices && ch_index[idx] >= 0);
+ return ch[ch_index[idx]].type;
}
-int font::get_code(int c)
+int font::get_code(glyph_t c)
{
- assert(c >= 0 && c < nindices && ch_index[c] >= 0);
- return ch[ch_index[c]].code;
+ int idx = c.glyph_index();
+ assert(idx >= 0 && idx < nindices && ch_index[idx] >= 0);
+ return ch[ch_index[idx]].code;
}
const char *font::get_name()
@@ -394,10 +404,11 @@ const char *font::get_internal_name()
return internalname;
}
-const char *font::get_special_device_encoding(int c)
+const char *font::get_special_device_encoding(glyph_t c)
{
- assert(c >= 0 && c < nindices && ch_index[c] >= 0);
- return ch[ch_index[c]].special_device_coding;
+ int idx = c.glyph_index();
+ assert(idx >= 0 && idx < nindices && ch_index[idx] >= 0);
+ return ch[ch_index[idx]].special_device_coding;
}
const char *font::get_image_generator()
@@ -466,8 +477,9 @@ void font::compact()
}
}
-void font::add_entry(int idx, const font_char_metric &metric)
+void font::add_entry(glyph_t glyph, const font_char_metric &metric)
{
+ int idx = glyph.glyph_index();
assert(idx >= 0);
if (idx >= nindices)
alloc_ch_index(idx);
@@ -479,8 +491,10 @@ void font::add_entry(int idx, const font_char_metric &metric)
ch[ch_used++] = metric;
}
-void font::copy_entry(int new_index, int old_index)
+void font::copy_entry(glyph_t new_glyph, glyph_t old_glyph)
{
+ int new_index = new_glyph.glyph_index();
+ int old_index = old_glyph.glyph_index();
assert(new_index >= 0 && old_index >= 0 && old_index < nindices);
if (new_index >= nindices)
alloc_ch_index(new_index);
@@ -677,14 +691,15 @@ int font::load(int *not_found, int head_only)
t.error("bad kern amount `%1'", p);
return 0;
}
- int i1 = name_to_index(c1);
- int i2 = name_to_index(c2);
- add_kern(i1, i2, n);
+ glyph_t glyph1 = name_to_index(c1);
+ glyph_t glyph2 = name_to_index(c2);
+ add_kern(glyph1, glyph2, n);
}
}
else if (strcmp(command, "charset") == 0) {
had_charset = 1;
- int last_index = -1;
+ glyph_t last_glyph;
+ int got_last_glyph = 0;
for (;;) {
if (!t.next()) {
command = 0;
@@ -699,7 +714,7 @@ int font::load(int *not_found, int head_only)
break;
}
if (p[0] == '"') {
- if (last_index == -1) {
+ if (!got_last_glyph) {
t.error("first charset entry is duplicate");
return 0;
}
@@ -707,8 +722,8 @@ int font::load(int *not_found, int head_only)
t.error("unnamed character cannot be duplicate");
return 0;
}
- int idx = name_to_index(nm);
- copy_entry(idx, last_index);
+ glyph_t glyph = name_to_index(nm);
+ copy_entry(glyph, last_glyph);
}
else {
font_char_metric metric;
@@ -762,17 +777,18 @@ int font::load(int *not_found, int head_only)
metric.special_device_coding = nam;
}
if (strcmp(nm, "---") == 0) {
- last_index = number_to_index(metric.code);
- add_entry(last_index, metric);
+ last_glyph = number_to_index(metric.code);
+ add_entry(last_glyph, metric);
}
else {
- last_index = name_to_index(nm);
- add_entry(last_index, metric);
- copy_entry(number_to_index(metric.code), last_index);
+ last_glyph = name_to_index(nm);
+ add_entry(last_glyph, metric);
+ copy_entry(number_to_index(metric.code), last_glyph);
}
+ got_last_glyph = 1;
}
}
- if (last_index == -1) {
+ if (!got_last_glyph) {
t.error("I didn't seem to find any characters");
return 0;
}
diff --git a/src/libs/libgroff/nametoindex.cpp b/src/libs/libgroff/nametoindex.cpp
index e4dacff2..feca1587 100644
--- a/src/libs/libgroff/nametoindex.cpp
+++ b/src/libs/libgroff/nametoindex.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -95,23 +95,23 @@ int character_indexer::named_char_index(const char *s)
static character_indexer indexer;
-int font::number_to_index(int n)
+glyph_t font::number_to_index(int n)
{
- return indexer.numbered_char_index(n);
+ return glyph_t(indexer.numbered_char_index(n));
}
-int font::name_to_index(const char *s)
+glyph_t font::name_to_index(const char *s)
{
assert(s != 0 && s[0] != '\0' && s[0] != ' ');
if (s[1] == '\0')
- return indexer.ascii_char_index(s[0]);
+ return glyph_t(indexer.ascii_char_index(s[0]));
/* char128 and \200 are synonyms */
if (s[0] == 'c' && s[1] == 'h' && s[2] == 'a' && s[3] == 'r') {
char *val;
long n = strtol(s + 4, &val, 10);
if (val != s + 4 && *val == '\0' && n >= 0 && n < 256)
- return indexer.ascii_char_index((unsigned char)n);
+ return glyph_t(indexer.ascii_char_index((unsigned char)n));
}
- return indexer.named_char_index(s);
+ return glyph_t(indexer.named_char_index(s));
}
diff --git a/src/roff/troff/charinfo.h b/src/roff/troff/charinfo.h
index 42190fd8..2941201e 100644
--- a/src/roff/troff/charinfo.h
+++ b/src/roff/troff/charinfo.h
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002
+/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -24,7 +24,7 @@ class macro;
class charinfo {
static int next_index;
charinfo *translation;
- int index;
+ glyph_t index;
int number;
macro *mac;
unsigned char special_translation;
@@ -57,7 +57,7 @@ public:
};
symbol nm;
charinfo(symbol s);
- int get_index();
+ glyph_t get_index();
int ends_sentence();
int overlaps_vertically();
int overlaps_horizontally();
@@ -171,7 +171,7 @@ inline void charinfo::set_flags(unsigned char c)
flags = c;
}
-inline int charinfo::get_index()
+inline glyph_t charinfo::get_index()
{
return index;
}
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 9de9a46a..473ffabf 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -30,6 +30,7 @@ Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
#include "token.h"
#include "div.h"
#include "reg.h"
+#include "font.h"
#include "charinfo.h"
#include "macropath.h"
#include "input.h"
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 84f42b3a..dd733397 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -33,11 +33,11 @@ Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
#include "token.h"
#include "div.h"
#include "reg.h"
+#include "font.h"
#include "charinfo.h"
#include "macropath.h"
#include "input.h"
#include "defs.h"
-#include "font.h"
#include "unicode.h"
// Needed for getpid() and isatty()
@@ -8094,7 +8094,7 @@ charinfo::charinfo(symbol s)
not_found(0), transparent_translate(1), translate_input(0),
mode(CHAR_NORMAL), nm(s)
{
- index = next_index++;
+ index = glyph_t(next_index++);
}
void charinfo::set_hyphenation_code(unsigned char c)
@@ -8194,7 +8194,7 @@ charinfo *get_charinfo_by_number(int n)
}
}
-int font::name_to_index(const char *nm)
+glyph_t font::name_to_index(const char *nm)
{
charinfo *ci;
if (nm[1] == 0)
@@ -8209,7 +8209,7 @@ int font::name_to_index(const char *nm)
return ci->get_index();
}
-int font::number_to_index(int n)
+glyph_t font::number_to_index(int n)
{
return get_charinfo_by_number(n)->get_index();
}
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 0d874d35..083c356e 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -37,8 +37,8 @@ extern int debug_state;
#include "token.h"
#include "div.h"
#include "reg.h"
-#include "charinfo.h"
#include "font.h"
+#include "charinfo.h"
#include "input.h"
#include "geometry.h"