Пример #1
0
/* Creates a file depending on PDC_FILE_ASCII and pdc->asciifile.
*/
size_t
pdc_write_file(
    pdc_core *pdc,
    const char *filename,
    const char *qualifier,
    const char *content,
    size_t len,
    int flags)
{
    size_t wlen = 0;
    pdc_file *sfp;


    sfp = pdc_fopen(pdc, filename, qualifier, NULL, 0, flags);
    if (sfp != NULL)
    {
        wlen = pdc_fwrite_ascii(pdc, content, len, sfp->fp);
        if (wlen < len)
        {
            pdc_set_fwrite_errmsg(pdc, filename);
            PDC_RETHROW(pdc);
        }
        pdc_fclose(sfp);
    }


    return wlen;
}
Пример #2
0
/* Creates a file depending on PDC_FILE_ASCII and pdc->asciifile.
*/
size_t
pdc_write_file(
    pdc_core *pdc,
    const char *filename,
    const char *qualifier,
    const char *content,
    size_t len,
    int flags)
{
    size_t wlen = 0;
    pdc_file *sfp;


    sfp = pdc_fopen(pdc, filename, qualifier, NULL, 0, flags);
    if (sfp != NULL)
    {
        wlen = pdc_fwrite_ascii(pdc, content, len, sfp->fp);
        pdc_fclose(sfp);
        if (wlen != len)
        {
            pdc_set_errmsg(pdc, PDC_E_IO_WRITE, filename, 0, 0, 0);
        }
    }


    return wlen;
}
Пример #3
0
void
pdf_data_source_file_terminate(PDF *p, PDF_data_source *src)
{
    pdc_free(p->pdc, (void *) src->buffer_start);
    pdc_fclose((pdc_file *) src->private_data);

    if (src->length != (long) 0 && src->total != src->length)
	pdc_error(p->pdc, PDC_E_IO_READ, "?", 0, 0, 0);
}
Пример #4
0
static pdc_bool
PFB_data_fill(PDF *p, PDF_data_source *src)
{
    pdc_bool logg = pdc_logg_is_enabled(p->pdc, 5, trc_font);
    t1_private_data *t1 = (t1_private_data *) src->private_data;
    pdc_bool succ = pdc_false;
    pdc_byte c, type;
    int i;

    c = (pdc_byte) pdf_t1getc(t1);

    if (c == PFB_MARKER)
    {
        type = (pdc_byte) pdf_t1getc(t1);

        if (logg)
            pdc_logg(p->pdc, "\t\t\treading segment of type x%02X", type);

        for (i = 1; i < 4; i++)
        {
            if (t1->length[i] == (size_t) 0)
            {
                succ = pdf_read_pfb_segment(p, src, t1, i);
                break;
            }
        }

        if (i < 4)
        {
            if (succ)
            {
                if (logg)
                    pdc_logg(p->pdc, " successful\n");
                return pdc_true;
            }
        }
        else
        {
            if (logg)
                pdc_logg(p->pdc, " (EOF)\n");
            return pdc_false;
        }
    }

    if (logg)
        pdc_logg(p->pdc, " unsuccessful\n");

    if (t1->fontfile)
        pdc_fclose(t1->fontfile);
    pdc_error(p->pdc, PDF_E_FONT_CORRUPT, "PFB", "", 0, 0);

    return pdc_false;
}
Пример #5
0
void
pdf_put_length_objs(PDF *p, PDF_data_source *t1src,
                    pdc_id length1_id, pdc_id length2_id, pdc_id length3_id)
{
    pdc_begin_obj(p->out, length1_id);              /* Length1 object */
    pdc_printf(p->out, "%ld\n",
            (long) ((t1_private_data *) t1src->private_data)->length[1]);
    pdc_end_obj(p->out);

    pdc_begin_obj(p->out, length2_id);              /* Length2 object */
    pdc_printf(p->out, "%ld\n",
            (long) ((t1_private_data *) t1src->private_data)->length[2]);
    pdc_end_obj(p->out);

    pdc_begin_obj(p->out, length3_id);              /* Length3 object */
    pdc_printf(p->out, "%ld\n",
            (long) ((t1_private_data *) t1src->private_data)->length[3]);
    pdc_end_obj(p->out);

    if (((t1_private_data *) t1src->private_data)->fontfile)
        pdc_fclose(((t1_private_data *) t1src->private_data)->fontfile);

    pdc_free(p->pdc, (void *) t1src->private_data);
}
Пример #6
0
static pdc_bool
pdf_parse_pfm(PDF *p, pdc_file *fp, pdf_font *font)
{
    static const char fn[] = "pdf_parse_pfm";
    fnt_font_metric *ftm = &font->ft.m;
    size_t length;
    pdc_byte *pfm;
    pdc_bool ismem;
    int i, dfFirstChar, dfLastChar, default_width;
    unsigned long dfExtentTable;

    /* read whole file and close it */
    pfm = (pdc_byte *) pdc_freadall(fp, &length, &ismem);
    pdc_fclose(fp);

    /* check whether this is really a valid PostScript PFM file */
    if (pfm == NULL ||
	(header_dfVersion != 0x100 && header_dfVersion != 0x200) ||
	dfDevice > length ||
	strncmp((const char *) pfm + dfDevice, PDF_STRING_PostScript, 10) ||
	ext_dfDriverInfo > length)
    {
	if (!ismem)
	    pdc_free(p->pdc, pfm);
        return pdc_false;
    }

    /* fetch relevant data from the PFM */
    ftm->type = fnt_Type1;

    font->ft.name = pdc_strdup(p->pdc, (const char *)pfm + ext_dfDriverInfo);
    ftm->name = pdc_strdup(p->pdc, font->ft.name);

    pdc_logg_cond(p->pdc, 1, trc_font,
        "\tPostScript font name: \"%s\"\n", ftm->name);

    switch (header_dfPitchAndFamily & 0xF0)
    {
	case PDF_ROMAN:
            ftm->flags |= FNT_SERIF;
	    break;
	case PDF_MODERN:
	    /* Has to be ignored, contrary to MS's specs */
	    break;
	case PDF_SCRIPT:
            ftm->flags |= FNT_SCRIPT;
	    break;
	case PDF_DECORATIVE:
	    /* the dfCharSet flag lies in this case... */
	    header_dfCharSet = PFM_SYMBOL_CHARSET;
	    break;
	case PDF_SWISS:
	case PDF_DONTCARE:
	default:
	    break;
    }

    /* temporarily */
    font->ft.enc = (pdc_encoding) header_dfCharSet;

    dfFirstChar = header_dfFirstChar;
    dfLastChar = header_dfLastChar;
    dfExtentTable = ext_dfExtentTable;

    /*
     * Some rare PFMs do not contain any ExtentTable if the fixed pitch flag
     * is set. Use the dfMaxWidth entry for all glyphs in this case.
     * If the user forced the font to be monospaced we use this value instead.
     */
    if ((!(header_dfPitchAndFamily & PDF_FIXED_PITCH) && dfExtentTable == 0) ||
        font->opt.monospace)
    {
        ftm->isFixedPitch = pdc_true;
        default_width = font->opt.monospace ? font->opt.monospace :
				(int) header_dfMaxWidth;
    }
    else
    {
	/* default values -- don't take the width of the default character */
        default_width = FNT_DEFAULT_WIDTH;
    }

    font->ft.numcodes = 256;
    ftm->numwidths = font->ft.numcodes;
    ftm->widths = (int *) pdc_calloc(p->pdc, ftm->numwidths * sizeof(int), fn);
    for (i = 0; i < font->ft.numcodes; i++)
        ftm->widths[i] = default_width;

    if (!ftm->isFixedPitch)
    {
	if (ext_dfExtentTable == 0 ||
	    ext_dfExtentTable + 2 * (header_dfLastChar-header_dfFirstChar) + 1 >
		length)
        {
	    if (!ismem)
		pdc_free(p->pdc, pfm);
	    return pdc_false;
	}

	for (i = dfFirstChar; i <= dfLastChar; i++)
            ftm->widths[i] =
                          (int) PFM_WORD(dfExtentTable + 2 * (i - dfFirstChar));
	/*
         * Check whether the font is actually opt.monospaced
	 * (the fixed pitch flag is not necessarily set)
	 */
        default_width = ftm->widths[dfFirstChar];

	for (i = dfFirstChar+1; i <= dfLastChar; i++)
            if (default_width != ftm->widths[i])
		break;

	if (i == dfLastChar + 1)
            ftm->isFixedPitch = pdc_true;
    }

    font->ft.weight = fnt_check_weight(header_dfWeight);
    ftm->defwidth = default_width;
    ftm->italicAngle = (header_dfItalic ? etmSlant/(10.0) : 0.0);
    ftm->capHeight = etmCapHeight;
    ftm->xHeight = etmXHeight;
    ftm->descender = -etmLowerCaseDescent;
    ftm->ascender = (int) header_dfAscent;

    ftm->underlinePosition = -etmUnderlineOffset;
    ftm->underlineThickness = etmUnderlineWidth;

    ftm->urx = header_dfMaxWidth;


    if (!ismem)
        pdc_free(p->pdc, pfm);

    return pdc_true;
}
Пример #7
0
static pdc_bool
pdf_parse_afm(
    PDF *p,
    pdc_file *fp,
    pdf_font *font,
    const char *fontname,
    const char *filename)
{
    static const char fn[] = "pdf_parse_afm";
    fnt_font_metric *ftm = &font->ft.m;
    const char *afmtype = NULL;
    char **wordlist = NULL, *keyword, *arg1;
    char line[AFM_LINEBUF];
    int i, cmp, lo, hi, nwords, nglyphs = 0, nline = 0;
    int tablen = ((sizeof keyStrings) / (sizeof (char *)));
    pdc_sint32 iz;
    double dz;
    pdc_scalar charwidth = -1;
    pdf_afmkey keynumber;
    fnt_glyphwidth *glw;
    pdc_bool toskip = pdc_false;
    pdc_bool is_zadbfont = !strcmp(fontname, "ZapfDingbats");

    /* all new glyph names of AGL 2.0 are missing */
    font->missingglyphs = 0xFFFFFFFF;

    /* read loop. because of Mac files we use pdc_fgetline */
    while (pdc_fgetline(line, AFM_LINEBUF, fp) != NULL)
    {
        /* split line */
        nline++;
        nwords = pdc_split_stringlist(p->pdc, line, AFM_SEPARATORS, 0,
                                      &wordlist);
        if (!nwords) continue;
        keyword = wordlist[0];

        /* find keynumber */
        lo = 0;
        hi = tablen;
        keynumber = NOPE;
        while (lo < hi)
        {
            i = (lo + hi) / 2;
            cmp = strcmp(keyword, keyStrings[i]);

            if (cmp == 0)
            {
                keynumber = (pdf_afmkey) i;
                break;
            }

            if (cmp < 0)
                hi = i;
            else
                lo = i + 1;
        }

        /* unkown key */
        if (keynumber == NOPE)
        {
            pdc_warning(p->pdc, PDF_E_T1_AFMBADKEY, keyword, filename, 0,0);
            goto PDF_PARSECONTD;
        }
        if (keynumber == ENDDIRECTION)
            toskip = pdc_false;

        if (nwords == 1 || toskip == pdc_true)
            goto PDF_PARSECONTD;

        /* key switch */
        arg1 = wordlist[1];
        switch (keynumber)
        {
            case STARTDIRECTION:
            if (pdc_str2integer(arg1, 0, &iz) != pdc_true)
                goto PDF_SYNTAXERROR;
            if (iz)
                toskip = pdc_true;
            break;

            case STARTCOMPFONTMETRICS:
            afmtype = "ACFM";
            goto PDF_SYNTAXERROR;

            case STARTMASTERFONTMETRICS:
            afmtype = "AMFM";
            goto PDF_SYNTAXERROR;

            case ISCIDFONT:
            afmtype = "CID font";
            if (!strcmp(arg1, "true"))
                goto PDF_SYNTAXERROR;
            break;

            case FONTNAME:
            font->ft.name = pdc_strdup(p->pdc, arg1);
            ftm->name = pdc_strdup(p->pdc, arg1);
            pdc_logg_cond(p->pdc, 1, trc_font,
                "\tPostScript font name: \"%s\"\n", ftm->name);
            break;

            /* Recognize Multiple Master fonts by last part of name */
            case FAMILYNAME:
            if (!strcmp(wordlist[nwords-1], "MM"))
                ftm->type = fnt_MMType1;
            else
                ftm->type = fnt_Type1;
            break;

            /* Default: FontSpecific */
            case ENCODINGSCHEME:
            if (!pdc_stricmp(arg1, "StandardEncoding") ||
                !pdc_stricmp(arg1, "AdobeStandardEncoding"))
                font->ft.issymbfont = pdc_false;
            break;

            case STDHW:
            if (pdc_str2double(arg1, &dz) != pdc_true)
                goto PDF_SYNTAXERROR;
            ftm->StdHW = (int) dz;
            break;

            case STDVW:
            if (pdc_str2double(arg1, &dz) != pdc_true)
                goto PDF_SYNTAXERROR;
            ftm->StdVW = (int) dz;
            break;

            case WEIGHT:
            font->ft.weight = fnt_check_weight(fnt_weightname2weight(arg1));
            break;

            case ISFIXEDPITCH:
            if (!pdc_stricmp(arg1, "false"))
                ftm->isFixedPitch = pdc_false;
            else
                ftm->isFixedPitch = pdc_true;
            break;

            /* New AFM 4.1 keyword "CharWidth" implies fixed pitch */
            case CHARWIDTH:
            if (pdc_str2double(arg1, &dz) != pdc_true)
                goto PDF_SYNTAXERROR;
            charwidth = dz;
            ftm->isFixedPitch = pdc_true;
            break;

            case ITALICANGLE:
            {
                if (pdc_str2double(arg1, &dz) != pdc_true)
                    goto PDF_SYNTAXERROR;
                ftm->italicAngle = dz;
            }
            break;

            case UNDERLINEPOSITION:
            if (pdc_str2double(arg1, &dz) != pdc_true)
                goto PDF_SYNTAXERROR;
            ftm->underlinePosition = (int) dz;
            break;

            case UNDERLINETHICKNESS:
            if (pdc_str2double(arg1, &dz) != pdc_true)
                goto PDF_SYNTAXERROR;
            ftm->underlineThickness = (int) dz;
            break;

            case FONTBBOX:
            {
                if (nwords != 5)
                    goto PDF_SYNTAXERROR;
                for (i = 1; i < nwords; i++)
                {
                    if (pdc_str2double(wordlist[i], &dz) != pdc_true)
                        goto PDF_SYNTAXERROR;
                    if (i == 1)
                        ftm->llx = dz;
                    else if (i == 2)
                        ftm->lly = dz;
                    else if (i == 3)
                        ftm->urx = dz;
                    else if (i == 4)
                        ftm->ury = dz;
                }
            }
            break;

            case CAPHEIGHT:
            if (pdc_str2double(arg1, &dz) != pdc_true)
                goto PDF_SYNTAXERROR;
            ftm->capHeight = (int) dz;
            break;

            case XHEIGHT:
            if (pdc_str2double(arg1, &dz) != pdc_true)
                goto PDF_SYNTAXERROR;
            ftm->xHeight = (int) dz;
            break;

            case DESCENDER:
            if (pdc_str2double(arg1, &dz) != pdc_true)
                goto PDF_SYNTAXERROR;
            ftm->descender = (int) dz;
            break;

            case ASCENDER:
            if (pdc_str2double(arg1, &dz) != pdc_true)
                goto PDF_SYNTAXERROR;
            ftm->ascender = (int) dz;
            break;

            /* Character widths */

            case STARTCHARMETRICS:
            if (pdc_str2integer(arg1, PDC_INT_UNSIGNED, (pdc_sint32 *) &nglyphs)
                != pdc_true || nglyphs <= 0)
                goto PDF_SYNTAXERROR;
            ftm->glw = (fnt_glyphwidth *) pdc_calloc(p->pdc,
                            (size_t) nglyphs * sizeof(fnt_glyphwidth), fn);
            break;

            /* Character code */
            case CODE:
            case CODEHEX:
            if (!nglyphs || !ftm->glw)
                goto PDF_SYNTAXERROR;
            if (font->ft.numglyphs >= nglyphs)
            {
                nglyphs++;
                ftm->glw = (fnt_glyphwidth *) pdc_realloc(p->pdc, ftm->glw,
                                (size_t) nglyphs * sizeof(fnt_glyphwidth), fn);
            }
            glw = &ftm->glw[font->ft.numglyphs];
            if (keynumber == CODE)
            {
                if (pdc_str2integer(arg1, 0, &iz) != pdc_true)
                    goto PDF_SYNTAXERROR;
            }
            else
            {
                if (pdc_str2integer(arg1, PDC_INT_HEXADEC, &iz) != pdc_true)
                    goto PDF_SYNTAXERROR;
            }
            glw->code = (pdc_short) iz;
            glw->unicode = 0;
            glw->width = (pdc_ushort)
                (font->opt.monospace ? font->opt.monospace : charwidth);
            font->ft.numglyphs++;

            /* Character width and name */
            for (i = 2; i < nwords; i++)
            {
                if (!strcmp(wordlist[i], "WX") ||
                    !strcmp(wordlist[i], "W0X") ||
                    !strcmp(wordlist[i], "W"))
                {
                    i++;
                    if (i == nwords)
                        goto PDF_SYNTAXERROR;
                    if (pdc_str2double(wordlist[i], &dz) != pdc_true)
                        goto PDF_SYNTAXERROR;
                    glw->width = (pdc_ushort)
                         (font->opt.monospace ? font->opt.monospace : dz);
                }

                if (!strcmp(wordlist[i], "N"))
                {
                    i++;
                    if (i == nwords)
                        goto PDF_SYNTAXERROR;

                    /* Unicode value by means of AGL,
                     * internal and private table
                     */
                    glw->unicode = is_zadbfont ?
                         (pdc_ushort) pdc_zadb2unicode(wordlist[i]):
                         pdc_insert_glyphname(p->pdc, wordlist[i]);
                    pdc_delete_missingglyph_bit(glw->unicode,
                                                &font->missingglyphs);

                }
            }
            break;


            default:
            break;
        }

        PDF_PARSECONTD:
        pdc_cleanup_stringlist(p->pdc, wordlist);
        wordlist = NULL;

        if (keynumber == ENDFONTMETRICS)
            break;
    }

    /* necessary font struct members */
    if (font->ft.name == NULL || ftm->glw == NULL)
        goto PDF_SYNTAXERROR;

    pdc_fclose(fp);

    ftm->numglwidths = font->ft.numglyphs;
    return pdc_true;

    PDF_SYNTAXERROR:
    pdc_fclose(fp);
    pdc_cleanup_stringlist(p->pdc, wordlist);

    if (afmtype)
        pdc_set_errmsg(p->pdc, PDF_E_T1_UNSUPP_FORMAT, afmtype, 0, 0, 0);
    else
        pdc_set_errmsg(p->pdc, PDC_E_IO_ILLSYNTAX, "AFM ", filename,
                       pdc_errprintf(p->pdc, "%d", nline), 0);
    return pdc_false;
}
Пример #8
0
pdc_file *
pdc_fopen(pdc_core *pdc, const char *filename, const char *qualifier,
          const pdc_byte *data, size_t size, int flags)
{
    static const char fn[] = "pdc_fopen";
    pdc_file *sfp;

    sfp = (pdc_file *) pdc_calloc(pdc, sizeof(pdc_file), fn);

    /* initialize */
    sfp->pdc = pdc;
    sfp->filename = pdc_strdup_ext(pdc, filename, 0, fn);

    if (flags & PDC_FILE_WRITEMODE || flags & PDC_FILE_APPENDMODE)
        sfp->wrmode = pdc_true;


    if (data != NULL || size > 0)
    {
        /* virtual file */
        if (sfp->wrmode)
        {
            sfp->data = (pdc_byte *) pdc_calloc(pdc, size, fn);
            if (data != NULL)
            {
                /* append mode */
                memcpy(sfp->data, data, size);
                sfp->pos = sfp->data + size;
            }
            else
            {
                sfp->pos = sfp->data;
            }
            sfp->end = sfp->pos;
            sfp->limit = sfp->data + size;
        }
        else
        {
            sfp->data = (pdc_byte *) data;
            sfp->pos = sfp->data;
            sfp->end = sfp->data + size;
        }
    }
    else
    {
        const char *mode;


        /* disk file */
        if (flags & PDC_FILE_BINARY)
            mode = READBMODE;
        else
            mode = READTMODE;
        if (flags & PDC_FILE_APPENDMODE)
            mode = APPENDMODE;
        else if (flags & PDC_FILE_WRITEMODE)
            mode = WRITEMODE;

        sfp->fp = pdc_fopen_logg(pdc, filename, mode);
        if (sfp->fp == NULL)
        {
            pdc_fclose(sfp);

            if (qualifier == NULL)
                qualifier = "";
            pdc_set_fopen_errmsg(pdc, PDC_E_IO_RDOPEN, qualifier, filename);
            return NULL;
        }
    }

    return sfp;
}
Пример #9
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);
}
Пример #10
0
static int
PFA_data_fill(PDF *p, PDF_data_source *src)
{
    static const char *fn = "PFA_data_fill";
    pdc_bool logg6 = pdc_logg_is_enabled(p->pdc, 6, trc_font);
#ifndef PDFLIB_EBCDIC
    static const char HexToBin['F' - '0' + 1] = {
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,
        0, 10, 11, 12, 13, 14, 15
    };
#else
#endif
    char *s, *c;
    int i;
    int len;
    t1_private_data *t1;
    pdf_t1portion t1portion;

    t1 = (t1_private_data *) src->private_data;

    if (t1->portion == t1_eof)
        return pdc_false;

    if (src->buffer_start == NULL)
    {
        src->buffer_start = (pdc_byte *)
                                pdc_malloc(p->pdc, PDC_BUFSIZE + 1, fn);
        src->buffer_length = PDC_BUFSIZE;
    }

    if (logg6)
        pdc_logg(p->pdc, "\t\t\tdata fill: portion=%s\n",
                 pdc_get_keyword(t1->portion, pdf_t1portion_keylist));

    s = pdc_fgetline((char *) src->buffer_start, PDC_BUFSIZE, t1->fontfile);
    if (s == NULL)
        return pdc_false;

    /* set unix line end */
    len = (int) strlen(s);
    s[len] = '\n';
    len++;
    s[len] = 0;

    /* check for line of zeros: set t1_zero flag if found */
    if (*s == '0')
    {
        for (i = 0; s[i] == '0'; i++)
        {
            /* */ ;
        }
        if (s[i] == '\n')
        {
            t1->portion = t1_zeros;

            if (logg6)
                pdc_logg(p->pdc, "\t\t\tlinefeed detected: set portion %s\n",
                         pdc_get_keyword(t1->portion,
                                         pdf_t1portion_keylist));
        }
    }

    /* check whether font data portion follows: set t1_encrypted flag later */
    t1portion = t1->portion;
    if (t1->portion != t1_encrypted &&
        !strncmp((const char *)s, PDF_CURRENTFILE, strlen(PDF_CURRENTFILE)))
    {
        t1portion = t1_encrypted;

        if (logg6)
            pdc_logg(p->pdc, "\t\t\t\"%s\" detected\n", PDF_CURRENTFILE);
    }

    src->next_byte = src->buffer_start;

    switch (t1->portion)
    {
        case t1_ascii:
        {
            t1->length[1] += (size_t) len;
            src->bytes_available = (size_t) len;
        }
        break;

        case t1_encrypted:
        {
            src->bytes_available = 0;

            /* Convert to upper case for safe binary conversion */
            for (c = s; *c != '\n'; c++)
            {
                *c = (char) pdc_toupper(*c);
            }

            /* convert ASCII to binary in-place */
            for (i = 0; s[i] != '\n'; i += 2)
            {
                if ((!pdc_isxdigit(s[i]) && !pdc_isspace(s[i])) ||
                    (!pdc_isxdigit(s[i+1]) && !pdc_isspace(s[i+1])))
                {
                    pdc_fclose(t1->fontfile);
                    pdc_error(p->pdc, PDF_E_FONT_CORRUPT_PFA, 0, 0, 0, 0);
                }
                s[i/2] = (char) (16*HexToBin[s[i]-'0'] + HexToBin[s[i+1]-'0']);

                src->bytes_available++;
            }
            t1->length[2] += src->bytes_available;
        }
        break;

        case t1_zeros:
        {
            t1->length[3] += (size_t) len;
            src->bytes_available = (size_t) len;
        }
        break;

        default:
        break;
    }

    t1->portion = t1portion;

    if (logg6)
        pdc_logg(p->pdc, "\t\t\tset portion %s\n",
                 pdc_get_keyword(t1->portion, pdf_t1portion_keylist));
    return pdc_true;
}
Пример #11
0
pdc_bool
pdf_t1open_fontfile(PDF *p, pdf_font *font, const char *filename,
                    PDF_data_source *t1src, pdc_bool requested)
{
    static const char *fn = "pdf_t1open_fontfile";
    t1_private_data  *t1 = NULL;
    pdc_file *fp = NULL;
    const char *stemp = NULL;
    pdc_byte magic[PFA_TESTBYTE];
    char fullname[PDC_FILENAMELEN];
    int fflags = PDC_FILE_BINARY;
    pdc_bool ispfb = pdc_true;

    if (filename)
    {
        pdc_bool retval = pdc_true;
        pdc_bool fnamegiven = (strcmp(filename, FNT_MISSING_FILENAME) == 0) ?
                              pdc_false : pdc_true;
        (void) retval;

        if (fnamegiven)
        {
            fp = pdc_fsearch_fopen(p->pdc, filename, fullname,
                                   "PostScript Type1 ", fflags);
            if (fp == NULL)
            {
                if (t1src)
                    PDC_RETHROW(p->pdc);
                return pdc_check_fopen_errmsg(p->pdc, requested);
            }

            pdc_logg_cond(p->pdc, 1, trc_font,
                "\tLoading PostScript Type1 fontfile \"%s\":\n", fullname);
        }

    }

    if (fp)
    {
        pdc_fread(magic, 1, PFA_TESTBYTE, fp);
        stemp = filename;
    }
    else if (font->ft.img)
    {
        strncpy((char *) magic, (const char *)font->ft.img, PFA_TESTBYTE);
        stemp = font->ft.name;
    }

    /* try to identify PFA files */
    if (magic[0] != PFB_MARKER)
    {
        char startsequ[PFA_TESTBYTE + 1];

        strcpy(startsequ, FNT_PFA_STARTSEQU);

        if (strncmp((const char *) magic, startsequ, PFA_TESTBYTE))
        {
            if (fp)
                pdc_fclose(fp);
            pdc_set_errmsg(p->pdc, PDF_E_T1_NOFONT, stemp, 0, 0, 0);
            if (t1src)
                PDC_RETHROW(p->pdc);
            return pdc_false;
        }
        ispfb = pdc_false;
    }

    pdc_logg_cond(p->pdc, 1, trc_font,
        "\tPostScript Type1 font of format \"%s\" detected\n",
        ispfb ? "PFB" : "PFA");

    if (t1src)
    {
        t1src->private_data = (unsigned char *)
                pdc_malloc(p->pdc, sizeof(t1_private_data), fn);
        t1 = (t1_private_data *) t1src->private_data;

        if (filename)
        {
            pdc_fclose(fp);
            if (ispfb)
            {
                t1->fontfile =
                    pdc_fsearch_fopen(p->pdc, fullname, NULL, "PFB ", fflags);
            }
            else
            {
                t1->fontfile =
                    pdc_fsearch_fopen(p->pdc, fullname, NULL, "PFA ",
                                      PDC_FILE_TEXT);
            }

            if (t1->fontfile == NULL)
                PDC_RETHROW(p->pdc);
        }
        else if (font->ft.img)
        {
            /* only for virtual PFB files */
            t1->fontfile = NULL;
            t1->img = font->ft.img;
            t1->pos = font->ft.img;
            t1->end = font->ft.img + font->ft.filelen;
        }

        t1src->init = t1data_init;
        t1src->fill = ispfb ? PFB_data_fill : PFA_data_fill;
        t1src->terminate = t1data_terminate;
    }
    else if (fp != NULL)
    {
        if (pdc_file_isvirtual(fp) == pdc_true)
        {
            if (ispfb)
                font->ft.img =
                    (pdc_byte *) pdc_freadall(fp, &font->ft.filelen, NULL);
            font->ft.imgname = pdc_strdup(p->pdc, fullname);
            pdc_lock_pvf(p->pdc, font->ft.imgname);
        }
        font->ft.filename = pdc_strdup(p->pdc, fullname);
        pdc_fclose(fp);
    }

    return pdc_true;
}