gbranden pushed a commit to branch master in repository groff. commit 47ad98c3ec79e65b6e890c607f3895370d615c0d Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Fri Jul 4 11:39:58 2025 -0500
[gropdf]: Refactor `LoadDownload()`. * src/devices/gropdf/gropdf.pl (LoadDownload): Drop scalar `f`; we won't need it anymore. Rename scalar `found` to `anyDownloadFilefound`, and manipulate it like a Boolean, not a counter. Attempt `open()` of "download" in each directory in the groff font search path directly, instead of indirectly through `OpenFontFile()`; we want to read all download files available, not stop at the first one encountered. Use an ordinary file handle (`DL`) for this `open()`; we don't need a scalar for it because we don't return it. Issue `Notice()`s of each open, whether successful or failed. Recast diagnostics. Annotate and motivate logic. --- ChangeLog | 14 ++++++++++++++ src/devices/gropdf/gropdf.pl | 36 +++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb9e74fbe..251c70d89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2025-07-04 G. Branden Robinson <g.branden.robin...@gmail.com> + + * src/devices/gropdf/gropdf.pl (LoadDownload): Drop scalar `f`; + we won't need it anymore. Rename scalar `found` to + `anyDownloadFilefound`, and manipulate it like a Boolean, not a + counter. Attempt `open()` of "download" in each directory in + the groff font search path directly, instead of indirectly + through `OpenFontFile()`; we want to read all download files + available, not stop at the first one encountered. Use an + ordinary file handle (`DL`) for this `open()`; we don't need a + scalar for it because we don't return it. Issue `Notice()`s of + each open, whether successful or failed. Recast diagnostics. + Annotate and motivate logic. + 2025-07-04 G. Branden Robinson <g.branden.robin...@gmail.com> * src/devices/gropdf/gropdf.pl: Trivially refactor. Rename diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl index 6d91f163f..7b5017ecb 100644 --- a/src/devices/gropdf/gropdf.pl +++ b/src/devices/gropdf/gropdf.pl @@ -1166,21 +1166,30 @@ sub ToPoints } } +# Read _all_ files named "download" in the groff font search path and +# populate the `download` hash using foundry+`internalname` as the keys +# and a file name as the values. If the file name is not found, +# populate the `missing` hash the same way. +# +# We don't use `OpenFontFile()` for this task because that search +# _stops_ at the first file successfully opened. sub LoadDownload { - my $f; - my $found=0; - + my $anyDownloadFilefound=0; my (@dirs)=split($cfg{RT_SEP},$fontPath); foreach my $dir (@dirs) { - $f=undef; - OpenFontFile(\$f,$dir,"download"); - next if !defined($f); - $found++; + my $downloadFile="$dir/$devnm/download"; + if (!open(DL,"<$downloadFile")) + { + Notice("cannot open '$downloadFile': $!"); + next; + } + $anyDownloadFilefound=1; - while (<$f>) + Notice("reading '$downloadFile'"); + while (<DL>) { chomp; s/#.*$//; @@ -1202,13 +1211,18 @@ sub LoadDownload next; } - $download{"$foundry $name"}=$file if !exists($download{"$foundry $name"}); + # The first successfully located font file wins; subsequent + # entries, in the same "download" file or later ones, do not + # override the first success. That seems okay because it is + # how $GROFF_FONT_PATH works otherwise. + $download{"$foundry $name"}=$file + if !exists($download{"$foundry $name"}); } - close($f); + close(DL); } - Die("failed to open 'download' file") if !$found; + Die("no 'download' files found") if !$anyDownloadFilefound; } # Locate and open a file in the groff font directory search path. _______________________________________________ groff-commit mailing list groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit