Esempio n. 1
0
void
pdf__initgraphics(PDF *p)
{
    pdc_matrix inv_ctm;

    pdf_reset_gstate(p);

    pdc_invert_matrix(p->pdc, &inv_ctm, &p->gstate[p->sl].ctm);
    pdf_concat_raw(p, &inv_ctm);

    /* This also resets the CTM which guards against rounding artifacts. */
    pdf_init_gstate(p);
}
Esempio n. 2
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);
    }
}