bugGNU roff - Bugs: bug #65619, [afmtodit] want a default value...

 
 

bug #65619: [afmtodit] want a default value for space width if unspecified

Submitter:  Alejandro Colomar <alx>
Submitted:  Sun 21 Apr 2024 09:24:09 AM UTC
   
 
Category:  Utilities Severity:  1 - Wish
Item Group:  Feature change Status:  Need Info
Privacy:  Public Assigned to:  deri
Open/Closed:  Open Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 04 May 2024 04:54:42 AM UTC, comment #5: 

comment #3:

> A useful change to afmtodit would be to look for other space glyphs in the font (u0020 and u00A0) if space is not found, then if none are found, use the value given on the command line, and if that is missing, it is not a special font, warn user the font will be unusable in groff and suggest they rerun afmtodit with a suitable -w flag.


This proposal sounds good to me.  Normally, I think the Unix command-line model treats options as overrides rather than fallbacks.  But sometimes you need the latter.  Sometimes you need both (witness preconv).

So, check for "space", "uni0020", and "uni00A0" in that order?

Hmm, that may be too simple.

There are over 100 matches for "space" in the Adobe Glyph List.

Leaving aside "monospace" names for A-Z, a-z, 0-9, and some other stuff.  I was going to guess the 94 graphical code points, but I see fun stuff like this too.

sterlingmonospace;FFE1

That ain't ASCII.  That ain't ASCII a 'tall.

But with respect to (non-zero-width) spaces, I see:

ideographicspace;3000
nbspace;00A0

There may be others, not sure I got 'em all.

Here's a fun one:

spacehackarabic;0020

NFI if we should deal with that one.

Advice desired.

G. Branden Robinson <gbranden>
Group administrator
Thu 02 May 2024 04:24:02 PM UTC, comment #4: 

Reopening since comment #3 raises an objection to -w's current behavior and suggests a "useful change to afmtodit," which based on comment #1 would solve the problem Alex is seeing.

It's not clear (to me), though, how the below case should be handled, or if this is the proper use case for -w:

comment #1:

> Other CJK fonts have proportional western glyphs and fixed width
> CJK, with no space glyph defined, this is when afmtodit fails to
> write a spacewidth parameter. See font TakaoPGothic as an example).

Dave <barx>
Group Member
Thu 02 May 2024 09:54:36 AM UTC, comment #3: 

Afmtodit has always used the width of the space glyph (if defined in the font), what your change did was enable this to be overridden on the command line, which is probably wrong. If the intention was to provide a fallback value when a spacewidth was not present, the logic could have been written that way.

A useful change to afmtodit would be to look for other space glyphs in the font (u0020 and u00A0) if space is not found, then if none are found, use the value given on the command line, and if that is missing, it is not a special font, warn user the font will be unusable in groff and suggest they rerun afmtodit with a suitable -w flag.

This was Branden's change:-

+my $sw = 0;
+$sw = conv($width{"space"}) if defined $width{"space"};
+$sw = $space_width if ($space_width);
+
 print("name $name\n");
 print("internalname $psname\n") if $psname;
 print("special\n") if $opt_s;
 printf("slant %g\n", $italic_angle) if $italic_angle != 0;
-printf("spacewidth %d\n", conv($width{"space"})) if defined $width{"space"};
+printf("spacewidth %d\n", $sw) if $sw;


Deri James <deri>
Group Member
Wed 01 May 2024 10:50:07 PM UTC, comment #2: 

Looks like Deri's right.

Lines 28-37 and 485-487 seem to do this work.

https://git.savannah.gnu.org/cgit/groff.git/tree/src/utils/afmtodit/afmtodit.pl?h=1.23.0#n28
https://git.savannah.gnu.org/cgit/groff.git/tree/src/utils/afmtodit/afmtodit.pl?h=1.23.0#n485

Closing as invalid; the desired behavior is already present in groff 1.23.0, and in fact it looks like I'm the one who implemented it, back in November 2022, though I have no recollection of putting in the logic to deduce it from the hash first.


commit 5a5a447b2a834f92112609a67821c1a37fdc66cd
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Fri Nov 11 15:49:24 2022 -0600

    [afmtodit]: Implement "-w" command-line option.

    * src/utils/afmtodit/afmtodit.pl: Add new command-line option to specify
      the generated font description's "spacewidth" parameter; in commit
      bf7f6862c3, 2021-09-24, I made libgroff complain if this directive is
      missing (since any font, even a "special" one, can be selected as
      current and the formatter's behavior when encountering an input space
      should be well-defined under that circumstance).  Adding this option
      enables a well-formed font description to be produced.

    * src/utils/afmtodit/afmtodit.pl (usage):
    * src/utils/afmtodit/afmtodit.1.man (Synopsis, Options): Document it.

    * NEWS: Add item.


The other half of this is that output drivers will compute a space width even if the font description files generated by afmtodit(1) lack them.


commit bf7f6862c384f9cff80737cccf6b8fafd4197e1c
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Fri Sep 24 17:48:26 2021 +1000

    [libgroff]: Make `spacewidth` mandatory.

    * src/libs/libgroff/font.cpp (font::load): Throw error if a font
      description file is missing a `spacewidth` directive, since it is now
      re-documented as mandatory.  Atypically, we don't return false in this
      scenario; instead we proceed with the existing logic to compute a
      space width for the font based on typical practices for Western
      alphabetic fonts (see, e.g., <https://type.today/en/journal/spaces>.

    Thanks to Deri James for the discussion.


G. Branden Robinson <gbranden>
Group administrator
Wed 24 Apr 2024 12:27:17 PM UTC, comment #1: 

If no -w is given afmtodit uses the width of the space glyph as the value. This is ideal since this is the value which the font designer has chosen as most appropriate for particular font. The various values for the URW fonts are:-

font/devpdf/U-AB:spacewidth 280
font/devpdf/U-AB:space  280
font/devpdf/U-AB:M      900
font/devpdf/U-ABI:spacewidth 280
font/devpdf/U-ABI:space 280
font/devpdf/U-ABI:M     900
font/devpdf/U-AI:spacewidth 277
font/devpdf/U-AI:space  277
font/devpdf/U-AI:M      919
font/devpdf/U-AR:spacewidth 277
font/devpdf/U-AR:space  277
font/devpdf/U-AR:M      919
font/devpdf/U-BMB:spacewidth 340
font/devpdf/U-BMB:space 340
font/devpdf/U-BMB:M     940
font/devpdf/U-BMBI:spacewidth 340
font/devpdf/U-BMBI:space        340
font/devpdf/U-BMBI:M    860
font/devpdf/U-BMI:spacewidth 300
font/devpdf/U-BMI:space 300
font/devpdf/U-BMI:M     860
font/devpdf/U-BMR:spacewidth 320
font/devpdf/U-BMR:space 320
font/devpdf/U-BMR:M     920
font/devpdf/U-CB:spacewidth 600
font/devpdf/U-CB:space  600
font/devpdf/U-CB:M      600
font/devpdf/U-CBI:spacewidth 600
font/devpdf/U-CBI:space 600
font/devpdf/U-CBI:M     600
font/devpdf/U-CI:spacewidth 600
font/devpdf/U-CI:space  600
font/devpdf/U-CI:M      600
font/devpdf/U-CR:spacewidth 600
font/devpdf/U-CR:space  600
font/devpdf/U-CR:M      600
font/devpdf/U-HB:spacewidth 278
font/devpdf/U-HB:space  278
font/devpdf/U-HB:M      833
font/devpdf/U-HBI:spacewidth 278
font/devpdf/U-HBI:space 278
font/devpdf/U-HBI:M     833
font/devpdf/U-HI:spacewidth 278
font/devpdf/U-HI:space  278
font/devpdf/U-HI:M      833
font/devpdf/U-HNB:spacewidth 228
font/devpdf/U-HNB:space 228
font/devpdf/U-HNB:M     683
font/devpdf/U-HNBI:spacewidth 228
font/devpdf/U-HNBI:space        228
font/devpdf/U-HNBI:M    683
font/devpdf/U-HNI:spacewidth 228
font/devpdf/U-HNI:space 228
font/devpdf/U-HNI:M     683
font/devpdf/U-HNR:spacewidth 228
font/devpdf/U-HNR:space 228
font/devpdf/U-HNR:M     683
font/devpdf/U-HR:spacewidth 278
font/devpdf/U-HR:space  278
font/devpdf/U-HR:M      833
font/devpdf/U-NB:spacewidth 287
font/devpdf/U-NB:space  287
font/devpdf/U-NB:M      981
font/devpdf/U-NBI:spacewidth 287
font/devpdf/U-NBI:space 287
font/devpdf/U-NBI:M     944
font/devpdf/U-NI:spacewidth 278
font/devpdf/U-NI:space  278
font/devpdf/U-NI:M      944
font/devpdf/U-NR:spacewidth 278
font/devpdf/U-NR:space  278
font/devpdf/U-NR:M      944
font/devpdf/U-PB:spacewidth 250
font/devpdf/U-PB:space  250
font/devpdf/U-PB:M      1000
font/devpdf/U-PBI:spacewidth 250
font/devpdf/U-PBI:space 250
font/devpdf/U-PBI:M     944
font/devpdf/U-PI:spacewidth 250
font/devpdf/U-PI:space  250
font/devpdf/U-PI:M      944
font/devpdf/U-PR:spacewidth 250
font/devpdf/U-PR:space  250
font/devpdf/U-PR:M      946
font/devpdf/U-S:spacewidth 250
font/devpdf/U-S:space   250
font/devpdf/U-TB:spacewidth 250
font/devpdf/U-TB:space  250
font/devpdf/U-TB:M      944
font/devpdf/U-TBI:spacewidth 250
font/devpdf/U-TBI:space 250
font/devpdf/U-TBI:M     889
font/devpdf/U-TI:spacewidth 250
font/devpdf/U-TI:space  250
font/devpdf/U-TI:M      833
font/devpdf/U-TR:spacewidth 250
font/devpdf/U-TR:space  250
font/devpdf/U-TR:M      889
font/devpdf/U-ZCMI:spacewidth 220
font/devpdf/U-ZCMI:space        220
font/devpdf/U-ZCMI:M    840
font/devpdf/U-ZD:spacewidth 278
font/devpdf/U-ZD:space  278

As you can see, generally, 1/3 of an em would deliver looser text, except for mono spaced fonts where it is considerably tighter. Most western language fonts do include a "space" glyph [1].

Some CJK fonts (which also include western glyphs) have all glyphs mono spaced but 2 different widths, a larger one for ideographs, the space width for these is usually matching the western glyph size. (See font DFSongStd as an example).

Other CJK fonts have proportional western glyphs and fixed width CJK, with no space glyph defined, this is when afmtodit fails to write a spacewidth parameter. See font TakaoPGothic as an example).

When fonts do not have a space glyph they sometimes have a u0020 and a u00A0 glyph which are also good candidates for setting spacewidth. The GNU Unifont Alex is using has both of these glyph which are good candidates for setting spacewidth since it is a mono spaced font.

[1] you can use \[space] in groff, if your font has a space glyph, and you seem to get a fixed width space. It is usually defined into font as something like:-

/space {
        0 512 hsbw
        endchar
        } ND

And hsbw operator is defined as:-

hsbw RD sbx wx hsbw ND

        sets the left sidebearing point at (sbx, 0) and sets the character
        width vector to (wx, 0) in character space. This command also
        sets the current point to (sbx, 0), but does not place the point in
        the character path. Use rmoveto for the first point in the path.
        The name hsbw stands for horizontal sidebearing and width; hor-
        izontal indicates that the y component of both the sidebearing
        and width is 0. Either sbw or hsbw must be used once as the first
        command in a character outline definition. It must be used only
        once. In non-marking characters, such as the space character, the
        left sidebearing point should be (0, 0).


Deri James <deri>
Group Member
Sun 21 Apr 2024 09:24:09 AM UTC, original submission:  

As suggested by Branden in <https://lists.gnu.org/archive/html/groff/2024-04/msg00089.html>, afmtodit(1) could provide a sane default for the space width when it is unspecified.

As suggested by Brian Inglis (and slightly differently by Branden too), it could be calculated as 1/3 of unitsPerEm, rounded to an integer.

Alejandro Colomar <alx>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by barx (Posted a comment)
  • -email is unavailable- added by gbranden (Posted a comment)
  • -email is unavailable- added by deri (Posted a comment)
  • -email is unavailable- added by alx (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-05-04 gbranden Assigned togbranden deri
    2024-05-02 barx StatusInvalid Need Info
        Open/ClosedClosed Open
    2024-05-01 gbranden Severity3 - Normal 1 - Wish
        StatusNone Invalid
        Assigned toNone gbranden
        Open/ClosedOpen Closed
        SummaryProvide a default value for afmtodit(1) -w, when unspecified [afmtodit] want a default value for space width if unspecified

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code