#region MigraDoc - Creating Documents on the Fly // // Authors: // Stefan Lange // Klaus Potzesny // David Stephensen // // Copyright (c) 2001-2017 empira Software GmbH, Cologne Area (Germany) // // http://www.pdfsharp.com // http://www.migradoc.com // http://sourceforge.net/projects/pdfsharp // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #endregion using MigraDoc.DocumentObjectModel.publics; using MigraDoc.DocumentObjectModel.Visitors; using MigraDoc.DocumentObjectModel.Shapes.Charts; using MigraDoc.DocumentObjectModel.Tables; namespace MigraDoc.DocumentObjectModel.Shapes { /// /// Represents a text frame that can be freely placed. /// public class TextFrame : Shape, IVisitable { /// /// Initializes a new instance of the TextFrame class. /// public TextFrame() { } /// /// Initializes a new instance of the TextFrame class with the specified parent. /// public TextFrame(DocumentObject parent) : base(parent) { } #region Methods /// /// Creates a deep copy of this object. /// public new TextFrame Clone() { return (TextFrame)DeepCopy(); } /// /// Implements the deep copy of the object. /// protected override object DeepCopy() { TextFrame textFrame = (TextFrame)base.DeepCopy(); if (textFrame._elements != null) { textFrame._elements = textFrame._elements.Clone(); textFrame._elements._parent = textFrame; } return textFrame; } /// /// Adds a new paragraph to the text frame. /// public Paragraph AddParagraph() { return Elements.AddParagraph(); } /// /// Adds a new paragraph with the specified text to the text frame. /// public Paragraph AddParagraph(string _paragraphText) { return Elements.AddParagraph(_paragraphText); } /// /// Adds a new chart with the specified type to the text frame. /// public Chart AddChart(ChartType _type) { return Elements.AddChart(_type); } /// /// Adds a new chart to the text frame. /// public Chart AddChart() { return Elements.AddChart(); } /// /// Adds a new table to the text frame. /// public Table AddTable() { return Elements.AddTable(); } /// /// Adds a new Image to the text frame. /// public Image AddImage(string _fileName) { return Elements.AddImage(_fileName); } /// /// Adds a new paragraph to the text frame. /// public void Add(Paragraph paragraph) { Elements.Add(paragraph); } /// /// Adds a new chart to the text frame. /// public void Add(Chart chart) { Elements.Add(chart); } /// /// Adds a new table to the text frame. /// public void Add(Table table) { Elements.Add(table); } /// /// Adds a new image to the text frame. /// public void Add(Image image) { Elements.Add(image); } #endregion #region Properties /// /// Gets or sets the Margin between the textframes content and its left edge. /// public Unit MarginLeft { get { return _marginLeft; } set { _marginLeft = value; } } [DV] public Unit _marginLeft = Unit.NullValue; /// /// Gets or sets the Margin between the textframes content and its right edge. /// public Unit MarginRight { get { return _marginRight; } set { _marginRight = value; } } [DV] public Unit _marginRight = Unit.NullValue; /// /// Gets or sets the Margin between the textframes content and its top edge. /// public Unit MarginTop { get { return _marginTop; } set { _marginTop = value; } } [DV] public Unit _marginTop = Unit.NullValue; /// /// Gets or sets the Margin between the textframes content and its bottom edge. /// public Unit MarginBottom { get { return _marginBottom; } set { _marginBottom = value; } } [DV] public Unit _marginBottom = Unit.NullValue; /// /// Sets all margins in one step with the same value. /// public Unit Margin { set { _marginLeft = value; _marginRight = value; _marginTop = value; _marginBottom = value; } } /// /// Gets or sets the text orientation for the texframe content. /// public TextOrientation Orientation { get { return (TextOrientation)_orientation.Value; } set { _orientation.Value = (int)value; } } [DV(Type = typeof(TextOrientation))] public NEnum _orientation = NEnum.NullValue(typeof(TextOrientation)); /// /// The document elements that build the textframe's content. /// public DocumentElements Elements { get { return _elements ?? (_elements = new DocumentElements(this)); } set { SetParent(value); _elements = value; } } [DV(ItemType = typeof(DocumentObject))] private DocumentElements _elements; #endregion /// /// Allows the visitor object to visit the document object and its child objects. /// void IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, bool visitChildren) { visitor.VisitTextFrame(this); if (visitChildren && _elements != null) ((IVisitable)_elements).AcceptVisitor(visitor, true); } #region public /// /// Converts TextFrame into DDL. /// public override void Serialize(Serializer serializer) { serializer.WriteLine("\\textframe"); int pos = serializer.BeginAttributes(); base.Serialize(serializer); if (!_marginLeft.IsNull) serializer.WriteSimpleAttribute("MarginLeft", MarginLeft); if (!_marginRight.IsNull) serializer.WriteSimpleAttribute("MarginRight", MarginRight); if (!_marginTop.IsNull) serializer.WriteSimpleAttribute("MarginTop", MarginTop); if (!_marginBottom.IsNull) serializer.WriteSimpleAttribute("MarginBottom", MarginBottom); if (!_orientation.IsNull) serializer.WriteSimpleAttribute("Orientation", Orientation); serializer.EndAttributes(pos); serializer.BeginContent(); if (_elements != null) _elements.Serialize(serializer); serializer.EndContent(); } /// /// Returns the meta object of this instance. /// public override Meta Meta { get { return _meta ?? (_meta = new Meta(typeof(TextFrame))); } } static Meta _meta; #endregion } }