示例#1
0
        private void PlaceImage(string filename, Rectangle rect, bool resize, idPDFCrop crop, bool rotate)
        {
            if (!File.Exists(filename))
            {
                Console.WriteLine("Image " + filename + " does not exist!");
                return;
            }


            if (crop != null)
            {
                application.PDFPlacePreferences.PDFCrop = crop;
            }

            rect.Place(filename, false);

            object obj = rect.AllGraphics.LastItem();

            if (rotate)
            {
                if (obj is Image)
                {
                    ((Image)obj).RotationAngle = 90;
                }
                if (obj is PDF)
                {
                    ((PDF)obj).RotationAngle = 90;
                }
            }

            if (resize)
            {
                rect.Fit(idFitOptions.idProportionally);
            }

            application.PDFPlacePreferences.PDFCrop = idPDFCrop.idCropContentAllLayers;
            //application.PDFPlacePreferences.PDFCrop = idPDFCrop..idCropContent;
        }
示例#2
0
        /*private static void SetPDFCrop(object tempimg)
        {
            if (tempimg is PDF)
            {
                idPDFCrop crop = ((PDF)tempimg).PDFAttributes.PDFCrop;
                ((PDF)tempimg).PDFAttributes.PDFCrop = idPDFCrop.idCropTrim;
            }
        }*/
        private Rectangle PlaceImageInRect(string filename, Bounds tempBounds, bool resize, idPDFCrop crop)
        {
            Rectangle temprect = currentPage.page.Rectangles.Add(miss, idLocationOptions.idAtEnd, miss);
            temprect.GeometricBounds = tempBounds.raw;
            temprect.StrokeWeight = 0;
            temprect.FillColor = document.Swatches["None"];

            PlaceImage(filename, temprect, resize, crop, false);

            return temprect;
        }
示例#3
0
        private void PlaceImage(string filename, Rectangle rect, bool resize, idPDFCrop crop, bool rotate)
        {
            if (crop != null)
                application.PDFPlacePreferences.PDFCrop = crop;

            rect.Place(filename, false);

            object obj = rect.AllGraphics.LastItem();

            if (rotate)
            {
                if (obj is Image)
                {
                    ((Image)obj).RotationAngle = 90;
                }
                if (obj is PDF)
                {
                    ((PDF)obj).RotationAngle = 90;
                }

            }

            if (resize)
                rect.Fit(idFitOptions.idProportionally);

            application.PDFPlacePreferences.PDFCrop = idPDFCrop.idCropContentAllLayers;
            //application.PDFPlacePreferences.PDFCrop = idPDFCrop..idCropContent;
        }
示例#4
0
        /*private static void SetPDFCrop(object tempimg)
        {
            if (tempimg is PDF)
            {
                idPDFCrop crop = ((PDF)tempimg).PDFAttributes.PDFCrop;
                ((PDF)tempimg).PDFAttributes.PDFCrop = idPDFCrop.idCropTrim;
            }
        }*/
        private Rectangle PlaceImageInRect(string filename, Bounds tempBounds, bool resize, idPDFCrop crop)
        {
            if (!File.Exists(filename))
            {
                Console.WriteLine("Image " + filename + " does not exist!");
                return null;
            }

            Rectangle temprect = currentPage.page.Rectangles.Add(miss, idLocationOptions.idAtEnd, miss);
            temprect.GeometricBounds = tempBounds.raw;
            temprect.StrokeWeight = 0;
            temprect.FillColor = document.Swatches["None"];

            PlaceImage(filename, temprect, resize, crop, false);

            return temprect;
        }
示例#5
0
        /*private static void SetPDFCrop(object tempimg)
         * {
         *  if (tempimg is PDF)
         *  {
         *      idPDFCrop crop = ((PDF)tempimg).PDFAttributes.PDFCrop;
         *      ((PDF)tempimg).PDFAttributes.PDFCrop = idPDFCrop.idCropTrim;
         *  }
         * }*/

        private Rectangle PlaceImageInRect(string filename, Bounds tempBounds, bool resize, idPDFCrop crop)
        {
            if (!File.Exists(filename))
            {
                Console.WriteLine("Image " + filename + " does not exist!");
                return(null);
            }


            Rectangle temprect = currentPage.page.Rectangles.Add(miss, idLocationOptions.idAtEnd, miss);

            temprect.GeometricBounds = tempBounds.raw;
            temprect.StrokeWeight    = 0;
            temprect.FillColor       = document.Swatches["None"];


            PlaceImage(filename, temprect, resize, crop, false);



            return(temprect);
        }
示例#6
0
        void ProcessImage(XmlElement node)
        {
            string src     = GetAttr(node, "src");
            string width   = GetAttr(node, "width");
            string noPrint = GetAttr(node, "noPrint");

            if (noPrint == "true")
            {
                return;
            }

            bool   forceTwoColums = GetConfigBool(src, "TwoColumns");
            bool   fitToPage      = GetConfigBool(src, "FitToPage");
            bool   rotate         = GetConfigBool(src, "Rotate");
            bool   border         = GetConfigBool(src, "Border");
            string overrideWidth  = GetConfig(src, "Width");

            if (overrideWidth != null && overrideWidth.Length > 0)
            {
                width = overrideWidth;
            }

            //int topOffset = 0;

            if (src.Trim().Length > 0)
            {
                if (src == "starwars.jpg")
                {
                    int x = 0;
                }

                string filename = GetAttachmentPath(src);



                string filenameRepl = filename.Replace(".png", ".pdf").Replace(".jpg", ".pdf").Replace(".gif", ".pdf");

                bool pdf = false;
                if (filenameRepl != filename && System.IO.File.Exists(filenameRepl))
                {
                    filename = filenameRepl;
                    pdf      = true;
                }
                else
                {
                    string srcpdf    = src.Replace(".png", ".pdf").Replace(".jpg", ".pdf").Replace(".gif", ".pdf");
                    string filecache = Layout.GetFileCache(srcpdf);
                    if (filecache != null)
                    {
                        filename = filecache;
                        pdf      = true;
                    }
                }

                idPDFCrop crop = idPDFCrop.idCropArt;

                Bounds    tempBounds = new Bounds(new double[] { 0.0, 0.0, 10.0, 10.0 });
                Rectangle temprect   = PlaceImageInRect(filename, tempBounds, false, crop);

                if (temprect == null)
                {
                    Console.WriteLine("Failed to place image " + src + ", continuing");
                    return;
                }

                object tempimg    = temprect.AllGraphics.FirstItem();
                Bounds tempbounds = Util.GetImageBounds(tempimg);


                double sizeY = tempbounds.height;

                double dpi = 72;
                if (!pdf)
                {
                    object[] dpis = ((Image)tempimg).ActualPpi;
                    dpi = (double)dpis[0];
                }
                double sizeX = tempbounds.width;
                temprect.Delete();

                if (rotate)
                {
                    double temp = sizeY;
                    sizeY = sizeX;
                    sizeX = temp;
                }

                Mode   type     = Mode.SingleColumn;
                double colsize  = 120;
                bool   forceNew = true;

                sizeX = (dpi / 72) * sizeX;
                sizeY = (dpi / 72) * sizeY;

                double newSX = sizeX;
                double newSY = sizeY;

                double w = 0;
                if (width.Length > 0)
                {
                    w = Double.Parse(width);
                }



                if (forceTwoColums || (!pdf && (sizeX < 180 || (width.Length > 0 && w <= 500))))
                {
                    // can fit in column - this needs more logic though
                    type = Mode.TwoColumns;

                    if (currentPage.currentFrame != null &&
                        currentPage.currentFrame.mode == Mode.TwoColumns)
                    {
                        currentPage.currentFrame.bottomOffset += 2;
                    }

                    //forceNew = false;
                    colsize = 58;

                    //if (currentPage.currentFrame != null)
                    //    currentPage.currentFrame.bottomOffset = 2;


                    if (width.Length > 0 && !forceTwoColums)
                    {
                        colsize = (w / 500) * colsize;
                    }
                }
                else
                {
                    if (width.Length > 0)
                    {
                        colsize = (w / 800) * colsize;
                    }
                }

                GuideFrame frame = GetTextFrame(type, FrameType.Image, forceNew);

                frame.AddPara("", "text", false);

                if (fitToPage)
                {
                    newSY = frame.page.contentBounds.bottom - frame.bounds.top;
                    newSY = newSY - 3;
                    newSX = (newSY / sizeY) * sizeX;
                }

                // wider than column/page
                if (newSX > colsize)
                {
                    newSX = colsize;
                    newSY = (newSX / sizeX) * sizeY;
                }
                else if (width.Length > 0 && !fitToPage)
                {
                    if (type == Mode.SingleColumn)
                    {
                        newSX = colsize * (w / 800);
                    }
                    else
                    {
                        newSX = colsize * (w / 500);
                    }

                    newSY = (newSX / sizeX) * sizeY;
                }

                // higher than page
                if (newSY > frame.page.contentBounds.height)
                {
                    newSY = frame.page.contentBounds.height - 2;
                    newSX = (newSY / sizeY) * sizeX;
                }


                Rectangle rect = frame.GetRect();

                //Bounds newBounds = new Bounds(frame.GeometricBounds);
                frame.bounds.height = 300;
                frame.ApplyBounds();

                Bounds newBounds = new Bounds();
                newBounds.width      = 10;
                newBounds.height     = 10;
                rect.GeometricBounds = newBounds.raw;

                rect.FillColor = document.Swatches["None"];

                if (src.ToLower().IndexOf(".jpg") > 0 || border)
                {
                    rect.StrokeWeight = 0.25;
                }
                else
                {
                    rect.StrokeWeight = 0;
                }

                Bounds rectBounds = newBounds.Clone();

                if (type == Mode.SingleColumn)
                {
                    //rectBounds.left = (currentPage.contentBounds.width - newSX) / 2;
                    Paragraph p = (Paragraph)frame.textFrame.Paragraphs.FirstItem();
                    p.Justification = idJustification.idCenterAlign;
                }
                rectBounds.width     = newSX;
                rectBounds.height    = newSY;
                rect.GeometricBounds = rectBounds.raw;

                PlaceImage(filename, rect, true, crop, rotate);
                object img = rect.AllGraphics.FirstItem();


                frame.bounds.height = newSY + 1;
                frame.ApplyBounds();

                frame.ResizeAndPaginate();
            }
            classes.Add("img");
        }