gbranden pushed a commit to branch master
in repository groff.
commit 320da4af2d73d03017c657f8ccd5154871b7a260
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Apr 20 18:04:24 2025 -0500
[troff]: Slightly refactor.
Boolify and rename `is_good_fontno()` to
`is_valid_font_mounting_position()`, and use it in more places instead
of complex expressions meaning the same thing.
* src/roff/troff/node.h: Update declaration.
* src/roff/troff/node.cpp: Update definition, and define earlier to
avoid necessity of forward declaration.
* src/roff/troff/env.cpp (environment::set_font)
(environment::environment): Update call sites.
* src/roff/troff/node.cpp (has_font, get_bold_fontno)
(env_space_width)
(env_sentence_space_width)
(env_half_narrow_space_width)
(env_narrow_space_width): Add call sites, replacing complex
expressions.
---
ChangeLog | 21 +++++++++++++++++++
src/roff/troff/env.cpp | 4 ++--
src/roff/troff/node.cpp | 56 +++++++++++++------------------------------------
src/roff/troff/node.h | 2 +-
4 files changed, 38 insertions(+), 45 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dcf5c665b..c6edd1df9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2025-04-20 G. Branden Robinson <[email protected]>
+
+ [troff]: Slightly refactor. Boolify and rename
+ `is_good_fontno()` to `is_valid_font_mounting_position()`, and
+ use it in more places instead of complex expressions meaning the
+ same thing.
+
+ * src/roff/troff/node.h: Update declaration.
+ * src/roff/troff/node.cpp: Update definition, and define earlier
+ to avoid necessity of forward declaration.
+
+ * src/roff/troff/env.cpp (environment::set_font)
+ (environment::environment): Update call sites.
+
+ * src/roff/troff/node.cpp (has_font, get_bold_fontno)
+ (env_space_width)
+ (env_sentence_space_width)
+ (env_half_narrow_space_width)
+ (env_narrow_space_width): Add call sites, replacing complex
+ expressions.
+
2025-04-20 G. Branden Robinson <[email protected]>
[troff]: Slightly refactor. Use a manifest constant for
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 0f12947c5..61c55a1bc 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -617,7 +617,7 @@ bool environment::set_font(int n)
{
if (line_interrupted)
return false;
- if (is_good_fontno(n)) {
+ if (is_valid_font_mounting_position(n)) {
prev_fontno = fontno;
fontno = n;
}
@@ -814,7 +814,7 @@ environment::environment(symbol nm)
{
prev_family = family = lookup_family(default_family);
prev_fontno = fontno = 1;
- if (!is_good_fontno(1))
+ if (!is_valid_font_mounting_position(1))
fatal("font mounted at position 1 is not valid");
if (family->resolve(1) == FONT_NOT_MOUNTED)
fatal("invalid default font family '%1'",
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 19762a540..846f362e9 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -6720,6 +6720,13 @@ static void font_lookup_error(font_lookup_info& finfo,
finfo.requested_position, msg);
}
+inline bool is_valid_font_mounting_position(int n)
+{
+ return (n >= 0)
+ && (n < font_table_size)
+ && (font_table[n] != 0 /* nullptr */);
+}
+
// Read the next token and look it up as a font name or position number.
// Return lookup success. Store, in the supplied struct argument, the
// requested name or position, and the position actually resolved.
@@ -6742,9 +6749,7 @@ static bool has_font(font_lookup_info *finfo)
}
else if (get_integer(&n)) {
finfo->requested_position = n;
- if (!((n < 0)
- || (n >= font_table_size)
- || (0 /* nullptr */ == font_table[n])))
+ if (is_valid_font_mounting_position(n))
finfo->position = curenv->get_family()->resolve(n);
}
return (finfo->position != FONT_NOT_MOUNTED);
@@ -6957,20 +6962,10 @@ int symbol_fontno(symbol s)
return FONT_NOT_MOUNTED;
}
-/* TODO: mark `inline`? */
-int is_good_fontno(int n)
-{
- return (n >= 0)
- && (n < font_table_size)
- && (font_table[n] != 0 /* nullptr */);
-}
-
+// XXX: This does _not_ return a font "number" (mounting position)!
int get_bold_fontno(int n)
{
- /* TODO: if (is_good_fontno(n)) */
- if ((n >= 0)
- && (n < font_table_size)
- && (font_table[n] != 0 /* nullptr */)) {
+ if (is_valid_font_mounting_position(n)) {
hunits offset;
if (font_table[n]->get_bold(&offset))
return offset.to_units() + 1;
@@ -6993,25 +6988,11 @@ hunits env_digit_width(environment *env)
return H0;
}
-// TODO: Make the following an inline function?
-// TODO: Double-check the putative name. Flip its sense?
-
-#if 0
-static inline bool is_font_unresolvable(int fn) {
- return (fn < 0)
- || (fn >= font_table_size)
- || (0 /* nullptr */ == font_table[fn]);
-}
-#endif
-
hunits env_space_width(environment *env)
{
int fn = env_resolve_font(env);
font_size fs = env->get_font_size();
- // TODO: is_font_unresolvable()
- if ((fn < 0)
- || (fn >= font_table_size)
- || (0 /* nullptr */ == font_table[fn]))
+ if (!is_valid_font_mounting_position(fn))
return scale(fs.to_units() / 3, env->get_space_size(), 12);
else
return font_table[fn]->get_space_width(fs, env->get_space_size());
@@ -7022,10 +7003,7 @@ hunits env_sentence_space_width(environment *env)
int fn = env_resolve_font(env);
font_size fs = env->get_font_size();
// TODO: use temp var for env->get_sentence_space_size()
- // TODO: is_font_unresolvable()
- if ((fn < 0)
- || (fn >= font_table_size)
- || (0 /* nullptr */ == font_table[fn]))
+ if (!is_valid_font_mounting_position(fn))
return scale(fs.to_units() / 3, env->get_sentence_space_size(), 12);
else
return font_table[fn]->get_space_width(fs, env->get_sentence_space_size());
@@ -7035,10 +7013,7 @@ hunits env_half_narrow_space_width(environment *env)
{
int fn = env_resolve_font(env);
font_size fs = env->get_font_size();
- // TODO: is_font_unresolvable()
- if ((fn < 0)
- || (fn >= font_table_size)
- || (0 /* nullptr */ == font_table[fn]))
+ if (!is_valid_font_mounting_position(fn))
return 0;
else
return font_table[fn]->get_half_narrow_space_width(fs);
@@ -7048,10 +7023,7 @@ hunits env_narrow_space_width(environment *env)
{
int fn = env_resolve_font(env);
font_size fs = env->get_font_size();
- // TODO: is_font_unresolvable()
- if ((fn < 0)
- || (fn >= font_table_size)
- || (0 /* nullptr */ == font_table[fn]))
+ if (!is_valid_font_mounting_position(fn))
return 0;
else
return font_table[fn]->get_narrow_space_width(fs);
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index 62b301aee..2b312b577 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -689,7 +689,7 @@ extern bool mount_font(int, symbol,
extern bool is_font_name(symbol, symbol);
extern bool is_abstract_style(symbol);
extern bool mount_style(int, symbol);
-extern int is_good_fontno(int);
+extern bool is_valid_font_mounting_position(int);
extern int symbol_fontno(symbol);
extern int next_available_font_position();
extern void init_size_list(int *);
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit