Patch: Remove bad heuristic in ttfdump.c

Troy Rollo <[email protected]>
Newsgroups gmane.comp.tex.live
Message-ID <[email protected]>
ttfdump.c includes an heurisic in which it looks for the strings "ttc" 
and "TTC" in the file name to determine whether the file is a TTC or a 
TTF. It does not restrict this to being the file extension, nor does it 
avoid it being in the directory portion of the path name, so that, for 
example it would match "kilowattcounter.ttf" or 
"msttcorefonts/Arial.ttf". Moreover, it makes this check (that is, two 
strstr calls) three times when it could have instead checked whether the 
"ttc" variable is null (which is a far cheaper operation).

Rather than fix the heuristic, it seems to me that the code should 
determine from the contents of the file itself what type of file it is.

The *attached* patch replaces the heuristic by attempting to open the 
file as a TTC regardless of the file name. If that succeeds (the ttc 
variable is non-null), then it will continue treating it as a TTC, 
otherwise it will attempt to open it as a TTF. The later checks are also 
changed to depend on the ttc variable being non-null.

The prior initialisation of ttc could also be dropped with these 
changes. This is left as an exercise for the reader.
remove-ttc-heuristic.diff (text/x-patch, 881 B)
--- texk/ttfdump/src/ttfdump.c.orig	2025-09-12 10:37:38.000000000 +1000
+++ texk/ttfdump/src/ttfdump.c	2025-09-12 10:58:35.466449129 +1000
@@ -172,13 +172,10 @@
     exit(EXIT_FAILURE);
   }
 
-  if (strstr (ttfname, "ttc") != NULL || strstr (ttfname, "TTC") != NULL)
-  {
-    ttc = ttfLoadTTCHeader(ttfname);
-
-    if (ttc == NULL)
-      exit(EXIT_FAILURE);
+  ttc = ttfLoadTTCHeader(ttfname);
 
+  if (ttc != NULL)
+  {
     if (collection < ttc->DirCount)
       font = ttc->font + collection;
     else
@@ -192,7 +189,7 @@
     exit(EXIT_FAILURE);
 
   print_prologue(dp_file);
-  if (strstr(ttfname, "ttc") != NULL || strstr(ttfname, "TTC") != NULL)
+  if (ttc != NULL)
   {
     print_ttc(ttc, dp_file);
   }
@@ -228,7 +225,7 @@
     }
   }
 
-  if (strstr(ttfname, "ttc") != NULL || strstr(ttfname, "TTC") != NULL)
+  if (ttc != NULL)
   {
     ttfFreeTTCFont(ttc);
   }
smime.p7s (application/pkcs7-signature, 4.8 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.