virtual public Point2D InverseTransform(Point2D src, Point2D dst)
        {
            double det = GetDeterminant();

            if (Math.Abs(det) < ZERO)
            {
                // awt.204=Determinant is zero
                throw new InvalidOperationException("awt.204"); //$NON-NLS-1$
            }

            if (dst == null)
            {
                if (src is Point2D.Double)
                {
                    dst = new Point2D.Double();
                }
                else
                {
                    dst = new Point2D.Float();
                }
            }

            double x = src.GetX() - m02;
            double y = src.GetY() - m12;

            dst.SetLocation((x * m11 - y * m01) / det, (y * m00 - x * m10) / det);
            return(dst);
        }
Exemple #2
0
        /**
         * Appends a straight line segment from the current point to the point <CODE>(x, y)</CODE>.
         */
        public virtual void LineTo(float x, float y) {
            if (currentPoint == null) {
                throw new Exception(START_PATH_ERR_MSG);
            }

            Point2D targetPoint = new Point2D.Float(x, y);
            this.LastSubpath.AddSegment(new Line(currentPoint, targetPoint));
            currentPoint = targetPoint;
        }
Exemple #3
0
        /**
         * Appends a cubic Bezier curve to the current path. The curve shall extend from
         * the current point to the point <CODE>(x3, y3)</CODE>.
         */
        public virtual void CurveTo(float x1, float y1, float x2, float y2, float x3, float y3) {
            if (currentPoint == null) {
                throw new Exception(START_PATH_ERR_MSG);
            }
            // Numbered in natural order
            Point2D secondPoint = new Point2D.Float(x1, y1);
            Point2D thirdPoint = new Point2D.Float(x2, y2);
            Point2D fourthPoint = new Point2D.Float(x3, y3);

            IList<Point2D> controlPoints = new List<Point2D>(new Point2D[] {currentPoint, secondPoint, thirdPoint, fourthPoint});
            this.LastSubpath.AddSegment(new BezierCurve(controlPoints));

            currentPoint = fourthPoint;
        }
Exemple #4
0
        virtual public Point2D DeltaTransform(Point2D src, Point2D dst) {
            if (dst == null) {
                if (src is Point2D.Double) {
                    dst = new Point2D.Double();
                } else {
                    dst = new Point2D.Float();
                }
            }

            double x = src.GetX();
            double y = src.GetY();

            dst.SetLocation(x * m00 + y * m01, x * m10 + y * m11);
            return dst;
        }
Exemple #5
0
 virtual public void Transform(Point2D[] src, int srcOff, Point2D[] dst, int dstOff, int length) {
     while (--length >= 0) {
         Point2D srcPoint = src[srcOff++]; 
         double x = srcPoint.GetX();
         double y = srcPoint.GetY();
         Point2D dstPoint = dst[dstOff]; 
         if (dstPoint == null) {
             if (srcPoint is Point2D.Double) {
                 dstPoint = new Point2D.Double();
             } else {
                 dstPoint = new Point2D.Float();
             }
         }
         dstPoint.SetLocation(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12);
         dst[dstOff++] = dstPoint;
     }
 }
Exemple #6
0
        public Point2D Transform(Point2D src, Point2D dst)
        {
            if (dst == null)
            {
                if (src is Point2D.Double)
                {
                    dst = new Point2D.Double();
                }
                else
                {
                    dst = new Point2D.Float();
                }
            }

            double x = src.GetX();
            double y = src.GetY();

            dst.SetLocation(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12);
            return(dst);
        }
 /**
 * Adds an <CODE>Image</CODE> to the page. The positioning of the <CODE>Image</CODE>
 * is done with the transformation matrix. To position an <CODE>image</CODE> at (x,y)
 * use AddImage(image, image_width, 0, 0, image_height, x, y). The image can be placed inline.
 * @param image the <CODE>Image</CODE> object
 * @param a an element of the transformation matrix
 * @param b an element of the transformation matrix
 * @param c an element of the transformation matrix
 * @param d an element of the transformation matrix
 * @param e an element of the transformation matrix
 * @param f an element of the transformation matrix
 * @param inlineImage <CODE>true</CODE> to place this image inline, <CODE>false</CODE> otherwise
 * @throws DocumentException on error
 */
 public virtual void AddImage(Image image, float a, float b, float c, float d, float e, float f, bool inlineImage) {
     if (image.Layer != null)
         BeginLayer(image.Layer);
     if (IsTagged()) {
         if (inText)
             EndText();
         AffineTransform transform = new AffineTransform(a, b, c, d, e, f);
         Point2D[] src = new Point2D.Float[] { new Point2D.Float(0, 0), new Point2D.Float(1, 0), new Point2D.Float(1, 1), new Point2D.Float(0, 1) };
         Point2D[] dst = new Point2D.Float[4];
         transform.Transform(src, 0, dst, 0, 4);
         float left = float.MaxValue;
         float right = float.MinValue;
         float bottom = float.MaxValue;
         float top = float.MinValue;
         for (int i = 0; i < 4; i++) {
             if (dst[i].GetX() < left)
                 left = (float) dst[i].GetX();
             if (dst[i].GetX() > right)
                 right = (float) dst[i].GetX();
             if (dst[i].GetY() < bottom)
                 bottom = (float) dst[i].GetY();
             if (dst[i].GetY() > top)
                 top = (float) dst[i].GetY();
         }
         image.SetAccessibleAttribute(PdfName.BBOX, new PdfArray(new float[] {left, bottom, right, top}));
     }
     if (writer != null && image.IsImgTemplate()) {
         writer.AddDirectImageSimple(image);
         PdfTemplate template = image.TemplateData;
         if (image.GetAccessibleAttributes() != null) {
             foreach (PdfName key in image.GetAccessibleAttributes().Keys) {
                 template.SetAccessibleAttribute(key, image.GetAccessibleAttribute(key));
             }
         }
         float w = template.Width;
         float h = template.Height;
         AddTemplate(template, a / w, b / w, c / h, d / h, e, f);
     }
     else {
         content.Append("q ");
         content.Append(a).Append(' ');
         content.Append(b).Append(' ');
         content.Append(c).Append(' ');
         content.Append(d).Append(' ');
         content.Append(e).Append(' ');
         content.Append(f).Append(" cm");
         if (inlineImage) {
             content.Append("\nBI\n");
             PdfImage pimage = new PdfImage(image, "", null);
             if (image is ImgJBIG2) {
                 byte[] globals = ((ImgJBIG2)image).GlobalBytes;
                 if (globals != null) {
                     PdfDictionary decodeparms = new PdfDictionary();
                     decodeparms.Put(PdfName.JBIG2GLOBALS, writer.GetReferenceJBIG2Globals(globals));
                     pimage.Put(PdfName.DECODEPARMS, decodeparms);
                 }
             }
             PdfWriter.CheckPdfIsoConformance(writer, PdfIsoKeys.PDFISOKEY_INLINE_IMAGE, pimage);
             foreach (PdfName key in pimage.Keys) {
                 if (!abrev.ContainsKey(key))
                     continue;
                 PdfObject value = pimage.Get(key);
                 String s = abrev[key];
                 content.Append(s);
                 bool check = true;
                 if (key.Equals(PdfName.COLORSPACE) && value.IsArray()) {
                     PdfArray ar = (PdfArray)value;
                     if (ar.Size == 4 
                         && PdfName.INDEXED.Equals(ar.GetAsName(0)) 
                         && ar[1].IsName()
                         && ar[2].IsNumber()
                         && ar[3].IsString()
                     ) {
                         check = false;
                     }
                     
                 }
                 if (check && key.Equals(PdfName.COLORSPACE) && !value.IsName()) {
                     PdfName cs = writer.GetColorspaceName();
                     PageResources prs = PageResources;
                     prs.AddColor(cs, writer.AddToBody(value).IndirectReference);
                     value = cs;
                 }
                 value.ToPdf(null, content);
                 content.Append('\n');
             }
             content.Append("ID\n");
             pimage.WriteContent(content);
             content.Append("\nEI\nQ").Append_i(separator);
         }
         else {
             PdfName name;
             PageResources prs = PageResources;
             Image maskImage = image.ImageMask;
             if (maskImage != null) {
                 name = writer.AddDirectImageSimple(maskImage);
                 prs.AddXObject(name, writer.GetImageReference(name));
             }
             name = writer.AddDirectImageSimple(image);
             name = prs.AddXObject(name, writer.GetImageReference(name));
             content.Append(' ').Append(name.GetBytes()).Append(" Do Q").Append_i(separator);
         }
     }
     if (image.HasBorders()) {
         SaveState();
         float w = image.Width;
         float h = image.Height;
         ConcatCTM(a / w, b / w, c / h, d / h, e, f);
         Rectangle(image);
         RestoreState();
     }
     if (image.Layer != null)
         EndLayer();
     Annotation annot = image.Annotation;
     if (annot == null)
         return;
     float[] r = new float[unitRect.Length];
     for (int k = 0; k < unitRect.Length; k += 2) {
         r[k] = a * unitRect[k] + c * unitRect[k + 1] + e;
         r[k + 1] = b * unitRect[k] + d * unitRect[k + 1] + f;
     }
     float llx = r[0];
     float lly = r[1];
     float urx = llx;
     float ury = lly;
     for (int k = 2; k < r.Length; k += 2) {
         llx = Math.Min(llx, r[k]);
         lly = Math.Min(lly, r[k + 1]);
         urx = Math.Max(urx, r[k]);
         ury = Math.Max(ury, r[k + 1]);
     }
     annot = new Annotation(annot);
     annot.SetDimensions(llx, lly, urx, ury);
     PdfAnnotation an = PdfAnnotationsImp.ConvertAnnotation(writer, annot, new Rectangle(llx, lly, urx, ury));
     if (an == null)
         return;
     AddAnnotation(an);
 }
        virtual public Point2D InverseTransform(Point2D src, Point2D dst) {
            double det = GetDeterminant();
            if (Math.Abs(det) < ZERO) {
                // awt.204=Determinant is zero
                throw new InvalidOperationException("awt.204"); //$NON-NLS-1$
            }

            if (dst == null) {
                if (src is Point2D.Double) {
                    dst = new Point2D.Double();
                } else {
                    dst = new Point2D.Float();
                }
            }

            double x = src.GetX() - m02;
            double y = src.GetY() - m12;

            dst.SetLocation((x * m11 - y * m01) / det, (y * m00 - x * m10) / det);
            return dst;
        }