[cups] filter/texttopdf.c does not recognise the freefonts with fontconfig

Matthias Apitz guru at unixarea.de
Mon Jan 25 22:30:18 PST 2016


Hello,

This port of a newer CUPS(...) to SunOS Solaris 10 is not below a good
star :-(

Now, as I have the cupsd running, the next problem is in
filter/texttopdf.c. I have installed the GNU freefonts from the archive
freefont-ttf-20100919.tar.gz and they are working fine on Linux.

On Solaris SPARC the fontconfig routines are scanning them (I checked
this with truss), but texttopdf.c is unwilling to use them. The failing
code from filter/texttopdf is:

...
EMB_PARAMS *font_load(const char *font)
{
  OTF_FILE *otf;

  FcPattern *pattern;
  FcFontSet *candidates;
  FcChar8   *fontname = NULL;
  FcResult   result;
  int i;

  fprintf(stderr, "font_load for font: %s\n", font);

  if ( (font[0]=='/')||(font[0]=='.') ) {
    candidates = NULL;
    fontname=(FcChar8 *)strdup(font);
  } else {
    FcInit ();
    fprintf(stderr, "FcInit() done\n");
    pattern = FcNameParse ((const FcChar8 *)font);
    FcPatternAddInteger (pattern, FC_SPACING, FC_MONO); // guide fc, in case substitution becomes necessary
    FcConfigSubstitute (0, pattern, FcMatchPattern);
    FcDefaultSubstitute (pattern);

    /* Receive a sorted list of fonts matching our pattern */
    candidates = FcFontSort (0, pattern, FcFalse, 0, &result);
    FcPatternDestroy (pattern);

    /* In the list of fonts returned by FcFontSort()
       find the first one that is both in TrueType format and monospaced */
    fprintf(stderr, "num candidates %d\n", candidates->nfont);
    for (i = 0; i < candidates->nfont; i++) {
      FcChar8 *fontformat=NULL; // TODO? or just try?
      int spacing=0; // sane default, as FC_MONO == 100
      FcPatternGetString  (candidates->fonts[i], FC_FONTFORMAT, 0, &fontformat);
      FcPatternGetInteger (candidates->fonts[i], FC_SPACING,    0, &spacing);

here the pointer 'fontformat' resulted as 0x0 from the above call, and
when I hack this as a workaround, like this:

      fontformat = "TrueType"; // hack

all is fine and texttopdf produces correct PDF code for all my
codepoints, including for Hebrew;

      if ( (fontformat)&&(spacing == FC_MONO) ) {
        if (strcmp((const char *)fontformat, "TrueType") == 0) {
          fontname = FcPatternFormat (candidates->fonts[i], (const FcChar8 *)"%{file|cescape}/%{index}");
          break;
        } else if (strcmp((const char *)fontformat, "CFF") == 0) {
          fontname = FcPatternFormat (candidates->fonts[i], (const FcChar8 *)"%{file|cescape}"); // TTC only possible with non-cff glyphs!
          break;
        }
      }
    }
    FcFontSetDestroy (candidates);
  }

  if (!fontname) {
    // TODO: try /usr/share/fonts/*/*/%s.ttf
    fprintf(stderr,"No viable font found\n");
    return NULL;
  }



What could be the problem with this fontconfig 2.11.91 call:

      FcPatternGetString  (candidates->fonts[i], FC_FONTFORMAT, 0, &fontformat);


Thanks

	matthias


-- 
Matthias Apitz, ✉ guru at unixarea.de, ⌂ http://www.unixarea.de/  ☎ +49-176-38902045
UNIX since V7 on PDP-11 | UNIX on mainframe since ESER 1055 (IBM /370)
UNIX on x86 since SVR4.2 UnixWare 2.1.2 | FreeBSD since 2.2.5



More information about the cups mailing list