コード例 #1
0
ファイル: p_util.c プロジェクト: pottootje1982/singalong
/*
 * Conversion to PDFDoc/EBCDIC or UTF-16/[EBCDIC-]UTF-8
 */
char *
pdf_convert_hypertext(PDF *p, const char *text, int len,
    pdc_text_format hypertextformat, pdc_encoding hypertextencoding,
    int codepage, int *outlen, pdc_bool oututf8, pdc_bool verbose)
{
    pdc_encodingvector *inev = NULL, *outev = NULL;
    pdc_byte *intext = (pdc_byte *) text, *outtext = NULL;
    pdc_text_format textformat = pdc_utf16be;
    int convflags = PDC_CONV_WITHBOM | PDC_CONV_TRYBYTES;

    *outlen = 0;

    if (text == NULL)
        return NULL;

    if (len == 0)
        len = (int) strlen(text);

    /* incoming encoding */
    if (hypertextencoding >= 0)
    {
        inev = pdc_get_encoding_vector(p->pdc, hypertextencoding);
    }

    /* PDFDocEncoding */
    outev = pdc_get_encoding_vector(p->pdc, pdc_pdfdoc);

    /* conversion to UTF-16-BE or PDFDocEncoding / EBCDIC */
    pdf_set_convertflags(p, &convflags);
    if (pdc_logg_is_enabled(p->pdc, 3, trc_text))
        convflags |= PDC_CONV_LOGGING;

    pdc_convert_string(p->pdc, hypertextformat, codepage, inev,
                       intext, len,
                       &textformat, outev, &outtext, outlen,
                       convflags, verbose);


    /* conversion to UTF-8 if Unicode */
    if (oututf8 && textformat == pdc_utf16be)
    {
        pdc_text_format outtextformat = PDC_UTF8;
        pdc_byte *newtext = NULL;

        convflags = PDC_CONV_WITHBOM;
        if (pdc_logg_is_enabled(p->pdc, 3, trc_text))
            convflags |= PDC_CONV_LOGGING;

        pdc_convert_string(p->pdc, textformat, 0, NULL, outtext, *outlen,
                           &outtextformat, NULL, &newtext, outlen,
                           convflags, verbose);
        pdc_free(p->pdc, outtext);
        outtext = newtext;
    }

    return (char *) outtext;
}
コード例 #2
0
void *
pdc_realloc(pdc_core *pdc, void *mem, size_t size, const char *caller)
{
    void *ret;
    pdc_bool logg1 = pdc_logg_is_enabled(pdc, 1, trc_memory);

    if (logg1)
        pdc_logg(pdc, "\ttry to realloc %p to %ld bytes\n", mem, size);

    if (size == (size_t) 0 || (long) size < 0L)
    {
        size = (size_t) 1;
        pdc_error(pdc, PDC_E_INT_ALLOC0, caller, 0, 0, 0);
    }

    ret = (mem == (void *) 0) ?
	(*pdc->pr->allocproc)(pdc->pr->opaque, size, caller) :
	(*pdc->pr->reallocproc)(pdc->pr->opaque, mem, size, caller);

    if (ret == (void *) 0)
	pdc_error(pdc, PDC_E_MEM_OUT, caller, 0, 0, 0);

    pdc_logg_cond(pdc, 1, trc_memory,
                       "\t%p realloced to\n"
                       "\t%p new, size=%ld, called from \"%s\"\n",
                       mem, ret, size, caller);

    return ret;
}
コード例 #3
0
void *
pdc_malloc(pdc_core *pdc, size_t size, const char *caller)
{
    void *ret;
    pdc_bool logg1 = pdc_logg_is_enabled(pdc, 1, trc_memory);

    if (logg1)
        pdc_logg(pdc, "\ttry to malloc %ld bytes\n", size);


    /* the behavior of malloc(0) is undefined in ANSI C, and may
     * result in a NULL pointer return value which makes PDFlib bail out.
     */
    if (size == (size_t) 0 || (long) size < 0L)
    {
	size = (size_t) 1;
	pdc_error(pdc, PDC_E_INT_ALLOC0, caller, 0, 0, 0);
    }

    if ((ret = (*pdc->pr->allocproc)(pdc->pr->opaque, size, caller)) ==
        (void *) 0)
    {
	pdc_error(pdc, PDC_E_MEM_OUT, caller, 0, 0, 0);
    }

    if (logg1)
        pdc_logg(pdc, "\t%p malloced, size=%ld, called from \"%s\"\n",
                       ret, size, caller);

    return ret;
}
コード例 #4
0
/* We cook up our own calloc routine, using the caller-supplied
 * malloc and memset.
 */
void *
pdc_calloc(pdc_core *pdc, size_t size, const char *caller)
{
    void *ret;
    pdc_bool logg1 = pdc_logg_is_enabled(pdc, 1, trc_memory);

    if (logg1)
        pdc_logg(pdc, "\ttry to calloc %ld bytes\n", size);

    if (size == (size_t) 0 || (long) size < 0L)
    {
	size = (size_t) 1;
	pdc_error(pdc, PDC_E_INT_ALLOC0, caller, 0, 0, 0);
    }

    if ((ret = (*pdc->pr->allocproc)(pdc->pr->opaque, size, caller)) ==
        (void *) 0)
    {
	pdc_error(pdc, PDC_E_MEM_OUT, caller, 0, 0, 0);
    }

    if (logg1)
        pdc_logg(pdc, "\t%p calloced, size=%ld, called from \"%s\"\n",
                      ret, size, caller);

    memset(ret, 0, size);
    return ret;
}
コード例 #5
0
static void
pdf_type3_protocol(PDF *p, pdf_font *font, pdc_encodingvector *ev)
{
    /* logging protocol */
    if (pdc_logg_is_enabled(p->pdc, 2, trc_font))
    {
        char *glyphname;
        pdc_ushort uv = 0;
        int gid, code, width = 0;

        for (gid = 0; gid < font->t3font->next_glyph; gid++)
        {
            glyphname = NULL;

            pdc_logg(p->pdc, "\t\tGlyph%4d: ", gid);

            if (ev != NULL)
            {
                code = font->ft.gid2code[gid];
                uv = ev->codes[code];
                if (glyphname == NULL)
                    glyphname = ev->chars[code];
                width = fnt_get_glyphwidth(code, &font->ft);

                pdc_logg(p->pdc, "code=%3d  ", code);
            }

            if (width == FNT_MISSING_WIDTH)
                width = 0;

            pdc_logg(p->pdc, "U+%04X  width=%4d  \"%s\"\n",
                     uv, width, glyphname);
        }
    }
}
コード例 #6
0
ファイル: pc_file.c プロジェクト: gcfavorites/tastools
static void
pdc_logg_openclose(pdc_core *pdc, FILE *fp, pdc_bool opened)
{
    int errno1 = errno, errno2 = 0;

    if (pdc_logg_is_enabled(pdc, 3, trc_filesearch))
    {
#if defined(WIN32)
        errno2 = (int) GetLastError();
#elif defined(MAC)
        errno2 = __MacOSErrNo;
#endif
        pdc_logg(pdc, "\t%p", fp);
        if (opened)
            pdc_logg(pdc, " opened");
        else
            pdc_logg(pdc, " closed");
#if PDC_FILENO_EXISTS
        if (fp != NULL && opened)
            pdc_logg(pdc, ", fileno=%d", fileno(fp));
#endif
        pdc_logg(pdc, ", errno=%d", errno1);
        if (errno2 != 0)
            pdc_logg(pdc, ", errno2=%d", errno2);
        pdc_logg(pdc, "\n");

        /* because of logfile IO */
        if (errno != errno1)
            errno = errno1;
    }
}
コード例 #7
0
ファイル: p_type1.c プロジェクト: Distrotech/PDFlib-Lite
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;
}
コード例 #8
0
ファイル: ft_font.c プロジェクト: xharbour/core
void
fnt_font_logg_widths(pdc_core *pdc, fnt_font *font)
{
    if (font != NULL &&
        pdc_logg_is_enabled(pdc, 2, trc_font))
    {
        int code, width;

        for (code = 0; code < PDC_NUM_UNIVAL; code++)
        {
            width = fnt_get_glyphwidth(code, font);
            if (width == FNT_MISSING_WIDTH)
                break;
            pdc_logg(pdc,
                  "\t\tWidth[%d]: %d\n", code, width);
        }
    }
}
コード例 #9
0
ファイル: ft_font.c プロジェクト: xharbour/core
void
fnt_font_logg_protocol(pdc_core *pdc, fnt_font *font)
{
    if (font != NULL &&
        pdc_logg_is_enabled(pdc, 2, trc_font))
    {
        const char *wname = fnt_weight2weightname(font->weight);
        char dwname[16];

        dwname[0] = 0;
        if (wname && *wname)
            sprintf(dwname, " (%s)", wname);

        pdc_logg(pdc,
                  "\n"
                  "\t\tFont type: %s\n"
                  "\t\tFlags: %d\n"
                  "\t\tFontBBox: %g,%g  %g,%g\n"
                  "\t\titalicAngle: %g\n"
                  "\t\tisFixedPitch: %d\n"
                  "\t\tunderlinePosition: %d\n"
                  "\t\tunderlineThickness: %d\n"
                  "\t\tcapHeight: %d\n"
                  "\t\txHeight: %d\n"
                  "\t\tascender: %d\n"
                  "\t\tdescender: %d\n"
                  "\t\tlinegap: %d\n"
                  "\t\tweight: %d%s\n"
                  "\t\tStdVW: %d\n"
                  "\t\tStdHW: %d\n"
                  "\t\tdefWidth: %d\n",
                  fnt_get_pdf_fonttype_name(font->m.type),
                  font->m.flags,
                  font->m.llx, font->m.lly, font->m.urx, font->m.ury,
                  font->m.italicAngle, font->m.isFixedPitch,
                  font->m.underlinePosition, font->m.underlineThickness,
                  font->m.capHeight, font->m.xHeight, font->m.ascender,
                  font->m.descender, font->linegap, font->weight,
                  dwname,
                  font->m.StdVW, font->m.StdHW,
                  font->m.defwidth);
    }
}
コード例 #10
0
ファイル: p_util.c プロジェクト: pottootje1982/singalong
char *
pdf_convert_name(PDF *p, const char *name, int len, int flags)
{
    char *resname;
    char *newname;
    int newlen;
    pdc_encoding htenc;
    int htcp;

    pdf_prepare_name_string(p, name, len, PDC_SHRT_MAX,
                            &newname, &newlen, &htenc, &htcp);

    flags |= PDC_CONV_EBCDIC;
    if (pdc_logg_is_enabled(p->pdc, 3, trc_text))
        flags |= PDC_CONV_LOGGING;

    resname = pdc_convert_name_ext(p->pdc, newname, newlen, htenc, htcp, flags);
    if (newname != name)
        pdc_free(p->pdc, newname);

    return resname;
}
コード例 #11
0
ファイル: p_util.c プロジェクト: pottootje1982/singalong
const char *
pdf_convert_filename(PDF *p, const char *filename, int len,
                     const char *paramname, int flags)
{
    const char *resfilename;
    char *newfilename;
    int newlen;
    pdc_encoding htenc;
    int htcp;

    pdf_prepare_name_string(p, filename, len, PDC_FILENAMELEN - 1,
                            &newfilename, &newlen, &htenc, &htcp);

    flags |= PDC_CONV_EBCDIC;
    if (pdc_logg_is_enabled(p->pdc, 3, trc_text))
        flags |= PDC_CONV_LOGGING;

    resfilename = pdc_convert_filename_ext(p->pdc, newfilename, len,
                                           paramname, htenc, htcp, flags);
    if (newfilename != filename)
        pdc_free(p->pdc, newfilename);

    return resfilename;
}
コード例 #12
0
void
pdc_error(
    pdc_core *	pdc,
    int		errnum,
    const char *parm1,
    const char *parm2,
    const char *parm3,
    const char *parm4)
{
    const char *logmsg = NULL;

    /* avoid recursive errors, but allow rethrow.
    */
    if (errnum != -1 && pdc->pr->in_error)
	return;

    pdc->pr->in_error = pdc_true;
    pdc->pr->x_thrown = pdc_true;

    if (errnum != -1)
    {
	const pdc_error_info *ei = get_error_info(pdc, errnum);

        make_errmsg(pdc, ei, parm1, parm2, parm3, parm4, pdc_true);
        pdc->pr->errnum = errnum;
    }

    if (pdc->pr->x_sp > pdc->pr->x_sp0)
    {
        if (pdc_logg_is_enabled(pdc, 2, trc_warning))
	    logmsg = "[Nested exception %d in %s]";
    }
    else
    {
	logmsg = "\n[Last exception %d in %s]";
    }

    if (logmsg != NULL)
    {
        pdc_logg(pdc, logmsg, pdc->pr->errnum,
	    (pdc->pr->errnum == 0 || !pdc->pr->apiname) ? "" : pdc->pr->apiname,
	    pdc->pr->x_sp0 + 1, pdc->pr->x_sp - pdc->pr->x_sp0);

        pdc_logg(pdc, "[\"%s\"]\n\n", pdc->pr->errbuf);
    }

    if (pdc->pr->x_sp == -1)
    {
	char errbuf[PDC_ERRBUF_SIZE];
        const char *apiname = pdc_get_apiname(pdc);
        const char *errmsg = pdc->pr->errbuf;

        if (strlen(apiname))
        {
            sprintf(errbuf, "[%d] %s: %s", pdc->pr->errnum, apiname, errmsg);
            errmsg = errbuf;
        }

        (*pdc->pr->errorhandler)(pdc->pr->opaque, PDF_UnknownError, errmsg);

	/*
	 * The error handler must never return. If it does, it is severely
	 * broken. We cannot remedy this, so we exit.
	 */
	 exit(99);

    }
    else
    {
        longjmp(pdc->pr->x_stack[pdc->pr->x_sp].jbuf.jbuf, 1);
    }

} /* pdc_error */
コード例 #13
0
pdc_id
pdf_write_info(PDF *p, pdc_bool moddate)
{
    pdc_bool logg3 = pdc_logg_is_enabled(p->pdc, 3, trc_xmp);
    char time_str[PDC_TIME_SBUF_SIZE];
    char producer[PDC_GEN_BUFSIZE];
    pdf_info    *info;
    pdc_id      info_id;



    const char *product = "PDFlib Lite";
    const char *security = "";

    (void) logg3;


    if (!p->pdc->smokerun)
        pdc_logg_cond(p->pdc, 1, trc_api,
            "[Full product name: \"%s\"]\n", product);

    info_id = pdc_begin_obj(p->out, PDC_NEW_ID);        /* Info object */

    pdc_begin_dict(p->out);

    /*
     * Although it would be syntactically correct, we must not remove
     * the space characters after the dictionary keys since this
     * would break the PDF properties feature in Windows Explorer.
     */

    if (p->userinfo)
    {
        for (info = p->userinfo; info != NULL; info = info->next)
        {
            pdf_put_pdfname(p, info->key);
            pdc_puts(p->out, " ");

            if (strcmp(info->key, "Trapped"))
                pdf_put_hypertext(p, info->value);
            else
                pdf_put_pdfname(p, info->value);

            pdc_puts(p->out, "\n");
        }
    }


    pdc_get_timestr(time_str, pdc_false);

    /* creation date and time */
    pdc_puts(p->out, "/CreationDate ");
    pdf_put_hypertext(p, time_str);
    pdc_puts(p->out, "\n");

    /* modification date and time */
    if (moddate)
    {
        pdc_puts(p->out, "/ModDate ");
        pdf_put_hypertext(p, time_str);
        pdc_puts(p->out, "\n");
    }

    /*
     * If you change the /Producer entry your license to use
     * PDFlib will be void!
     */

    if (p->pdc->binding)
        pdc_sprintf(p->pdc, pdc_false, producer, "%s %s%s (%s/%s)", product,
            PDFLIB_VERSIONSTRING, security, p->pdc->binding, PDF_PLATFORM);
    else
        pdc_sprintf(p->pdc, pdc_false, producer, "%s %s%s (%s)", product,
            PDFLIB_VERSIONSTRING, security, PDF_PLATFORM);

    pdc_puts(p->out, "/Producer ");
    pdf_put_hypertext(p, producer);
    pdc_puts(p->out, "\n");

    pdc_end_dict(p->out);
    pdc_end_obj(p->out);                        /* Info object */




    return info_id;
}
コード例 #14
0
ファイル: p_util.c プロジェクト: pottootje1982/singalong
char *
pdf_get_opt_filename(PDF *p, const char *keyword, pdc_resopt *resopts,
                     pdc_encoding enc, int codepage)
{
    pdc_bool logg1 = pdc_logg_is_enabled(p->pdc, 1, trc_optlist);
    pdc_bool logg3 = pdc_logg_is_enabled(p->pdc, 3, trc_text);
    pdc_byte *filename = NULL;
    char **strlist;

    if (pdc_get_optvalues(keyword, resopts, NULL, &strlist))
    {
        pdc_encodingvector *inev = NULL, *outev = NULL;
        pdc_text_format intextformat = pdc_bytes;
        pdc_text_format outtextformat = pdc_utf16; /* sic! */
        int convflags = PDC_CONV_NOBOM | PDC_CONV_TRYBYTES | PDC_CONV_NEWALLOC;
        pdc_bool isutf8;
        int ic, outlen;

        /* whole option list or string list is in UTF-8 */
        isutf8 = pdc_is_lastopt_utf8(resopts);

        if (!isutf8)
        {
            if (enc < 0 && enc != pdc_unicode && enc != pdc_cid)
                enc = pdf_get_hypertextencoding(p, "auto", &codepage,
                                                pdc_true);
            if (enc >= 0)
                inev = pdc_get_encoding_vector(p->pdc, enc);
        }
        else
        {
            intextformat = PDC_UTF8;
        }

        if (logg1)
        {
            if (isutf8)
            {
                pdc_logg(p->pdc, "\tOption \"%s\" is "PDC_UTF8_STRG" encoded\n",
                         keyword);
            }
            else
            {
                pdc_logg(p->pdc, "\tOption \"%s\" is %s encoded\n",
                         keyword, pdc_get_user_encoding(p->pdc, enc));
            }
        }

        outev = pdc_get_encoding_vector(p->pdc, pdc_winansi);

        if (logg3)
            convflags |= PDC_CONV_LOGGING;
        pdf_set_convertflags(p, &convflags);

        pdc_convert_string(p->pdc, intextformat, codepage, inev,
                    (pdc_byte *) strlist[0], (int) strlen(strlist[0]),
                    &outtextformat, outev, &filename, &outlen,
                    convflags, pdc_true);

        if (outtextformat == pdc_utf16)
        {
            pdc_ushort uv, *unifilename = (pdc_ushort *) filename;
            int code;

            if (p->compatibility < PDC_1_7)
                pdc_error(p->pdc, PDC_E_IO_UNSUPP_PDFUNINAME, 0, 0, 0, 0);

            /* we must replace non-WinAnsi characters by period
             * and omit the BOM to get a WinAnsi string.
             */
            outlen /= 2;
            for (ic = 0; ic < outlen; ic++)
            {
                uv = unifilename[ic];

                code = pdc_get_encoding_bytecode(p->pdc, outev, uv);
                if (code <= 0)
                    uv = PDC_UNICODE_PERIOD;

                filename[ic] = (char) uv;
            }
            filename[ic] = 0;
        }

        if (logg3)
            pdc_logg_hexdump(p->pdc, "output filename", "\t\t",
                             (char *) filename, strlen((char *) filename));
    }

    return (char *) filename;
}
コード例 #15
0
pdc_bool
pdf_get_metrics_tt(PDF *p, pdf_font *font, const char *fontname,
                   pdc_encoding enc, const char *filename)
{
    pdc_bool logg1 = pdc_logg_is_enabled(p->pdc, 1, trc_font);
    pdc_bool logg2 = pdc_logg_is_enabled(p->pdc, 2, trc_font);
    int filesize = 0;
    double kbfilesize = 0;
    int foundglyphs, flags = 0;
    tt_file *ttf;
    pdc_bool retval;
    pdc_encoding enc_req;
    pdc_encodingvector *ev = NULL;
    pdc_bool isotf;
    int errcode = 0;

    (void) logg2;

    /*
     * Initialisation
     */
    ttf = fnt_new_tt(p->pdc, &font->ft);
    ttf->filename = filename;
    ttf->fontname = fontname;
    ttf->verbose = font->verbose;
    ttf->incore = pdc_true;
    ttf->monospace = font->opt.monospace;
    filesize = font->ft.filelen;
    kbfilesize = filesize / 1024.0;

    /*
     * Read font file
     */
    retval = fnt_read_tt(ttf);
    if (retval == pdc_false)
        goto PDF_TRUETYPE_ERROR2;

    /*
     * Font type
     */
    if (ttf->tab_CFF_)
    {
        isotf = pdc_true;
        font->ft.m.type = fnt_Type1C;
	font->cff_offset = (long) ttf->tab_CFF_->offset;
	font->cff_length = ttf->tab_CFF_->length;
    }
    else
    {
        isotf = pdc_false;
        font->ft.m.type = fnt_TrueType;
        TT_IOCHECK(ttf, tt_tag2idx(ttf, fnt_str_glyf) != -1);
        TT_IOCHECK(ttf, tt_tag2idx(ttf, fnt_str_loca) != -1);
    }

    /* Number of Glyphs */
    if (ttf->numGlyphs <= 1)
    {
        errcode = FNT_E_TT_NOGLYFDESC;
        goto PDF_TRUETYPE_ERROR1;
    }


    /*
     * Encoding
     */
    if (isotf)
    {
        /* OpenType font with CFF table */
        if (ttf->charcoll != cc_none)
        {
            /* CID font */
            if (font->ft.m.charcoll != cc_none)
            {
                if (!ttf->regisadobe)
                {
                    errcode = PDF_E_CJK_UNSUPP_REGISTRY;
                    goto PDF_TRUETYPE_ERROR1;
                }

                if (font->ft.m.charcoll != ttf->charcoll)
                {
                    errcode = PDF_E_CJK_UNSUPP_CHARCOLL;
                    goto PDF_TRUETYPE_ERROR1;
                }


                if (font->outcmapname != NULL)
                    enc = pdc_cid;

                if (logg1)
                    pdc_logg(p->pdc, "\tCID font ordering: \"%s\"\n",
                             fnt_get_ordering_cid(ttf->charcoll));
            }
            else if (enc == pdc_unicode || enc == pdc_glyphid)
            {
                font->ft.m.charcoll = ttf->charcoll;
                font->supplement = ttf->supplement;
            }
            else
            {
                errcode = PDF_E_FONT_ONLY_CMAP;
                goto PDF_TRUETYPE_ERROR1;
            }
        }
        else if (font->ft.m.charcoll != cc_none)
        {
            /* SID font */
            errcode = PDF_E_FONT_UNSUPP_CMAP;
            goto PDF_TRUETYPE_ERROR1;
        }
    }
    else
    {
        if (font->ft.m.charcoll != cc_none)
        {
            int i;
            pdc_bool iscjk = pdc_false;

            for (i = 0; i < PDC_NUMCHARCOLL; i++)
            {
                if (ttf->tab_OS_2->charcolls[i])
                    iscjk = pdc_true;

                if (ttf->tab_OS_2->charcolls[i] == font->ft.m.charcoll)
                    break;
            }
            if (i == PDC_NUMCHARCOLL)
            {
                if (iscjk)
                {
                    /* CJK font */
                    errcode = PDF_E_CJK_UNSUPP_CHARCOLL;
                    goto PDF_TRUETYPE_ERROR1;
                }
                else
                {
                    /* no CJK font */
                    errcode = PDF_E_FONT_UNSUPP_CMAP;
                    goto PDF_TRUETYPE_ERROR1;
                }
            }
            else
            {
                if (font->outcmapname != NULL)
                {
                    ttf->charcoll = font->ft.m.charcoll;
                    enc = pdc_cid;
                }
            }
        }
    }

    /* encoding vector */
    enc_req = fnt_get_tt_encoding_key(ttf, enc);
    if (enc_req == pdc_invalidenc)
    {
        errcode = FNT_E_TT_BADCMAP;
        goto PDF_TRUETYPE_ERROR1;
    }
    else if (enc_req != enc)
    {
        if (strcmp(font->encapiname, "auto"))
        {
            pdc_warning(p->pdc, PDF_E_FONT_FORCEENC,
                        pdf_get_encoding_name(p, enc_req, NULL),
                        0, 0, 0);
        }
        enc = enc_req;
    }
    if (enc >= 0)
        ev = pdc_get_encoding_vector(p->pdc, enc);
    font->ft.enc = enc;
    font->ft.issymbfont = ttf->issymbol;
    font->hasnomac = !ttf->tab_cmap || !ttf->tab_cmap->mac;


    /* builtin encoding */
    if (enc == pdc_builtin)
    {
        if (font->ft.issymbfont == pdc_false)
        {
            errcode = PDF_E_FONT_BADENC;
            goto PDF_TRUETYPE_ERROR1;
        }
        else
        {
            /* encoding vector for builtin */
            ev = pdf_create_font_encoding(p, enc, font, fontname, pdc_true);
            font->symenc = font->ft.enc;
        }
    }

    {
        /* optimizing PDF output */
        if (enc == pdc_ebcdic ||
            enc == pdc_ebcdic_37 ||
            enc == pdc_ebcdic_winansi)
            font->towinansi = pdc_winansi;

    }

    /* /FontName in FontDescriptor */
    font->ft.m.name = pdc_strdup(p->pdc, ttf->tab_name->englishname4);

    /* /BaseFont name */
    font->ft.name = pdc_strdup(p->pdc, ttf->tab_name->englishname6);


#define PDF_RESTRICTED_TT_EMBEDDING	0x02
    /* check embedding flags */
    if ((font->opt.embedding) && ttf->tab_OS_2 &&
	ttf->tab_OS_2->fsType == PDF_RESTRICTED_TT_EMBEDDING)
    {
        errcode = FNT_E_TT_EMBED;
        goto PDF_TRUETYPE_ERROR1;
    }


    if (logg1)
    {
        pdc_logg(p->pdc,
            "\tFull font name: \"%s\"\n"
            "\tPostScript font name: \"%s\"\n"
            "\tFont embedding: %s\n"
            "\tVertical font: %s\n",
            font->ft.name, font->ft.m.name,
            PDC_BOOLSTR(font->opt.embedding),
            PDC_BOOLSTR(font->ft.vertical));

        if (ttf->tab_name->producer != NULL)
            pdc_logg(p->pdc, "\tFont producer: \"%s\"\n",
                     ttf->tab_name->producer);

        pdc_logg(p->pdc, "\tNumber of Glyphs: %d\n", ttf->numGlyphs);
    }

    /* Save font values */
    fnt_set_tt_fontvalues(ttf);

    /* Flags for creating font arrays */
    flags = TT_FONT_code2gid | TT_FONT_m_widths;



    /* Create font mapping and width arrays */
    foundglyphs = fnt_set_tt_fontarrays(ttf, flags);

   /***********************************/
    if (font->symenc != pdc_invalidenc)
        font->ft.enc = pdc_builtin;
   /***********************************/

    if (!foundglyphs)
    {
        errcode = PDF_E_FONT_BADENC;
        goto PDF_TRUETYPE_ERROR1;
    }


    fnt_delete_tt(ttf);

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

    return pdc_true;

    PDF_TRUETYPE_ERROR1:
    pdc_set_errmsg(p->pdc, errcode, 0, 0, 0, 0);

    PDF_TRUETYPE_ERROR2:
    fnt_delete_tt(ttf);

    return pdc_false;
}
コード例 #16
0
ファイル: ft_corefont.c プロジェクト: LuaDist/cd
static void
fnt_parse_cid_widths(pdc_core *pdc, fnt_font *font)
{
    static const char fn[] = "fnt_parse_cid_widths";
    int slot, slota, slotm;
    const char *chunk;
    char **strlist = NULL, **sstrlist = NULL, *str;
    int cid = 0, cidfirst, cidlast, width;
    int il, is, ns, nss = 0;
    int wformat = 2;

    /* search for font name */
    slotm = 100;
    for (slot = 0; slot < slotm; slot += FNT_CIDMETRIC_INCR)
    {
        if (!strcmp(fnt_cid_width_arrays[slot], font->name))
            break;
    }
    if (slot == slotm)
        return;

    /* we take the maximum */
    font->m.numwidths = fnt_get_maxcid(font->m.charcoll, -1) + 1;
    font->m.widths = (int *) pdc_malloc(pdc,
                                 font->m.numwidths * sizeof(int), fn);

    slota = slot + 1;                       /* skip font name  */
    slotm = slot + FNT_CIDMETRIC_INCR;
    for (slot = slota; slot < slotm; slot++)
    {
        chunk = fnt_cid_width_arrays[slot];

        ns = pdc_split_stringlist(pdc, chunk, " \n", 0, &strlist);
        for (is = 0; is < ns; is++)
        {
            str = strlist[is];

            /* check for next format 1 chunk */
            if (wformat == 2 && strchr(str, '['))
            {
                nss = pdc_split_stringlist(pdc, str, " [", 0, &sstrlist);
                str = sstrlist[0];
                pdc_str2integer(str, 0, &cidfirst);
                for (; cid < cidfirst; cid++)
                    font->m.widths[cid] = FNT_DEFAULT_CIDWIDTH;
                str = sstrlist[1];
                wformat = 1;
            }

            /* format 1:  cid [width_1 width_2 ... width_n] */
            if (wformat == 1)
            {
                il = (int) strlen(str) - 1;
                if (str[il] == ']')
                {
                    str[il] = 0;
                    wformat = 2;
                }

                pdc_str2integer(str, 0, &font->m.widths[cid]);
                cid++;

                if (nss)
                {
                    pdc_cleanup_stringlist(pdc, sstrlist);
                    nss = 0;
                }
            }
            else
            {
                /* format 2:  cid_first cid_last width */
                pdc_str2integer(str, 0, &cidfirst);
                is++;
                str = strlist[is];
                pdc_str2integer(str, 0, &cidlast);
                is++;
                str = strlist[is];
                pdc_str2integer(str, 0, &width);

                for (; cid < cidfirst; cid++)
                    font->m.widths[cid] = FNT_DEFAULT_CIDWIDTH;
                for (; cid <= cidlast; cid++)
                    font->m.widths[cid] = width;
            }
        }

        pdc_cleanup_stringlist(pdc, strlist);
    }

    for (; cid < font->m.numwidths; cid++)
        font->m.widths[cid] = FNT_DEFAULT_CIDWIDTH;

    if (pdc_logg_is_enabled(pdc, 5, trc_font))
    {
        for (cid = 0; cid < font->m.numwidths; cid++)
            pdc_logg(pdc, "\t\t\tCID width[%d]: %d\n",
                     cid, font->m.widths[cid]);
    }
}
コード例 #17
0
ファイル: pc_optparse.c プロジェクト: Vulcanior/IUP
pdc_resopt *
pdc_parse_optionlist(pdc_core *pdc, const char *optlist,
                     const pdc_defopt *defopt,
                     const pdc_clientdata *clientdata, pdc_bool verbose)
{
    static const char *fn = "pdc_parse_optionlist";
    pdc_bool logg5 = pdc_logg_is_enabled(pdc, 5, trc_optlist);
    const char *stemp1 = NULL, *stemp2 = NULL, *stemp3 = NULL, *s1, *s2;
    char **items = NULL, *keyword = NULL;
    char **values = NULL, *value = NULL, **strings = NULL;
    int i, j, k, nd, is, iss, it, iv, icoord;
    int numdef, nitems = 0, nvalues, ncoords = 0, errcode = 0;
    void *resval;
    double dz, maxval;
    int retval, iz;
    pdc_sint32 lz = 0;
    pdc_uint32 ulz = 0;
    size_t len;
    const pdc_defopt *dopt = NULL;
    pdc_resopt *resopt = NULL;
    pdc_bool ignore = pdc_false;
    pdc_bool boolval = pdc_false;
    pdc_bool tocheck = pdc_false;
    pdc_bool issorted = pdc_true;
    pdc_bool ishandle = pdc_true;
    pdc_bool isutf8 = pdc_false;

    pdc_logg_cond(pdc, 1, trc_optlist, "\n\tOption list: \"%T\"\n",
                      optlist ? optlist : "", 0);

    /* split option list */
    if (optlist != NULL)
    {
        nitems = pdc_split_stringlist(pdc, optlist, PDC_OPT_LISTSEPS,
                                      PDC_SPLIT_ISOPTLIST, &items);
        isutf8 = pdc_is_utf8_bytecode(optlist);
    }
    if (nitems < 0)
    {
        keyword = (char *) optlist;
        errcode = PDC_E_OPT_NOTBAL;
        goto PDC_OPT_SYNTAXERROR;
    }

    /* initialize result list */
    for (numdef = 0; defopt[numdef].name != NULL; numdef++)
    {
	/* */ ;
    }

    /* allocate temporary memory for option parser result struct */
    resopt = (pdc_resopt *) pdc_calloc_tmp(pdc, numdef * sizeof(pdc_resopt),
                                    fn, pdc, pdc_cleanup_optionlist_tmp);
    for (i = 0; i < numdef; i++)
    {
        resopt[i].numdef = numdef;
        resopt[i].defopt = &defopt[i];

        if (defopt[i].flags & PDC_OPT_IGNOREIF1 ||
            defopt[i].flags & PDC_OPT_IGNOREIF2 ||
            defopt[i].flags & PDC_OPT_REQUIRIF1 ||
            defopt[i].flags & PDC_OPT_REQUIRIF2 ||
            defopt[i].flags & PDC_OPT_REQUIRED)
            tocheck = pdc_true;

        if (i && issorted)
            issorted = (strcmp(defopt[i-1].name, defopt[i].name) <= 0) ?
                       pdc_true : pdc_false;
    }

    /* loop over all option list elements */
    for (is = 0; is < nitems; is++)
    {
        pdc_bool isequal = pdc_false;

        /* search keyword */
        boolval = pdc_undef;
        keyword = items[is];
        for (it = 0; it < numdef; it++)
        {
            s1 = keyword;
            s2 = defopt[it].name;

            /* if (!pdc_stricmp(keyword, defopt[it].name))
             *     isequal = pdc_true;
             */
            for (; *s1; ++s1, ++s2)
            {
                if (pdc_tolower(*s1) != pdc_tolower(*s2))
                    break;
            }
            if (pdc_tolower(*s1) == pdc_tolower(*s2))
                isequal = pdc_true;

            /* special handling for booleans */
            if (defopt[it].type == pdc_booleanlist)
            {
                if (isequal ||
                    (keyword[1] != 0 &&
                     !pdc_stricmp(&keyword[2], defopt[it].name)))
                {
                    iss = is + 1;
                    if (iss == nitems ||
                        (pdc_stricmp(items[iss], "true") &&
                         pdc_stricmp(items[iss], "false")))
                    {
                        i = pdc_strincmp(defopt[it].name, "no", 2) ? 0 : 2;
                        if (!pdc_strincmp(&keyword[i], "no", 2))
                        {
                            boolval = pdc_false;
                            break;
                        }
                        else if (isequal)
                        {
                            boolval = pdc_true;
                            break;
                        }
                    }
                }
            }

            if (isequal)
                break;
        }

        if (logg5)
            pdc_logg(pdc, "\t\t\toption \"%s\" specified: ", keyword);

        if (it == numdef)
        {
            errcode = PDC_E_OPT_UNKNOWNKEY;
            goto PDC_OPT_SYNTAXERROR;
        }

        /* initialize */
        dopt = &defopt[it];
        ignore = pdc_false;
        nvalues = 1;
        values = NULL;
        ishandle = pdc_true;

        /* compatibility */
        if (clientdata && clientdata->compatibility)
        {
            int compatibility = clientdata->compatibility;

            for (iv = PDC_1_3; iv <= PDC_X_X_LAST; iv++)
            {
                if (logg5 && (dopt->flags & (1L<<iv)))
                    pdc_logg(pdc, "(compatibility >= %s) ",
                             pdc_get_pdfversion(pdc, iv));

                if ((dopt->flags & (1L<<iv)) && compatibility < iv)
                {
                    if (logg5)
                        pdc_logg(pdc, "\n");
                    stemp2 = pdc_get_pdfversion(pdc, compatibility);
                    errcode = PDC_E_OPT_VERSION;
                    goto PDC_OPT_SYNTAXERROR;
                }
            }
        }

        /* not supported */
        if (dopt->flags & PDC_OPT_UNSUPP)
        {
            if (logg5)
                pdc_logg(pdc, "(unsupported)\n");

            keyword = (char *) dopt->name;
            errcode = PDC_E_OPT_UNSUPP;
            goto PDC_OPT_SYNTAXERROR;
        }

        /* parse values */
        if (boolval == pdc_undef)
        {
            is++;
            if (is == nitems)
            {
                errcode = PDC_E_OPT_NOVALUES;
                goto PDC_OPT_SYNTAXERROR;
            }
            if (!ignore)
            {
                if (dopt->type == pdc_stringlist &&
                    pdc_is_utf8_bytecode(items[is]))
                    resopt[it].flags |= PDC_OPT_ISUTF8;

                if (dopt->type != pdc_stringlist || dopt->maxnum > 1)
                    nvalues = pdc_split_stringlist(pdc, items[is],
                                    (dopt->flags & PDC_OPT_SUBOPTLIST) ?
                                    PDC_OPT_LISTSEPS : NULL,
                                    PDC_SPLIT_ISOPTLIST, &values);

                if (dopt->flags & PDC_OPT_DUPORIGVAL)
                    resopt[it].origval = pdc_strdup(pdc, items[is]);
            }
        }

        /* ignore */
        if (ignore) continue;

        /* number of values check */
        if (nvalues < dopt->minnum)
        {
            stemp2 = pdc_errprintf(pdc, "%d", dopt->minnum);
            errcode = PDC_E_OPT_TOOFEWVALUES;
            goto PDC_OPT_SYNTAXERROR;
        }
        else if (nvalues > dopt->maxnum)
        {
            stemp2 = pdc_errprintf(pdc, "%d", dopt->maxnum);
            errcode = PDC_E_OPT_TOOMANYVALUES;
            goto PDC_OPT_SYNTAXERROR;
        }

        /* number of values must be even */
        if (dopt->flags & PDC_OPT_EVENNUM && (nvalues % 2))
        {
            errcode = PDC_E_OPT_ODDNUM;
            goto PDC_OPT_SYNTAXERROR;
        }

        /* number of values must be odd */
        if (dopt->flags & PDC_OPT_ODDNUM && !(nvalues % 2))
        {
            errcode = PDC_E_OPT_EVENNUM;
            goto PDC_OPT_SYNTAXERROR;
        }

        /* deprecated option since PDFlib 7 */
        if (dopt->flags & PDC_OPT_PDFLIB_7)
        {
            pdc_logg_cond(pdc, 2, trc_api,
                  "[Option \"%s\" is deprecated since PDFlib 7]\n",
                  keyword);
        }

        /* option already exists */
        if (resopt[it].num)
        {
            pdc_delete_optvalue(pdc, &resopt[it]);
        }

        /* no values */
        if (!nvalues ) continue;

        /* maximal value */
        switch (dopt->type)
        {
            case pdc_3ddatahandle:
            maxval = clientdata->max3ddata;
            break;

            case pdc_3dviewhandle:
            maxval = clientdata->max3dview;
            break;

            case pdc_actionhandle:
            maxval = clientdata->maxaction;
            break;

            case pdc_bookmarkhandle:
            maxval = clientdata->maxbookmark;
            break;

            case pdc_colorhandle:
            maxval = clientdata->maxcolor;
            break;

            case pdc_documenthandle:
            maxval = clientdata->maxdocument;
            break;

            case pdc_fonthandle:
            maxval = clientdata->maxfont;
            break;

            case pdc_gstatehandle:
            maxval = clientdata->maxgstate;
            break;

            case pdc_iccprofilehandle:
            maxval = clientdata->maxiccprofile;
            break;

            case pdc_imagehandle:
            maxval = clientdata->maximage;
            break;

	    case pdc_layerhandle:
            maxval = clientdata->maxlayer;
            break;

            case pdc_pagehandle:
            maxval = clientdata->maxpage;
            break;

            case pdc_patternhandle:
            maxval = clientdata->maxpattern;
            break;

            case pdc_shadinghandle:
            maxval = clientdata->maxshading;
            break;

            case pdc_tablehandle:
            maxval = clientdata->maxtable;
            break;

            case pdc_templatehandle:
            maxval = clientdata->maxtemplate;
            break;

            case pdc_textflowhandle:
            maxval = clientdata->maxtextflow;
            break;

            case pdc_stringhandle:
            maxval = clientdata->maxstring;
            break;

            case pdc_polylinelist:
            ncoords = 0;

            default:
            maxval = dopt->maxval;
            ishandle = pdc_false;
            break;
        }

        /* allocate value array */
        resopt[it].val = pdc_calloc(pdc,
                            (size_t) (nvalues * pdc_typesizes[dopt->type]), fn);
        resopt[it].num = nvalues;
        resopt[it].currind = it;

        if (dopt->flags & PDC_OPT_PERCENT)
            memset(resopt[it].pcbits, 0, PDC_PCBITS_SIZE);

        if (logg5)
            pdc_logg(pdc, "{");

        /* analyze type */
        resval = resopt[it].val;
        for (iv = 0; iv < nvalues; iv++)
        {
            errcode = 0;
            if (dopt->maxnum > 1 && nvalues)
                value = values[iv];
            else
                value = items[is];
            if (logg5)
                pdc_logg(pdc, "%s{%T}", iv ? " " : "", value, 0);
            switch (dopt->type)
            {
                /* boolean list */
                case pdc_booleanlist:
                if (boolval == pdc_true || !pdc_stricmp(value, "true"))
                {
                    *(pdc_bool *) resval = pdc_true;
                }
                else if (boolval == pdc_false || !pdc_stricmp(value, "false"))
                {
                    *(pdc_bool *) resval = pdc_false;
                }
                else
                {
                    errcode = PDC_E_OPT_ILLBOOLEAN;
                }
                break;

                /* string list */
                case pdc_stringlist:
                if (dopt->flags & PDC_OPT_NOSPACES)
                {
                    if (pdc_split_stringlist(pdc, value, NULL, 0, &strings) > 1)
                        errcode = PDC_E_OPT_ILLSPACES;
                    pdc_cleanup_stringlist(pdc, strings);
                }
                if (!errcode)
                {
                    len = strlen(value);
                    dz = (double) len;
                    if (dz < dopt->minval)
                    {
                        stemp3 = pdc_errprintf(pdc, "%d", (int) dopt->minval);
                        errcode = PDC_E_OPT_TOOSHORTSTR;
                    }
                    else if (dz > maxval)
                    {
                        stemp3 = pdc_errprintf(pdc, "%d", (int) maxval);
                        errcode = PDC_E_OPT_TOOLONGSTR;
                    }

                    if (dopt->flags & PDC_OPT_CONVUTF8)
                    {
                        int flags = PDC_CONV_EBCDIC | PDC_CONV_WITHBOM;

                        if (isutf8 || (resopt[it].flags & PDC_OPT_ISUTF8))
                            flags |= PDC_CONV_ISUTF8;

                        *((char **) resval) =
                            pdc_convert_name(pdc, value, 0, flags);
                    }
                    else
                    {
                        *((char **) resval) = pdc_strdup(pdc, value);
                    }
                }
                break;

                /* keyword list */
                case pdc_keywordlist:
                if (dopt->flags & PDC_OPT_CASESENS)
                    iz = pdc_get_keycode(value, dopt->keylist);
                else
                    iz = pdc_get_keycode_ci(value, dopt->keylist);
                if (iz == PDC_KEY_NOTFOUND)
                {
                    errcode = PDC_E_OPT_ILLKEYWORD;
                }
                else
                {
                    *(int *) resval = iz;
                }
                break;

                /* character list */
                case pdc_unicharlist:
                iz = pdc_string2unicode(pdc, value, dopt->flags, dopt->keylist,
                                        pdc_false);
                if (iz < 0)
                {
                    errcode = PDC_E_OPT_ILLCHAR;
                    break;
                }
                dz = iz;
                if (dz < dopt->minval)
                {
                    stemp3 = pdc_errprintf(pdc, "%g", dopt->minval);
                    errcode = PDC_E_OPT_TOOSMALLVAL;
                }
                else if (dz > maxval)
                {
                    stemp3 = pdc_errprintf(pdc, "%g", maxval);
                    errcode = PDC_E_OPT_TOOBIGVAL;
                }
                *(int *) resval = iz;
                break;

                /* string list */
                case pdc_polylinelist:
                {
                    int np = pdc_split_stringlist(pdc, value, NULL, 0,
                                                  &strings);
                    pdc_polyline *pl = (pdc_polyline *) resval;

                    pl->np = np / 2;
                    pl->p = NULL;

                    /* number of coordinates must be even */
                    if (np % 2)
                    {
                        errcode = PDC_E_OPT_ODDNUM;
                        np = 0;
                    }

                    /* polyline must be a box */
                    else if ((dopt->flags & PDC_OPT_ISBOX) && np != 4)
                    {
                        errcode = PDC_E_OPT_ILLBOX;
                        np = 0;
                    }

                    /* polyline will be closed */
                    else if ((dopt->flags & PDC_OPT_CLOSEPOLY) && np <= 4)
                    {
                        errcode = PDC_E_OPT_ILLPOLYLINE;
                        np = 0;
                    }

                    /* polyline not empty */
                    if (np)
                    {
                        if (dopt->flags & PDC_OPT_CLOSEPOLY)
                            pl->np += 1;
                        pl->p = (pdc_vector *) pdc_malloc(pdc,
                                        pl->np * sizeof(pdc_vector), fn);

                        iz = PDC_KEY_NOTFOUND;
                        j = 0;
                        icoord = ncoords;
                        for (i = 0; i < np; i++)
                        {
                            char *sk = strings[i];

                            if (dopt->keylist)
                            {
                                /* optional keyword list */
                                if (dopt->flags & PDC_OPT_CASESENS)
                                    iz = pdc_get_keycode(sk, dopt->keylist);
                                else
                                    iz = pdc_get_keycode_ci(sk, dopt->keylist);
                            }
                            if (iz == PDC_KEY_NOTFOUND)
                            {
                                /* percentage */
                                if (dopt->flags & PDC_OPT_PERCENT)
                                {
                                    k = (int) strlen(sk) - 1;
                                    if (sk[k] == '%')
                                    {
                                        sk[k] = 0;
                                        if (ncoords < PDC_MAX_PERCENTS)
                                        {
                                            pdc_setbit(resopt[it].pcbits,
                                                       ncoords);
                                        }
                                        else
                                        {
                                            errcode = PDC_E_OPT_TOOMANYPERCVALS;
                                        }
                                    }
                                }

                                retval = pdc_str2double(sk, &dz);
                                if (!retval)
                                {
                                    errcode = PDC_E_OPT_ILLNUMBER;
                                }
                                else if (pdc_getbit(resopt[it].pcbits, ncoords))
                                {
                                    if (dopt->flags & PDC_OPT_PERCRANGE)
                                    {
                                        if (dz < 0)
                                            errcode = PDC_E_OPT_TOOSMALLPERCVAL;
                                        if (dz > 100)
                                            errcode = PDC_E_OPT_TOOBIGPERCVAL;
                                    }
                                    dz /= 100.0;
                                }
                            }
                            else
                            {
                                dz = (double) iz;
                            }

                            if (!(i % 2))
                            {
                                pl->p[j].x = dz;
                            }
                            else
                            {
                                pl->p[j].y = dz;
                                j++;
                            }
                            ncoords++;
                        }

                        if (dopt->flags & PDC_OPT_CLOSEPOLY)
                        {
                            pl->p[pl->np - 1] = pl->p[0];
                            if (pdc_getbit(resopt[it].pcbits, icoord))
                                pdc_setbit(resopt[it].pcbits, ncoords);
                            ncoords++;
                            if (pdc_getbit(resopt[it].pcbits, icoord + 1))
                                pdc_setbit(resopt[it].pcbits, ncoords);
                            ncoords++;
                        }
                    }
                    pdc_cleanup_stringlist(pdc, strings);
                }
                break;

                /* number list */
                case pdc_3ddatahandle:
                case pdc_3dviewhandle:
                case pdc_actionhandle:
                case pdc_bookmarkhandle:
                case pdc_colorhandle:
                case pdc_documenthandle:
                case pdc_fonthandle:
                case pdc_gstatehandle:
                case pdc_iccprofilehandle:
                case pdc_imagehandle:
                case pdc_layerhandle:
                case pdc_pagehandle:
                case pdc_patternhandle:
                case pdc_shadinghandle:
                case pdc_tablehandle:
                case pdc_templatehandle:
                case pdc_textflowhandle:
                case pdc_integerlist:
                case pdc_floatlist:
                case pdc_doublelist:
                case pdc_scalarlist:

                if (dopt->keylist &&
                    (!(dopt->flags & PDC_OPT_KEYLIST1) || !iv))
                {
                    /* optional keyword and/or allowed integer list */
                    if (dopt->flags & PDC_OPT_CASESENS)
                        iz = pdc_get_keycode(value, dopt->keylist);
                    else
                        iz = pdc_get_keycode_ci(value, dopt->keylist);
                    if (iz == PDC_KEY_NOTFOUND)
                    {
                        if (dopt->flags & PDC_OPT_INTLIST)
                        {
                            errcode = PDC_E_OPT_ILLINTEGER;
                            break;
                        }
                    }
                    else
                    {
                        switch (dopt->type)
                        {
                            default:
                            case pdc_integerlist:
                            *(int *) resval = iz;
                            break;

                            case pdc_floatlist:
                            *(float *) resval = (float) iz;
                            break;

                            case pdc_doublelist:
                            *(double *) resval = (double) iz;
                            break;

                            case pdc_scalarlist:
                            *(pdc_scalar *) resval = (pdc_scalar) iz;
                            break;
                        }
                        break;
                    }
                }

                /* percentage */
                if (dopt->flags & PDC_OPT_PERCENT)
                {
                    i = (int) strlen(value) - 1;
                    if (value[i] == '%')
                    {
                        value[i] = 0;
                        if (iv < PDC_MAX_PERCENTS)
                        {
                            pdc_setbit(resopt[it].pcbits, iv);
                        }
                        else
                        {
                            errcode = PDC_E_OPT_TOOMANYPERCVALS;
                        }
                    }
                }

                case pdc_stringhandle:

                if (dopt->type == pdc_floatlist ||
                    dopt->type == pdc_doublelist ||
                    dopt->type == pdc_scalarlist)
                {
                    retval = pdc_str2double(value, &dz);
                }
                else
                {
                    if (dopt->minval >= 0)
                    {
                        retval = pdc_str2integer(value, PDC_INT_UNSIGNED, &ulz);
                        dz = ulz;
                    }
                    else
                    {
                        retval = pdc_str2integer(value, 0, &lz);
                        dz = lz;
                    }

                    if (retval && ishandle && pdc->hastobepos &&
                        dopt->type != pdc_bookmarkhandle &&
                        dopt->type != pdc_stringhandle)
                    {
                        dz -= 1;
                        lz = (pdc_sint32) dz;
                        ulz = (pdc_uint32) dz;
                    }
                }
                if (!retval)
                {
                    errcode = PDC_E_OPT_ILLNUMBER;
                }
                else
                {
                    if (pdc_getbit(resopt[it].pcbits, iv))
                    {
                        if (dopt->flags & PDC_OPT_PERCRANGE)
                        {
                            if (dz < 0)
                                errcode = PDC_E_OPT_TOOSMALLPERCVAL;
                            if (dz > 100)
                                errcode = PDC_E_OPT_TOOBIGPERCVAL;
                        }
                        dz /= 100.0;
                    }

                    if (errcode == 0)
                    {
                        if (dz < dopt->minval)
                        {
                            if (ishandle)
                            {
                                stemp3 = pdc_get_keyword(dopt->type,
                                                         pdc_handletypes);
                                errcode = PDC_E_OPT_ILLHANDLE;
                            }
                            else
                            {
                                stemp3 = pdc_errprintf(pdc, "%g", dopt->minval);
                                errcode = PDC_E_OPT_TOOSMALLVAL;
                            }
                        }
                        else if (dz > maxval)
                        {
                            if (ishandle)
                            {
                                stemp3 = pdc_get_keyword(dopt->type,
                                                         pdc_handletypes);
                                errcode = PDC_E_OPT_ILLHANDLE;
                            }
                            else
                            {
                                stemp3 = pdc_errprintf(pdc, "%g", maxval);
                                errcode = PDC_E_OPT_TOOBIGVAL;
                            }
                        }
                        else if (dopt->flags & PDC_OPT_NOZERO &&
                                 fabs(dz) < PDC_FLOAT_PREC)
                        {
                            errcode = PDC_E_OPT_ZEROVAL;
                        }
                        else if (dopt->type == pdc_scalarlist)
                        {
                            *(pdc_scalar *) resval = dz;
                        }
                        else if (dopt->type == pdc_doublelist)
                        {
                            *(double *) resval = dz;
                        }
                        else if (dopt->type == pdc_floatlist)
                        {
                            *(float *) resval = (float) dz;
                        }
                        else
                        {
                            if (dopt->minval >= 0)
                                *(pdc_uint32 *) resval = ulz;
                            else
                                *(pdc_sint32 *) resval = lz;
                        }
                    }
                }
                break;
            }

            if (errcode)
            {
                stemp2 = pdc_errprintf(pdc, "%.*s", PDC_ERR_MAXSTRLEN, value);
                goto PDC_OPT_SYNTAXERROR;
            }

            /* increment value pointer */
            resval = (void *) ((char *)(resval) + pdc_typesizes[dopt->type]);
        }
        pdc_cleanup_stringlist(pdc, values);
        values = NULL;

        if (logg5)
            pdc_logg(pdc, "}\n");

        /* build OR bit pattern */
        if (dopt->flags & PDC_OPT_BUILDOR && nvalues > 1)
        {
            int *bcode = (int *) resopt[it].val;
            for (iv = 1; iv < nvalues; iv++)
            {
                bcode[0] |= bcode[iv];
            }
            resopt[it].num = 1;
        }
    }
    pdc_cleanup_stringlist(pdc, items);
    items = NULL;

    /* required and to be ignored options */
    for (is = 0; tocheck && is < numdef; is++)
    {
        /* to be ignored option */
        if (resopt[is].num)
        {
            nd = 0;
            if (defopt[is].flags & PDC_OPT_IGNOREIF1) nd = 1;
            if (defopt[is].flags & PDC_OPT_IGNOREIF2) nd = 2;
            for (it = is - 1; it >= is - nd && it >= 0; it--)
            {
                if (resopt[it].num)
                {
                    pdc_delete_optvalue(pdc, &resopt[is]);
                    if (verbose)
                        pdc_warning(pdc, PDC_E_OPT_IGNORE, defopt[is].name,
                                    defopt[it].name, 0, 0);
                }
            }
        }

        /* required option */
        if (!resopt[is].num &&
            ((defopt[is].flags & PDC_OPT_REQUIRED) ||
             (defopt[is].flags & PDC_OPT_REQUIRIF1 && resopt[is-1].num) ||
             (defopt[is].flags & PDC_OPT_REQUIRIF2 &&
              (resopt[is-1].num || resopt[is-2].num))))
        {
            keyword = (char *) defopt[is].name;
            errcode = PDC_E_OPT_NOTFOUND;
            goto PDC_OPT_SYNTAXERROR;
        }
    }

    /* is no sorted */
    if (!issorted)
    {
        qsort((void *)resopt, (size_t) numdef, sizeof(pdc_resopt),
              pdc_optname_compare);
    }

    /* global UTF-8 check after sort */
    if (isutf8)
        resopt[0].isutf8 = pdc_true;

    /* index of last got option */
    resopt[0].lastind = -1;

    /* protocol */
    if (pdc_logg_is_enabled(pdc, 1, trc_optlist))
    {
        for (is = 0; is < numdef; is++)
        {
            if (resopt[is].num)
                pdc_logg(pdc, "\tOption \"%s\": %d value%s found\n",
                         resopt[is].defopt->name, resopt[is].num,
                         resopt[is].num == 1 ? "" : "s");
            else if (logg5)
                pdc_logg(pdc, "\t\t\toption \"%s\" not specified\n",
                         resopt[is].defopt->name);
            for (iv = 0; iv < resopt[is].num; iv++)
            {
                switch (resopt[is].defopt->type)
                {
                    case pdc_booleanlist:
                    case pdc_keywordlist:
                    case pdc_integerlist:
                    case pdc_3ddatahandle:
                    case pdc_3dviewhandle:
                    case pdc_actionhandle:
                    case pdc_bookmarkhandle:
                    case pdc_colorhandle:
                    case pdc_documenthandle:
                    case pdc_fonthandle:
                    case pdc_gstatehandle:
                    case pdc_iccprofilehandle:
                    case pdc_imagehandle:
                    case pdc_layerhandle:
                    case pdc_pagehandle:
                    case pdc_patternhandle:
                    case pdc_shadinghandle:
                    case pdc_tablehandle:
                    case pdc_templatehandle:
                    case pdc_textflowhandle:
                    case pdc_stringhandle:
                    pdc_logg(pdc, "\tValue %d: %d\n",
                             iv + 1, *((int *) resopt[is].val + iv));
                    break;

                    case pdc_stringlist:
                    pdc_logg(pdc, "\tValue %d: \"%T\"\n",
                             iv + 1, *((char **) resopt[is].val + iv), 0);
                    break;

                    case pdc_floatlist:
                    pdc_logg(pdc, "\tValue %d: %f\n",
                             iv + 1, *((float *) resopt[is].val + iv));
                    break;

                    case pdc_doublelist:
                    pdc_logg(pdc, "\tValue %d: %f\n",
                             iv + 1, *((double *) resopt[is].val + iv));
                    break;

                    case pdc_scalarlist:
                    pdc_logg(pdc, "\tValue %d: %f\n",
                             iv + 1, *((pdc_scalar *) resopt[is].val + iv));
                    break;

                    case pdc_unicharlist:
                    pdc_logg(pdc, "\tValue %d: %d\n",
                             iv + 1, *((int *) resopt[is].val + iv));
                    break;

                    case pdc_polylinelist:
                    pdc_logg(pdc, "\t\t#%d: ", iv + 1);
                    {
                        pdc_polyline *pl = (pdc_polyline *) resopt[is].val + iv;

                        for (j = 0; j < pl->np; j++)
                            pdc_logg(pdc, "%f,%f  ", pl->p[j].x, pl->p[j].y);
                        pdc_logg(pdc, "\n");
                    }
                    break;
                }
            }
        }
    }

    return resopt;

    PDC_OPT_SYNTAXERROR:
    stemp1 = pdc_errprintf(pdc, "%.*s", PDC_ERR_MAXSTRLEN, keyword);
    pdc_cleanup_stringlist(pdc, items);
    pdc_cleanup_stringlist(pdc, values);

    pdc_set_errmsg(pdc, errcode, stemp1, stemp2, stemp3, 0);
    if (verbose)
        pdc_error(pdc, -1, 0, 0, 0, 0);

    return NULL;
}
コード例 #18
0
ファイル: p_type1.c プロジェクト: Distrotech/PDFlib-Lite
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;
}
コード例 #19
0
ファイル: p_util.c プロジェクト: pottootje1982/singalong
int
pdf_get_opt_textlist(PDF *p, const char *keyword, pdc_resopt *resopts,
                     pdc_encoding enc, int codepage, pdc_bool ishypertext,
                     const char *fieldname, char **text, char ***textlist)
{
    pdc_bool logg1 = pdc_logg_is_enabled(p->pdc, 1, trc_optlist);
    int ns;
    char **strlist;

    ns = pdc_get_optvalues(keyword, resopts, NULL, &strlist);
    if (ns)
    {
        pdc_byte *string = NULL;
        pdc_encodingvector *inev = NULL, *outev = NULL;
        pdc_text_format intextformat = pdc_bytes;
        pdc_text_format outtextformat = pdc_utf16be;
        pdc_text_format textformat;
        int convflags = PDC_CONV_WITHBOM;
        pdc_bool isutf8;
        int i, outlen;

        /* whole option list or string list is in UTF-8 */
        isutf8 = pdc_is_lastopt_utf8(resopts);

        /* Encoding */
        if (ishypertext)
        {
            /* Initialize */
            if (!isutf8)
            {
                if (enc < 0 && enc != pdc_unicode && enc != pdc_cid)
                    enc = pdf_get_hypertextencoding(p, "auto", &codepage,
                                                    pdc_true);
                if (enc >= 0)
                    inev = pdc_get_encoding_vector(p->pdc, enc);
            }

            outev = pdc_get_encoding_vector(p->pdc, pdc_pdfdoc);

            /* conversion to PDFDocEncoding if possible */
            convflags |= PDC_CONV_TRYBYTES;
        }
        else
        {
            if (enc == pdc_invalidenc)
            {
                if (fieldname)
                {
                    pdc_cleanup_optionlist(p->pdc, resopts);
                    pdc_error(p->pdc, PDF_E_FF_FONTMISSING, fieldname, 0, 0, 0);
                }
                return 0;
            }
            else if (enc >= 0 && !isutf8)
            {
                /* bug #2069: always conversion to UTF-16BE */
                inev = pdc_get_encoding_vector(p->pdc, enc);
            }
        }

        if (logg1)
        {
            if (isutf8)
            {
                pdc_logg(p->pdc, "\tOption \"%s\" is "PDC_UTF8_STRG" encoded\n",
                         keyword);
            }
            else
            {
                pdc_logg(p->pdc, "\tOption \"%s\" is %s encoded\n",
                         keyword, pdc_get_user_encoding(p->pdc, enc));
            }
        }

        for (i = 0; i < ns; i++)
        {
            string = (pdc_byte *) strlist[i];

            {
                if (ishypertext || isutf8 || inev != NULL)
                {
                    intextformat = isutf8 ?  PDC_UTF8 : pdc_bytes;

                    if (pdc_logg_is_enabled(p->pdc, 3, trc_text))
                        convflags |= PDC_CONV_LOGGING;
                    pdf_set_convertflags(p, &convflags);
                    textformat = outtextformat;
                    pdc_convert_string(p->pdc, intextformat, codepage, inev,
                                string, (int) strlen((char *) string),
                                &textformat, outev, &string, &outlen,
                                convflags, pdc_true);
                    pdc_free(p->pdc, strlist[i]);
                    strlist[i] = (char *) string;
                }
            }
        }

        if (text)
            *text = strlist[0];
        else
            *textlist = strlist;

        if (fieldname)
        {
            strlist = (char **) pdc_save_lastopt(resopts, PDC_OPT_SAVEALL);
            pdf_insert_stringlist(p, strlist, ns);
        }
    }

    return ns;
}