Menu

#627 replace _Macintosh with __APPLE__ in variable.c

None
closed-accepted
nobody
None
5
2014-12-04
2013-06-28
No

The variable _Macintosh is not defined anywhere. It should be __APPLE___ instead. MacPorts has been including this patch for a very long time (https://trac.macports.org/browser/trunk/dports/math/gnuplot/files/patch-src-variable_c.diff?rev=76048). After applying it, show fontpath properly changes from

system fontpath is "/usr/X11R6/lib/X11/fonts/Type1"

to

system fontpath is "/System/Library/Fonts!" "/Library/Fonts!" "/Users/mojca/Library/Fonts!"

MacPorts also removes the exclamation marks, but since exclamation marks are supposed to mean recursive search (which makes sense) and the author of the patch cannot recall why he removed them, it should be fine to leave them there.

This is the patch:

--- a/src/variable.c
+++ b/src/variable.c
@@ -250,7 +250,7 @@ static const struct path_table fontpath_tbl[] =
 };
 #endif

-#if defined(_Macintosh) && !defined(FONTPATHSET)
+#if defined(__APPLE__) && !defined(FONTPATHSET)
 #  define FONTPATHSET
 static const struct path_table fontpath_tbl[] =
 {

Now, honestly, I don't know when fontpath is used at all and I would like to know that, but I wasn't able to figure it out.

With the old libGD (and patched variable.c) Arial wasn't found in PNG (if it was located under /Library/Fonts/Microsoft/Arial.ttf; it was found under /Library/Fonts/Arial.ttf, but libGD has already been compiled with -DDEFAULT_FONTPATH="/System/Library/Fonts:/Library/Fonts" and I doubt that gnuplot had any influence) and lead to warnings in PNG, so this didn't seem to have any influence on GD.

With the new libGD Arial is found, but it's probably found via fontconfig. If I try to use a font in PostScript, it never writes the path to the font, it simply writes down whatever font I tell it to use, even if that font doesn't exist.

Bottomline: I have no clue where (if anywhere) fontpath is used. But please replace _Macintosh with __APPLE__ if it is still used somewhere. (If it is not, it might make more sense to remove fontpath altogether.)

Discussion

  • Ethan Merritt

    Ethan Merritt - 2013-07-02

    Interesting point about where fontpath is ever used. From a quick look it seems that it is only used by gd.trm post.trm and svg.trm. The svg embedded font code has never been tested and is probably useless. The PostScript embedded font code does work, but I suspect that the full-blown font path mechanism is overkill for a relatively rare use case. So it is primarily for the benefit of libgd, which has been moving towards using fontconfig instead.

    Both post.trm and gd.trm allow an environmental variable for the font path anyhow, which is more easily customized than a compile-time decision.

    So it may indeed be true that large chunks of code in misc.c and variable.c can be deprecated.

     
  • Ethan Merritt

    Ethan Merritt - 2013-07-02

    ifdef _Macintosh is used in 4 places:

    ./src/plot.c:i #if defined(_Windows) || defined(_Macintosh)
    ./src/command.c: #elif defined(_Macintosh)
    ./src/variable.c:#if defined(_Macintosh) && !defined(FONTPATHSET)
    ./src/plot.h: #if defined(_Windows) || defined(_Macintosh)

    Are you suggesting to replace all 4 of these with APPLE?
    Have you checked that the program will compile and run correctly if you do this?

     
  • Mojca Miklavec

    Mojca Miklavec - 2013-07-02

    ./src/plot.c & plot.h: just delete "|| defined(_Macintosh)", I don't think there is any reason to use gnu_main() instead of main()

    ./src/command.c: strcmp(term->name, "macintosh"): there is no terminal named macintosh any more, just delete the whole chunk

    ./src/variable.c: this is the line I asked you to change

    So no - not all four. Just that one line, the other three can go away entirely.

    How can I test font embeding in PostScript?

     
  • Ethan Merritt

    Ethan Merritt - 2013-07-02
    • status: open --> closed-accepted
    • Group: -->
     
  • Ethan Merritt

    Ethan Merritt - 2013-07-02

    OK. Done.

    PostScript embedded fonts - see demo fontfile.dem

     
  • Mojca Miklavec

    Mojca Miklavec - 2013-07-03

    Thank you. Against all odds ;) it worked properly (after manually setting the path to those PostScript fonts: set fontpath '/opt/local/share/fonts!'):

    Font file 'p052003l.pfb' contains the font 'URWPalladioL-Roma'. Location:
       /opt/local/share/fonts/urw-fonts/p052003l.pfb
    Font file 'p052023l.pfb' contains the font 'URWPalladioL-Ital'. Location:
       /opt/local/share/fonts/urw-fonts/p052023l.pfb
    Font file 'Calibri.ttf' contains the font 'Calibri'. Location:
       /Library/Fonts/Microsoft/Calibri.ttf
    
     Now have a look at the file fontfile.ps
    Font file 'p052003l.pfb' contains the font 'URWPalladioL-Roma'. Location:
       /opt/local/share/fonts/urw-fonts/p052003l.pfb
    Font file 'p052023l.pfb' contains the font 'URWPalladioL-Ital'. Location:
       /opt/local/share/fonts/urw-fonts/p052023l.pfb
    Font file 'Calibri.ttf' contains the font 'Calibri'. Location:
       /Library/Fonts/Microsoft/Calibri.ttf
    

    With previous version of gnuplot I get

    "fontfile.dem", line 27: Font file 'Calibri.ttf' not found
    

    Can you please also apply the same patch to branch-4-6-stable?

     
  • Ethan Merritt

    Ethan Merritt - 2013-07-03

    OK. 4.6 also done

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.