/// <summary>
        /// Converts a paragraph to a textline list.
        /// </summary>
        /// <param name="maximumWidth">Unit to use for measuring the maximum width of an textline</param>
        /// <param name="paragraph">paragraph to convert to textlines.</param>
        /// <returns></returns>
        public TextlineCollection ConvertToTextlines(Unit maximumWidth, Paragraph paragraph)
        {
            IList <Textline> result             = new List <Textline>();
            float            maximumPointWidth  = maximumWidth.Points;
            float            totalMeasuredWidth = 0f;
            Textline         currentTextline    = new Textline(paragraph);

            TextElementCollection splittedTextElements = new TextElementCollection();

            if (paragraph.TextElements.Count() > 0)
            {
                foreach (TextElement textElement in paragraph.TextElements)
                {
                    splittedTextElements.AddRange(ConvertToTextElements(textElement));
                }

                foreach (TextElement splittedTextElement in splittedTextElements)
                {
                    float width          = MeasureTextElementWidth(splittedTextElement);
                    float tempTotalWidth = totalMeasuredWidth + width;

                    if (tempTotalWidth > maximumPointWidth)
                    {
                        currentTextline.Width  = new Unit(totalMeasuredWidth);
                        currentTextline.Height = paragraph.Leading;
                        result.Add(currentTextline);
                        currentTextline    = new Textline(paragraph);
                        totalMeasuredWidth = width;
                    }
                    else
                    {
                        totalMeasuredWidth = tempTotalWidth;
                    }

                    currentTextline.Add(splittedTextElement);
                }

                currentTextline.Width = new Unit(totalMeasuredWidth);
            }
            else
            {
                currentTextline.Width = new Unit(0f);
            }

            currentTextline.Height        = paragraph.Leading;
            currentTextline.EndsParagraph = true;

            result.Add(currentTextline);
            return(new TextlineCollection(result.ToList()));
        }
Beispiel #2
0
        private void ProcessContent(XmlContent xmlContent, Content businessContent)
        {
            if (xmlContent != null)
            {
                foreach (IXmlElement dataElement in xmlContent.Elements)
                {
                    switch (dataElement.GetType().Name.ToLower())
                    {
                    case "text":
                        var dataText = (Data.Xml.Elements.Text)dataElement;
                        var bText    = new Text.Text(businessContent, dataElement.Key,
                                                     string.IsNullOrEmpty(dataText.Rotation)
                                                          ? 0
                                                          : float.Parse(dataText.Rotation));
                        bText.LayoutContainer = new LayoutContainer(bText, dataElement.XmlLayoutDefinition);
                        foreach (Paragraph dParagraph in dataText.Paragraphs)
                        {
                            var bParagraph = new Text.Paragraph(bText,
                                                                dParagraph.Leading,
                                                                dParagraph.Alignment);

                            bParagraph.Offset = dParagraph.Offset != null ? new Unit(dParagraph.Offset) : null;
                            bParagraph.Symbol = dParagraph.Symbol != null ? dParagraph.Symbol : null;

                            bText.Add(bParagraph);

                            foreach (TextElement dTextElement in dParagraph.TextElements)
                            {
                                var bTextElement = new Text.TextElement(bParagraph,
                                                                        dTextElement
                                                                        .Value,
                                                                        dTextElement
                                                                        .Font,
                                                                        dTextElement
                                                                        .Style,
                                                                        dTextElement
                                                                        .
                                                                        Fontsize,
                                                                        dTextElement
                                                                        .Color);
                                if (!string.IsNullOrEmpty(dTextElement.Charspacing))
                                {
                                    bTextElement.CharSpacing = new Unit(dTextElement.Charspacing);
                                }
                                bParagraph.Add(bTextElement);
                            }
                        }
                        if (!string.IsNullOrEmpty(dataElement.ZOrder))
                        {
                            bText.ZOrder = Convert.ToUInt16(dataElement.ZOrder);
                        }

                        if (!string.IsNullOrEmpty(dataText.OverflowElement))
                        {
                            bText.SetOverflowElement(dataText.OverflowElement);
                        }

                        bText.SetTextlines();

                        businessContent.Elements.Add(bText);
                        break;

                    case "line":
                        var dataLine = (Data.Xml.Elements.Line)dataElement;
                        var bLine    = new Line(businessContent, dataElement.Key, dataLine.Width, dataLine.Color);
                        bLine.LayoutContainer = new LayoutContainer(bLine, dataElement.XmlLayoutDefinition);

                        if (!string.IsNullOrEmpty(dataElement.ZOrder))
                        {
                            bLine.ZOrder = Convert.ToUInt16(dataElement.ZOrder);
                        }
                        businessContent.Elements.Add(bLine);

                        break;

                    case "image":
                        var dataImage = (Data.Xml.Elements.Image)dataElement;
                        var bImage    = new Image(businessContent, dataImage.Key, dataImage.Path);
                        bImage.LayoutContainer = new LayoutContainer(bImage, dataElement.XmlLayoutDefinition);

                        bImage.ConvertDPI();

                        if (!string.IsNullOrEmpty(dataElement.ZOrder))
                        {
                            bImage.ZOrder = Convert.ToUInt16(dataElement.ZOrder);
                        }

                        businessContent.Elements.Add(bImage);

                        break;

                    case "rectangle":
                        var dataRectangle = (Data.Xml.Elements.Rectangle)dataElement;

                        var bRectangle = new Rectangle(businessContent, dataRectangle.Key,
                                                       dataRectangle.Bordercolor, dataRectangle.Borderwidth);
                        bRectangle.LayoutContainer = new LayoutContainer(bRectangle, dataElement.XmlLayoutDefinition);
                        bRectangle.Contents        = new Content(bRectangle);

                        if (dataRectangle.XmlContent != null)
                        {
                            ProcessContent(dataRectangle.XmlContent, bRectangle.Contents);
                            bRectangle.Contents.UpdateContentHeight();
                            bRectangle.LayoutContainer.TryResize(bRectangle.Layout.Width, bRectangle.Contents.Height);
                            bRectangle.Relocate();
                        }
                        if (!string.IsNullOrEmpty(dataRectangle.Fillcolor))
                        {
                            bRectangle.FillColor = businessContent.Page.Document.Colors[dataRectangle.Fillcolor];
                        }
                        if (!string.IsNullOrEmpty(dataRectangle.Roundness))
                        {
                            bRectangle.Roundness = new Unit(dataRectangle.Roundness);
                        }
                        if (!string.IsNullOrEmpty(dataElement.ZOrder))
                        {
                            bRectangle.ZOrder = Convert.ToUInt16(dataElement.ZOrder);
                        }


                        businessContent.Elements.Add(bRectangle);
                        break;
                    }
                }
            }
        }