Exemple #1
0
        private void DoIndentedText(string text, string heading)
        {
            if (text.Length > 0)
            {
                text = HandleText(text);

                GuideFrame left = LeftHeader(heading);

                GuideFrame right       = GetTextFrame(Mode.SingleColumn, FrameType.Text, true);
                Bounds     rightBounds = right.bounds;

                rightBounds.top   = left.bounds.top + 1;
                rightBounds.left += INDENTED + 1;
                right.ApplyBounds();
                right.AddPara(text, "text", true);

                right.ResizeToFit();

                if (right.OverflowsPage())
                {
                    if (right.page.contentBounds.bottom - right.bounds.top > 20)
                    {
                        GuidePage newPage = this.GetNextPage(right.page, true);

                        GuideFrame newFrame = right.SplitFrame(newPage);

                        newFrame.bounds.left = newFrame.page.contentBounds.left + INDENTED + 2;
                        //newFrame.TransformBoundsForNewPage(newPage);
                        newFrame.bounds.top = right.page.contentBounds.top;
                        newFrame.ApplyBounds();
                        newFrame.ResizeToFit();
                    }
                    else
                    {
                        //MoveFrameToNext(left, leftBounds, false);
                        left.MoveFrameToNext(false);

                        right.MoveToPage(currentPage);
                        right.bounds.top = left.bounds.top + 1;
                        right.ApplyBounds();
                        right.ResizeToFit();
                    }
                }
                else
                {
                    currentPage.nextTopMin = Math.Max(left.bounds.bottom + left.bottomOffset, right.bounds.bottom + left.bottomOffset);
                }
            }
        }
Exemple #2
0
        private double DoHeaderIcon(double iconTop, string icon, string text)
        {
            if (text.Length > 0)
            {
                string iconPath   = GetIconPath(icon);
                Bounds iconBounds = new Bounds();
                iconBounds.top  = iconTop;
                iconBounds.left = currentPage.contentBounds.left + GRAPHSIZE + 2;
                double iconSize = ICONSIZE;
                iconBounds.width  = iconSize;
                iconBounds.height = iconSize;

                //PlaceImageInRect(iconPath, iconBounds, true, idPDFCrop.idCropContent);
                PlaceImageInRect(iconPath, iconBounds, true, idPDFCrop.idCropContentAllLayers);

                GuideFrame right       = GetTextFrame(Mode.SingleColumn, FrameType.Text, true);
                Bounds     rightBounds = right.bounds;
                rightBounds.top  = iconTop + 1;
                rightBounds.left = iconBounds.left + iconSize + 2;
                right.ApplyBounds();
                right.AddPara(text, "text", true);

                right.ResizeToFit();

                iconTop += Math.Max(iconSize, right.bounds.height) + 1;
            }
            return(iconTop);
        }
Exemple #3
0
        private GuideFrame LeftHeader(string heading)
        {
            GuideFrame left = GetTextFrame(Mode.SingleColumn, FrameType.IndentedHeader, true);

            left.AddPara(heading, "indentedHeader", false);
            left.bounds.width = INDENTED;
            left.ApplyBounds();
            left.ResizeToFit();
            return(left);
        }
Exemple #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");
        }
Exemple #5
0
        void ProcessText(XmlElement node)
        {
            string style = GetAttr(node, "class");

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

            Mode requiredMode = Mode.SingleColumn;
            Mode currentMode  = currentPage.currentMode;

            bool forceNew  = true;
            bool isHeading = Util.IsHeading(style);

            //if (style.indexOf('heading')<0 && style!='text' && style!='Discussion')
            //		style = 'text';

            if (!isHeading && style != "Discussion" && style != "indentedHeader")
            {
                style = "text";
            }

            string nextNode = Util.GetNextNodeName(node);


            if (currentMode == Mode.TwoColumns && !isHeading)
            {
                if (nextNode == "problem" || nextNode == "climb" ||
                    nextNode == "text")
                {
                    requiredMode = Mode.TwoColumns;
                    forceNew     = false;

                    if (style == "text")
                    {
                        style = "Discussion";
                    }
                }
            }



            string text = node.InnerText;

            text = HandleText(text);
            text = text.Replace('↓', 'ŏ');
            text = text.Replace("<br/>", "\n");


            text = text.Replace("\n* ", "\n• ");

            bool newPage = GetConfigBool(text, "NewPage");

            if (newPage)
            {
                NextPage();
            }

            int colon = text.IndexOf(":");

            if (style != "indentedHeader" || colon < 0)
            {
                FrameType type = FrameType.Text;

                if (isHeading)
                {
                    type = FrameType.Heading;
                }

                GuideFrame frame = GetTextFrame(requiredMode, type, forceNew);

                if (style == "heading1" && node.PreviousSibling == null)
                {
                    frame.bounds.top -= 4;
                    frame.ApplyBounds();
                    frame.bottomOffset += 4;
                }
                else if (style == "heading2" || (style == "heading3"))
                {
                    frame.bounds.top++;
                    if (style == "heading3")
                    {
                        frame.bottomOffset -= 0.5;
                    }

                    frame.ApplyBounds();
                }

                if (text != null && text.Length > 0)
                {
                    InsertionPoint ip = frame.AddPara(text, style, true);
                    ip.KeepFirstLines = 10;
                }

                frame.ResizeAndPaginate();
            }
            else
            {
                string head = text.Substring(0, colon).Trim();
                string rem  = text.Substring(colon + 1).Trim();

                DoIndentedText(rem, head);
            }
        }
Exemple #6
0
        void ProcessHeader(XmlElement node)
        {
            string intro           = GetAttr(node, "intro");
            string name            = GetAttr(node, "name");
            string sun             = GetAttr(node, "sun");
            string rock            = GetAttr(node, "rock");
            string walk            = GetAttr(node, "walk");
            string history         = GetAttr(node, "history");
            string access          = GetAttr(node, "access");
            string acknowledgement = GetAttr(node, "acknowledgement");

            GuideFrame frame = GetTextFrame(Mode.SingleColumn, FrameType.Multi, true);


            frame.AddPara(name, "heading1", true);
            frame.bounds.top -= 4;
            frame.ApplyBounds();
            frame.ResizeAndPaginate();
            frame.bottomOffset += 2;

            double bottomExtra = 0;
            double iconTop     = currentPage.GetNextTop();

            bool done = false;

            string graphPath = GetAttachmentPath("graph.pdf");

            if (File.Exists(graphPath) && this.xml.SelectNodes("//climb").Count > 0)
            {
                Bounds graphBounds = new Bounds();
                graphBounds.top    = iconTop;
                graphBounds.height = GRAPHSIZE;
                graphBounds.left   = currentPage.contentBounds.left;
                graphBounds.width  = GRAPHSIZE;
                //PlaceImageInRect( graphPath, graphBounds, true, idPDFCrop.idCropContent);
                PlaceImageInRect(graphPath, graphBounds, true, idPDFCrop.idCropContentAllLayers);

                bottomExtra = graphBounds.bottom + 3;

                done = true;
            }
            if (walk.Length > 0 || sun.Length > 0 || rock.Length > 0)
            {
                done    = true;
                iconTop = DoHeaderIcon(iconTop, "walk2.pdf", walk);
                iconTop = DoHeaderIcon(iconTop, "sun2.pdf", sun);
                iconTop = DoHeaderIcon(iconTop, "rock2.pdf", rock);

                iconTop += 4;
            }

            if (done)
            {
                bottomExtra            = Math.Max(iconTop, bottomExtra);
                currentPage.nextTopMin = bottomExtra;

                MasterSpread master = GetMaster("FP-Master");

                // assume every rect needs moving
                Rectangles rects = master.Rectangles;
                foreach (Rectangle rect in rects)
                {
                    Bounds b = new Bounds(rect.GeometricBounds);
                    b.bottom             = bottomExtra - 2;
                    rect.GeometricBounds = b.raw;
                }
            }
            else
            {
                frame.bottomOffset += 2;
            }

            //DoIndentedText(walk, "Walk");
            //DoIndentedText(sun, "Sun");
            //DoIndentedText(rock, "Rock");



            DoIndentedText(acknowledgement, "Author");
            DoIndentedText(intro, "Intro");
            DoIndentedText(history, "History");
            DoIndentedText(access, "Access");

            currentPage.frames[currentPage.frames.Count - 1].bottomOffset += 1;
            //currentPage.currentY += 3;
        }