public void ConvertToTextlines_Text() { Page page = new Page(new Document(), "PAGE", "200mm", "200mm", "rgb", "3mm", 1); Font f = new Font("FONT", @"C:\Windows\Fonts", "UTF-8", "false", "10pt"); FontStyle fs = new FontStyle(f, "STYLE", "arial.ttf"); f.AddStyle(fs); Content container = new Content(page); object[] paramList = new object[2]; paramList[0] = container; paramList[1] = "TEXT"; OpenTemplater.Models.Text.Text text = MockRepository.GeneratePartialMock <OpenTemplater.Models.Text.Text>(paramList); Paragraph p = new Paragraph(text, "10pt", "left"); TextElement te = new TextElement(p, "Dit is een hele mooie tekst.", fs, new Unit(10), new Color("blue")); p.Add(te); p.Add(te); p.Add(te); text.Add(p); TextModule tm = new TextModule(); TextlineCollection textlineCollection = tm.ConvertToTextlines(new Unit("35mm"), text); // There should be 4 texlines. Assert.AreEqual(4, textlineCollection.Count); // Each textline should be shorter than 35 milimeters. foreach (Textline textline in textlineCollection) { Assert.AreEqual(true, textline.Width.Points <= new Unit("35mm").Points); } // The total height of the textlines should be 40mm. Assert.AreEqual(40, textlineCollection.Height.Points); }
public void TextOverflow() { Page page = new Page(new Document(), "PAGE", "200mm", "200mm", "rgb", "3mm", 1); Font f = new Font("FONT", @"C:\Windows\Fonts", "UTF-8", "false", "10pt"); FontStyle fs = new FontStyle(f, "STYLE", "arial.ttf"); f.AddStyle(fs); object[] paramList; Content container = new Content(page); paramList = new object[2]; paramList[0] = container; paramList[1] = "TEXT"; OpenTemplater.Models.Text.Text textNonFitting = MockRepository.GeneratePartialMock <OpenTemplater.Models.Text.Text>(paramList); OpenTemplater.Models.Text.Text textFitting = MockRepository.GeneratePartialMock <OpenTemplater.Models.Text.Text>(paramList); //Paragraph p = new Paragraph(text, "10pt", "left"); //TextElement te = new TextElement(p, "Dit is een hele mooie tekst.", fs, new Unit(10), new Color("blue")); }
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; } } } }