groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] unicode support, part 7: cleanup glyph to name/number API


From: Bruno Haible
Subject: [Groff] unicode support, part 7: cleanup glyph to name/number API
Date: Wed, 15 Feb 2006 13:23:45 +0100
User-agent: KMail/1.5

Hi,

Now the glyph API is in good shape. This patch
  - fixes the naming, mentioning "glyph" instead of "index",
  - moves the 4 static functions that create and analyze glyphs out of the
    class 'font'. They semantically belong to the class glyph; the class
    'font' is built on top of it.

2006-02-15  Bruno Haible  <address@hidden>

        * src/include/font.h (name_to_glyph): Renamed from font::name_to_index.
        (number_to_glyph): Renamed from font::number_to_index.
        (glyph_to_name): Renamed from font::index_to_name.
        (glyph_to_number): Renamed from font::index_to_number.
        * src/libs/libgroff/nametoindex.cpp: Likewise.
        * src/roff/troff/charinfo.h (charinfo::as_glyph): Renamed from
        charinfo::get_index.
        * src/roff/troff/input.cpp: All callers changed.
        * src/roff/troff/node.cpp: Likewise.
        * src/libs/libgroff/font.cpp: Likewise.
        * src/devices/grops/ps.cpp: Likewise.
        * src/devices/grohtml/post-html.cpp: Likewise.
        * src/libs/libdriver/printer.cpp: Likewise.

diff -r -c3 groff-20060213.orig/src/devices/grohtml/post-html.cpp 
groff-20060213/src/devices/grohtml/post-html.cpp
--- groff-20060213.orig/src/devices/grohtml/post-html.cpp       2006-02-13 
13:00:19.000000000 +0100
+++ groff-20060213/src/devices/grohtml/post-html.cpp    2006-02-15 
03:06:59.000000000 +0100
@@ -1417,7 +1417,7 @@
        if (html_glyph)
          html_string += html_glyph;
        else {
-         glyph g = s->f->name_to_index((troff_charname + '\0').contents());
+         glyph g = name_to_glyph((troff_charname + '\0').contents());
          if (s->f->contains(g))
            html_string += s->f->get_code(g);
        }
@@ -4220,7 +4220,7 @@
   }
   res               = r;
   html.set_fixed_point(point);
-  space_glyph       = font::name_to_index("space");
+  space_glyph       = name_to_glyph("space");
   space_width       = font::hor;
   paper_length      = font::paperlength;
   linelength        = font::res*13/2;
@@ -4302,7 +4302,7 @@
   if ((f == 0) || name.empty())
     return NULL;
   else {
-    glyph g = f->name_to_index((char *)(name + '\0').contents());
+    glyph g = name_to_glyph((char *)(name + '\0').contents());
     if (f->contains(g))
       return get_html_entity(f->get_code(g));
     else
@@ -4650,7 +4650,7 @@
     nbsp_width = -num;
     num = 160;         // &nbsp;
   }
-  glyph g = font::number_to_index(num);
+  glyph g = number_to_glyph(num);
   int fn = env->fontno;
   if (fn < 0 || fn >= nfonts) {
     error("bad font position `%1'", fn);
@@ -4681,7 +4681,7 @@
 glyph html_printer::set_char_and_width(const char *nm, const environment *env,
                                       int *widthp, font **f)
 {
-  glyph g = font::name_to_index(nm);
+  glyph g = name_to_glyph(nm);
   int fn = env->fontno;
   if (fn < 0 || fn >= nfonts) {
     error("bad font position `%1'", fn);
diff -r -c3 groff-20060213.orig/src/devices/grops/ps.cpp 
groff-20060213/src/devices/grops/ps.cpp
--- groff-20060213.orig/src/devices/grops/ps.cpp        2006-02-13 
13:00:19.000000000 +0100
+++ groff-20060213/src/devices/grops/ps.cpp     2006-02-15 03:04:40.000000000 
+0100
@@ -630,7 +630,7 @@
   }
   res = r;
   out.set_fixed_point(point);
-  space_glyph = font::name_to_index("space");
+  space_glyph = name_to_glyph("space");
   if (pl == 0)
     paper_length = font::paperlength;
   else
diff -r -c3 groff-20060213.orig/src/include/font.h 
groff-20060213/src/include/font.h
--- groff-20060213.orig/src/include/font.h      2006-02-15 02:44:49.000000000 
+0100
+++ groff-20060213/src/include/font.h   2006-02-15 03:14:23.000000000 +0100
@@ -27,8 +27,7 @@
                                     int);              // lineno
 
 // A glyph is represented by a font-independent `glyph' object.
-// The functions font::name_to_index and font::number_to_index return such
-// an object.
+// The functions name_to_glyph and number_to_glyph return such an object.
 //
 // There are two types of glyphs:
 //
@@ -52,7 +52,6 @@
 struct glyph {
 private:
   glyphinfo *ptr;      // Pointer to the complete information.
-  friend class font;
   friend class character_indexer;
   friend class charinfo;
   glyph(glyphinfo *);  // Glyph with given complete information.
@@ -103,6 +102,37 @@
   return ptr != other.ptr;
 }
 
+// The next two functions and glyph::glyph_name() exist in two versions: one in
+// roff/troff/input.cpp for troff, and one in
+// libs/libgroff/nametoindex.cpp for the preprocessors and the
+// postprocessors.
+extern glyph name_to_glyph(const char *);      // Convert the glyph with
+                       // the given name (arg1) to a `glyph' object.  This
+                       // has the same semantics as the groff escape sequence
+                       // \C'name'.  If such a `glyph' object does not yet
+                       // exist, a new one is allocated.
+extern glyph number_to_glyph(int);     // Convert the font-dependent glyph
+                       // with the given number (in the font) to a `glyph'
+                       // object.  This has the same semantics as the groff
+                       // escape sequence \N'number'.  If such a `glyph'
+                       // object does not yet exist, a new one is allocated.
+inline const char *glyph_to_name(glyph);       // Convert the given glyph
+                       // back to its name.  Return NULL if the glyph
+                       // doesn't have a name.
+inline int glyph_to_number(glyph);     // Convert the given glyph back to
+                       // its number.  Return -1 if it does not designate
+                       // a numbered character.
+
+inline const char *glyph_to_name(glyph g)
+{
+  return g.glyph_name();
+}
+
+inline int glyph_to_number(glyph g)
+{
+  return g.glyph_number();
+}
+
 // Types used in non-public members of `class font'.
 struct font_kern_list;
 struct font_char_metric;
@@ -239,27 +269,6 @@
                        // device) and initialize some static variables with
                        // info from there.
 
-  // The next two functions exist in two versions: one in
-  // roff/troff/input.cpp for troff, and one in
-  // libs/libgroff/nametoindex.cpp for the preprocessors and the
-  // postprocessors.
-  static glyph name_to_index(const char *);    // Convert the glyph with
-                       // the given name (arg1) to a `glyph' object.  This
-                       // has the same semantics as the groff escape sequence
-                       // \C'name'.  If such a `glyph' object does not yet
-                       // exist, a new one is allocated.
-  static glyph number_to_index(int);   // Convert the font-dependent glyph
-                       // with the given number (in the font) to a `glyph'
-                       // object.  This has the same semantics as the groff
-                       // escape sequence \N'number'.  If such a `glyph'
-                       // object does not yet exist, a new one is allocated.
-  static const char *index_to_name(glyph);     // Convert the given glyph
-                       // back to its name.  Return NULL if the glyph
-                       // doesn't have a name.
-  static int index_to_number(glyph);   // Convert the given glyph back to
-                       // its number.  Return -1 if it does not designate
-                       // a numbered character.
-
   static FONT_COMMAND_HANDLER
     set_unknown_desc_command_handler(FONT_COMMAND_HANDLER);    // Register
                        // a function which defines the semantics of
@@ -373,14 +382,4 @@
                        // case of failure.
 };
 
-inline const char *font::index_to_name(glyph g)
-{
-  return g.glyph_name();
-}
-
-inline int font::index_to_number(glyph g)
-{
-  return g.glyph_number();
-}
-
 // end of font.h
diff -r -c3 groff-20060213.orig/src/libs/libdriver/printer.cpp 
groff-20060213/src/libs/libdriver/printer.cpp
--- groff-20060213.orig/src/libs/libdriver/printer.cpp  2006-02-13 
13:00:19.000000000 +0100
+++ groff-20060213/src/libs/libdriver/printer.cpp       2006-02-15 
03:06:59.000000000 +0100
@@ -205,7 +205,7 @@
 glyph printer::set_char_and_width(const char *nm, const environment *env,
                                  int *widthp, font **f)
 {
-  glyph g = font::name_to_index(nm);
+  glyph g = name_to_glyph(nm);
   int fn = env->fontno;
   if (fn < 0 || fn >= nfonts) {
     error("bad font position `%1'", fn);
@@ -235,7 +235,7 @@
 
 void printer::set_numbered_char(int num, const environment *env, int *widthp)
 {
-  glyph g = font::number_to_index(num);
+  glyph g = number_to_glyph(num);
   int fn = env->fontno;
   if (fn < 0 || fn >= nfonts) {
     error("bad font position `%1'", fn);
diff -r -c3 groff-20060213.orig/src/libs/libgroff/font.cpp 
groff-20060213/src/libs/libgroff/font.cpp
--- groff-20060213.orig/src/libs/libgroff/font.cpp      2006-02-13 
13:00:19.000000000 +0100
+++ groff-20060213/src/libs/libgroff/font.cpp   2006-02-15 03:06:59.000000000 
+0100
@@ -693,8 +693,8 @@
          t.error("bad kern amount `%1'", p);
          return 0;
        }
-       glyph g1 = name_to_index(c1);
-       glyph g2 = name_to_index(c2);
+       glyph g1 = name_to_glyph(c1);
+       glyph g2 = name_to_glyph(c2);
        add_kern(g1, g2, n);
       }
     }
@@ -724,7 +724,7 @@
            t.error("unnamed character cannot be duplicate");
            return 0;
          }
-         glyph g = name_to_index(nm);
+         glyph g = name_to_glyph(nm);
          copy_entry(g, last_glyph);
        }
        else {
@@ -779,13 +779,13 @@
            metric.special_device_coding = nam;
          }
          if (strcmp(nm, "---") == 0) {
-           last_glyph = number_to_index(metric.code);
+           last_glyph = number_to_glyph(metric.code);
            add_entry(last_glyph, metric);
          }
          else {
-           last_glyph = name_to_index(nm);
+           last_glyph = name_to_glyph(nm);
            add_entry(last_glyph, metric);
-           copy_entry(number_to_index(metric.code), last_glyph);
+           copy_entry(number_to_glyph(metric.code), last_glyph);
          }
          got_last_glyph = 1;
        }
diff -r -c3 groff-20060213.orig/src/libs/libgroff/nametoindex.cpp 
groff-20060213/src/libs/libgroff/nametoindex.cpp
--- groff-20060213.orig/src/libs/libgroff/nametoindex.cpp       2006-02-15 
02:44:49.000000000 +0100
+++ groff-20060213/src/libs/libgroff/nametoindex.cpp    2006-02-15 
03:06:59.000000000 +0100
@@ -127,12 +127,12 @@
 
 static character_indexer indexer;
 
-glyph font::number_to_index(int n)
+glyph number_to_glyph(int n)
 {
   return indexer.numbered_char_index(n);
 }
 
-glyph font::name_to_index(const char *s)
+glyph name_to_glyph(const char *s)
 {
   assert(s != 0 && s[0] != '\0' && s[0] != ' ');
   if (s[1] == '\0')
diff -r -c3 groff-20060213.orig/src/roff/troff/charinfo.h 
groff-20060213/src/roff/troff/charinfo.h
--- groff-20060213.orig/src/roff/troff/charinfo.h       2006-02-15 
02:44:49.000000000 +0100
+++ groff-20060213/src/roff/troff/charinfo.h    2006-02-15 03:12:56.000000000 
+0100
@@ -55,7 +55,7 @@
   };
   symbol nm;
   charinfo(symbol s);
-  glyph get_index();
+  glyph as_glyph();
   int ends_sentence();
   int overlaps_vertically();
   int overlaps_horizontally();
@@ -169,7 +169,7 @@
   flags = c;
 }
 
-inline glyph charinfo::get_index()
+inline glyph charinfo::as_glyph()
 {
   return glyph(this);
 }
diff -r -c3 groff-20060213.orig/src/roff/troff/input.cpp 
groff-20060213/src/roff/troff/input.cpp
--- groff-20060213.orig/src/roff/troff/input.cpp        2006-02-15 
02:44:49.000000000 +0100
+++ groff-20060213/src/roff/troff/input.cpp     2006-02-15 03:12:56.000000000 
+0100
@@ -8195,7 +8195,7 @@
   }
 }
 
-glyph font::name_to_index(const char *nm)
+glyph name_to_glyph(const char *nm)
 {
   charinfo *ci;
   if (nm[1] == 0)
@@ -8204,15 +8204,12 @@
     ci = get_charinfo(symbol(nm + 1));
   else
     ci = get_charinfo(symbol(nm));
-  if (ci == 0)
-    abort();
-  else
-    return ci->get_index();
+  return ci->as_glyph();
 }
 
-glyph font::number_to_index(int n)
+glyph number_to_glyph(int n)
 {
-  return get_charinfo_by_number(n)->get_index();
+  return get_charinfo_by_number(n)->as_glyph();
 }
 
 const char *glyph::glyph_name()
diff -r -c3 groff-20060213.orig/src/roff/troff/node.cpp 
groff-20060213/src/roff/troff/node.cpp
--- groff-20060213.orig/src/roff/troff/node.cpp 2006-02-13 13:00:20.000000000 
+0100
+++ groff-20060213/src/roff/troff/node.cpp      2006-02-15 03:15:22.000000000 
+0100
@@ -234,7 +234,7 @@
 
 inline int font_info::contains(charinfo *ci)
 {
-  return fm != 0 && fm->contains(ci->get_index());
+  return fm != 0 && fm->contains(ci->as_glyph());
 }
 
 inline int font_info::is_special()
@@ -431,8 +431,8 @@
 hunits font_info::get_narrow_space_width(font_size fs)
 {
   charinfo *ci = get_charinfo(symbol("|"));
-  if (fm->contains(ci->get_index()))
-    return hunits(fm->get_width(ci->get_index(), fs.to_scaled_points()));
+  if (fm->contains(ci->as_glyph()))
+    return hunits(fm->get_width(ci->as_glyph(), fs.to_scaled_points()));
   else
     return hunits(fs.to_units()/6);
 }
@@ -440,8 +440,8 @@
 hunits font_info::get_half_narrow_space_width(font_size fs)
 {
   charinfo *ci = get_charinfo(symbol("^"));
-  if (fm->contains(ci->get_index()))
-    return hunits(fm->get_width(ci->get_index(), fs.to_scaled_points()));
+  if (fm->contains(ci->as_glyph()))
+    return hunits(fm->get_width(ci->as_glyph(), fs.to_scaled_points()));
   else
     return hunits(fs.to_units()/12);
 }
@@ -491,16 +491,16 @@
   if (is_constant_spaced)
     return constant_space_width;
   else if (is_bold)
-    return (hunits(fm->get_width(c->get_index(), size.to_scaled_points()))
+    return (hunits(fm->get_width(c->as_glyph(), size.to_scaled_points()))
            + track_kern + bold_offset);
   else
-    return (hunits(fm->get_width(c->get_index(), size.to_scaled_points()))
+    return (hunits(fm->get_width(c->as_glyph(), size.to_scaled_points()))
            + track_kern);
 }
 
 vunits tfont::get_char_height(charinfo *c)
 {
-  vunits v = fm->get_height(c->get_index(), size.to_scaled_points());
+  vunits v = fm->get_height(c->as_glyph(), size.to_scaled_points());
   if (height != 0 && height != size.to_scaled_points())
     return scale(v, height, size.to_scaled_points());
   else
@@ -509,7 +509,7 @@
 
 vunits tfont::get_char_depth(charinfo *c)
 {
-  vunits v = fm->get_depth(c->get_index(), size.to_scaled_points());
+  vunits v = fm->get_depth(c->as_glyph(), size.to_scaled_points());
   if (height != 0 && height != size.to_scaled_points())
     return scale(v, height, size.to_scaled_points());
   else
@@ -518,23 +518,23 @@
 
 hunits tfont::get_char_skew(charinfo *c)
 {
-  return hunits(fm->get_skew(c->get_index(), size.to_scaled_points(), slant));
+  return hunits(fm->get_skew(c->as_glyph(), size.to_scaled_points(), slant));
 }
 
 hunits tfont::get_italic_correction(charinfo *c)
 {
-  return hunits(fm->get_italic_correction(c->get_index(), 
size.to_scaled_points()));
+  return hunits(fm->get_italic_correction(c->as_glyph(), 
size.to_scaled_points()));
 }
 
 hunits tfont::get_left_italic_correction(charinfo *c)
 {
-  return hunits(fm->get_left_italic_correction(c->get_index(),
+  return hunits(fm->get_left_italic_correction(c->as_glyph(),
                                               size.to_scaled_points()));
 }
 
 hunits tfont::get_subscript_correction(charinfo *c)
 {
-  return hunits(fm->get_subscript_correction(c->get_index(),
+  return hunits(fm->get_subscript_correction(c->as_glyph(),
                                             size.to_scaled_points()));
 }
 
@@ -545,12 +545,12 @@
 
 inline int tfont::contains(charinfo *ci)
 {
-  return fm->contains(ci->get_index());
+  return fm->contains(ci->as_glyph());
 }
 
 inline int tfont::get_character_type(charinfo *ci)
 {
-  return fm->get_character_type(ci->get_index());
+  return fm->get_character_type(ci->as_glyph());
 }
 
 inline int tfont::get_bold(hunits *res)
@@ -642,7 +642,7 @@
       break;
     }
   }
-  if (ci != 0 && fm->contains(ci->get_index()))
+  if (ci != 0 && fm->contains(ci->as_glyph()))
     return ci;
   return 0;
 }
@@ -652,8 +652,8 @@
   if (kern_mode == 0)
     return 0;
   else {
-    int n = fm->get_kern(c1->get_index(),
-                        c2->get_index(),
+    int n = fm->get_kern(c1->as_glyph(),
+                        c2->as_glyph(),
                         size.to_scaled_points());
     if (n) {
       *res = hunits(n);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]