gbranden pushed a commit to branch master
in repository groff.

commit 0a75fc20b1e1ca8e9c6c6c867cdd2417af65029e
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Jun 3 05:27:05 2025 -0500

    [troff]: Refactor.
    
    ...moving font selection logic into a dedicated function (so that the
    `\f` escape handler can also use it).
    
    * src/roff/troff/env.h: Give new `select_font()` function external
      linkage.
    
    * src/roff/troff/env.cpp (select_font_request): Move bulk of logic from
      here...
      (select_font): ...to here.  Also recognize an empty symbol, in
      addition to a null one, as equivalent to `.ft P`, to accommodate what
      the `\f` escape sequence handler will pass as an argument.
---
 ChangeLog              | 13 +++++++++++++
 src/roff/troff/env.cpp | 13 +++++++++----
 src/roff/troff/env.h   |  1 +
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e46d77f0d..3593c9b42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2025-06-03  G. Branden Robinson <[email protected]>
+
+       [troff]: Refactor, moving font selection logic into a dedicated
+       function (so that the `\f` escape handler can also use it).
+
+       * src/roff/troff/env.h: Give new `select_font()` function
+       external linkage.
+       * src/roff/troff/env.cpp (select_font_request): Move bulk of
+       logic from here...
+       (select_font): ...to here.  Also recognize an empty symbol, in
+       addition to a null one, as equivalent to `.ft P`, to accommodate
+       what the `\f` escape sequence handler will pass as an argument.
+
 2025-06-03  G. Branden Robinson <[email protected]>
 
        [troff]: Trivially refactor, continuing reform of functions that
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 90f1697b4..5f607c6aa 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1273,11 +1273,11 @@ void stroke_color_change()
 
 static symbol P_symbol("P");
 
-static void select_font_request()
+// Select font with name or mounting position `s`.
+void select_font(symbol s)
 {
-  symbol s = get_name();
   bool is_number = true;
-  if (s.is_null())
+  if (s.is_null() || s.is_empty())
     s = P_symbol;
   if (s == P_symbol)
     is_number = false;
@@ -1292,7 +1292,7 @@ static void select_font_request()
        break;
       }
   }
-  // environment::set_font warns if a bogus mounting position is
+  // environment::set_font warns if an unused mounting position is
   // requested.  We must warn here if a bogus font name is selected.
   if (is_number) {
     errno = 0;
@@ -1309,6 +1309,11 @@ static void select_font_request()
     else if (!curenv->set_font(s))
       warning(WARN_FONT, "cannot select font '%1'", s.contents());
   }
+}
+
+static void select_font_request()
+{
+  select_font(get_name());
   skip_line();
 }
 
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index aea185561..9d9797134 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -423,6 +423,7 @@ extern environment *curenv;
 extern void pop_env();
 extern void push_env(int);
 
+void select_font(symbol);
 void init_environments();
 
 extern double spread_limit;

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

Reply via email to