gbranden pushed a commit to branch master
in repository groff.

commit 0833ab8b6e0a6c496d52ebdae05778f51a3f1c1c
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Mar 5 09:01:58 2026 -0600

    [troff]: Refactor.
    
    Refactor resolution of currently selected font (which can be an abstract
    style, or even invalid) to a font mounting position.
    
    * src/roff/troff/node.h: Declare function
      `resolve_current_font_to_mounting_position()`; we'll need access to it
      from "input.cpp" in a forthcoming change.
    
    * src/roff/troff/node.cpp (env_resolve_font): Drop `static` storage
      class and `inline`.  "[T]he ... otherwise perfectly logical
      combination of external linkage and inlining is banned to make life
      simpler for compiler writers[.]" (_The C++ Programming Language,
      Special Edition_, Stroustrup, 1997, p. 199)  And rename this...
      (resolve_current_font_to_mounting_position): ...to this.  Annotate
      purpose.
    
      (device_extension_node::device_extension_node)
      (make_composite_node)
      (make_glyph_node)
      (env_space_width)
      (env_sentence_space_width)
      (env_half_narrow_space_width)
      (env_narrow_space_width): Update call sites.
---
 ChangeLog               | 24 ++++++++++++++++++++++++
 src/roff/troff/node.cpp | 19 +++++++++++--------
 src/roff/troff/node.h   |  1 +
 3 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e1bbafb31..a187abdf4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2026-03-05  G. Branden Robinson <[email protected]>
+
+       [troff]: Refactor resolution of currently selected font (which
+       can be an abstract style, or even invalid) to a font mounting
+       position.
+       * src/roff/troff/node.h: Declare function
+       `resolve_current_font_to_mounting_position()`; we'll need access
+       to it from "input.cpp" in a forthcoming change.
+       * src/roff/troff/node.cpp (env_resolve_font): Drop `static`
+       storage class and `inline`.  "[T]he ... otherwise perfectly
+       logical combination of external linkage and inlining is banned
+       to make life simpler for compiler writers[.]" (_The C++
+       Programming Language, Special Edition_, Stroustrup, 1997, p.
+       199)  And rename this...
+       (resolve_current_font_to_mounting_position): ...to this.
+       Annotate purpose.
+       (device_extension_node::device_extension_node)
+       (make_composite_node)
+       (make_glyph_node)
+       (env_space_width)
+       (env_sentence_space_width)
+       (env_half_narrow_space_width)
+       (env_narrow_space_width): Update call sites.
+
 2026-03-07  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp: Boolify
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 5074ae9b7..053d727ff 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -237,7 +237,10 @@ public:
   friend tfont *make_tfont(tfont_spec &);
 };
 
-static inline int env_resolve_font(environment *env)
+// This operation isn't a member function of `class environment`; we
+// need it only when translating nodes into troff output, so that we
+// know if we must emit an `f` trout/grout command.
+int resolve_current_font_to_mounting_position(environment *env)
 {
   return env->get_family()->resolve(env->get_font());
 }
@@ -4365,7 +4368,7 @@ device_extension_node::device_extension_node(const macro 
&m, bool b)
   font_size fs = curenv->get_font_size();
   int char_height = curenv->get_char_height();
   int char_slant = curenv->get_char_slant();
-  int fontno = env_resolve_font(curenv);
+  int fontno = resolve_current_font_to_mounting_position(curenv);
   tf = font_table[fontno]->get_tfont(fs, char_height, char_slant,
                                     fontno);
   if (curenv->is_composite())
@@ -5549,7 +5552,7 @@ void composite_node::dump_node()
 
 static node *make_composite_node(charinfo *s, environment *env)
 {
-  int fontno = env_resolve_font(env);
+  int fontno = resolve_current_font_to_mounting_position(env);
   if (fontno < 0) {
     error("cannot format composite glyph: no current font");
     return 0 /* nullptr */;
@@ -5570,7 +5573,7 @@ static node *make_composite_node(charinfo *s, environment 
*env)
 static node *make_glyph_node(charinfo *s, environment *env,
                             bool want_warnings = true)
 {
-  int fontno = env_resolve_font(env);
+  int fontno = resolve_current_font_to_mounting_position(env);
   if (fontno < 0) {
     error("cannot format glyph: no current font");
     return 0 /* nullptr */;
@@ -7237,7 +7240,7 @@ hunits env_digit_width(environment *env)
 
 hunits env_space_width(environment *env)
 {
-  int fn = env_resolve_font(env);
+  int fn = resolve_current_font_to_mounting_position(env);
   font_size fs = env->get_font_size();
   if (!is_valid_font_mounting_position(fn))
     return scale(fs.to_units() / 3, env->get_space_size(), 12);
@@ -7247,7 +7250,7 @@ hunits env_space_width(environment *env)
 
 hunits env_sentence_space_width(environment *env)
 {
-  int fn = env_resolve_font(env);
+  int fn = resolve_current_font_to_mounting_position(env);
   font_size fs = env->get_font_size();
   units sss = env->get_sentence_space_size();
   if (!is_valid_font_mounting_position(fn))
@@ -7258,7 +7261,7 @@ hunits env_sentence_space_width(environment *env)
 
 hunits env_half_narrow_space_width(environment *env)
 {
-  int fn = env_resolve_font(env);
+  int fn = resolve_current_font_to_mounting_position(env);
   font_size fs = env->get_font_size();
   if (!is_valid_font_mounting_position(fn))
     return H0;
@@ -7268,7 +7271,7 @@ hunits env_half_narrow_space_width(environment *env)
 
 hunits env_narrow_space_width(environment *env)
 {
-  int fn = env_resolve_font(env);
+  int fn = resolve_current_font_to_mounting_position(env);
   font_size fs = env->get_font_size();
   if (!is_valid_font_mounting_position(fn))
     return H0;
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index 726684d7d..051b62e78 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -754,6 +754,7 @@ public:
   static void invalidate_fontno(int);
 };
 
+extern int resolve_current_font_to_mounting_position(environment *);
 font_family *lookup_family(symbol);
 symbol get_font_name(int, environment *);
 symbol get_style_name(int);

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to