One feature that would be nice would be a property on the XImage to set the transparency of the image.
In order to accomplish this, I added an alpha property to the XImage, then I changed the DrawImage in XGraphicsPdfRenderer. It works, but I am fairly new to the PDF spec, so I was wondering if it is a standard way to apply the transparency.
Thanks
public void DrawImage(XImage image, double x, double y, double width, double height) { string transparencyGraphicsState = "";
if (image.Alpha < 1.0F) { PdfExtGState extGState = this.Owner.ExtGStateTable.GetExtGStateNonStroke(image.Alpha); string gs = this.Resources.AddExtGState(extGState); transparencyGraphicsState = String.Format("{0} gs\n", gs);
// Must create transparany group if (this.page != null) this.page.transparencyUsed = true; }
string name = Realize(image); if (!(image is XForm)) { if (this.gfx.PageDirection == XPageDirection.Downwards) { AppendFormat("{6}q {2:0.####} 0 0 -{3:0.####} {0:0.####} {4:0.####} cm {5} Do Q\n", x, y, width, height, y + height, name, transparencyGraphicsState); } else { AppendFormat("{5}q {2:0.####} 0 0 {3:0.####} {0:0.####} {1:0.####} cm {4} Do Q\n", x, y, width, height, name, transparencyGraphicsState); } } else { BeginPage();
XForm form = (XForm)image; form.Finish();
PdfFormXObject pdfForm = Owner.FormTable.GetForm(form);
double cx = width / image.PointWidth; double cy = height / image.PointHeight;
if (cx != 0 && cy != 0) { if (this.gfx.PageDirection == XPageDirection.Downwards) { AppendFormat("{6}q {2:0.####} 0 0 -{3:0.####} {0:0.####} {4:0.####} cm 100 Tz {5} Do Q\n", x, y, cx, cy, y + height, name, transparencyGraphicsState); } else { AppendFormat("{5}q {2:0.####} 0 0 {3:0.####} {0:0.####} {1:0.####} cm {4} Do Q\n", x, y, cx, cy, name, transparencyGraphicsState); } } } }
|