summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwlemb <wlemb>2004-06-30 11:35:24 +0000
committerwlemb <wlemb>2004-06-30 11:35:24 +0000
commit5f659ae16cbad14977838e9f8f0de74a3c26c7db (patch)
treedc243ed3d0fcd1c72eeafec77373b6014810ab34
parent6e5ac034c3358b9519d887aa71233ddba406d1f9 (diff)
downloadgroff-5f659ae16cbad14977838e9f8f0de74a3c26c7db.tar.gz
Implement two new conditional operators `F <name>' and `S <name>'
which check whether <name> is a valid font or style, respectively. * src/libs/libgroff/font.cpp (text_file): Add `silent' member. (text_file::text_file): Updated. (text_file::error): Don't emit message if `silent' is set. (font::load_font): Add optional third argument (which is directly passed to `load'. (font::load): Add optional second argument to check the header of a font only, without emitting warning or error messages. * src/include/font.h (font): Updated. * src/roff/troff/input.cpp (do_if_request): Implement `S' and `F' conditionals. * src/roff/troff/node.cpp (mount_font_no_translate): Add optional fourth argument to check a font without mounting. (check_font, check_style): New functions. * src/roff/troff/node.h: Updated. * man/groff_diff.man, man/groff.man, NEWS, doc/groff.texinfo: Updated.
-rw-r--r--ChangeLog26
-rw-r--r--NEWS5
-rw-r--r--doc/groff.texinfo17
-rw-r--r--man/groff.man13
-rw-r--r--man/groff_diff.man37
-rw-r--r--src/include/font.h4
-rw-r--r--src/libs/libgroff/font.cpp15
-rw-r--r--src/roff/troff/input.cpp18
-rw-r--r--src/roff/troff/node.cpp22
-rw-r--r--src/roff/troff/node.h52
10 files changed, 161 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog
index f81de2a8..541a8b75 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,28 @@
-2004-06-27 Werner LEMBERG <wl@gnu.org
+2004-06-29 Werner LEMBERG <wl@gnu.org>
+
+ Implement two new conditional operators `F <name>' and `S <name>'
+ which check whether <name> is a valid font or style, respectively.
+
+ * src/libs/libgroff/font.cpp (text_file): Add `silent' member.
+ (text_file::text_file): Updated.
+ (text_file::error): Don't emit message if `silent' is set.
+ (font::load_font): Add optional third argument (which is directly
+ passed to `load'.
+ (font::load): Add optional second argument to check the header of
+ a font only, without emitting warning or error messages.
+ * src/include/font.h (font): Updated.
+
+ * src/roff/troff/input.cpp (do_if_request): Implement `S' and `F'
+ conditionals.
+ * src/roff/troff/node.cpp (mount_font_no_translate): Add optional
+ fourth argument to check a font without mounting.
+ (check_font, check_style): New functions.
+ * src/roff/troff/node.h: Updated.
+
+ * man/groff_diff.man, man/groff.man, NEWS, doc/groff.texinfo:
+ Updated.
+
+2004-06-27 Werner LEMBERG <wl@gnu.org>
Implement new string-valued register `.sty' to return the current
style name.
diff --git a/NEWS b/NEWS
index 84df4f0c..e1f0cab5 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,11 @@ Troff
o A new read-only, string-valued register `.sty' returns the name of the
current style.
+o Two new conditional operators `F <name>' and `S <name>' have been added.
+ `F' is true if a font <name> exists. `S' is true if a style <name> has
+ been registered.
+
+
Gxditview
---------
diff --git a/doc/groff.texinfo b/doc/groff.texinfo
index f5fdce39..612a4405 100644
--- a/doc/groff.texinfo
+++ b/doc/groff.texinfo
@@ -8282,8 +8282,12 @@ the current environment.
@cindex @code{fspecial} request, and font translations
@cindex @code{fp} request, and font translations
@cindex @code{sty} request, and font translations
+@cindex @code{if} request, and font translations
+@cindex @code{ie} request, and font translations
+@cindex @code{while} request, and font translations
Translate font@tie{}@var{f} to font@tie{}@var{g}. Whenever a font
-named@tie{}@var{f} is referred to in a @code{\f} escape sequence, or in the
+named@tie{}@var{f} is referred to in a @code{\f} escape sequence,
+in the @code{F} and @code{S} conditional operators, or in the
@code{ft}, @code{ul}, @code{bd}, @code{cs}, @code{tkf},
@code{special}, @code{fspecial}, @code{fp}, or @code{sty} requests,
font@tie{}@var{g} is used. If @var{g} is missing or equal to@tie{}@var{f}
@@ -10208,6 +10212,17 @@ conditional operator is a misnomer since it tests names of output
glyphs.}; @var{g} is either an @acronym{ASCII} character or a special
character (@code{\(@var{gg}} or @code{\[@var{ggg}]}); the condition
is also true if @var{g} has been defined by the @code{char} request.
+
+@item F @var{font}
+True if a font named @var{font} exists. @var{font} is handled as if it was
+opened with the @code{ft} request (this is, font translation and styles are
+applied), without actually mounting it.
+
+This test doesn't load the complete font but only its header to verify
+its validity.
+
+@item S @var{style}
+True if style @var{style} has been registered. Font translation is applied.
@end table
Note that these operators can't be combined with other operators like
diff --git a/man/groff.man b/man/groff.man
index 0e08c332..6bd261d8 100644
--- a/man/groff.man
+++ b/man/groff.man
@@ -2,7 +2,7 @@
.ig
groff.man
-Last update: 27 Jun 2004
+Last update: 29 Jun 2004
This file is part of groff, the GNU roff type-setting system.
@@ -1015,6 +1015,17 @@ True if there is a register named
Formatter is
.BR troff .
.
+.TPx
+.BI F font
+True if there exists a font named
+.IR font .
+.
+.TPx
+.BI S style
+True if a style named
+.I style
+has been registered.
+.
.RE
.PD
.
diff --git a/man/groff_diff.man b/man/groff_diff.man
index b3ebc940..19e9a600 100644
--- a/man/groff_diff.man
+++ b/man/groff_diff.man
@@ -3,7 +3,7 @@
.ig
groff_diff.man
-Last update : 27 Jun 2004
+Last update : 29 Jun 2004
This file is part of groff, the GNU roff type-setting system.
It is the source of the man-page groff_diff(7).
@@ -1440,7 +1440,11 @@ Whenever a font named
.I f
is referred to in an
.B \[rs]f
-escape sequence, or in the
+escape sequence, in the
+.B F
+and
+.B S
+conditional operators, or in the
.BR ft ,
.BR ul ,
.BR bd ,
@@ -3079,6 +3083,26 @@ has been defined by the
.B char
request.
.
+.TP
+.BI .if\ F f
+True if font
+.I f
+exists.
+.
+.B f
+is handled as if it was opened with the
+.B ft
+request (this is, font translation and styles are applied), without
+actually mounting it.
+.
+.TP
+.BI .if\ S s
+True if style
+.I s
+has been registered.
+.
+Font translation is applied.
+.
.P
The
.B tr
@@ -3095,16 +3119,11 @@ Example:
.ne 6v+\n(.Vu
.ft CB
.nf
-.Text .de foo
-.Text . nop Hello, I'm `foo'.
-.Text . nop I will now define `bar'.
+.Text .if t \[rs]{\[rs]
.Text . de bar
.Text . nop Hello, I'm `bar'.
.Text . .
-.Text . nop Done.
-.Text ..
-.Text .foo
-.Text .bar
+.Text .\[rs]}
.fi
.
.
diff --git a/src/include/font.h b/src/include/font.h
index 3d46138e..987cf6cc 100644
--- a/src/include/font.h
+++ b/src/include/font.h
@@ -57,7 +57,7 @@ public:
static int scan_papersize(const char *, const char **, double *, double *);
- static font *load_font(const char *, int *not_found = 0);
+ static font *load_font(const char *, int * = 0, int = 0);
static void command_line_font_dir(const char *path);
static FILE *open_file(const char *name, char **pathp);
static int load_desc();
@@ -117,5 +117,5 @@ private:
const char *file, int lineno);
protected:
font(const char *);
- int load(int *not_found = 0);
+ int load(int * = 0, int = 0);
};
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index 7883fdf6..6af6c30b 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -71,6 +71,7 @@ struct text_file {
int lineno;
int size;
int skip_comments;
+ int silent;
char *buf;
text_file(FILE *fp, char *p);
~text_file();
@@ -82,7 +83,7 @@ struct text_file {
};
text_file::text_file(FILE *p, char *s)
-: fp(p), path(s), lineno(0), size(0), skip_comments(1), buf(0)
+: fp(p), path(s), lineno(0), size(0), skip_comments(1), silent(0), buf(0)
{
}
@@ -141,7 +142,8 @@ void text_file::error(const char *format,
const errarg &arg2,
const errarg &arg3)
{
- error_with_file_and_line(path, lineno, format, arg1, arg2, arg3);
+ if (!silent)
+ error_with_file_and_line(path, lineno, format, arg1, arg2, arg3);
}
@@ -479,10 +481,10 @@ void font::copy_entry(int new_index, int old_index)
ch_index[new_index] = ch_index[old_index];
}
-font *font::load_font(const char *s, int *not_found)
+font *font::load_font(const char *s, int *not_found, int head_only)
{
font *f = new font(s);
- if (!f->load(not_found)) {
+ if (!f->load(not_found, head_only)) {
delete f;
return 0;
}
@@ -557,7 +559,7 @@ again:
// If the font can't be found, then if not_found is non-NULL, it will be set
// to 1 otherwise a message will be printed.
-int font::load(int *not_found)
+int font::load(int *not_found, int head_only)
{
char *path;
FILE *fp;
@@ -570,6 +572,7 @@ int font::load(int *not_found)
}
text_file t(fp, path);
t.skip_comments = 1;
+ t.silent = head_only;
char *p;
for (;;) {
if (!t.next()) {
@@ -638,6 +641,8 @@ int font::load(int *not_found)
else
break;
}
+ if (head_only)
+ return 1;
char *command = p;
int had_charset = 0;
t.skip_comments = 0;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 62be5844..2bcb579c 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5272,6 +5272,24 @@ int do_if_request()
result = character_exists(ci, curenv);
tok.next();
}
+ else if (c == 'F') {
+ tok.next();
+ symbol nm = get_long_name(1);
+ if (nm.is_null()) {
+ skip_alternative();
+ return 0;
+ }
+ result = check_font(curenv->get_family()->nm, nm);
+ }
+ else if (c == 'S') {
+ tok.next();
+ symbol nm = get_long_name(1);
+ if (nm.is_null()) {
+ skip_alternative();
+ return 0;
+ }
+ result = check_style(nm);
+ }
else if (tok.space())
result = 0;
else if (tok.delimiter()) {
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 02624a3a..5a2cf7f6 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -5391,7 +5391,8 @@ static symbol get_font_translation(symbol nm)
dictionary font_dictionary(50);
-static int mount_font_no_translate(int n, symbol name, symbol external_name)
+static int mount_font_no_translate(int n, symbol name, symbol external_name,
+ int check_only = 0)
{
assert(n >= 0);
// We store the address of this char in font_dictionary to indicate
@@ -5401,7 +5402,9 @@ static int mount_font_no_translate(int n, symbol name, symbol external_name)
void *p = font_dictionary.lookup(external_name);
if (p == 0) {
int not_found;
- fm = font::load_font(external_name.contents(), &not_found);
+ fm = font::load_font(external_name.contents(), &not_found, check_only);
+ if (check_only)
+ return fm != 0;
if (!fm) {
if (not_found)
warning(WARN_FONT, "can't find font `%1'", external_name.contents());
@@ -5418,6 +5421,8 @@ static int mount_font_no_translate(int n, symbol name, symbol external_name)
}
else
fm = (font*)p;
+ if (check_only)
+ return 1;
if (n >= font_table_size) {
if (n - font_table_size > 1000) {
error("font position too much larger than first unused position");
@@ -5443,6 +5448,19 @@ int mount_font(int n, symbol name, symbol external_name)
return mount_font_no_translate(n, name, external_name);
}
+int check_font(symbol fam, symbol name)
+{
+ if (check_style(name))
+ name = concat(fam, name);
+ return mount_font_no_translate(0, name, name, 1);
+}
+
+int check_style(symbol s)
+{
+ int i = symbol_fontno(s);
+ return i < 0 ? 0 : font_table[i]->is_style();
+}
+
void mount_style(int n, symbol name)
{
assert(n >= 0);
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index 7baef298..31c58581 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -51,8 +51,8 @@ struct node {
node *next;
node *last;
node();
- node(node *n);
- node *add_char(charinfo *c, environment *, hunits *widthp, int *spacep);
+ node(node *);
+ node *add_char(charinfo *, environment *, hunits *, int *);
virtual ~node();
virtual node *copy() = 0;
@@ -67,7 +67,7 @@ struct node {
virtual int merge_space(hunits, hunits, hunits);
virtual vunits vertical_width();
virtual node *last_char_node();
- virtual void vertical_extent(vunits *min, vunits *max);
+ virtual void vertical_extent(vunits *, vunits *);
virtual int character_type();
virtual void set_vertical_size(vertical_size *);
virtual int ends_sentence();
@@ -81,9 +81,7 @@ struct node {
virtual void spread_space(int *, hunits *);
virtual void freeze_space();
virtual void is_escape_colon();
- virtual breakpoint *get_breakpoints(hunits width, int nspaces,
- breakpoint *rest = 0,
- int is_inner = 0);
+ virtual breakpoint *get_breakpoints(hunits, int, breakpoint * = 0, int = 0);
virtual int nbreaks();
virtual void split(int, node **, node **);
virtual hyphenation_type get_hyphenation_type();
@@ -172,8 +170,7 @@ public:
void is_escape_colon();
void spread_space(int *, hunits *);
void tprint(troff_output_file *);
- breakpoint *get_breakpoints(hunits width, int nspaces, breakpoint *rest = 0,
- int is_inner = 0);
+ breakpoint *get_breakpoints(hunits, int, breakpoint * = 0, int = 0);
int nbreaks();
void split(int, node **, node **);
void ascii_print(ascii_output_file *);
@@ -222,8 +219,7 @@ public:
void asciify(macro *);
const char *type();
int force_tprint();
- breakpoint *get_breakpoints(hunits width, int nspaces, breakpoint *rest = 0,
- int is_inner = 0);
+ breakpoint *get_breakpoints(hunits, int, breakpoint * = 0, int = 0);
int nbreaks();
void split(int, node **, node **);
int merge_space(hunits, hunits, hunits);
@@ -235,7 +231,7 @@ public:
class diverted_space_node : public node {
public:
vunits n;
- diverted_space_node(vunits d, node *p = 0);
+ diverted_space_node(vunits, node * = 0);
node *copy();
int reread(int *);
int same(node *);
@@ -247,7 +243,7 @@ class diverted_copy_file_node : public node {
symbol filename;
public:
vunits n;
- diverted_copy_file_node(symbol s, node *p = 0);
+ diverted_copy_file_node(symbol, node * = 0);
node *copy();
int reread(int *);
int same(node *);
@@ -388,7 +384,7 @@ public:
class zero_width_node : public node {
node *n;
public:
- zero_width_node(node *gn);
+ zero_width_node(node *);
~zero_width_node();
node *copy();
void tprint(troff_output_file *);
@@ -397,7 +393,7 @@ public:
int force_tprint();
void append(node *);
int character_type();
- void vertical_extent(vunits *min, vunits *max);
+ void vertical_extent(vunits *, vunits *);
};
class left_italic_corrected_node : public node {
@@ -492,8 +488,8 @@ class suppress_node : public node {
int image_id;
public:
suppress_node(int, int);
- suppress_node(symbol f, char p, int id);
- suppress_node(int, int, symbol f, char p, int id);
+ suppress_node(symbol, char, int);
+ suppress_node(int, int, symbol, char, int);
node *copy();
void tprint(troff_output_file *);
hunits width();
@@ -501,7 +497,7 @@ public:
const char *type();
int force_tprint();
private:
- void put(troff_output_file *out, const char *s);
+ void put(troff_output_file *, const char *);
};
struct hvpair {
@@ -530,15 +526,15 @@ public:
};
class charinfo;
-node *make_node(charinfo *ci, environment *);
+node *make_node(charinfo *, environment *);
int character_exists(charinfo *, environment *);
-int same_node_list(node *n1, node *n2);
-node *reverse_node_list(node *n);
+int same_node_list(node *, node *);
+node *reverse_node_list(node *);
void delete_node_list(node *);
node *copy_node_list(node *);
-int get_bold_fontno(int f);
+int get_bold_fontno(int);
inline hyphen_list::hyphen_list(unsigned char code, hyphen_list *p)
: hyphen(0), breakable(0), hyphenation_code(code), next(p)
@@ -546,9 +542,11 @@ inline hyphen_list::hyphen_list(unsigned char code, hyphen_list *p)
}
extern void read_desc();
-extern int mount_font(int n, symbol, symbol = NULL_SYMBOL);
-extern void mount_style(int n, symbol);
-extern int is_good_fontno(int n);
+extern int mount_font(int, symbol, symbol = NULL_SYMBOL);
+extern int check_font(symbol, symbol);
+extern int check_style(symbol);
+extern void mount_style(int, symbol);
+extern int is_good_fontno(int);
extern int symbol_fontno(symbol);
extern int next_available_font_position();
extern void init_size_table(int *);
@@ -559,7 +557,7 @@ class output_file {
public:
output_file();
virtual ~output_file();
- virtual void trailer(vunits page_length);
+ virtual void trailer(vunits);
virtual void flush() = 0;
virtual void transparent_char(unsigned char) = 0;
virtual void print_line(hunits x, vunits y, node *n,
@@ -567,7 +565,7 @@ public:
virtual void begin_page(int pageno, vunits page_length) = 0;
virtual void copy_file(hunits x, vunits y, const char *filename) = 0;
virtual int is_printing() = 0;
- virtual void put_filename(const char *filename);
+ virtual void put_filename(const char *);
virtual void on();
virtual void off();
#ifdef COLUMN
@@ -581,7 +579,7 @@ extern char *pipe_command;
extern output_file *the_output;
extern void init_output();
-int in_output_page_list(int n);
+int in_output_page_list(int);
class font_family {
int *map;