Пример #1
0
pdc_bool
pdf_get_metrics_pfm(
    PDF *p,
    pdc_font *font,
    const char *fontname,
    pdc_encoding enc,
    const char *filename)
{
    pdc_file *pfmfile;

    /* open PFM file */
    pfmfile = pdf_fopen(p, filename, "PFM ", PDC_FILE_BINARY);
    if (pfmfile == NULL)
    {
	if (font->verbose_open)
	    pdc_error(p->pdc, -1, 0, 0, 0, 0);

        return pdc_false;
    }

    /* Read PFM metrics */
    if (!pdf_parse_pfm(p, pfmfile, font))
    {
	pdc_set_errmsg(p->pdc, PDF_E_FONT_CORRUPT, "PFM", filename, 0, 0);

        if (font->verbose == pdc_true)
	    pdc_error(p->pdc, -1, 0, 0, 0, 0);

        return pdc_false;
    }

    /* Check encoding */
    if (!pdf_check_pfm_encoding(p, font, fontname, enc))
        return pdc_false;

    if (!pdf_make_fontflag(p, font))
        return pdc_false;

    return pdc_true;
}
Пример #2
0
int
main( void )
{
    short       j, k, ib, nindx, nchars, nleng, htab, zero;
    short       *hrshlst;
    signed char ix, iy;
    long        fpos;
    PDFstrm     *pdfs;

    hrshlst = (short *) malloc( 4 * 176 * sizeof ( short ) );

    ib = 0;
    for ( j = 0; j < 4; j++ )
        for ( k = 0; k < 176; k++ )
            hrshlst[ib++] = *( hersh[j] + k );

    pdfs = pdf_fopen( PL_XFONT, "wb+" );
    if ( !pdfs )
    {
        printf( "Error opening extended font file.\n" );
        exit( 1 );
    }

    htab = 4 * 256 + 176;

    pdf_wr_2bytes( pdfs, htab );
    pdf_wr_2nbytes( pdfs, (U_SHORT *) hrshlst, 4 * 176 );

    nleng = 1;
    zero  = 0;
    nindx = 0;
    fpos  = ftell( pdfs->file );
    pdf_wr_2bytes( pdfs, nindx );
    for ( j = 0; j < 30; j++ )
    {
        for ( k = 0; k < 100; k++ )
        {
            ib = *( findex[j] + k );
            if ( ib == 0 )
            {
                pdf_wr_2bytes( pdfs, zero );
                nindx++;
            }
            else
            {
                pdf_wr_2bytes( pdfs, nleng );
                nindx++;
                for (;; )
                {
                    ix = *( buffer[ib / 100] + ib % 100 ) / 128 - 64;
                    iy = *( buffer[ib / 100] + ib % 100 ) % 128 - 64;
                    ib++;
                    if ( ix == -64 )
                        ix = 64;
                    if ( iy == -64 )
                        iy = 64;
                    nleng++;
                    if ( ix == 64 && iy == 64 )
                        break;
                }
            }
        }
    }
    fseek( pdfs->file, fpos, 0 );
    pdf_wr_2bytes( pdfs, nindx );

    fseek( pdfs->file, 0, 2 );
    fpos   = ftell( pdfs->file );
    nleng  = 1;
    nchars = 0;
    pdf_wr_2bytes( pdfs, nleng );
    for ( j = 0; j < 30; j++ )
    {
        for ( k = 0; k < 100; k++ )
        {
            ib = *( findex[j] + k );
            if ( ib != 0 )
            {
                for (;; )
                {
                    ix = *( buffer[ib / 100] + ib % 100 ) / 128 - 64;
                    iy = *( buffer[ib / 100] + ib % 100 ) % 128 - 64;
                    ib++;
                    if ( ix == -64 )
                        ix = 64;
                    if ( iy == -64 )
                        iy = 64;
                    fputc( ix, pdfs->file );
                    fputc( iy, pdfs->file );
                    nleng++;
                    if ( ix == 64 && iy == 64 )
                        break;
                }
                nchars++;
            }
        }
    }
    nleng--;
    fseek( pdfs->file, fpos, 0 );
    pdf_wr_2bytes( pdfs, nleng );
    pdf_close( pdfs );

    printf( "There are %d characters in font set.\n", nchars - 1 );
    exit( 0 );
}
Пример #3
0
PDFstrm *
plLibOpenPdfstrm(const char *fn)		/* pmr: const */
{
    PDFstrm *file;
    char *fs = NULL, *dn = NULL;

#ifndef WIN32
    /* EMBOSS additions to avoid need for PLPLOT_LIB */
    static const char *prefix = PREFIX;
    static const char *top    = EMBOSS_TOP;
    
    if(!strcmp(prefix,"/usr/local"))
    {
        plGetName(prefix, "share/EMBOSS", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;

        plGetName(top, "plplot/lib", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;
    }
    else
    {
        plGetName(prefix, "share/EMBOSS", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;
    }
    /* End of EMBOSS additions */
#endif

/****   search build tree               ****/

    if (plInBuildTree() == 1) {
      plGetName(BUILD_DIR, "data", fn, &fs);

      if ((file = pdf_fopen(fs, "rb")) != NULL)
        goto done;
    }

/****	search PLPLOT_LIB_ENV = $(EPLPLOT_LIB)	****/

#if defined(PLPLOT_LIB_ENV)
    if ((dn = getenv(PLPLOT_LIB_ENV)) != NULL) {
        plGetName(dn, "", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;

        fprintf(stderr, PLPLOT_LIB_ENV"=\"%s\"\n", dn); /* what IS set? */
    }
#endif  /* PLPLOT_LIB_ENV */

/****	search current directory	****/

    if ((file = pdf_fopen(fn, "rb")) != NULL)
        goto done;

/****	search PLPLOT_HOME_ENV/lib = $(EPLPLOT_HOME)/lib	****/

#if defined (PLPLOT_HOME_ENV)
    if ((dn = getenv(PLPLOT_HOME_ENV)) != NULL) {
        plGetName(dn, "lib", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;
        fprintf(stderr, PLPLOT_HOME_ENV"=\"%s\"\n",dn); /* what IS set? */
    }
#endif  /* PLPLOT_HOME_ENV/lib */

/**** 	search installed location	****/

#if defined (DATA_DIR)
    plGetName(DATA_DIR, "", fn, &fs);

    if ((file = pdf_fopen(fs, "rb")) != NULL)
        goto done;
#endif  /* DATA_DIR */

/**** 	search hardwired location	****/

#ifdef PLLIBDEV
    plGetName(PLLIBDEV, "", fn, &fs);

    if ((file = pdf_fopen(fs, "rb")) != NULL)
	goto done;
#endif	/* PLLIBDEV */

#ifdef macintosh
    file = plMacLibOpen(fn);
    if (file != NULL)
        goto done;
#endif /* macintosh */

    if (plplotLibDir != NULL) {
	plGetName(plplotLibDir, "", fn, &fs);
	if ((file = pdf_fopen(fs, "rb")) != NULL)
	    goto done;

    }

/**** 	not found, give up 	****/
    pldebug("plLibOpenPdfstr", "File %s not found.\n", fn);
    return NULL;

 done:
    /* pldebug("plLibOpenPdfstr", "Found file %s\n", fs); */
    free_mem(fs);
    return (file);
}
Пример #4
0
PDFstrm *
plLibOpenPdfstrm(char *fn)
{
    PDFstrm *file;
    char *fs = NULL, *dn = NULL;

/****	search PLPLOT_LIB_ENV = $(PLPLOT_LIB)	****/

#if defined(PLPLOT_LIB_ENV)
    if ((dn = getenv(PLPLOT_LIB_ENV)) != NULL) {
        plGetName(dn, "", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;

        fprintf(stderr, PLPLOT_LIB_ENV"=\"%s\"\n", dn); /* what IS set? */
    }
#endif  /* PLPLOT_LIB_ENV */

/****	search current directory	****/

    if ((file = pdf_fopen(fn, "rb")) != NULL)
        goto done;

/****	search PLPLOT_HOME_ENV/lib = $(PLPLOT_HOME)/lib	****/

#if defined (PLPLOT_HOME_ENV)
    if ((dn = getenv(PLPLOT_HOME_ENV)) != NULL) {
        plGetName(dn, "lib", fn, &fs);

        if ((file = pdf_fopen(fs, "rb")) != NULL)
            goto done;
        fprintf(stderr, PLPLOT_HOME_ENV"=\"%s\"\n",dn); /* what IS set? */
    }
#endif  /* PLPLOT_HOME_ENV/lib */

/**** 	search installed location	****/

#if defined (DATA_DIR)
    plGetName(DATA_DIR, "", fn, &fs);

    if ((file = pdf_fopen(fs, "rb")) != NULL)
        goto done;
#endif  /* DATA_DIR */

/**** 	search hardwired location	****/

#ifdef PLLIBDEV
    plGetName(PLLIBDEV, "", fn, &fs);

    if ((file = pdf_fopen(fs, "rb")) != NULL)
	goto done;
#endif	/* PLLIBDEV */

#ifdef macintosh
    file = plMacLibOpen(fn);
    if (file != NULL)
        goto done;
#endif /* macintosh */

    if (plplotLibDir != NULL) {
	plGetName(plplotLibDir, "", fn, &fs);
	if ((file = pdf_fopen(fs, "rb")) != NULL)
	    goto done;

    }
    
/**** 	not found, give up 	****/

    return NULL;

 done:
    free_mem(fs);
    return (file);
}
Пример #5
0
static void
pdf_read_resourcefile(PDF *p, const char *filename)
{
    pdc_file   *fp = NULL;
    char      **linelist;
    char       *line;
    char       *category = NULL;
    char       *uprfilename = NULL;
#if defined(AS400) || defined(WIN32)
#define BUFSIZE 2048
    char        buffer[BUFSIZE];
#ifdef WIN32
    char        regkey[128];
    HKEY        hKey = NULL;
    DWORD       size, lType;
#endif
#endif
    int         il, nlines = 0, nextcat, begin;

#ifdef WIN32

/* don't add patchlevel's to registry searchpath */
#define stringiz1(x)	#x
#define stringiz(x)	stringiz1(x)

#define PDFLIBKEY  "Software\\PDFlib\\PDFlib\\"

    strcpy(regkey, PDFLIBKEY);
    strcat(regkey, PDFLIB_VERSIONSTRING);

    /* process registry entries */
    if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, regkey, 0L,
        (REGSAM) KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
    {
        size = BUFSIZE - 2;
        if (RegQueryValueExA(hKey, "SearchPath", (LPDWORD) NULL,
                             &lType, (LPBYTE) buffer, &size)
            == ERROR_SUCCESS && *buffer)
        {
            char **pathlist;
            int ip, np;

            np = pdc_split_stringlist(p->pdc, buffer,
                                      ";", &pathlist);
            for (ip = 0; ip < np; ip++)
                pdf_add_resource(p, "SearchPath", pathlist[ip]);
            pdc_cleanup_stringlist(p->pdc, pathlist);
        }

        size = BUFSIZE - 2;
        if (RegQueryValueExA(hKey, "prefix", (LPDWORD) NULL,
                             &lType, (LPBYTE) buffer, &size)
            == ERROR_SUCCESS && *buffer)
        {
            /* '/' because of downward compatibility */
            if (p->prefix)
            {
                pdc_free(p->pdc, p->prefix);
                p->prefix = NULL;
            }
            p->prefix = pdc_strdup(p->pdc,
                            &buffer[buffer[0] == '/' ? 1 : 0]);
        }

        RegCloseKey(hKey);
    }
#endif  /* WIN32 */

#ifdef AS400
    strcpy (buffer, "/pdflib/");
    strcat (buffer, PDFLIB_VERSIONSTRING);
    il = (int) strlen(buffer);
    strcat (buffer, "/fonts");
    pdf_add_resource(p, "SearchPath", buffer);
    strcpy(&buffer[il], "/bind/data");
    pdf_add_resource(p, "SearchPath", buffer);
#endif  /* AS400 */

    /* searching for name of upr file */
    uprfilename = (char *)filename;
    if (!uprfilename || *uprfilename == '\0')
    {
        /* user-supplied upr file */
        uprfilename = pdc_getenv(RESOURCEFILE);
        if (!uprfilename || *uprfilename == '\0')
        {
            uprfilename = DEFAULTRESOURCEFILE;

            /* user-supplied upr file */
            fp = pdf_fopen(p, uprfilename, NULL, 0);
            if (fp == NULL)
            {
                uprfilename = NULL;
#ifdef WIN32
                /* process registry entries */
                if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, regkey, 0L,
                    (REGSAM) KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
                {
                    size = BUFSIZE - 2;
                    if (RegQueryValueExA(hKey, "resourcefile", (LPDWORD) NULL,
                                         &lType, (LPBYTE) buffer, &size)
                        == ERROR_SUCCESS && *buffer)
                    {
                        uprfilename = buffer;
                    }

                    RegCloseKey(hKey);
                }
#endif  /* WIN32 */
            }
        }

        if (!uprfilename || *uprfilename == '\0')
            return;

        if (p->resourcefilename)
        {
            pdc_free(p->pdc, p->resourcefilename);
            p->resourcefilename = NULL;
        }
        p->resourcefilename = pdc_strdup(p->pdc, uprfilename);
    }

    /* read upr file */
    if ((fp == NULL) && ((fp = pdf_fopen(p, uprfilename, "UPR ", 0)) == NULL))
	pdc_error(p->pdc, -1, 0, 0, 0, 0);

    nlines = pdc_read_textfile(p->pdc, fp, &linelist);
    pdc_fclose(fp);

    if (!nlines) return;

    /* Lines loop */
    begin = 1;
    nextcat = 0;
    for (il = 0; il < nlines; il++)
    {
        line = linelist[il];

        /* Next category */
        if (line[0] == '.' && strlen(line) == 1)
        {
            begin = 0;
            nextcat = 1;
            continue;
        }

        /* Skip category list */
        if (begin) continue;

        /* Prefiex or category expected */
        if (nextcat)
        {
            /* Directory prefix */
            if (line[0] == '/')
            {
                if (p->prefix)
                {
                    pdc_free(p->pdc, p->prefix);
                    p->prefix = NULL;
                }
                p->prefix = pdc_strdup(p->pdc, &line[1]);
                continue;
            }

            /* Ressource Category */
            category = line;
            nextcat = 0;
            continue;
        }

        /* Add resource */
        pdf_add_resource(p, category, line);
    }

    pdc_cleanup_stringlist(p->pdc, linelist);
}
Пример #6
0
int
main( void )
{
    size_t  i, j, k, ib, nstd;
    U_SHORT nchars, nleng, htab, nindx, zero;
    U_SHORT *hrshlst, *hrshidx;
    int     ix, iy;
    long    fpos;
    PDFstrm *pdfs;

    hrshlst = (U_SHORT *) malloc( 176 * sizeof ( U_SHORT ) );
    hrshidx = (U_SHORT *) malloc( 176 * sizeof ( U_SHORT ) );

    ib = 0;
    for ( k = 0; k < 176; k++ )
        hrshlst[ib++] = (U_SHORT) *( hersh[0] + k );

// Sort list

    qsort( (char *) hrshlst, ib, sizeof ( U_SHORT ), compare );

// Remove duplicates

    k = 0;
    j = 0;
    do
    {
        if ( hrshlst[k] == hrshlst[j] )
            j++;
        else
            hrshlst[++k] = hrshlst[j];
    } while ( j < ib );

    nstd = k + 1;

// Now reindex the fonts

    for ( k = 0; k < 176; k++ )
        for ( i = 0; i < nstd; i++ )
            if ( *( hersh[0] + k ) == hrshlst[i] )
            {
                hrshidx[k] = (U_SHORT) ( i + 1 );
                break;
            }

    pdfs = pdf_fopen( PL_SFONT, "wb+" );
    if ( !pdfs )
    {
        printf( "Error opening standard font file.\n" );
        exit( 1 );
    }

    htab = 1 * 256 + 176;
    pdf_wr_2bytes( pdfs, htab );
    pdf_wr_2nbytes( pdfs, hrshidx, 176 );

    zero  = 0;
    nindx = 0;
    nleng = 1;
    fpos  = ftell( pdfs->file );

    pdf_wr_2bytes( pdfs, nindx );
    for ( j = 0; j < nstd; j++ )
    {
        ib = (size_t) *( findex[( hrshlst[j] - 1 ) / 100] + ( hrshlst[j] - 1 ) % 100 );
        if ( ib == 0 )
        {
            pdf_wr_2bytes( pdfs, zero );
            nindx++;
        }
        else
        {
            pdf_wr_2bytes( pdfs, nleng );
            nindx++;
            for (;; )
            {
                ix = *( buffer[ib / 100] + ib % 100 ) / 128 - 64;
                iy = *( buffer[ib / 100] + ib % 100 ) % 128 - 64;
                ib++;
                if ( ix == -64 )
                    ix = 64;
                if ( iy == -64 )
                    iy = 64;
                nleng++;
                if ( ix == 64 && iy == 64 )
                    break;
            }
        }
    }
    fseek( pdfs->file, fpos, 0 );
    pdf_wr_2bytes( pdfs, nindx );

    nchars = 0;
    nleng  = 1;
    fseek( pdfs->file, 0, 2 );            // Go to end of file
    fpos = ftell( pdfs->file );           // Save current position
    pdf_wr_2bytes( pdfs, nleng );

    for ( j = 0; j < nstd; j++ )
    {
        ib = (size_t) *( findex[( hrshlst[j] - 1 ) / 100] + ( hrshlst[j] - 1 ) % 100 );
        if ( ib != 0 )
        {
            for (;; )
            {
                ix = *( buffer[ib / 100] + ib % 100 ) / 128 - 64;
                iy = *( buffer[ib / 100] + ib % 100 ) % 128 - 64;
                ib++;
                if ( ix == -64 )
                    ix = 64;
                if ( iy == -64 )
                    iy = 64;
                fputc( ix, pdfs->file );
                fputc( iy, pdfs->file );
                nleng++;
                if ( ix == 64 && iy == 64 )
                    break;
            }
            nchars++;
        }
    }
    nleng--;
    fseek( pdfs->file, fpos, 0 );
    pdf_wr_2bytes( pdfs, nleng );
    pdf_close( pdfs );
    free( hrshlst );
    free( hrshidx );
    printf( "There are %d characters in standard font set.\n", nchars - 1 );
    exit( 0 );
}