Example #1
0
void
pdf__end_glyph(PDF *p)
{
    pdf_t3font *t3font = p->fonts[p->t3slot].t3font;
    pdf_t3glyph *glyph = &t3font->glyphs[t3font->curr_glyph];
    int ig = t3font->curr_glyph;

    if (t3font->pass != 1 && glyph->charproc_id != PDC_BAD_ID)
    {
        /* check whether pdf__save() and pdf__restore() calls are balanced */
        if (p->curr_ppt->sl > 0)
            pdc_error(p->pdc, PDF_E_GSTATE_UNMATCHEDSAVE, 0, 0, 0, 0);

        pdf_end_text(p);
        pdc_end_pdfstream(p->out);              /* glyph description stream */
        pdc_end_obj(p->out);                    /* glyph description */

        pdc_put_pdfstreamlength(p->out, p->length_id);
    }

    PDF_SET_STATE(p, pdf_state_font);

    pdc_logg_cond(p->pdc, 1, trc_font,
        "\tEnd of Type3 font glyph \"%s\"\n",
        t3font->glyphs[ig].name);

    if (!p->pdc->smokerun)
        pdc_logg_cond(p->pdc, 1, trc_api, "[End glyph %d]\n", ig);
}
Example #2
0
void
pdf_concat_raw(PDF *p, pdc_matrix *m)
{
    if (!pdc_is_identity_matrix(m))
    {
        char sa[32], sb[32], sc[32], sd[32];

        pdc_sprintf(p->pdc, pdc_true, sa, "%f", m->a);
        pdc_sprintf(p->pdc, pdc_true, sb, "%f", m->b);
        pdc_sprintf(p->pdc, pdc_true, sc, "%f", m->c);
        pdc_sprintf(p->pdc, pdc_true, sd, "%f", m->d);

        if ((!strcmp(sa, "0") || !strcmp(sd, "0")) &&
            (!strcmp(sb, "0") || !strcmp(sc, "0")))
        {
            pdc_error(p->pdc, PDC_E_ILLARG_MATRIX,
                      pdc_errprintf(p->pdc, "%f %f %f %f %f %f",
                                    m->a, m->b, m->c, m->d, m->e, m->f),
                      0, 0, 0);
        }

        pdf_end_text(p);

        pdc_printf(p->out, "%s %s %s %s %f %f cm\n",
                   sa, sb, sc, sd, m->e, m->f);

        pdc_multiply_matrix(m, &p->curr_ppt->gstate[p->curr_ppt->sl].ctm);
    }
}
Example #3
0
void
pdf__restore(PDF *p)
{
    if (p->sl == 0)
	pdc_error(p->pdc, PDF_E_GSTATE_RESTORE, 0, 0, 0, 0);

    pdf_end_text(p);

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

    p->sl--;
}
Example #4
0
static void
pdf_begin_path(PDF *p)
{
    if (PDF_GET_STATE(p) == pdf_state_path)
	return;




    pdf_end_text(p);
    PDF_PUSH_STATE(p, "pdf_begin_path", pdf_state_path);
}
Example #5
0
/* Finish the pattern definition. */
PDFLIB_API void PDFLIB_CALL
PDF_end_pattern(PDF *p)
{
    static const char fn[] = "PDF_end_pattern";
    long length;

    PDF_TRACE(("%s\t(pdf[%p]);\n", fn, (void *) p));

    if (PDF_SANITY_CHECK_FAILED(p))
	return;

    PDF_CHECK_SCOPE(p, fn, pdf_state_pattern);

    /* check whether PDF_save() and PDF_restore() calls are balanced */
    if (p->sl > 0)
	pdf_error(p, PDF_RuntimeError,
	    "Unmatched save level at end of pattern");

    pdf_end_text(p);
    p->contents = c_none;

    if (p->compresslevel)
	pdf_compress_end(p);
					
    length = pdf_tell(p) - p->start_contents_pos;
    pdf_end_stream(p);
    pdf_end_obj(p);				/* pattern */

    pdf_begin_obj(p, p->contents_length_id);	/* Length object */
    pdf_printf(p, "%ld\n", length);
    pdf_end_obj(p);
  
    pdf_begin_obj(p, p->res_id);		/* Resource object */
    pdf_begin_dict(p);				/* Resource dict */

    pdf_write_page_procsets(p);			/* ProcSet resources */

    pdf_write_page_fonts(p);			/* Font resources */

    pdf_write_page_colorspaces(p);		/* Color space resources */

    pdf_write_page_pattern(p);			/* Pattern resources */

    pdf_write_xobjects(p);			/* XObject resources */

    pdf_end_dict(p);				/* resource dict */
    pdf_end_obj(p);				/* resource object */

    PDF_POP_STATE(p, fn);

    if (p->flush & PDF_FLUSH_PAGE)
	pdf_flush_stream(p);
}
Example #6
0
void
pdf__shfill(PDF *p, int shading)
{
    if (p->compatibility == PDC_1_3)
	pdc_error(p->pdc, PDF_E_SHADING13, 0, 0, 0, 0);

    pdf_check_handle(p, shading, pdc_shadinghandle);

    pdf_end_text(p);
    pdc_printf(p->out, "/Sh%d sh\n", shading);

    p->shadings[shading].used_on_current_page = pdc_true;
}
Example #7
0
void
pdf_concat_raw(PDF *p, pdc_matrix *m)
{
    if (pdc_is_identity_matrix(m))
	return;

    pdf_end_text(p);

    pdc_printf(p->out, "%f %f %f %f %f %f cm\n",
		    m->a, m->b, m->c, m->d, m->e, m->f);

    pdc_multiply_matrix(m, &p->gstate[p->sl].ctm);
}
Example #8
0
void
pdf__save(PDF *p)
{
    if (p->sl == PDF_MAX_SAVE_LEVEL - 1)
	pdc_error(p->pdc, PDF_E_GSTATE_SAVELEVEL,
	    pdc_errprintf(p->pdc, "%d", PDF_MAX_SAVE_LEVEL - 1), 0, 0, 0);

    pdf_end_text(p);

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

    /* propagate states to next level */
    p->sl++;
    memcpy(&p->gstate[p->sl], &p->gstate[p->sl - 1], sizeof(pdf_gstate));
    memcpy(&p->tstate[p->sl], &p->tstate[p->sl - 1], sizeof(pdf_tstate));
    memcpy(&p->cstate[p->sl], &p->cstate[p->sl - 1], sizeof(pdf_cstate));
}
Example #9
0
void
pdf__end_glyph(PDF *p)
{
    PDF_SET_STATE(p, pdf_state_font);

    /* check whether pdf__save() and pdf__restore() calls are balanced */
    if (p->sl > 0)
        pdc_error(p->pdc, PDF_E_GSTATE_UNMATCHEDSAVE, 0, 0, 0, 0);

    pdf_end_text(p);
    p->contents = c_none;

    pdc_end_pdfstream(p->out);                  /* glyph description stream */
    pdc_end_obj(p->out);                        /* glyph description */

    pdc_put_pdfstreamlength(p->out, p->length_id);
}
Example #10
0
void
pdf__save(PDF *p)
{
    pdf_ppt *	ppt = p->curr_ppt;
    int		sl = ppt->sl;

    if (sl == PDF_MAX_SAVE_LEVEL - 1)
	pdc_error(p->pdc, PDF_E_GSTATE_SAVELEVEL,
	    pdc_errprintf(p->pdc, "%d", PDF_MAX_SAVE_LEVEL - 1), 0, 0, 0);

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

    /* propagate states to next level */
    memcpy(&ppt->gstate[sl + 1], &ppt->gstate[sl], sizeof(pdf_gstate));
    pdf_save_cstate(p);
    pdf_save_tstate(p);
    ++ppt->sl;
}
Example #11
0
void
pdf_end_contents_section(PDF *p)
{
    long length;

    if (p->contents == c_none)
	return;

    pdf_end_text(p);
    p->contents = c_none;

    pdf_compress_end(p);
						/* Contents object */
    length = pdf_tell(p) - p->start_contents_pos;
    pdf_end_stream(p);
    pdf_end_obj(p);

    pdf_begin_obj(p, p->contents_length_id);	/* Length object */
    pdf_printf(p, "%ld\n", length);
    pdf_end_obj(p);
}
Example #12
0
/* Finish the pattern definition. */
void
pdf__end_pattern(PDF *p)
{
    /* check whether pdf__save() and pdf__restore() calls are balanced */
    if (p->curr_ppt->sl > 0)
	pdc_error(p->pdc, PDF_E_GSTATE_UNMATCHEDSAVE, 0, 0, 0, 0);

    pdf_end_text(p);
    pdc_end_pdfstream(p->out);
    pdc_end_obj(p->out);			/* pattern */

    pdc_put_pdfstreamlength(p->out, p->length_id);

    pdc_begin_obj(p->out, p->res_id);		/* Resource object */
    pdc_begin_dict(p->out);			/* Resource dict */

    pdf_write_page_fonts(p);			/* Font resources */

    pdf_write_page_colorspaces(p);		/* Color space resources */

    pdf_write_page_pattern(p);			/* Pattern resources */

    pdf_write_xobjects(p);			/* XObject resources */

    pdf_write_page_extgstates(p);		/* ExtGState resources */

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

    pdf_pg_resume(p, -1);

    if (p->flush & pdc_flush_content)
	pdc_flush_stream(p->out);

    if (!p->pdc->smokerun)
        pdc_logg_cond(p->pdc, 1, trc_api, "[End pattern %d]\n",
                      p->pattern_number -1);
}
Example #13
0
PDFLIB_API void PDFLIB_CALL
PDF_place_image(PDF *p, int im, float x, float y, float scale)
{
    static const char fn[] = "PDF_place_image";
    pdf_matrix m;
    pdf_image *image;
    int row;
    int imageno;

    PDF_TRACE(("%s\t(pdf[%p], %d, %f, %f, %f);\n",
	fn, (void *) p, im, x, y, scale));

    if (PDF_SANITY_CHECK_FAILED(p))
	return;

    if (im < 0 || im >= p->images_capacity || !p->images[im].in_use
	|| p->xobjects[p->images[im].no].type == pdi_xobject)
    {
    	pdf_error(p, PDF_ValueError,
		"Bad image or template handle %d in PDF_place_image", im);
    }

    PDF_CHECK_SCOPE(p, fn, pdf_state_ppt);

    if (PDF_GET_STATE(p) == pdf_state_template && im == p->templ)
	pdf_error(p, PDF_ValueError,
		"Can't use template within its own definition");

    image = &p->images[im];

    if (fabs(scale) < (float) PDF_SMALLREAL)
	pdf_error(p, PDF_ValueError,
		"Scaling factor 0 for image %s", image->filename);

    if (p->xobjects[image->no].type == form_xobject) {
	pdf_end_text(p);
	pdf_begin_contents_section(p);

	imageno = image->no;
	
	m.a = scale;
	m.d = scale;
	m.b = m.c = (float) 0.0;
	m.e = x;
	m.f = y;

	PDF_save(p);

	    pdf_concat_raw(p, &m);
	    if (!p->inheritgs)
		pdf_reset_gstate(p);

	    pdf_printf(p, "/I%d Do\n", imageno);
	    p->xobjects[imageno].flags |= xobj_flag_write;

	PDF_restore(p);

	return;
    }

    switch (image->colorspace) {
        case ImageMask:
        case DeviceGray:
	    p->procset	|= ImageB;
	    break;

	/*
	 * It appears that indexed images require both, although this is
	 * not documented.
	 */
        case Indexed:
	    p->procset	|= ImageI;
	    p->procset	|= ImageC;
	    break;

        case DeviceRGB:
        case DeviceCMYK:
	    p->procset	|= ImageC;
	    break;

	case CalGray:
        case CalRGB:
        case Lab:
        case PatternCS:
        case Separation:
            pdf_error(p, PDF_SystemError,
                "Bogus colorspace (%d) in PDF_place_image",
                    (int) image->colorspace);

        /* image has been colorized with a spot color */
        default:
            break;
    
	/* york: check the above carefully!
	** original version:
	default:
	    pdf_error(p, PDF_SystemError,
	    	"Bogus colorspace (%d) in PDF_place_image",
		    (int) image->colorspace);
	*/
    }

    pdf_end_text(p);
    pdf_begin_contents_section(p);

    imageno = image->no;	/* number of first strip */

    if (image->strips == 1)
	image->rowsperstrip = (int) image->height;

    for (row = 0; row < image->height; row += image->rowsperstrip, imageno++) {
	int height;	/* height of the current strip */

	height = (row + image->rowsperstrip > image->height ? 
		    (int) image->height - row : image->rowsperstrip);

	PDF_save(p);

	m.a = image->width * scale;
	m.d = height * scale;
	m.b = m.c = (float) 0.0;
	m.e = x;
	m.f = y + scale * (image->height - row - height);
	pdf_concat_raw(p, &m);

	pdf_printf(p, "/I%d Do\n", imageno);
	p->xobjects[imageno].flags |= xobj_flag_write;

	if (image->mask != -1)
	    p->xobjects[p->images[image->mask].no].flags |= xobj_flag_write;

	PDF_restore(p);
    }
}