summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwlemb <wlemb>2001-12-20 21:16:32 +0000
committerwlemb <wlemb>2001-12-20 21:16:32 +0000
commitb25c4dc312ee0234534d37a394dd7dfb13e2d7be (patch)
tree6f71d57af315c44419a4ac421f4169227c2b88ba
parentea9d446a4090d15702fbfdc618c29618ce68e60c (diff)
downloadgroff-b25c4dc312ee0234534d37a394dd7dfb13e2d7be.tar.gz
Implement a fallback character request `.fchar'.
* src/roff/troff/charinfo.h (charinfo): New flag `fallback'. (is_fallback): New inline function. * src/roff/troff/input.cc (do_define_character): New function. (define_character): Call `do_define_character'. (define_fallback_character): New function. (init_input_requests): Add `fchar'. (charinfo::charinfo): Updated. (charinfo::set_macro): New argument to set `fallback' flag. * src/roff/troff/node.cc (make_glyph_node, make_node, node::add_char): Check `fallback' flag. * NEWS, man/groff_diff.man, man/groff_man: Updated.
-rw-r--r--ChangeLog16
-rw-r--r--NEWS9
-rw-r--r--man/groff.man9
-rw-r--r--man/groff_diff.man16
-rw-r--r--src/roff/troff/charinfo.h11
-rw-r--r--src/roff/troff/input.cc20
-rw-r--r--src/roff/troff/node.cc6
7 files changed, 77 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index beb72f2c..65481a38 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2001-12-19 Werner LEMBERG <wl@gnu.org>
+
+ Implement a fallback character request `.fchar'.
+
+ * src/roff/troff/charinfo.h (charinfo): New flag `fallback'.
+ (is_fallback): New inline function.
+ * src/roff/troff/input.cc (do_define_character): New function.
+ (define_character): Call `do_define_character'.
+ (define_fallback_character): New function.
+ (init_input_requests): Add `fchar'.
+ (charinfo::charinfo): Updated.
+ (charinfo::set_macro): New argument to set `fallback' flag.
+ * src/roff/troff/node.cc (make_glyph_node, make_node,
+ node::add_char): Check `fallback' flag.
+ * NEWS, man/groff_diff.man, man/groff_man: Updated.
+
2001-12-16 Werner LEMBERG <wl@gnu.org>
* groff.texinfo: Document exact search algorithm for glyphs.
diff --git a/NEWS b/NEWS
index 4313ef73..ae01a9c6 100644
--- a/NEWS
+++ b/NEWS
@@ -40,7 +40,14 @@ o It is now possible to have whitespace between the first and second dot (or
..
o `.fn' is a new string-valued register which returns the (internal) real
- font name; style and families are properly concatenated.
+ font name; styles and families are properly concatenated.
+
+o The new request `fchar' can be used to provide fallback characters. Its
+ syntax is the same as the `char' request; the only difference is that a
+ character defined with `.char' hides the glyph with the same name in the
+ current font, whereas a character defined with `.fchar' is checked only if
+ the particular glyph isn't found in the current font. This test happens
+ before checking special fonts.
o A new escape sequence `\O' is available (mainly for internal use with
grohtml). Please see groff_diff.man and groff.texinfo for more details.
diff --git a/man/groff.man b/man/groff.man
index a64e9f0e..b845985a 100644
--- a/man/groff.man
+++ b/man/groff.man
@@ -987,7 +987,7 @@ to
.REQ .char c anything
Define character
.argument c
-to string
+as string
.argument anything .
.
.REQ .chop object
@@ -1171,12 +1171,19 @@ Disable field mechanism.
Set field delimiter to
.argument a
and pad character to space.
+.
.REQ .fc a b
Set field delimiter to
.argument a
and pad character to
.argument b .
.
+.REQ .fchar c anything
+Define fallback character
+.argument c
+as string
+.argument anything .
+.
.REQ .fi
Fill output lines.
.
diff --git a/man/groff_diff.man b/man/groff_diff.man
index fe3ae95b..644639e1 100644
--- a/man/groff_diff.man
+++ b/man/groff_diff.man
@@ -1088,6 +1088,22 @@ See the description of the
request for more information on font families.
.
.TP
+.BI .fchar\ c\ string
+Define fallback character
+.I c
+to be
+.IR string .
+The syntax of this request is the same as the
+.B char
+request; the only difference is that a character defined with
+.B char
+hides the glyph with the same name in the current font, whereas a character
+defined with
+.B fchar
+is checked only if the particular glyph isn't found in the current font.
+This test happens before checking special fonts.
+.
+.TP
.BI .fspecial\ f\ s1\ s2\|.\|.\|.
When the current font is
.IR f ,
diff --git a/src/roff/troff/charinfo.h b/src/roff/troff/charinfo.h
index a4ecd574..048d6266 100644
--- a/src/roff/troff/charinfo.h
+++ b/src/roff/troff/charinfo.h
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2001 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -33,6 +33,7 @@ class charinfo {
char not_found;
char transparent_translate; // non-zero means translation applies to
// to transparent throughput
+ char fallback;
public:
enum {
ENDS_SENTENCE = 1,
@@ -68,12 +69,13 @@ public:
void set_flags(unsigned char);
void set_special_translation(int, int);
int get_special_translation(int = 0);
- macro *set_macro(macro *);
+ macro *set_macro(macro *, int = 0);
macro *get_macro();
int first_time_not_found();
void set_number(int);
int get_number();
int numbered();
+ int is_fallback();
symbol *get_symbol();
};
@@ -116,6 +118,11 @@ inline int charinfo::numbered()
return flags & NUMBERED;
}
+inline int charinfo::is_fallback()
+{
+ return fallback;
+}
+
inline charinfo *charinfo::get_translation(int transparent_throughput)
{
return (transparent_throughput && !transparent_translate
diff --git a/src/roff/troff/input.cc b/src/roff/troff/input.cc
index 1baeea24..26846577 100644
--- a/src/roff/troff/input.cc
+++ b/src/roff/troff/input.cc
@@ -3579,7 +3579,7 @@ void append_string()
do_define_string(1);
}
-void define_character()
+void do_define_character(int fallback)
{
node *n;
int c;
@@ -3613,12 +3613,22 @@ void define_character()
m->append((unsigned char)c);
c = get_copy(&n);
}
- m = ci->set_macro(m);
+ m = ci->set_macro(m, fallback);
if (m)
delete m;
tok.next();
}
+void define_character()
+{
+ do_define_character(0);
+}
+
+void define_fallback_character()
+{
+ do_define_character(1);
+}
+
static void remove_character()
{
tok.skip();
@@ -6708,6 +6718,7 @@ void init_input_requests()
init_request("rd", read_request);
init_request("cp", compatible);
init_request("char", define_character);
+ init_request("fchar", define_fallback_character);
init_request("rchar", remove_character);
init_request("hcode", hyphenation_code);
init_request("while", while_request);
@@ -7125,7 +7136,7 @@ int charinfo::next_index = 0;
charinfo::charinfo(symbol s)
: translation(0), mac(0), special_translation(TRANSLATE_NONE),
hyphenation_code(0), flags(0), ascii_code(0), not_found(0),
- transparent_translate(1), nm(s)
+ transparent_translate(1), fallback(0), nm(s)
{
index = next_index++;
}
@@ -7154,10 +7165,11 @@ void charinfo::set_ascii_code(unsigned char c)
ascii_code = c;
}
-macro *charinfo::set_macro(macro *m)
+macro *charinfo::set_macro(macro *m, int f)
{
macro *tem = mac;
mac = m;
+ fallback = f;
return tem;
}
diff --git a/src/roff/troff/node.cc b/src/roff/troff/node.cc
index b1bd80dd..68df49bf 100644
--- a/src/roff/troff/node.cc
+++ b/src/roff/troff/node.cc
@@ -4389,6 +4389,8 @@ node *make_glyph_node(charinfo *s, environment *env, int no_error_message = 0)
int fn = fontno;
int found = font_table[fontno]->contains(s);
if (!found) {
+ if (s->is_fallback())
+ return make_composite_node(s, env);
if (s->numbered()) {
if (!no_error_message)
warning(WARN_CHAR, "can't find numbered character %1",
@@ -4467,7 +4469,7 @@ node *make_node(charinfo *ci, environment *env)
if (tem)
ci = tem;
macro *mac = ci->get_macro();
- if (mac)
+ if (mac && !ci->is_fallback())
return make_composite_node(ci, env);
else
return make_glyph_node(ci, env);
@@ -4513,7 +4515,7 @@ node *node::add_char(charinfo *ci, environment *env,
if (tem)
ci = tem;
macro *mac = ci->get_macro();
- if (mac) {
+ if (mac && !ci->is_fallback()) {
res = make_composite_node(ci, env);
if (res) {
res->next = this;