Пример #1
0
void
fnt_register_errtab(pdc_core *pdc)
{
    pdc_register_errtab(pdc, PDC_ET_FONT, fnt_errors, N_FNT_ERRORS);
}
Пример #2
0
PDF *
pdf__new(
    void  (*errorhandler)(PDF *p, int type, const char *msg),
    void* (*allocproc)(PDF *p, size_t size, const char *caller),
    void* (*reallocproc)(PDF *p, void *mem, size_t size, const char *caller),
    void  (*freeproc)(PDF *p, void *mem),
    void   *opaque)
{
    PDF *	p;
    pdc_core *	pdc;

    /* If allocproc is NULL, all entries are supplied internally by PDFlib */
    if (allocproc == NULL) {
	allocproc	= default_malloc;
	reallocproc	= default_realloc;
	freeproc	= default_free;
    }

    p = (PDF *) (*allocproc) (NULL, sizeof(PDF), "PDF_new");

    if (p == NULL)
	return NULL;

    /*
     * Guard against crashes when PDF_delete is called without any
     * PDF_open_*() in between.
     */
    memset((void *)p, 0, (size_t) sizeof(PDF));

    /* these two are required by PDF_get_opaque() */
    p->magic = PDC_MAGIC;
    p->opaque = opaque;

    pdc = pdc_new_core(
	(pdc_error_fp) errorhandler,
	(pdc_alloc_fp) allocproc,
	(pdc_realloc_fp) reallocproc,
	(pdc_free_fp) freeproc, p,
        PDFLIB_PRODUCTNAME,
        PDFLIB_VERSIONSTRING);

    if (pdc == NULL)
    {
	(*freeproc)(p, p);
	return NULL;
    }

    pdc_register_errtab(pdc, PDC_ET_PDFLIB, pdf_errors, N_PDF_ERRORS);
    fnt_register_errtab(pdc);

    PDC_TRY(pdc)
    {
        p->freeproc	= freeproc;
        p->pdc		= pdc;
        p->compatibility    = PDF_DEF_COMPATIBILITY;
        p->errorpolicy      = errpol_legacy;

        p->userinfo         = NULL;
        p->document         = NULL;

        p->errorhandler	= errorhandler;

        p->flush	    = pdc_flush_page;

        p->hypertextencoding= pdc_invalidenc;
        p->hypertextformat  = pdc_auto;
        p->hypertextcodepage= 0;
        p->usercoordinates  = pdc_false;
        p->usehyptxtenc     = pdc_false;

        p->currfo           = NULL;
        p->curr_ppt         = NULL;

        p->glyphcheck = text_nocheck;
        p->textformat       = pdc_auto;
        p->in_text	    = pdc_false;


        p->rendintent       = AutoIntent;
        p->preserveoldpantonenames = pdc_false;
        p->spotcolorlookup  = pdc_true;
        p->ydirection       = 1;
        p->names	    = NULL;
        p->names_capacity   = 0;
        p->xobjects     = NULL;
        p->state_sp	= 0;
        p->doc_pages    = NULL;

        p->actions = NULL;





        PDF_SET_STATE(p, pdf_state_object);

        /* all debug flags are cleared by default
         * because of the above memset... */

        /* ...but warning messages for non-fatal errors should be set,
         * as well as font warnings -- the client must explicitly disable these.
         */
        p->debug[(int) 'e'] = pdc_true;
        p->debug[(int) 'F'] = pdc_true;
        p->debug[(int) 'I'] = pdc_true;

        pdf_init_stringlists(p);
        pdf_init_font_options(p, NULL);

        p->out = pdc_boot_output(p->pdc);


    }
    PDC_CATCH(pdc)
    {
        pdc_delete_core(pdc);
        return (PDF *) 0;
    }
    return p;
} /* pdf__new */
Пример #3
0
/* pdc_new_core() never throws exceptions.
** it returns NULL if there's not enough memory.
*/
pdc_core *
pdc_new_core(
    pdc_error_fp errorhandler,
    pdc_alloc_fp allocproc,
    pdc_realloc_fp reallocproc,
    pdc_free_fp freeproc,
    void *opaque,
    const char *prodname,
    const char *version)
{
    static const char fn[] = "pdc_new_core";

    pdc_core_priv *pdc_pr;
    pdc_core *pdc;
    int i;

    /* if allocproc is NULL, we use pdc's default memory handling.
    */
    if (allocproc == (pdc_alloc_fp) 0)
    {
	allocproc	= default_malloc;
	reallocproc	= default_realloc;
	freeproc	= default_free;
    }

    if (errorhandler == (pdc_error_fp) 0)
	errorhandler = default_errorhandler;

    pdc_pr = (pdc_core_priv *)
                (*allocproc)(opaque, sizeof (pdc_core_priv), fn);

    if (pdc_pr == (pdc_core_priv *) 0)
        return (pdc_core *) 0;

    pdc = (pdc_core *)
                (*allocproc)(opaque, sizeof (pdc_core), fn);

    if (pdc == (pdc_core *) 0)
        return (pdc_core *) 0;

    pdc->pr = pdc_pr;

    /* initialize client members
    */
    pdc->reslist = NULL;
    pdc->filesystem = NULL;
    pdc->logg = NULL;
    pdc->loggenv = pdc_false;
    pdc->encstack = NULL;
    pdc->pglyphtab = NULL;
    pdc->bstr_pool = NULL;
    pdc->ustr_pool = NULL;
    pdc->last_rand = 1;
    pdc->prodname = prodname;
    pdc->version = version;
    pdc->binding = NULL;
    pdc->unicaplang = pdc_false;
    pdc->objorient = pdc_false;
    pdc->hastobepos = pdc_false;
    pdc->ptfrun = pdc_false;
    pdc->smokerun = pdc_false;
    pdc->charref = pdc_false;
    pdc->escapesequ = pdc_false;
    pdc->honorlang = pdc_false;
    pdc->compatibility = PDC_X_X_LAST;
    pdc->floatdigits = 4;
    pdc->uniqueno = 0;


#ifdef PDC_DEBUG
    pdc->pr->hexdump = pdc_true;
#endif

    /* set diverse handlers
    */
    pdc->pr->errorhandler = errorhandler;
    pdc->pr->allocproc = allocproc;
    pdc->pr->reallocproc = reallocproc;
    pdc->pr->freeproc = freeproc;
    pdc->pr->opaque = opaque;

    /* initialize error & exception handling.
    */
    pdc->pr->in_error = pdc_true;  /* disable error messages */
    pdc->pr->x_thrown = pdc_false;
    pdc->pr->epcount = 0;
    pdc->pr->errnum = 0;
    pdc->pr->premsg = NULL;
    pdc->pr->errbuf[0] = 0;
    pdc->pr->apiname[0] = 0;
    pdc->pr->x_sp = -1;
    pdc->pr->x_ssize = PDC_XSTACK_INISIZE;

#ifdef PDC_ALIGN16
    pdc->pr->x_alias = (char *)
        (*allocproc)(opaque, 16 + pdc->pr->x_ssize * sizeof (pdc_xframe), fn);

    if (pdc->pr->x_alias == (char *) 0)
        pdc->pr->x_stack = (pdc_xframe *) 0;
    else
        pdc->pr->x_stack = (pdc_xframe *)
            (((unsigned long) pdc->pr->x_alias + 16) & 0xFFFFFFFFFFFFFFF0);
#else
    pdc->pr->x_stack = (pdc_xframe *)
        (*allocproc)(opaque, pdc->pr->x_ssize * sizeof (pdc_xframe), fn);
#endif

    if (pdc->pr->x_stack == (pdc_xframe *) 0)
    {
	(*freeproc)(opaque, pdc);
	return (pdc_core *) 0;
    }

    pdc_tmlist_init(pdc);

    /* initialize error tables.
    */
    for (i = 0; i < N_ERRTABS; ++i)
        pdc->pr->err_tables[i].ei = (pdc_error_info *) 0;

    pdc_register_errtab(pdc, PDC_ET_CORE, core_errors, N_CORE_ERRORS);

    /* initialize mempool for strings
    */
    pdc_init_strings(pdc);
    if (pdc->bstr_pool == NULL || pdc->ustr_pool == NULL)
    {
        (*freeproc)(opaque, pdc);
        return (pdc_core *) 0;
    }

    /* enable error messages
    */
    pdc->pr->in_error = pdc_false;


    return pdc;
}