Esempio n. 1
0
        public void ExpandIndexPages()
        {
            if (indexPage != null)
            {
                int pages = Math.Max(1, components.Count                                // how many lines do we have?
                                     / (int)Math.Floor(indexElementHeight / lineHeight) // how many lines fit in each element?
                                     / indexesPerIndexPage);                            // how many elements per page?

                for (int i = indexPageOriginalIndex; i < pages + indexPageOriginalIndex; i++)
                {
                    PrintablePage pp = new PrintablePage(indexPage.Width, indexPage.Height);
                    foreach (PrintableComponent pc in indexPage.Children)
                    {
                        if (pc is TextComponent && ((TextComponent)pc).BindingOption == TextComponent.SpecialBinding.Index)
                        {
                            IndexComponent ic = IndexComponent.FromTextComponent((TextComponent)pc);
                            pp.AddChild(ic);
                            indexElements.Add(ic);
                        }
                        else
                        {
                            pp.AddChild(pc.Clone());
                        }
                    }
                    doc.Pages.Insert(i, pp);
                }
            }
        }
        public PrintableDocument GeneratePrintableDocument()
        {
            PrintableDocument doc = new PrintableDocument();

            XDocument xdoc      = XDocument.Parse(xml);
            XElement  xdocument = xdoc.Root;
            XElement  xpages    = xdocument.Element("Pages");

            if (xpages != null)
            {
                foreach (var p in xpages.Elements())
                {
                    PrintablePage page = parsePage(p, doc);
                    if (p.Element("Binding") != null)
                    {
                        parseBinding(p.Element("Binding"), page);
                    }
                    if (p.Element("Children") != null)
                    {
                        foreach (XElement childelem in p.Element("Children").Elements())
                        {
                            parseComponent(childelem, page);
                        }
                        page.Children.Sort(delegate(PrintableComponent pc1, PrintableComponent pc2) { return((pc1.Left + pc2.Top).CompareTo((pc2.Left + pc2.Top))); });
                    }
                }
            }
            return(doc);
        }
Esempio n. 3
0
        public IndexBuilder(PrintableDocument pd)
        {
            doc           = pd;
            components    = new List <IndexItem>();
            indexElements = new List <IndexComponent>();

            // loop through the whole document, picking up the elements designated as index holders and adding all other elements to the components list;
            foreach (PrintablePage pp in pd.Pages)
            {
                if (indexPage == null)
                {
                    indexesPerIndexPage = 0;
                }

                foreach (PrintableComponent pc in pp.Children)
                {
                    if (pc is CompositeComponent)
                    {
                        AddComponent((CompositeComponent)pc);
                    }

                    if ((indexPage == null || indexPage == pp) && pc is TextComponent && ((TextComponent)pc).BindingOption == TextComponent.SpecialBinding.Index)
                    {
                        if (indexPage == null) // no index page set?
                        {
                            indexPage = pp;
                            indexPageOriginalIndex = doc.Pages.IndexOf(indexPage);
                        }

                        if (indexElementHeight == 0.0)
                        {
                            indexElementHeight = pc.Height;
                        }
                        else
                        {
                            pc.Height = indexElementHeight;
                        }

                        if (indexStyle == null)
                        {
                            indexStyle = ((TextComponent)pc).Style;
                            lineHeight = Util.PointToMillimeter(((TextComponent)pc).Style.AsXFont().GetHeight());
                        }
                        else
                        {
                            ((TextComponent)pc).Style = indexStyle;
                        }

                        indexesPerIndexPage++;
                    }
                }
            }
            if (indexPage != null)
            {
                doc.Pages.Remove(indexPage);
            }
        }
        /// <summary>
        /// Parses an XElement with page information into a PrintablePage
        /// </summary>
        /// <param name="pageElement">XElement with information for a page</param>
        /// <param name="doc">Optional document object, page and styles will be added to this</param>
        /// <returns>PrintablePage with the information from the element</returns>
        private PrintablePage parsePage(XElement pageElement, PrintableDocument doc = null)
        {
            double width = 0.0, height = 0.0;

            try {
                width  = double.Parse(pageElement.Attribute("Width").Value);
                height = double.Parse(pageElement.Attribute("Height").Value);
            }
            catch (Exception e) {
                throw new Exception("Page has invalid size");
            }
            PrintablePage page = new PrintablePage(width, height);

            if (doc != null)
            {
                doc.Pages.Add(page);
            }

            return(page);
        }