Пример #1
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");
        }
Пример #2
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);
            }
        }
Пример #3
0
        void ProcessGps(XmlElement node)
        {
            LeftHeader("GPS");

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

            InsertionPoint ip = frame.lastInsertionPoint;

            Table table = ip.Tables.Add(idLocationOptions.idAtEnd, miss);

            table.ColumnCount = 6;


            XmlNodeList nl = node.SelectNodes("point");

            table.BodyRowCount = nl.Count + 1;

            Row header = (Row)table.Rows.FirstItem();

            header.RowType = idRowTypes.idHeaderRow;

            table.Width = 120;
            ((Cell)header.Cells[1]).Contents = "Code";
            ((Column)table.Columns[1]).Width = 13;

            ((Cell)header.Cells[2]).Contents = "Description";
            ((Column)table.Columns[2]).Width = 56;

            ((Cell)header.Cells[3]).Contents = "Zone";
            ((Column)table.Columns[3]).Width = 10;
            //((Cell)header.Cells[3]).Width = 8;
            ((Cell)header.Cells[4]).Contents = "Easting";
            ((Column)table.Columns[4]).Width = 14;
            ((Cell)header.Cells[5]).Contents = "Northing";
            ((Column)table.Columns[5]).Width = 14;
            ((Cell)header.Cells[6]).Contents = "Height";
            ((Column)table.Columns[6]).Width = 12;
            //((Cell)header.Cells[7]).Contents = "";
            //((Column)table.Columns[7]).Width = 16;



            ParagraphStyle ps = GetParaStyle("ClimbHeading");

            for (int i = 1; i <= 6; i++)
            {
                //    ((Paragraph)((Cell)header.Cells[i]).Paragraphs.FirstItem()).AppliedParagraphStyle = ps;
            }

            int rowindex = 2;

            foreach (XmlElement point in nl)
            {
                Row row = (Row)table.Rows[rowindex];

                ((Cell)row.Cells[1]).Contents = GetAttr(point, "code");
                ((Cell)row.Cells[2]).Contents = GetAttr(point, "description");
                ((Cell)row.Cells[3]).Contents = GetAttr(point, "zone");
                ((Cell)row.Cells[4]).Contents = GetAttr(point, "easting");
                ((Cell)row.Cells[5]).Contents = GetAttr(point, "northing");

                String h = GetAttr(point, "height");

                if (h == "0")
                {
                    h = "";
                }

                ((Cell)row.Cells[6]).Contents = h;

                //((Cell)row.Cells[7]).Contents = "GDA94 UTM";

                rowindex++;
            }

            foreach (Cell cell in table.Cells)
            {
                cell.BottomEdgeStrokeWeight = 0.25;
                cell.TopEdgeStrokeWeight    = 0.25;
                cell.LeftEdgeStrokeWeight   = 0.25;
                cell.RightEdgeStrokeWeight  = 0.25;
                if (cell.Paragraphs.Count > 0)
                {
                    ((Paragraph)cell.Paragraphs.FirstItem()).AppliedParagraphStyle = document.ParagraphStyles["GPSText"];
                }
            }

            foreach (Cell c in header.Cells)
            {
                c.FillColor = document.Swatches["Black"];
                ((Paragraph)c.Paragraphs.FirstItem()).AppliedParagraphStyle = document.ParagraphStyles["GPSHeader"];
            }

            frame.ResizeAndPaginate();
        }
Пример #4
0
        void ProcessClimb(XmlElement node)
        {
            string txt    = node.InnerText;
            string number = GetAttr(node, "number");
            string name   = GetAttr(node, "name");
            string stars  = GetAttr(node, "stars");
            string grade  = GetAttr(node, "grade");
            string extra  = GetAttr(node, "extra");
            string length = GetAttr(node, "length");
            string fa     = GetAttr(node, "fa");

            string origStars = stars;

            stars = stars.Replace("*", "«");


            string heading = "";

            if (stars.Length > 0)
            {
                heading += stars + " ";
            }
            if (number.Length > 0)
            {
                heading += number + "  ";
            }
            if (name.Length > 0)
            {
                heading += name + "  ";
            }

            if (length.Length > 0)
            {
                heading += length + "  ";
            }
            if (grade.Length > 0)
            {
                heading += grade + "  ";
            }

            extra = extra.Replace('↓', 'ŏ');


            if (name == "Cascade Crack")
            {
                int x = 0;
            }

            Mode mode     = Mode.TwoColumns;
            bool forceNew = false;

            if (currentPage.currentMode == Mode.SingleColumn)
            {
                XmlNode next = node.NextSibling;
                if (next == null || next.Name != node.Name)
                {
                    mode     = Mode.SingleColumn;
                    forceNew = true;
                }
            }


            GuideFrame frame = GetTextFrame(mode, FrameType.Multi, forceNew);



            //string[] split = txt.Split("\n");

            //txt = split[ split.length-1 ];

            txt = txt.Trim();
            txt = txt.Replace('\t', ' ');
            txt = txt.Replace("<br/>", "\n");
            int len = txt.Length;

            if (len == 1 && txt.ToCharArray()[0] == 65279)
            {
                txt = "";
            }

            if (extra.Length > 0)
            {
                extra += " ";
                extra  = extra.Replace("B ", "Þ");
                extra  = "  " + extra;
            }

            int offset = 0;

            if (txt.Length > 0 && name.Length == 0 && txt.IndexOf('\r', 0) < 0)
            {
                extra += "  -  ";
                extra += txt;
                txt    = "";
                offset = 2;
            }

            // reformat dates
            txt = FixDates(txt);
            fa  = FixDates(fa);

            // create and add index entries
            string grade2digits = grade;

            if (grade2digits.Length == 1)
            {
                grade2digits = "0" + grade2digits;
            }

            if (grade2digits.Length > 2)
            {
                grade2digits = grade2digits.Substring(0, 2);
            }

            if (grade2digits.Length == 0)
            {
                grade2digits = "-";
            }

            string nameShort = name;

            if (name.Length > 24)
            {
                nameShort = name.Substring(0, 21) + "...";
            }

            string stars2 = origStars;

            if (stars2.Length == 0)
            {
                stars2 += "   ";
            }
            if (stars2.Length == 1)
            {
                stars2 += "  ";
            }
            if (stars2.Length == 2)
            {
                stars2 += " ";
            }

            string gradeIndex = grade2digits + " " + origStars + "\t" + nameShort;
            string nameIndex  = nameShort + "\t" + grade2digits + " " + origStars;

            if (grade.Length > 0)
            {
                frame.AddPara(gradeIndex, "gradeIndexTag", false);
            }

            frame.AddPara(nameIndex, "alphaIndexTag", false);

            Story story = frame.story;

            int starsStart = story.Characters.Count;

            if (starsStart > 0)
            {
                starsStart++;
            }

            // add header
            InsertionPoint headPara = frame.AddPara(heading, "ClimbHeading", false);

            // add extra and unbold

            InsertionPoint ip = (InsertionPoint)story.InsertionPoints.LastItem();

            ip.Contents = extra;


            Characters chars = story.Characters;

            for (int i = chars.Count; i > chars.Count - extra.Length; i--)
            {
                //chars[i].fontStyle = "Regular";
                Character c = (Character)chars[i];
                c.FontStyle = "Regular";
            }

            if (stars.Length > 0)
            {
                //var starsStart = chars.length - heading.length - extra.length + offset;

                for (int i = starsStart + 1; i <= starsStart + stars.Length; i++)
                {
                    Character c = (Character)chars[i];
                    c.AppliedFont = this.application.Fonts["Wingdings"];
                    c.FontStyle   = "Regular";
                }
            }

            headPara.KeepAllLinesTogether = true;
            headPara.KeepLinesTogether    = true;
            headPara.KeepFirstLines       = 2;
            if (txt.Length > 0 || fa.Length > 0)
            {
                headPara.KeepWithNext = 1;

                if (txt.Length > 0)
                {
                    InsertionPoint ctp = frame.AddPara(txt, "ClimbText", true);

                    if (fa.Length == 0)
                    {
                        ctp.SpaceAfter = SPACEAFTERCLIMB;
                    }

                    // deal with multi pitch stuff
                    string[] split = txt.Split('\n');
                    for (int i = 0; i < split.Length; i++)
                    {
                        string line = split[i].Trim();
                        int    idx  = line.IndexOf(". ");
                        if (idx > -1 && idx < 16)
                        {
                            int idx2 = line.IndexOf(". ", idx + 1);
                            if (idx2 > -1 && idx2 < 16)
                            {
                                idx = idx2;
                            }

                            // apply bold - TODO more fancy style
                            Paragraph p = frame.currentParagraphs[i];
                            for (int c = 1; c <= idx; c++)
                            {
                                Character character = p.Characters[c];
                                character.FontStyle = "Bold";
                                character.PointSize = character.PointSize--;
                            }
                        }
                    }
                }

                if (fa.Length > 0)
                {
                    InsertionPoint fap = frame.AddPara(fa, "FA", true);
                    fap.SpaceAfter = SPACEAFTERCLIMB;
                }
            }
            else
            {
                headPara.KeepWithNext = 0;
                headPara.SpaceAfter   = SPACEAFTERCLIMB;
            }

            //ResizeToFit(frame);
            frame.ResizeAndPaginate();

            classes.Add("problem");
        }
Пример #5
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;
        }