示例#1
0
void
pdf_cleanup_stringlists(PDF *p)
{
    int i;

    if (p->stringlists)
    {
        for (i = 0; i < p->stringlists_number; i++)
        {
            if (p->stringlists[i])
                pdc_cleanup_optstringlist(p->pdc,
                    p->stringlists[i], p->stringlistsizes[i]);
        }
        pdc_free(p->pdc, p->stringlists);
        pdc_free(p->pdc, p->stringlistsizes);
    }

    pdf_init_stringlists(p);
}
示例#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 */