gbranden pushed a commit to branch master
in repository groff.

commit 93bb2ee9c7d295b6ef2cb9b155b02cfb6258af64
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Jun 4 05:12:36 2025 -0500

    [libgroff]: Trivially refactor `font` class.
    
    ...for clarity.  Fonts have up to three names in groff: (1) a font
    description file name; (2) a GNU troff identifier used for its selection
    [and often, but not necessarily, the same as (1); see the `fp` request];
    (3) an "internalname" that serves multiple purposes-- for some output
    drivers, it's a file name of an actual digital font file, and for
    others, it's an integer that encodes styling properties.  [Item (3)
    screams for further refactoring.]  It's important to know which of these
    names we're dealing with, so eliminate the unqualified term "name" in
    the API.
    
    * src/include/font.h (class font): Rename public member function
      `get_name()` to `get_filename()`.  Rename private member variable
      `name` to `filename`.
    
    * src/libs/libgroff/font.cpp (font::font): Rename constructor argument
      from `s` to `fn`.
    
      (font::~font): Delete `filename`, not `name`.
    
      (font::get_name): Rename this...
      (font::get_filename): ...to this.
    
      (font::load_font): Rename `s` argument to `fn`.
    
      (font::get_filename, font::load): Track rename of member variable.
    
    * src/libs/libdriver/printer.cpp (printer::find_font)
      (printer::set_char_and_width, printer::set_numbered_char):
    * src/devices/grohtml/post-html.cpp (html_printer::set_style)
      (html_printer::is_bold, html_printer::make_bold)
      (html_printer::is_font_courier, html_printer::do_font)
      (html_printer::set_numbered_char)
      (html_printer::set_char_and_width)
    * src/devices/grops/ps.cpp (ps_printer::set_style): Update call sites.
---
 ChangeLog                         | 35 +++++++++++++++++++++++++++++++++++
 src/devices/grohtml/post-html.cpp | 24 ++++++++++++------------
 src/devices/grops/ps.cpp          |  2 +-
 src/include/font.h                |  7 ++++---
 src/libs/libdriver/printer.cpp    |  8 ++++----
 src/libs/libgroff/font.cpp        | 22 +++++++++++-----------
 6 files changed, 67 insertions(+), 31 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 231af72c1..1231564e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,38 @@
+2025-06-04  G. Branden Robinson <[email protected]>
+
+       [libgroff]: Trivially refactor `font` class for clarity.  Fonts
+       have up to three names in groff: (1) a font description file
+       name; (2) a GNU troff identifier used for its selection [and
+       often, but not necessarily, the same as (1); see the `fp`
+       request]; (3) an "internalname" that serves multiple purposes--
+       for some output drivers, it's a file name of an actual digital
+       font file, and for others, it's an integer that encodes styling
+       properties.  [Item (3) screams for further refactoring.]  It's
+       important to know which of these names we're dealing with, so
+       eliminate the unqualified term "name" in the API.
+
+       * src/include/font.h (class font): Rename public member function
+       `get_name()` to `get_filename()`.  Rename private member
+       variable `name` to `filename`.
+       * src/libs/libgroff/font.cpp
+       (font::font): Rename constructor argument from `s` to `fn`.
+       (font::~font): Delete `filename`, not `name`.
+       (font::get_name): Rename this...
+       (font::get_filename): ...to this.
+       (font::load_font): Rename `s` argument to `fn`.
+       (font::get_filename, font::load): Track rename of member
+       variable.
+
+       * src/libs/libdriver/printer.cpp (printer::find_font)
+       (printer::set_char_and_width, printer::set_numbered_char):
+       * src/devices/grohtml/post-html.cpp (html_printer::set_style)
+       (html_printer::is_bold, html_printer::make_bold)
+       (html_printer::is_font_courier, html_printer::do_font)
+       (html_printer::set_numbered_char)
+       (html_printer::set_char_and_width)
+       * src/devices/grops/ps.cpp (ps_printer::set_style): Update call
+       sites.
+
 2025-06-04  G. Branden Robinson <[email protected]>
 
        * src/libs/libdriver/printer.cpp: Fix code style nits.
diff --git a/src/devices/grohtml/post-html.cpp 
b/src/devices/grohtml/post-html.cpp
index d3d4f4256..e59a987ac 100644
--- a/src/devices/grohtml/post-html.cpp
+++ b/src/devices/grohtml/post-html.cpp
@@ -2206,7 +2206,7 @@ static void usage(FILE *stream);
 
 void html_printer::set_style(const style &sty)
 {
-  const char *fontname = sty.f->get_name();
+  const char *fontname = sty.f->get_filename();
   if (0 /* nullptr */ == fontname)
     fatal("no internalname specified for font");
 
@@ -2222,7 +2222,7 @@ void html_printer::set_style(const style &sty)
 
 int html_printer::is_bold (font *f)
 {
-  const char *fontname = f->get_name();
+  const char *fontname = f->get_filename();
   return (strcmp(fontname, "B") == 0) || (strcmp(fontname, "BI") == 0);
 }
 
@@ -2232,7 +2232,7 @@ int html_printer::is_bold (font *f)
 
 font *html_printer::make_bold (font *f)
 {
-  const char *fontname = f->get_name();
+  const char *fontname = f->get_filename();
 
   if (strcmp(fontname, "B") == 0)
     return f;
@@ -2240,7 +2240,7 @@ font *html_printer::make_bold (font *f)
     return font::load_font("BI");
   if (strcmp(fontname, "BI") == 0)
     return f;
-  return 0;
+  return 0 /* nullptr */;
 }
 
 void html_printer::end_of_line()
@@ -3989,10 +3989,10 @@ int html_printer::is_line_start (int nf)
 
 int html_printer::is_font_courier (font *f)
 {
-  if (f != 0) {
-    const char *fontname = f->get_name();
+  if (f != 0 /* nullptr */) {
+    const char *fontname = f->get_filename();
 
-    return( (fontname != 0) && (fontname[0] == 'C') );
+    return((fontname != 0 /* nullptr */) && (fontname[0] == 'C'));
   }
   return FALSE;
 }
@@ -4112,11 +4112,11 @@ void html_printer::do_font (text_glob *g)
 
   if (g->text_style.f != output_style.f) {
     if (output_style.f != 0) {
-      end_font(output_style.f->get_name());
+      end_font(output_style.f->get_filename());
     }
     output_style.f = g->text_style.f;
     if (output_style.f != 0) {
-      start_font(output_style.f->get_name());
+      start_font(output_style.f->get_filename());
     }
   }
   if (output_style.point_size != g->text_style.point_size) {
@@ -4868,7 +4868,7 @@ void html_printer::set_numbered_char(int num, const 
environment *env,
     return;
   }
   if (!f->contains(g)) {
-    error("font '%1' has no glyph at index %2", f->get_name(), num);
+    error("font '%1' has no glyph at index %2", f->get_filename(), num);
     return;
   }
   int w;
@@ -4900,10 +4900,10 @@ glyph *html_printer::set_char_and_width(const char *nm,
   if (!(*f)->contains(g)) {
     if ((nm[0] != '\0') && ('\0' == nm[1]))
       error("font '%1' does not contain ordinary character '%2'",
-           (*f)->get_name(), nm[0]);
+           (*f)->get_filename(), nm[0]);
     else
       error("font '%1' does not contain special character '%2'",
-           (*f)->get_name(), nm);
+           (*f)->get_filename(), nm);
     return UNDEFINED_GLYPH;
   }
   int w = (*f)->get_width(g, env->size);
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index 68d27186f..3c4e221cb 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -947,7 +947,7 @@ void ps_printer::set_style(const style &sty)
   const char *psname = sty.f->get_internal_name();
   if (0 /* nullptr */ == psname)
     fatal("no 'internalname' specified for font '%1'",
-         sty.f->get_name());
+         sty.f->get_filename());
   char *encoding = ((ps_font *)sty.f)->encoding;
   if (sty.sub == 0) {
     if (encoding != 0 /* nullptr */) {
diff --git a/src/include/font.h b/src/include/font.h
index 575ea3aef..9bcf933f0 100644
--- a/src/include/font.h
+++ b/src/include/font.h
@@ -189,7 +189,8 @@ public:
                        // special device-dependent information about
                        // the given glyph.  Return null pointer if
                        // there is no special information.
-  const char *get_name();      // Return the name of this font.
+  const char *get_filename();  // Return file name containing font
+                       // description.
   const char *get_internal_name();     // Return the 'internalname'
                        // attribute of this font or null pointer if it
                        // has none.
@@ -284,7 +285,7 @@ private:
   int space_width;     // The normal width of a space.  Used by
                        // get_space_width().
   bool special;                // See public is_special() above.
-  char *name;          // The name of this font.  Used by get_name().
+  char *filename;      // File name of font description.
   char *internalname;  // The 'internalname' attribute of this font, or
                        // a null pointer.  Used by get_internal_name().
   double slant;                // The natural slant angle (in degrees) of this 
font.
@@ -341,7 +342,7 @@ private:
   font_char_metric *get_font_wchar_metric(int);
 
 protected:
-  font(const char *);  // Initialize a font with the given name.
+  font(const char *);  // Load font description from file name.
 
   // Load the font description file with the name in member variable
   // `name` into this object.  If arg1 is true, only the part of the
diff --git a/src/libs/libdriver/printer.cpp b/src/libs/libdriver/printer.cpp
index 171a8a9b5..dde12d093 100644
--- a/src/libs/libdriver/printer.cpp
+++ b/src/libs/libdriver/printer.cpp
@@ -135,7 +135,7 @@ void printer::load_font(int n, const char *nm)
 font *printer::find_font(const char *nm)
 {
   for (font_pointer_list *p = font_list; p; p = p->next)
-    if (strcmp(p->p->get_name(), nm) == 0)
+    if (strcmp(p->p->get_filename(), nm) == 0)
       return p->p;
   font *f = make_font(nm);
   if (0 /* nullptr */ == f)
@@ -223,10 +223,10 @@ glyph *printer::set_char_and_width(const char *nm,
   if (!(*f)->contains(g)) {
     if ((nm[0] != '\0') && ('\0' == nm[1]))
       error("font '%1' does not contain ordinary character '%2'",
-           (*f)->get_name(), nm[0]);
+           (*f)->get_filename(), nm[0]);
     else
       error("font '%1' does not contain special character '%2'",
-           (*f)->get_name(), nm);
+           (*f)->get_filename(), nm);
     return UNDEFINED_GLYPH;
   }
   int w = (*f)->get_width(g, env->size);
@@ -250,7 +250,7 @@ void printer::set_numbered_char(int num, const environment 
*env, int
     return;
   }
   if (!f->contains(g)) {
-    error("font '%1' has no glyph at index %2", f->get_name(), num);
+    error("font '%1' has no glyph at index %2", f->get_filename(), num);
     return;
   }
   int w = f->get_width(g, env->size);
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index 1be3bf625..c0d428963 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -226,15 +226,15 @@ int glyph_to_unicode(glyph *g)
 
 /* font functions */
 
-font::font(const char *s) : ligatures(0),
+font::font(const char *fn) : ligatures(0),
   kern_hash_table(0 /* nullptr */),
   space_width(0), special(false), internalname(0 /* nullptr */),
   slant(0.0), zoom(0), ch_index(0 /* nullptr */), nindices(0),
   ch(0 /* nullptr */), wch(0 /* nullptr */), ch_used(0), ch_size(0),
   widths_cache(0 /* nullptr */)
 {
-  name = new char[strlen(s) + 1];
-  strcpy(name, s);
+  filename = new char[strlen(fn) + 1];
+  strcpy(filename, fn);
 }
 
 font::~font()
@@ -255,7 +255,7 @@ font::~font()
     }
     delete[] kern_hash_table;
   }
-  delete[] name;
+  delete[] filename;
   delete[] internalname;
   while (widths_cache) {
     font_widths_cache *tem = widths_cache;
@@ -690,9 +690,9 @@ int font::get_code(glyph *g)
   abort(); // -Wreturn-type
 }
 
-const char *font::get_name()
+const char *font::get_filename()
 {
-  return name;
+  return filename;
 }
 
 const char *font::get_internal_name()
@@ -812,9 +812,9 @@ void font::copy_entry(glyph *new_glyph, glyph *old_glyph)
   ch_index[new_index] = ch_index[old_index];
 }
 
-font *font::load_font(const char *s, bool load_header_only)
+font *font::load_font(const char *fn, bool load_header_only)
 {
-  font *f = new font(s);
+  font *f = new font(fn);
   if (!f->load(load_header_only)) {
     delete f;
     return 0 /* nullptr */;
@@ -892,7 +892,7 @@ again:
 bool font::load(bool load_header_only)
 {
   char *path;
-  FILE *fp = open_file(name, &path);
+  FILE *fp = open_file(filename, &path);
   if (0 /* nullptr */ == fp)
     return false;
   text_file t(fp, path);
@@ -907,9 +907,9 @@ bool font::load(bool load_header_only)
        t.error("'name' directive requires an argument");
        return false;
       }
-      if (strcmp(p, name) != 0) {
+      if (strcmp(p, filename) != 0) {
        t.error("font description file name '%1' does not match 'name'"
-               " argument '%2'", name, p);
+               " argument '%2'", filename, p);
        return false;
       }
       saw_name_directive = true;

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

Reply via email to