void
pdf_showimage(pdf_csi *csi, fz_pixmap *image)
{
	pdf_gstate *gstate = csi->gstate + csi->gtop;
	fz_rect bbox;

	bbox = fz_transformrect(gstate->ctm, fz_unitrect);

	if (gstate->blendmode != FZ_BNORMAL)
		csi->dev->begingroup(csi->dev->user, bbox, 0, 0, gstate->blendmode, 1);

	if (image->mask)
		csi->dev->clipimagemask(csi->dev->user, image->mask, gstate->ctm);

	if (!image->colorspace)
	{

		switch (gstate->fill.kind)
		{
		case PDF_MNONE:
			break;
		case PDF_MCOLOR:
			csi->dev->fillimagemask(csi->dev->user, image, gstate->ctm,
				gstate->fill.cs, gstate->fill.v, gstate->fill.alpha);
			break;
		case PDF_MPATTERN:
			if (gstate->fill.pattern)
			{
				csi->dev->clipimagemask(csi->dev->user, image, gstate->ctm);
				pdf_showpattern(csi, gstate->fill.pattern, bbox, PDF_MFILL);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		case PDF_MSHADE:
			if (gstate->fill.shade)
			{
				csi->dev->clipimagemask(csi->dev->user, image, gstate->ctm);
				csi->dev->fillshade(csi->dev->user, gstate->fill.shade, gstate->ctm, gstate->fill.alpha);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		}
	}
	else
	{
		csi->dev->fillimage(csi->dev->user, image, gstate->ctm, gstate->fill.alpha);
	}

	if (image->mask)
		csi->dev->popclip(csi->dev->user);

	if (gstate->blendmode != FZ_BNORMAL)
		csi->dev->endgroup(csi->dev->user);
}
Exemple #2
0
void
pdf_flushtext(pdf_csi *csi)
{
	pdf_gstate *gstate = csi->gstate + csi->gtop;
	fz_text *text;
	int dofill = 0;
	int dostroke = 0;
	int doclip = 0;
	int doinvisible = 0;
	fz_rect bbox;

	if (!csi->text)
		return;
	text = csi->text;
	csi->text = nil;

	dofill = dostroke = doclip = doinvisible = 0;
	switch (csi->textmode)
	{
	case 0: dofill = 1; break;
	case 1: dostroke = 1; break;
	case 2: dofill = dostroke = 1; break;
	case 3: doinvisible = 1; break;
	case 4: dofill = doclip = 1; break;
	case 5: dostroke = doclip = 1; break;
	case 6: dofill = dostroke = doclip = 1; break;
	case 7: doclip = 1; break;
	}

	bbox = fz_boundtext(text, gstate->ctm);

	pdf_begingroup(csi, bbox);

	if (doinvisible)
		csi->dev->ignoretext(csi->dev->user, text, gstate->ctm);

	if (doclip)
	{
		if (csi->accumulate < 2)
			gstate->clipdepth++;
		csi->dev->cliptext(csi->dev->user, text, gstate->ctm, csi->accumulate);
		csi->accumulate = 2;
	}

	if (dofill)
	{
		switch (gstate->fill.kind)
		{
		case PDF_MNONE:
			break;
		case PDF_MCOLOR:
			csi->dev->filltext(csi->dev->user, text, gstate->ctm,
				gstate->fill.colorspace, gstate->fill.v, gstate->fill.alpha);
			break;
		case PDF_MPATTERN:
			if (gstate->fill.pattern)
			{
				csi->dev->cliptext(csi->dev->user, text, gstate->ctm, 0);
				pdf_showpattern(csi, gstate->fill.pattern, bbox, PDF_MFILL);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		case PDF_MSHADE:
			if (gstate->fill.shade)
			{
				csi->dev->cliptext(csi->dev->user, text, gstate->ctm, 0);
				csi->dev->fillshade(csi->dev->user, gstate->fill.shade, csi->topctm, gstate->fill.alpha);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		}
	}

	if (dostroke)
	{
		switch (gstate->stroke.kind)
		{
		case PDF_MNONE:
			break;
		case PDF_MCOLOR:
			csi->dev->stroketext(csi->dev->user, text, &gstate->strokestate, gstate->ctm,
				gstate->stroke.colorspace, gstate->stroke.v, gstate->stroke.alpha);
			break;
		case PDF_MPATTERN:
			if (gstate->stroke.pattern)
			{
				csi->dev->clipstroketext(csi->dev->user, text, &gstate->strokestate, gstate->ctm);
				pdf_showpattern(csi, gstate->stroke.pattern, bbox, PDF_MFILL);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		case PDF_MSHADE:
			if (gstate->stroke.shade)
			{
				csi->dev->clipstroketext(csi->dev->user, text, &gstate->strokestate, gstate->ctm);
				csi->dev->fillshade(csi->dev->user, gstate->stroke.shade, csi->topctm, gstate->stroke.alpha);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		}
	}

	pdf_endgroup(csi);

	fz_freetext(text);
}
Exemple #3
0
void
pdf_showpath(pdf_csi *csi, int doclose, int dofill, int dostroke, int evenodd)
{
	pdf_gstate *gstate = csi->gstate + csi->gtop;
	fz_path *path;
	fz_rect bbox;

	path = csi->path;
	csi->path = fz_newpath();

	if (doclose)
		fz_closepath(path);

	if (dostroke)
		bbox = fz_boundpath(path, &gstate->strokestate, gstate->ctm);
	else
		bbox = fz_boundpath(path, nil, gstate->ctm);

	if (csi->clip)
	{
		gstate->clipdepth++;
		csi->dev->clippath(csi->dev->user, path, evenodd, gstate->ctm);
		csi->clip = 0;
	}

	pdf_begingroup(csi, bbox);

	if (dofill)
	{
		switch (gstate->fill.kind)
		{
		case PDF_MNONE:
			break;
		case PDF_MCOLOR:
			csi->dev->fillpath(csi->dev->user, path, evenodd, gstate->ctm,
				gstate->fill.colorspace, gstate->fill.v, gstate->fill.alpha);
			break;
		case PDF_MPATTERN:
			if (gstate->fill.pattern)
			{
				csi->dev->clippath(csi->dev->user, path, evenodd, gstate->ctm);
				pdf_showpattern(csi, gstate->fill.pattern, bbox, PDF_MFILL);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		case PDF_MSHADE:
			if (gstate->fill.shade)
			{
				csi->dev->clippath(csi->dev->user, path, evenodd, gstate->ctm);
				csi->dev->fillshade(csi->dev->user, gstate->fill.shade, csi->topctm, gstate->fill.alpha);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		}
	}

	if (dostroke)
	{
		switch (gstate->stroke.kind)
		{
		case PDF_MNONE:
			break;
		case PDF_MCOLOR:
			csi->dev->strokepath(csi->dev->user, path, &gstate->strokestate, gstate->ctm,
				gstate->stroke.colorspace, gstate->stroke.v, gstate->stroke.alpha);
			break;
		case PDF_MPATTERN:
			if (gstate->stroke.pattern)
			{
				csi->dev->clipstrokepath(csi->dev->user, path, &gstate->strokestate, gstate->ctm);
				pdf_showpattern(csi, gstate->stroke.pattern, bbox, PDF_MFILL);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		case PDF_MSHADE:
			if (gstate->stroke.shade)
			{
				csi->dev->clipstrokepath(csi->dev->user, path, &gstate->strokestate, gstate->ctm);
				csi->dev->fillshade(csi->dev->user, gstate->stroke.shade, csi->topctm, gstate->stroke.alpha);
				csi->dev->popclip(csi->dev->user);
			}
			break;
		}
	}

	pdf_endgroup(csi);

	fz_freepath(path);
}