/// <summary>
        ///   Renders the paragraph content to RTF.
        /// </summary>
        private void RenderContent()
        {
            DocumentElements elements = DocumentRelations.GetParent(_paragraph) as DocumentElements;

            //First paragraph of a footnote writes the reference symbol:
            if (DocumentRelations.GetParent(elements) is Footnote && _paragraph == elements.First)
            {
                FootnoteRenderer ftntRenderer = new FootnoteRenderer(DocumentRelations.GetParent(elements) as Footnote,
                                                                     _docRenderer);
                ftntRenderer.RenderReference();
            }
            foreach (DocumentObject docObj in _paragraph.Elements)
            {
                if (docObj == _paragraph.Elements.LastObject)
                {
                    if (docObj is Character)
                    {
                        if (((Character)docObj).SymbolName == SymbolName.LineBreak)
                        {
                            continue; //Ignore last linebreak.
                        }
                    }
                }
                RendererBase rndrr = RendererFactory.CreateRenderer(docObj, _docRenderer);
                if (rndrr != null)
                {
                    rndrr.Render();
                }
            }
        }
        /// <summary>
        ///   Renders the paragraph to RTF.
        /// </summary>
        internal override void Render()
        {
            _useEffectiveValue = true;
            DocumentElements elements = DocumentRelations.GetParent(_paragraph) as DocumentElements;

            _rtfWriter.WriteControl("pard");
            bool isCellParagraph     = DocumentRelations.GetParent(elements) is Cell;
            bool isFootnoteParagraph = isCellParagraph ? false : DocumentRelations.GetParent(elements) is Footnote;

            if (isCellParagraph)
            {
                _rtfWriter.WriteControl("intbl");
            }

            RenderStyleAndFormat();
            if (!_paragraph.IsNull("Elements"))
            {
                RenderContent();
            }
            EndStyleAndFormatAfterContent();

            if ((!isCellParagraph && !isFootnoteParagraph) || _paragraph != elements.LastObject)
            {
                _rtfWriter.WriteControl("par");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Renders an image to RTF.
        /// </summary>
        internal override void Render()
        {
            bool             renderInParagraph = RenderInParagraph();
            DocumentElements elms = DocumentRelations.GetParent(this.image) as DocumentElements;

            if (elms != null && !renderInParagraph && !(DocumentRelations.GetParent(elms) is Section || DocumentRelations.GetParent(elms) is HeaderFooter))
            {
                Trace.WriteLine(Messages.ImageFreelyPlacedInWrongContext(this.image.Name), "warning");
                return;
            }
            if (renderInParagraph)
            {
                StartDummyParagraph();
            }

            if (!this.isInline)
            {
                StartShapeArea();
            }

            RenderImage();
            if (!this.isInline)
            {
                EndShapeArea();
            }

            if (renderInParagraph)
            {
                EndDummyParagraph();
            }
        }
        /// <summary>
        /// Renders a TextFrame to RTF.
        /// </summary>
        internal override void Render()
        {
            DocumentElements elms = DocumentRelations.GetParent(_textFrame) as DocumentElements;
            bool             renderInParagraph = RenderInParagraph();

            if (renderInParagraph)
            {
                StartDummyParagraph();
            }

            StartShapeArea();

            //Properties
            RenderNameValuePair("shapeType", "202");//202 entspr. Textrahmen.

            TranslateAsNameValuePair("MarginLeft", "dxTextLeft", RtfUnit.EMU, "0");
            TranslateAsNameValuePair("MarginTop", "dyTextTop", RtfUnit.EMU, "0");
            TranslateAsNameValuePair("MarginRight", "dxTextRight", RtfUnit.EMU, "0");
            TranslateAsNameValuePair("MarginBottom", "dyTextBottom", RtfUnit.EMU, "0");

            if (_textFrame.IsNull("Elements") ||
                !CollectionContainsObjectAssignableTo(_textFrame.Elements,
                                                      typeof(Shape), typeof(Table)))
            {
                TranslateAsNameValuePair("Orientation", "txflTextFlow", RtfUnit.Undefined, null);
            }
            else
            {
                TextOrientation orient = _textFrame.Orientation;
                if (orient != TextOrientation.Horizontal && orient != TextOrientation.HorizontalRotatedFarEast)
                {
                    Debug.WriteLine(Messages2.TextframeContentsNotTurned, "warning");
                }
            }
            _rtfWriter.StartContent();
            _rtfWriter.WriteControl("shptxt");
            _rtfWriter.StartContent();
            foreach (DocumentObject docObj in _textFrame.Elements)
            {
                RendererBase rndrr = RendererFactory.CreateRenderer(docObj, _docRenderer);
                if (rndrr != null)
                {
                    rndrr.Render();
                }
            }
            //Text fields need to close with a paragraph.
            RenderTrailingParagraph(_textFrame.Elements);

            _rtfWriter.EndContent();
            _rtfWriter.EndContent();
            EndShapeArea();
            if (renderInParagraph)
            {
                RenderLayoutPicture();
                EndDummyParagraph();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Renders a section to RTF
        /// </summary>
        internal override void Render()
        {
            _useEffectiveValue = true;

            Sections secs = DocumentRelations.GetParent(_section) as Sections;

            if (_section != secs.First)
            {
                _rtfWriter.WriteControl("pard");
                _rtfWriter.WriteControl("sect");
            }
            _rtfWriter.WriteControl("sectd");

            //Rendering some footnote attributes:
            _docRenderer.RenderSectionProperties();

            object pageStp = _section.PageSetup;

            if (pageStp != null)
            {
                RendererFactory.CreateRenderer((PageSetup)pageStp, _docRenderer).Render();
            }

            object hdrs = GetValueAsIntended("Headers");

            if (hdrs != null)
            {
                HeadersFootersRenderer hfr = new HeadersFootersRenderer(hdrs as HeadersFooters, _docRenderer);
                // PageSetup has to be set here, because HeaderFooter could be from a different section than PageSetup.
                hfr.PageSetup = (PageSetup)pageStp;
                hfr.Render();
            }

            object ftrs = GetValueAsIntended("Footers");

            if (ftrs != null)
            {
                HeadersFootersRenderer hfr = new HeadersFootersRenderer(ftrs as HeadersFooters, _docRenderer);
                hfr.PageSetup = (PageSetup)pageStp;
                hfr.Render();
            }

            if (!_section.IsNull("Elements"))
            {
                foreach (DocumentObject docObj in _section.Elements)
                {
                    RendererBase rndrr = RendererFactory.CreateRenderer(docObj, _docRenderer);
                    if (rndrr != null)
                    {
                        rndrr.Render();
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Renders a section to RTF
        /// </summary>
        internal override void Render()
        {
            this.useEffectiveValue = true;

            Sections secs = DocumentRelations.GetParent(this.section) as Sections;

            if (this.section != secs.First)
            {
                this.rtfWriter.WriteControl("pard");
                this.rtfWriter.WriteControl("sect");
            }
            this.rtfWriter.WriteControl("sectd");

            //Rendering some footnote attributes:
            this.docRenderer.RenderSectionProperties();

            object pageStp = this.section.PageSetup;

            if (pageStp != null)
            {
                RendererFactory.CreateRenderer((PageSetup)pageStp, this.docRenderer).Render();
            }

            object hdrs = GetValueAsIntended("Headers");

            if (hdrs != null)
            {
                HeadersFootersRenderer hfr = new HeadersFootersRenderer(hdrs as HeadersFooters, this.docRenderer);
                //PageSetup muss hier gesetzt werden, da die HeaderFooter anderem Abschnitt gehören können als das PageSetup
                hfr.PageSetup = (PageSetup)pageStp;
                hfr.Render();
            }

            object ftrs = GetValueAsIntended("Footers");

            if (ftrs != null)
            {
                HeadersFootersRenderer hfr = new HeadersFootersRenderer(ftrs as HeadersFooters, this.docRenderer);
                hfr.PageSetup = (PageSetup)pageStp;
                hfr.Render();
            }

            if (!section.IsNull("Elements"))
            {
                foreach (DocumentObject docObj in this.section.Elements)
                {
                    RendererBase rndrr = RendererFactory.CreateRenderer(docObj, this.docRenderer);
                    if (rndrr != null)
                    {
                        rndrr.Render();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Renders a Table to RTF.
        /// </summary>
        internal override void Render()
        {
            DocumentElements elms         = DocumentRelations.GetParent(_table) as DocumentElements;
            MergedCellList   mrgdCellList = new MergedCellList(_table);

            foreach (Row row in _table.Rows)
            {
                RowRenderer rowRenderer = new RowRenderer(row, _docRenderer);
                rowRenderer.CellList = mrgdCellList;
                rowRenderer.Render();
            }
        }
        /// <summary>
        /// Renders a TextFrame to CSV.
        /// </summary>
        internal override void Render()
        {
            DocumentElements elms = DocumentRelations.GetParent(this.textFrame) as DocumentElements;
            bool             renderInParagraph = RenderInParagraph();

            if (renderInParagraph)
            {
                StartDummyParagraph();
            }

            StartShapeArea();

            //Properties
            RenderNameValuePair("shapeType", "202");//202 entspr. Textrahmen.

            if (this.textFrame.IsNull("Elements") ||
                !CollectionContainsObjectAssignableTo(this.textFrame.Elements,
                                                      typeof(Shape), typeof(Table)))
            {
            }
            else
            {
                TextOrientation orient = this.textFrame.Orientation;
                if (orient != TextOrientation.Horizontal && orient != TextOrientation.HorizontalRotatedFarEast)
                {
                    Trace.WriteLine(Messages.TextframeContentsNotTurned, "warning");
                }
            }
            csvWriter.StartContent();
            csvWriter.StartContent();
            foreach (DocumentObject docObj in this.textFrame.Elements)
            {
                RendererBase rndrr = RendererFactory.CreateRenderer(docObj, this.docRenderer);
                if (rndrr != null)
                {
                    rndrr.Render();
                }
            }
            //Text fields need to close with a paragraph.
            RenderTrailingParagraph(this.textFrame.Elements);

            this.csvWriter.EndContent();
            this.csvWriter.EndContent();
            EndShapeArea();
            if (renderInParagraph)
            {
                RenderLayoutPicture();
                EndDummyParagraph();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// A shape that shall be placed between its predecessor and its successor must be embedded in a paragraph.
        /// </summary>
        protected virtual bool RenderInParagraph()
        {
            if (_shape.IsNull("RelativeVertical") || _shape.RelativeVertical == RelativeVertical.Line || _shape.RelativeVertical == RelativeVertical.Paragraph)
            {
                DocumentObjectCollection docObjects = DocumentRelations.GetParent(_shape) as DocumentObjectCollection;
                if (DocumentRelations.GetParent(docObjects) is Paragraph)//don't embed it twice!
                {
                    return(false);
                }

                return(_shape.IsNull("WrapFormat.Style") || _shape.WrapFormat.Style == WrapStyle.TopBottom);
            }

            return(false);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Render a Row to CSV.
        /// </summary>
        internal override void Render()
        {
            this.useEffectiveValue = true;
            new RowsRenderer(DocumentRelations.GetParent(this.row) as Rows, this.docRenderer).Render();

            int thisRowIdx = this.row.Index;

            foreach (Cell cell in this.row.Cells)
            {
                CellRenderer cellRndrr = new CellRenderer(cell, this.docRenderer);
                cellRndrr.CellList = this.cellList;
                cellRndrr.Render();
            }

            this.csvWriter.WriteNewLine();
        }
Ejemplo n.º 11
0
        protected Font GetParentFont(DocumentObject obj)
        {
            DocumentObject parentElements = DocumentRelations.GetParent(obj);
            DocumentObject parentObject   = DocumentRelations.GetParent(parentElements);
            Font           parentFont     = null;

            if (parentObject is Paragraph)
            {
                ParagraphFormat format = ((Paragraph)parentObject).Format;
                parentFont = format.font;
            }
            else //Hyperlink or FormattedText
            {
                parentFont = parentObject.GetValue("Font") as Font;
            }
            return(parentFont);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Renders an image to RTF.
        /// </summary>
        internal override void Render()
        {
            string fileName = Path.GetTempFileName();

            if (!StoreTempImage(fileName))
            {
                return;
            }

            bool             renderInParagraph = RenderInParagraph();
            DocumentElements elms = DocumentRelations.GetParent(_chart) as DocumentElements;

            if (elms != null && !renderInParagraph && !(DocumentRelations.GetParent(elms) is Section || DocumentRelations.GetParent(elms) is HeaderFooter))
            {
                Debug.WriteLine(Messages2.ChartFreelyPlacedInWrongContext, "warning");
                return;
            }
            if (renderInParagraph)
            {
                StartDummyParagraph();
            }

            if (!_isInline)
            {
                StartShapeArea();
            }

            RenderImage(fileName);

            if (!_isInline)
            {
                EndShapeArea();
            }

            if (renderInParagraph)
            {
                EndDummyParagraph();
            }

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Renders the paragraph to CSV.
        /// </summary>
        internal override void Render()
        {
            useEffectiveValue = true;
            DocumentElements elements = DocumentRelations.GetParent(this.paragraph) as DocumentElements;


            bool isCellParagraph     = DocumentRelations.GetParent(elements) is Cell;
            bool isFootnoteParagraph = isCellParagraph ? false : DocumentRelations.GetParent(elements) is Footnote;

            if (!this.paragraph.IsNull("Elements"))
            {
                RenderContent();
            }

            if ((!isCellParagraph && !isFootnoteParagraph) || this.paragraph != elements.LastObject)
            {
                this.csvWriter.WriteNewLine();
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Render a Row to RTF.
        /// </summary>
        internal override void Render()
        {
            _useEffectiveValue = true;
            _rtfWriter.WriteControl("trowd");
            new RowsRenderer(DocumentRelations.GetParent(_row) as Rows, _docRenderer).Render();
            RenderRowHeight();
            //MigraDoc always keeps together table rows.
            _rtfWriter.WriteControl("trkeep");
            Translate("HeadingFormat", "trhdr");

            // trkeepfollow is intended to keep table rows together.
            // Unfortunalte, this does not work in word.
            int thisRowIdx = _row.Index;

            for (int rowIdx = 0; rowIdx <= _row.Index; ++rowIdx)
            {
                object keepWith = _row.Table.Rows[rowIdx].GetValue("KeepWith");
                if (keepWith != null && (int)keepWith + rowIdx > thisRowIdx)
                {
                    _rtfWriter.WriteControl("trkeepfollow");
                }
            }
            RenderTopBottomPadding();

            //Cell borders etc. are written before the contents.
            for (int idx = 0; idx < _row.Table.Columns.Count; ++idx)
            {
                Cell cell = _row.Cells[idx];
                CellFormatRenderer cellFrmtRenderer =
                    new CellFormatRenderer(cell, _docRenderer);
                cellFrmtRenderer.CellList = _cellList;
                cellFrmtRenderer.Render();
            }
            foreach (Cell cell in _row.Cells)
            {
                CellRenderer cellRndrr = new CellRenderer(cell, _docRenderer);
                cellRndrr.CellList = _cellList;
                cellRndrr.Render();
            }

            _rtfWriter.WriteControl("row");
        }
        /// <summary>
        /// Formats (measures) the table.
        /// </summary>
        /// <param name="area">The area on which to fit the table.</param>
        /// <param name="previousFormatInfo"></param>
        internal override void Format(Area area, FormatInfo previousFormatInfo)
        {
            DocumentElements elements = DocumentRelations.GetParent(this.table) as DocumentElements;

            if (elements != null)
            {
                Section section = DocumentRelations.GetParent(elements) as Section;
                if (section != null)
                {
                    this.doHorizontalBreak = section.PageSetup.HorizontalPageBreak;
                }
            }

            this.renderInfo = new TableRenderInfo();
            InitFormat(area, previousFormatInfo);

            // Don't take any Rows higher then MaxElementHeight
            XUnit topHeight   = this.CalcStartingHeight();
            XUnit probeHeight = topHeight;
            XUnit offset      = 0;

            if (this.startRow > this.lastHeaderRow + 1 &&
                this.startRow < this.table.Rows.Count)
            {
                offset = (XUnit)this.bottomBorderMap[this.startRow] - topHeight;
            }
            else
            {
                offset = -CalcMaxTopBorderWidth(0);
            }

            int   probeRow       = this.startRow;
            XUnit currentHeight  = 0;
            XUnit startingHeight = 0;
            bool  isEmpty        = false;

            while (probeRow < this.table.Rows.Count)
            {
                bool firstProbe = probeRow == this.startRow;
                probeRow = (int)this.connectedRowsMap[probeRow];
                // Don't take any Rows higher then MaxElementHeight
                probeHeight = (XUnit)this.bottomBorderMap[probeRow + 1] - offset;
                if (firstProbe && probeHeight > MaxElementHeight - Tolerance)
                {
                    probeHeight = MaxElementHeight - Tolerance;
                }

                //The height for the first new row(s) + headerrows:
                if (startingHeight == 0)
                {
                    if (probeHeight > area.Height)
                    {
                        isEmpty = true;
                        break;
                    }
                    startingHeight = probeHeight;
                }

                if (probeHeight > area.Height)
                {
                    break;
                }

                else
                {
                    this.currRow  = probeRow;
                    currentHeight = probeHeight;
                    ++probeRow;
                }
            }
            if (!isEmpty)
            {
                TableFormatInfo formatInfo = (TableFormatInfo)this.renderInfo.FormatInfo;
                formatInfo.startRow = this.startRow;
                formatInfo.isEnding = currRow >= this.table.Rows.Count - 1;
                formatInfo.endRow   = this.currRow;
            }
            FinishLayoutInfo(area, currentHeight, startingHeight);
        }
Ejemplo n.º 16
0
        /// <summary>
        ///   Formats (measures) the table.
        /// </summary>
        /// <param name="area"> The area on which to fit the table. </param>
        /// <param name="previousFormatInfo"> </param>
        internal override void Format(Area area, FormatInfo previousFormatInfo)
        {
            DocumentElements elements = DocumentRelations.GetParent(_table) as DocumentElements;

            if (elements != null)
            {
                Section section = DocumentRelations.GetParent(elements) as Section;
                if (section != null)
                {
                    _doHorizontalBreak = section.PageSetup.HorizontalPageBreak;
                }
            }

            _renderInfo = new TableRenderInfo();
            InitFormat(area, previousFormatInfo);

            // Don't take any Rows higher then MaxElementHeight
            XUnit topHeight   = CalcStartingHeight();
            XUnit probeHeight = topHeight;
            XUnit offset;

            if (_startRow > _lastHeaderRow + 1 &&
                _startRow < _table.Rows.Count)
            {
                offset = _bottomBorderMap[_startRow] - topHeight;
            }
            else
            {
                offset = -CalcMaxTopBorderWidth(0);
            }

            int   probeRow       = _startRow;
            XUnit currentHeight  = 0;
            XUnit startingHeight = 0;
            bool  isEmpty        = false;

            while (probeRow < _table.Rows.Count)
            {
                bool firstProbe = probeRow == _startRow;
                probeRow = _connectedRowsMap[probeRow];
                // Don't take any Rows higher then MaxElementHeight
                probeHeight = _bottomBorderMap[probeRow + 1] - offset;
                // First test whether MaxElementHeight has been set.
                if (MaxElementHeight > 0 && firstProbe && probeHeight > MaxElementHeight - Tolerance)
                {
                    probeHeight = MaxElementHeight - Tolerance;
                }
                //if (firstProbe && probeHeight > MaxElementHeight - Tolerance)
                //    probeHeight = MaxElementHeight - Tolerance;

                //The height for the first new row(s) + headerrows:
                if (startingHeight == 0)
                {
                    if (probeHeight > area.Height)
                    {
                        isEmpty = true;
                        break;
                    }
                    startingHeight = probeHeight;
                }

                if (probeHeight > area.Height)
                {
                    break;
                }

                else
                {
                    _currRow      = probeRow;
                    currentHeight = probeHeight;
                    ++probeRow;
                }
            }
            if (!isEmpty)
            {
                TableFormatInfo formatInfo = (TableFormatInfo)_renderInfo.FormatInfo;
                formatInfo.StartRow  = _startRow;
                formatInfo._isEnding = _currRow >= _table.Rows.Count - 1;
                formatInfo.EndRow    = _currRow;

                UpdateThisPagesBookmarks(_startRow, _currRow);
            }
            FinishLayoutInfo(area, currentHeight, startingHeight);
        }
Ejemplo n.º 17
0
 internal ShadingRenderer(DocumentObject domObj, CsvDocumentRenderer docRenderer)
     : base(domObj, docRenderer)
 {
     this.shading       = domObj as Shading;
     this.isCellShading = !(DocumentRelations.GetParent(shading) is ParagraphFormat);
 }
Ejemplo n.º 18
0
 internal ShadingRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
     : base(domObj, docRenderer)
 {
     _shading       = domObj as Shading;
     _isCellShading = !(DocumentRelations.GetParent(_shading) is ParagraphFormat);
 }
Ejemplo n.º 19
0
 internal StyleRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer)
     : base(domObj, docRenderer)
 {
     _style  = domObj as Style;
     _styles = DocumentRelations.GetParent(_style) as Styles;
 }