Beispiel #1
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 */
Beispiel #2
0
void
pdf__begin_font(
    PDF *p,
    const char *fontname, int len,
    pdc_scalar a, pdc_scalar b, pdc_scalar c, pdc_scalar d,
    pdc_scalar e, pdc_scalar f,
    const char *optlist)
{
    static const char fn[] = "pdf__begin_font";
    pdc_resopt *results;
    pdf_font tmpfont, *font;
    pdf_font_options fo;
    pdc_scalar det;
    pdc_clientdata cdata;
    int colorized = pdc_false;
    int metricsonly = pdc_false;
    int slot;

    if (fontname == NULL)
        pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "fontname", 0, 0, 0);

    /* Converting fontname */
    fontname = pdf_convert_name(p, fontname, len,
                                PDC_CONV_WITHBOM | PDC_CONV_TMPALLOC);
    if (fontname == NULL || *fontname == '\0')
        pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "fontname", 0, 0, 0);

    pdc_logg_cond(p->pdc, 1, trc_font,
        "\tBegin of Type3 font \"%s\"\n", fontname);

    /* error message prefix */
    pdc_push_errmsg(p->pdc, PDF_E_T3_FONT_PREFIX, fontname, 0, 0, 0);

    /* look for an already existing font */
    for (slot = 0; slot < p->fonts_number; slot++)
    {
        if (!pdc_strcmp(p->fonts[slot].apiname, fontname))
        {
            if (p->fonts[slot].t3font->pass == 1)
            {
                pdc_logg_cond(p->pdc, 1, trc_font,
                    "\tType3 font [%d] with metric definition found\n", slot);

                PDF_CHECK_STATE(p, pdf_state_document);

                p->fonts[slot].t3font->pass = 2;
                p->t3slot = slot;

                pdc_pop_errmsg(p->pdc);

                pdf_pg_suspend(p);
                PDF_SET_STATE(p, pdf_state_font);
                return;
            }

            pdc_error(p->pdc, PDF_E_T3_FONTEXISTS, 0, 0, 0, 0);
        }
    }

    pdc_check_number(p->pdc, "a", a);
    pdc_check_number(p->pdc, "b", b);
    pdc_check_number(p->pdc, "c", c);
    pdc_check_number(p->pdc, "d", d);
    pdc_check_number(p->pdc, "e", e);
    pdc_check_number(p->pdc, "f", f);

    det = a*d - b*c;

    if (det == 0)
        pdc_error(p->pdc, PDC_E_ILLARG_MATRIX,
            pdc_errprintf(p->pdc, "%f %f %f %f %f %f", a, b, c, d, e, f),
            0, 0, 0);

    /* parsing optlist */
    pdf_set_clientdata(p, &cdata);
    results = pdc_parse_optionlist(p->pdc, optlist, pdf_begin_font_options,
                                   &cdata, pdc_true);

    pdc_get_optvalues("colorized", results, &colorized, NULL);
    pdc_get_optvalues("widthsonly", results, &metricsonly, NULL);


    pdc_cleanup_optionlist(p->pdc, results);

    /* initialize font struct */
    font = &tmpfont;
    pdf_init_font_options(p, &fo);
    pdf_init_font(p, font, &fo);

    /*
     * We store the new font in a font slot marked with "invalidenc" encoding.
     * When the font is used for the first time we modify the encoding.
     * Later uses will make a copy if the encoding is different.
     */

    /* API font name */
    font->apiname = pdc_strdup(p->pdc, fontname);

    font->ft.m.type = fnt_Type3;
    font->hasoriginal = pdc_true;

    font->ft.matrix.a = a;
    font->ft.matrix.b = b;
    font->ft.matrix.c = c;
    font->ft.matrix.d = d;
    font->ft.matrix.e = e;
    font->ft.matrix.f = f;

    font->t3font = (pdf_t3font*) pdc_malloc(p->pdc, sizeof(pdf_t3font), fn);
    pdf_init_t3font(p, font->t3font, T3GLYPHS_CHUNKSIZE);

    font->t3font->colorized = colorized;


    /* the resource id is needed until the font dict is written */
    font->t3font->res_id = pdc_alloc_id(p->out);

    /* Now everything is fine, insert Type3 font with invalid encoding */
    slot = pdf_insert_font(p, font);

    /*
     * We must store a pointer to the current font because its glyph
     * definitions may use other fonts and we would be unable to find
     * "our" current font again. This pointer lives throughout the
     * font definition, and will be reset in PDF_end_font() below.
     */
    p->t3slot = slot;

    if (metricsonly)
    {
        font->t3font->pass = 1;
        pdc_logg_cond(p->pdc, 2, trc_font,
                          "\t\tonly for metric definition\n");
    }
    else
    {
        pdf_pg_suspend(p);
    }

    pdc_pop_errmsg(p->pdc);

    PDF_SET_STATE(p, pdf_state_font);

    if (!p->pdc->smokerun)
        pdc_logg_cond(p->pdc, 1, trc_api, "[Begin font %d]\n", p->t3slot);
}