[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 08/11: Convert some font class `int` members to `bool`.
From: |
G. Branden Robinson |
Subject: |
[groff] 08/11: Convert some font class `int` members to `bool`. |
Date: |
Fri, 13 Aug 2021 10:05:49 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 749502cc77c6620f2e593d95fd72eda8d9e26659
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Aug 13 20:27:06 2021 +1000
Convert some font class `int` members to `bool`.
* src/include/font.h (font class): Demote integers to Booleans and use
Boolean literals where possible. Rename some member variables to look
like logical predicates.
- contains()
- is_special()
- has_ligature()
- tcommand -> has_tcommand
- unscaled_charwidths
- pass_filenames
- use_charnames_in_special
- is_unicode
- special (private)
* src/libs/libgroff/font.cpp (font::font): Construct object using
Boolean literal.
(font::contains):
(font::is_special):
(font::has_ligature): Convert return type to `bool`.
(font::load):
(font::load_desc): Assign to member variables using Boolean literals.
* src/libs/libgroff/fontfile.cpp: Initialize appropriate globals using
`bool` type and Boolean literals.
* src/roff/troff/troff.h:
* src/roff/troff/input.cpp (main):
* src/roff/troff/node.cpp (troff_output_file::put_char_width): Rename
`tcommand_flag` to `device_has_command` to suggest a logical
predicate, and to emphasize the formatter's concern with what the
output device can accept in the intermediate output language.
* src/roff/troff/input.cpp: Initialize `device_has_tcommand` global
using `bool` type and Boolean literal.
---
ChangeLog | 36 ++++++++++++++++++++++++++++++++++++
src/include/font.h | 42 +++++++++++++++++++++---------------------
src/libs/libgroff/font.cpp | 36 +++++++++++++++++++++---------------
src/libs/libgroff/fontfile.cpp | 16 +++++++++++-----
src/roff/troff/input.cpp | 4 ++--
src/roff/troff/node.cpp | 2 +-
src/roff/troff/troff.h | 8 +++++++-
7 files changed, 99 insertions(+), 45 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index de87665..049a8a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,41 @@
2021-08-13 G. Branden Robinson <g.branden.robinson@gmail.com>
+ Convert font class `int` members to `bool` where appropriate.
+
+ * src/include/font.h (font class): Demote integers to Booleans
+ and use Boolean literals where possible. Rename some member
+ variables to look like logical predicates.
+ - contains()
+ - is_special()
+ - has_ligature()
+ - tcommand -> has_tcommand
+ - unscaled_charwidths
+ - pass_filenames
+ - use_charnames_in_special
+ - is_unicode
+ - special (private)
+ * src/libs/libgroff/font.cpp (font::font): Construct object
+ using Boolean literal.
+ (font::contains):
+ (font::is_special):
+ (font::has_ligature): Convert return type to `bool`.
+ (font::load):
+ (font::load_desc): Assign to member variables using Boolean
+ literals.
+ * src/libs/libgroff/fontfile.cpp: Initialize appropriate globals
+ using `bool` type and Boolean literals.
+ * src/roff/troff/troff.h:
+ * src/roff/troff/input.cpp (main):
+ * src/roff/troff/node.cpp (troff_output_file::put_char_width):
+ Rename `tcommand_flag` to `device_has_command` to suggest a
+ logical predicate, and to emphasize the formatter's concern with
+ what the output device can accept in the intermediate output
+ language.
+ * src/roff/troff/input.cpp: Initialize `device_has_tcommand`
+ global using `bool` type and Boolean literal.
+
+2021-08-13 G. Branden Robinson <g.branden.robinson@gmail.com>
+
[me]: Clarify breadth of application of `ll` macro.
* doc/meref.me: Document application of .ll macro only to the 3
diff --git a/src/include/font.h b/src/include/font.h
index 6a2d564..2b6fe48 100644
--- a/src/include/font.h
+++ b/src/include/font.h
@@ -105,11 +105,11 @@ public:
};
virtual ~font(); // Destructor.
- int contains(glyph *); // 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().
+ bool contains(glyph *); // This font contains the given glyph.
+ bool is_special(); // This font is searched for glyphs not defined
+ // in the current font. See section 'Special
+ // Fonts' in the groff Texinfo manual. Used by
+ // make_glyph_node().
int get_width(glyph *, int); // A rectangle represents the shape of the
// given glyph (arg1) at the given point size
// (arg2). Return the horizontal dimension of this
@@ -158,9 +158,8 @@ public:
// natural and artificial slant. It basically means
// how much an accent must be shifted horizontally
// to put it on the optical axis of the glyph.
- 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.
+ bool has_ligature(int); // This font has the given ligature type
+ // (one of LIG_ff, LIG_fi, ...).
int get_italic_correction(glyph *, int); // If the given glyph (arg1)
// at the given point size (arg2) is followed by an
// unslanted glyph, some horizontal white space may
@@ -244,16 +243,14 @@ public:
// DESC file.
static int spare2;
static int sizescale; // The 'sizescale' attribute given in the DESC
file.
- static int tcommand; // Nonzero if the DESC file has the 'tcommand'
- // attribute.
- static int unscaled_charwidths; // Nonzero if the DESC file has the
- // 'unscaled_charwidths' attribute.
- static int pass_filenames; // Nonzero if the DESC file has the
- // 'pass_filenames' attribute.
- static int use_charnames_in_special; // Nonzero if the DESC file has the
- // 'use_charnames_in_special' attribute.
- static int is_unicode; // Nonzero if the DESC file has the 'unicode'
- // attribute.
+ static bool has_tcommand; // DESC file has 'tcommand' directive.
+ static bool unscaled_charwidths; // DESC file has
+ // 'unscaled_charwidths' directive.
+ static bool pass_filenames; // DESC file has 'pass_filenames'
+ // directive.
+ static bool use_charnames_in_special; // DESC file has
+ // 'use_charnames_in_special' directive.
+ static bool is_unicode; // DESC file has the 'unicode' directive.
static const char *image_generator; // The 'image_generator' attribute
// given in the DESC file.
static const char **font_name_table; // The 'fonts' attribute given in
@@ -275,8 +272,7 @@ private:
// Used by get_kern().
int space_width; // The normal width of a space. Used by
// get_space_width().
- int special; // 1 if this font is special, 0 otherwise. Used by
- // is_special().
+ bool special; // See public is_special() above.
char *name; // The name of this font. Used by get_name().
char *internalname; // The 'internalname' attribute of this font, or
// NULL. Used by get_internal_name().
@@ -344,4 +340,8 @@ protected:
// case of failure.
};
-// end of font.h
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index d0488bc..588acab 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -191,7 +191,7 @@ int glyph_to_unicode(glyph *g)
/* font functions */
font::font(const char *s)
-: ligatures(0), kern_hash_table(0), space_width(0), special(0),
+: ligatures(0), kern_hash_table(0), space_width(0), special(false),
ch_index(0), nindices(0), ch(0), ch_used(0), ch_size(0), widths_cache(0)
{
name = new char[strlen(s) + 1];
@@ -300,26 +300,26 @@ int font::get_skew(glyph *g, int point_size, int sl)
return int(h * tan((slant + sl) * PI / 180.0) + .5);
}
-int font::contains(glyph *g)
+bool font::contains(glyph *g)
{
int idx = glyph_to_index(g);
assert(idx >= 0);
// Explicitly enumerated glyph?
if (idx < nindices && ch_index[idx] >= 0)
- return 1;
+ return true;
if (is_unicode) {
// Unicode font
// ASCII or Unicode character, or groff glyph name that maps to Unicode?
if (glyph_to_unicode(g) >= 0)
- return 1;
+ return true;
// Numbered character?
if (glyph_to_number(g) >= 0)
- return 1;
+ return true;
}
- return 0;
+ return false;
}
-int font::is_special()
+bool font::is_special()
{
return special;
}
@@ -522,9 +522,9 @@ int font::get_kern(glyph *g1, glyph *g2, int point_size)
return 0;
}
-int font::has_ligature(int mask)
+bool font::has_ligature(int mask)
{
- return mask & ligatures;
+ return (bool) (mask & ligatures);
}
int font::get_character_type(glyph *g)
@@ -837,7 +837,7 @@ int font::load(int *not_found, int head_only)
strcpy(internalname, p);
}
else if (strcmp(p, "special") == 0) {
- special = 1;
+ special = true;
}
else if (strcmp(p, "kernpairs") != 0 && strcmp(p, "charset") != 0) {
char *command = p;
@@ -1121,9 +1121,9 @@ int font::load_desc()
}
}
else if (strcmp("unscaled_charwidths", p) == 0)
- unscaled_charwidths = 1;
+ unscaled_charwidths = true;
else if (strcmp("pass_filenames", p) == 0)
- pass_filenames = 1;
+ pass_filenames = true;
else if (strcmp("sizes", p) == 0) {
int n = 16;
sizes = new int[n];
@@ -1195,11 +1195,11 @@ int font::load_desc()
}
}
else if (strcmp("tcommand", p) == 0)
- tcommand = 1;
+ has_tcommand = true;
else if (strcmp("use_charnames_in_special", p) == 0)
- use_charnames_in_special = 1;
+ use_charnames_in_special = true;
else if (strcmp("unicode", p) == 0)
- is_unicode = 1;
+ is_unicode = true;
else if (strcmp("image_generator", p) == 0) {
p = strtok(0, WS);
if (!p) {
@@ -1259,3 +1259,9 @@
font::set_unknown_desc_command_handler(FONT_COMMAND_HANDLER func)
unknown_desc_command_handler = func;
return prev;
}
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/libs/libgroff/fontfile.cpp b/src/libs/libgroff/fontfile.cpp
index e48843b..ad5e0c4 100644
--- a/src/libs/libgroff/fontfile.cpp
+++ b/src/libs/libgroff/fontfile.cpp
@@ -41,11 +41,11 @@ const char *font::papersize = 0;
int font::biggestfont = 0;
int font::spare2 = 0;
int font::sizescale = 1;
-int font::tcommand = 0;
-int font::pass_filenames = 0;
-int font::unscaled_charwidths = 0;
-int font::use_charnames_in_special = 0;
-int font::is_unicode = 0;
+bool font::has_tcommand = false;
+bool font::pass_filenames = false;
+bool font::unscaled_charwidths = false;
+bool font::use_charnames_in_special = false;
+bool font::is_unicode = false;
const char *font::image_generator = NULL;
const char **font::font_name_table = 0;
int *font::sizes = 0;
@@ -66,3 +66,9 @@ FILE *font::open_file(const char *nm, char **pathp)
a_delete filename;
return fp;
}
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 11514da..39fd0e0 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -112,7 +112,7 @@ int have_input = 0; // whether \f, \F, \D'F...',
\H, \m, \M,
// \O[345], \R, \s, or \S has been processed
// in token::next()
int old_have_input = 0; // value of have_input right before \n
-int tcommand_flag = 0;
+bool device_has_tcommand = false; // 't' ouput command supported
int unsafe_flag = 0; // safer by default
int have_string_arg = 0; // whether we have \*[foo bar...]
@@ -8135,7 +8135,7 @@ int main(int argc, char **argv)
hresolution = font::hor;
vresolution = font::vert;
sizescale = font::sizescale;
- tcommand_flag = font::tcommand;
+ device_has_tcommand = font::has_tcommand;
warn_scale = (double)units_per_inch;
warn_scaling_indicator = 'i';
if (!fflag && font::family != 0 && *font::family != '\0')
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 9ac336c..bd75877 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -1077,7 +1077,7 @@ void troff_output_file::put_char_width(charinfo *ci,
tfont *tf,
put('\n');
hpos += w.to_units() + kk;
}
- else if (tcommand_flag) {
+ else if (device_has_tcommand) {
if (tbuf_len > 0 && hpos == output_hpos && vpos == output_vpos
&& (!gcol || gcol == current_glyph_color)
&& (!fcol || fcol == current_fill_color)
diff --git a/src/roff/troff/troff.h b/src/roff/troff/troff.h
index d9fc4d6..793ac19 100644
--- a/src/roff/troff/troff.h
+++ b/src/roff/troff/troff.h
@@ -42,7 +42,7 @@ extern int suppress_output_flag;
extern int color_flag;
extern int is_html;
-extern int tcommand_flag;
+extern bool device_has_tcommand;
extern int vresolution;
extern int hresolution;
extern int sizescale;
@@ -89,3 +89,9 @@ int output_warning(warning_type, const char *,
const errarg & = empty_errarg,
const errarg & = empty_errarg,
const errarg & = empty_errarg);
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 08/11: Convert some font class `int` members to `bool`.,
G. Branden Robinson <=