gbranden pushed a commit to branch master
in repository groff.
commit 67d37815075556da2001c1fdf0e794d4fdd90835
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue May 13 08:34:14 2025 -0500
[troff]: Slighty refactor (boolify, rename) [1/3].
* src/roff/troff/node.cpp (class font_info, class tfont_spec): Demote
member variable `is_bold` from `char` to `bool`, and rename it to
`has_emboldening`. It only ever takes two values, so the use of a
`char` instead of an `int` (in pre-standard C++) might have been a
premature space optimization. The new name avoids collision with the
member function `is_emboldened` and also somewhat better implies a
process applied to a font rather than an inherent property of a
typeface. Both senses of "bold" exist in *roff; this is the one
manipulated by the `bd` request.
(font_info::font_info, tfont_spec::tfont_spec): Use Boolean, not
integer, literal for it in initializer list.
(font_info::font_info, tfont_spec::tfont_spec)
(font_info::get_tfont, font_info::is_emboldened)
(font_info::unbold, font_info::set_bold, tfont_spec::operator==)
(tfont::get_width, tfont::is_emboldened): Track rename.
(font_info::get_tfont, font_info::is_emboldened)
(font_info::unbold, font_info::set_bold, tfont_spec::operator==)
(tfont::get_width, tfont::is_emboldened): Use Boolean, not integer,
literals in assignments to variables of type `bool`.
---
ChangeLog | 24 ++++++++++++++++++++++++
src/roff/troff/node.cpp | 36 ++++++++++++++++++------------------
2 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4735c73f9..a6e6ec543 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2025-05-13 G. Branden Robinson <[email protected]>
+
+ [troff]: Slighty refactor (boolify, rename).
+
+ * src/roff/troff/node.cpp (class font_info, class tfont_spec):
+ Demote member variable `is_bold` from `char` to `bool`, and
+ rename it to `has_emboldening`. It only ever takes two values,
+ so the use of a `char` instead of an `int` (in pre-standard C++)
+ might have been a premature space optimization. The new name
+ avoids collision with the member function `is_emboldened` and
+ also somewhat better implies a process applied to a font rather
+ than an inherent property of a typeface. Both senses of "bold"
+ exist in *roff; this is the one manipulated by the `bd` request.
+ (font_info::font_info, tfont_spec::tfont_spec): Use Boolean, not
+ integer, literal for it in initializer list.
+ (font_info::font_info, tfont_spec::tfont_spec)
+ (font_info::get_tfont, font_info::is_emboldened)
+ (font_info::unbold, font_info::set_bold, tfont_spec::operator==)
+ (tfont::get_width, tfont::is_emboldened): Track rename.
+ (font_info::get_tfont, font_info::is_emboldened)
+ (font_info::unbold, font_info::set_bold, tfont_spec::operator==)
+ (tfont::get_width, tfont::is_emboldened): Use Boolean, not
+ integer, literals in assignments to variables of type `bool`.
+
2025-05-13 G. Branden Robinson <[email protected]>
* src/roff/troff/env.cpp (compare_ranges, distribute_space)
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index e36af7d98..badc8df04 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -146,7 +146,7 @@ class font_info {
symbol internal_name;
symbol external_name;
font *fm;
- char is_bold;
+ bool has_emboldening;
hunits bold_offset;
track_kerning_function track_kern;
constant_space_type is_constant_spaced;
@@ -186,7 +186,7 @@ protected:
int input_position;
font *fm;
font_size size;
- char is_bold;
+ bool has_emboldening;
char is_constant_spaced;
int ligature_mode;
int kern_mode;
@@ -245,7 +245,7 @@ static int font_table_size = 0;
font_info::font_info(symbol nm, int n, symbol enm, font *f)
: last_tfont(0), number(n), last_size(0),
internal_name(nm), external_name(enm), fm(f),
- is_bold(0), is_constant_spaced(CONSTANT_SPACE_NONE),
+ has_emboldening(false), is_constant_spaced(CONSTANT_SPACE_NONE),
last_ligature_mode(1), last_kern_mode(1), cond_bold_list(0), sf(0)
{
}
@@ -306,12 +306,12 @@ tfont *font_info::get_tfont(font_size fs, int height, int
slant, int fontno)
tfont_spec spec(f->external_name, f->number, f->fm, fs, height, slant);
for (conditional_bold *p = cond_bold_list; p; p = p->next)
if (p->fontno == fontno) {
- spec.is_bold = 1;
+ spec.has_emboldening = true;
spec.bold_offset = p->offset;
break;
}
- if (!spec.is_bold && is_bold) {
- spec.is_bold = 1;
+ if (!spec.has_emboldening && has_emboldening) {
+ spec.has_emboldening = true;
spec.bold_offset = bold_offset;
}
spec.track_kern = track_kern.compute(fs.to_scaled_points());
@@ -350,7 +350,7 @@ tfont *font_info::get_tfont(font_size fs, int height, int
slant, int fontno)
bool font_info::is_emboldened(hunits *res)
{
- if (is_bold) {
+ if (has_emboldening) {
*res = bold_offset;
return true;
}
@@ -360,16 +360,16 @@ bool font_info::is_emboldened(hunits *res)
void font_info::unbold()
{
- if (is_bold) {
- is_bold = 0;
+ if (has_emboldening) {
+ has_emboldening = false;
flush();
}
}
void font_info::set_bold(hunits offset)
{
- if (!is_bold || offset != bold_offset) {
- is_bold = 1;
+ if (!has_emboldening || offset != bold_offset) {
+ has_emboldening = true;
bold_offset = offset;
flush();
}
@@ -490,8 +490,8 @@ hunits font_info::get_half_narrow_space_width(font_size fs)
tfont_spec::tfont_spec(symbol nm, int n, font *f,
font_size s, int h, int sl)
: name(nm), input_position(n), fm(f), size(s),
- is_bold(0), is_constant_spaced(0), ligature_mode(1), kern_mode(1),
- height(h), slant(sl)
+ has_emboldening(false), is_constant_spaced(0), ligature_mode(1),
+ kern_mode(1), height(h), slant(sl)
{
if (height == size.to_scaled_points())
height = 0;
@@ -505,9 +505,9 @@ bool tfont_spec::operator==(const tfont_spec &spec)
&& name == spec.name
&& height == spec.height
&& slant == spec.slant
- && (is_bold
- ? (spec.is_bold && bold_offset == spec.bold_offset)
- : !spec.is_bold)
+ && (has_emboldening
+ ? (spec.has_emboldening && bold_offset == spec.bold_offset)
+ : !spec.has_emboldening)
&& track_kern == spec.track_kern
&& (is_constant_spaced
? (spec.is_constant_spaced
@@ -529,7 +529,7 @@ hunits tfont::get_width(charinfo *c)
{
if (is_constant_spaced)
return constant_space_width;
- else if (is_bold)
+ else if (has_emboldening)
return (hunits(fm->get_width(c->as_glyph(), size.to_scaled_points()))
+ track_kern + bold_offset);
else
@@ -594,7 +594,7 @@ inline int tfont::get_character_type(charinfo *ci)
inline bool tfont::is_emboldened(hunits *res)
{
- if (is_bold) {
+ if (has_emboldening) {
*res = bold_offset;
return true;
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit