public ImageArea(FontState fontState, FonetImage img, int AllocationWidth, int width, int height, int startIndent, int endIndent, int align) : base(fontState, width, 0, 0, 0) { this.currentHeight = height; this.contentRectangleWidth = width; this.height = height; this.image = img; this.align = align; }
public PdfXObject AddImage(FonetImage img) { // check if already created string url = img.Uri; PdfXObject xObject = (PdfXObject)this.xObjectsMap[url]; if (xObject == null) { PdfICCStream iccStream = null; ColorSpace cs = img.ColorSpace; if (cs.HasICCProfile()) { iccStream = new PdfICCStream(doc.NextObjectId(), cs.GetICCProfile()); iccStream.NumComponents = new PdfNumeric(cs.GetNumComponents()); iccStream.AddFilter(new FlateFilter()); this.objects.Add(iccStream); } // else, create a new one PdfName name = new PdfName("XO" + xObjectsMap.Count); xObject = new PdfXObject(img.Bitmaps, name, doc.NextObjectId()); xObject.SubType = PdfName.Names.Image; xObject.Dictionary[PdfName.Names.Width] = new PdfNumeric(img.Width); xObject.Dictionary[PdfName.Names.Height] = new PdfNumeric(img.Height); xObject.Dictionary[PdfName.Names.BitsPerComponent] = new PdfNumeric(img.BitsPerPixel); // Check for ICC color space if (iccStream != null) { PdfArray ar = new PdfArray(); ar.Add(PdfName.Names.ICCBased); ar.Add(iccStream.GetReference()); xObject.Dictionary[PdfName.Names.ColorSpace] = ar; } else { xObject.Dictionary[PdfName.Names.ColorSpace] = new PdfName(img.ColorSpace.GetColorSpacePDFString()); } xObject.AddFilter(img.Filter); this.objects.Add(xObject); this.xObjectsMap.Add(url, xObject); } return xObject; }
/// <summary> /// Renders an image, clipping it as specified. /// </summary> /// <param name="x">The x position of left edge in millipoints.</param> /// <param name="y">The y position of top edge in millipoints.</param> /// <param name="clipX">The left edge of the clip in millipoints.</param> /// <param name="clipY">The top edge of the clip in millipoints.</param> /// <param name="clipW">The clip width in millipoints.</param> /// <param name="clipH">The clip height in millipoints.</param> /// <param name="image">The image to be rendered.</param> private void DrawImageClipped( int x, int y, int clipX, int clipY, int clipW, int clipH, FonetImage image) { float cx1 = ((float) x)/1000f; float cy1 = ((float) y - clipH)/1000f; float cx2 = ((float) x + clipW)/1000f; float cy2 = ((float) y)/1000f; int imgX = x - clipX; int imgY = y - clipY; int imgW = image.Width*1000; int imgH = image.Height*1000; PdfXObject xobj = this.pdfDoc.AddImage(image); CloseText(); currentStream.Write("ET\nq\n" + // clipping PdfNumber.doubleOut(cx1) + " " + PdfNumber.doubleOut(cy1) + " m\n" + PdfNumber.doubleOut(cx2) + " " + PdfNumber.doubleOut(cy1) + " l\n" + PdfNumber.doubleOut(cx2) + " " + PdfNumber.doubleOut(cy2) + " l\n" + PdfNumber.doubleOut(cx1) + " " + PdfNumber.doubleOut(cy2) + " l\n" + "W\n" + "n\n" + // image matrix PdfNumber.doubleOut(((float) imgW)/1000f) + " 0 0 " + PdfNumber.doubleOut(((float) imgH)/1000f) + " " + PdfNumber.doubleOut(((float) imgX)/1000f) + " " + PdfNumber.doubleOut(((float) imgY - imgH)/1000f) + " cm\n" + "s\n" + // the image itself "/" + xobj.Name.Name + " Do\nQ\nBT\n"); }
/// <summary> /// Renders an image, scaling it to the given width and height. /// If the scaled width and height is the same intrinsic size /// of the image, the image is not scaled /// </summary> /// <param name="x">The x position of left edge in millipoints.</param> /// <param name="y">The y position of top edge in millipoints.</param> /// <param name="w">The width in millipoints.</param> /// <param name="h">The height in millipoints.</param> /// <param name="image">The image to be rendered.</param> private void DrawImageScaled( int x, int y, int w, int h, FonetImage image) { PdfXObject xobj = this.pdfDoc.AddImage(image); CloseText(); currentStream.Write("ET\nq\n" + PdfNumber.doubleOut(((float) w)/1000f) + " 0 0 " + PdfNumber.doubleOut(((float) h)/1000f) + " " + PdfNumber.doubleOut(((float) x)/1000f) + " " + PdfNumber.doubleOut(((float) (y - h))/1000f) + " cm\n" + "/" + xobj.Name.Name + " Do\nQ\nBT\n"); }
/// <summary> /// Renders an image, rendered at the image's intrinsic size. /// This by default calls drawImageScaled() with the image's /// intrinsic width and height, but implementations may /// override this method if it can provide a more efficient solution. /// </summary> /// <param name="x">The x position of left edge in millipoints.</param> /// <param name="y">The y position of top edge in millipoints.</param> /// <param name="image">The image to be rendered.</param> private void DrawImage(int x, int y, FonetImage image) { int w = image.Width*1000; int h = image.Height*1000; DrawImageScaled(x, y, w, h, image); }