コード例 #1
0
ファイル: GuidePage.cs プロジェクト: cammckenzie/thesarvo
        public GuideFrame CreateTextFrame(Mode mode, FrameType type)
        {
            Bounds newBounds = contentBounds.Clone();

            newBounds.top    = GetNextTop();
            newBounds.height = 10;


            TextFrame textFrame = page.TextFrames.Add(miss, idLocationOptions.idAtEnd, miss);

            textFrame.GeometricBounds = newBounds.raw;
            textFrame.TextFramePreferences.FirstBaselineOffset = idFirstBaseline.idLeadingOffset;

            if (mode == Mode.TwoColumns)
            {
                textFrame.TextFramePreferences.TextColumnCount = 2;
            }

            //$.global.textFrames.push( myTextFrame );

            GuideFrame frame = new GuideFrame(textFrame, this.guide, this, mode, type);

            frame.bounds = newBounds;

            //currentFrame = frame;
            frames.Add(frame);

            //currentMode = mode;

            return(frame);
        }
コード例 #2
0
        public void TransformBoundsForNewPage(GuidePage newPage)
        {
            Bounds oldBounds = bounds.Clone();

            bounds.top    = newPage.GetNextTop();
            bounds.height = oldBounds.height;
            bounds.left   = (oldBounds.left - page.contentBounds.left) + newPage.contentBounds.left;
            bounds.width  = oldBounds.width;

            ApplyBounds();
        }
コード例 #3
0
ファイル: Guide.cs プロジェクト: drollins/thesarvo
        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);

                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");
        }
コード例 #4
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");
        }