internal Renderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) { _documentObject = renderInfo.DocumentObject; _gfx = gfx; _renderInfo = renderInfo; _fieldInfos = fieldInfos; }
internal Renderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) { this.documentObject = renderInfo.DocumentObject; this.gfx = gfx; this.renderInfo = renderInfo; this.fieldInfos = fieldInfos; }
internal ShapeRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { this.shape = (Shape)renderInfo.DocumentObject; LineFormat lf = (LineFormat)this.shape.GetValue("LineFormat", GV.ReadOnly); this.lineFormatRenderer = new LineFormatRenderer(lf, gfx); FillFormat ff = (FillFormat)this.shape.GetValue("FillFormat", GV.ReadOnly); this.fillFormatRenderer = new FillFormatRenderer(ff, gfx); }
internal static XUnit GetTotalHeight(RenderInfo[] renderInfos) { if (renderInfos == null || renderInfos.Length == 0) return 0; int lastIdx = renderInfos.Length - 1; RenderInfo firstRenderInfo = renderInfos[0]; RenderInfo lastRenderInfo = renderInfos[lastIdx]; LayoutInfo firstLayoutInfo = firstRenderInfo.LayoutInfo; LayoutInfo lastLayoutInfo = lastRenderInfo.LayoutInfo; XUnit top = firstLayoutInfo.ContentArea.Y - firstLayoutInfo.MarginTop; XUnit bottom = lastLayoutInfo.ContentArea.Y + lastLayoutInfo.ContentArea.Height; bottom += lastLayoutInfo.MarginBottom; return bottom - top; }
/// <summary> /// Renders the contents shifted to the given Coordinates. /// </summary> /// <param name="xShift">The x shift.</param> /// <param name="yShift">The y shift.</param> /// <param name="renderInfos">The render infos.</param> protected void RenderByInfos(XUnit xShift, XUnit yShift, RenderInfo[] renderInfos) { if (renderInfos == null) return; foreach (RenderInfo renderInfo in renderInfos) { XUnit savedX = renderInfo.LayoutInfo.ContentArea.X; XUnit savedY = renderInfo.LayoutInfo.ContentArea.Y; renderInfo.LayoutInfo.ContentArea.X += xShift; renderInfo.LayoutInfo.ContentArea.Y += yShift; Renderer renderer = Create(_gfx, _documentRenderer, renderInfo, _fieldInfos); renderer.Render(); renderInfo.LayoutInfo.ContentArea.X = savedX; renderInfo.LayoutInfo.ContentArea.Y = savedY; } }
/// <summary> /// Finishes rendering for the page. /// </summary> /// <param name="lastRenderInfo">The last render info.</param> /// <param name="pagebreakBefore">set to <c>true</c> if there is a pagebreak before this page.</param> /// <param name="renderInfos">The render infos.</param> /// <returns> /// The RenderInfo to set as previous RenderInfo. /// </returns> RenderInfo FinishPage(RenderInfo lastRenderInfo, bool pagebreakBefore, ref ArrayList renderInfos) { RenderInfo prevRenderInfo; if (lastRenderInfo.FormatInfo.IsEmpty || pagebreakBefore) { prevRenderInfo = null; } else { prevRenderInfo = lastRenderInfo; renderInfos.Add(lastRenderInfo); if (lastRenderInfo.FormatInfo.IsEnding) { prevRenderInfo = null; } } this.areaProvider.StoreRenderInfos(renderInfos); renderInfos = new ArrayList(); return(prevRenderInfo); }
/// <summary> /// Indicates that the Ending of the element has to be removed. /// </summary> /// <param name="prevRenderInfo">The prev render info.</param> /// <param name="succedingRenderInfo">The succeding render info.</param> /// <param name="remainingArea">The remaining area.</param> bool PreviousRendererNeedsRemoveEnding(RenderInfo prevRenderInfo, RenderInfo succedingRenderInfo, Area remainingArea) { if (prevRenderInfo == null) { return(false); } LayoutInfo layoutInfo = succedingRenderInfo.LayoutInfo; FormatInfo formatInfo = succedingRenderInfo.FormatInfo; LayoutInfo prevLayoutInfo = prevRenderInfo.LayoutInfo; if (formatInfo.IsEnding && !formatInfo.EndingIsComplete) { Area area = this.areaProvider.ProbeNextArea(); if (area.Height > prevLayoutInfo.TrailingHeight + layoutInfo.TrailingHeight + Renderer.Tolerance) { return(true); } } return(false); }
/// <summary> /// Renders a MigraDoc document to the specified graphics object. /// </summary> public void RenderPage(XGraphics gfx, int page, PageRenderOptions options) { if (this.formattedDocument.IsEmptyPage(page)) { return; } FieldInfos fieldInfos = this.formattedDocument.GetFieldInfos(page); if (this.printDate != DateTime.MinValue) { fieldInfos.date = this.printDate; } else { fieldInfos.date = DateTime.Now; } if ((options & PageRenderOptions.RenderHeader) == PageRenderOptions.RenderHeader) { RenderHeader(gfx, page); } if ((options & PageRenderOptions.RenderFooter) == PageRenderOptions.RenderFooter) { RenderFooter(gfx, page); } if ((options & PageRenderOptions.RenderContent) == PageRenderOptions.RenderContent) { RenderInfo[] renderInfos = this.formattedDocument.GetRenderInfos(page); //foreach (RenderInfo renderInfo in renderInfos) int count = renderInfos.Length; for (int idx = 0; idx < count; idx++) { RenderInfo renderInfo = renderInfos[idx]; Renderer renderer = Renderer.Create(gfx, this, renderInfo, fieldInfos); renderer.Render(); } } }
internal TextFrameRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { this.textframe = (TextFrame)renderInfo.DocumentObject; }
/// <summary> /// Creates a fitting renderer for the render info to render and layout with. /// </summary> /// <param name="gfx">The XGraphics object to render on.</param> /// <param name="documentRenderer">The document renderer.</param> /// <param name="renderInfo">The RenderInfo object stored after a previous call of Format().</param> /// <param name="fieldInfos">The field infos.</param> /// <returns>The fitting Renderer.</returns> internal static Renderer Create(XGraphics gfx, DocumentRenderer documentRenderer, RenderInfo renderInfo, FieldInfos fieldInfos) { Renderer renderer = null; if (renderInfo.DocumentObject is Paragraph) renderer = new ParagraphRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is Table) renderer = new TableRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is PageBreak) renderer = new PageBreakRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is TextFrame) renderer = new TextFrameRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is Chart) renderer = new ChartRenderer(gfx, renderInfo, fieldInfos); //else if (renderInfo.DocumentObject is Chart) // renderer = new ChartRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is Image) renderer = new ImageRenderer(gfx, renderInfo, fieldInfos); if (renderer != null) renderer._documentRenderer = documentRenderer; return renderer; }
public ImageRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { _image = (Image)renderInfo.DocumentObject; }
private void RenderFooter(XGraphics graphics, int page) { FormattedHeaderFooter formattedFooter = _formattedDocument.GetFormattedFooter(page); if (formattedFooter == null) { return; } Rectangle footerArea = _formattedDocument.GetFooterArea(page); RenderInfo[] renderInfos = formattedFooter.GetRenderInfos(); #if true #if true // The footer is bottom-aligned and grows with its contents. topY specifies the Y position where the footer begins. XUnit topY = footerArea.Y + footerArea.Height - RenderInfo.GetTotalHeight(renderInfos); // Hack: The purpose of "topY" is unclear, but two paragraphs in the footer will use the same topY and will be rendered at the same position. // offsetY specifies the offset (amount of movement) for all footer items. It's the difference between topY and the position calculated for the first item. XUnit offsetY = 0; bool notFirst = false; FieldInfos fieldInfos = _formattedDocument.GetFieldInfos(page); foreach (RenderInfo renderInfo in renderInfos) { Renderer renderer = Renderer.Create(graphics, this, renderInfo, fieldInfos); if (!notFirst) { offsetY = renderer.RenderInfo.LayoutInfo.ContentArea.Y - topY; notFirst = true; } XUnit savedY = renderer.RenderInfo.LayoutInfo.ContentArea.Y; // Apply offsetY only to items that do not have an absolute position. if (renderer.RenderInfo.LayoutInfo.Floating != Floating.None) { renderer.RenderInfo.LayoutInfo.ContentArea.Y -= offsetY; } renderer.Render(); renderer.RenderInfo.LayoutInfo.ContentArea.Y = savedY; } #else // TODO Document the purpose of "topY". XUnit topY = footerArea.Y + footerArea.Height - RenderInfo.GetTotalHeight(renderInfos); // Hack: The purpose of "topY" is unclear, but two paragraphs in the footer will use the same topY and will be rendered at the same position. XUnit offsetY = 0; FieldInfos fieldInfos = _formattedDocument.GetFieldInfos(page); foreach (RenderInfo renderInfo in renderInfos) { Renderer renderer = Renderer.Create(graphics, this, renderInfo, fieldInfos); XUnit savedY = renderer.RenderInfo.LayoutInfo.ContentArea.Y; renderer.RenderInfo.LayoutInfo.ContentArea.Y = topY + offsetY; renderer.Render(); renderer.RenderInfo.LayoutInfo.ContentArea.Y = savedY; offsetY += renderer.RenderInfo.LayoutInfo.ContentArea.Height; } #endif #else XUnit topY = footerArea.Y + footerArea.Height - RenderInfo.GetTotalHeight(renderInfos); FieldInfos fieldInfos = _formattedDocument.GetFieldInfos(page); foreach (RenderInfo renderInfo in renderInfos) { Renderer renderer = Renderer.Create(graphics, this, renderInfo, fieldInfos); XUnit savedY = renderer.RenderInfo.LayoutInfo.ContentArea.Y; renderer.RenderInfo.LayoutInfo.ContentArea.Y = topY; renderer.Render(); renderer.RenderInfo.LayoutInfo.ContentArea.Y = savedY; } #endif }
/// <summary> /// Initializes a ParagraphRenderer object for rendering. /// </summary> /// <param name="gfx">The XGraphics object to render on.</param> /// <param name="renderInfo">The render info object containing information necessary for rendering.</param> /// <param name="fieldInfos">The field infos.</param> internal PageBreakRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { _renderInfo = renderInfo; }
internal TextFrameRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { _textframe = (TextFrame)renderInfo.DocumentObject; }
internal BarcodeRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { _barcode = (Barcode)renderInfo.DocumentObject; }
/// <summary> /// Finishes rendering for the page. /// </summary> /// <param name="lastRenderInfo">The last render info.</param> /// <param name="pagebreakBefore">set to <c>true</c> if there is a pagebreak before this page.</param> /// <param name="renderInfos">The render infos.</param> /// <returns> /// The RenderInfo to set as previous RenderInfo. /// </returns> RenderInfo FinishPage(RenderInfo lastRenderInfo, bool pagebreakBefore, ref ArrayList renderInfos) { RenderInfo prevRenderInfo; if (lastRenderInfo.FormatInfo.IsEmpty || pagebreakBefore) { prevRenderInfo = null; } else { prevRenderInfo = lastRenderInfo; renderInfos.Add(lastRenderInfo); if (lastRenderInfo.FormatInfo.IsEnding) prevRenderInfo = null; } this.areaProvider.StoreRenderInfos(renderInfos); renderInfos = new ArrayList(); return prevRenderInfo; }
internal TableRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { _table = (Table)_renderInfo.DocumentObject; }
internal ChartRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { _chart = (Chart)renderInfo.DocumentObject; }
internal HtmlFormRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { _form = (HtmlForm)renderInfo.DocumentObject; }
internal BarcodeRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { this.barcode = (Barcode)renderInfo.DocumentObject; }
/// <summary> /// Indicates that the Ending of the element has to be removed. /// </summary> /// <param name="prevRenderInfo">The prev render info.</param> /// <param name="succedingRenderInfo">The succeding render info.</param> /// <param name="remainingArea">The remaining area.</param> bool PreviousRendererNeedsRemoveEnding(RenderInfo prevRenderInfo, RenderInfo succedingRenderInfo, Area remainingArea) { if (prevRenderInfo == null) return false; LayoutInfo layoutInfo = succedingRenderInfo.LayoutInfo; FormatInfo formatInfo = succedingRenderInfo.FormatInfo; LayoutInfo prevLayoutInfo = prevRenderInfo.LayoutInfo; if (formatInfo.IsEnding && !formatInfo.EndingIsComplete) { Area area = this.areaProvider.ProbeNextArea(); if (area.Height > prevLayoutInfo.TrailingHeight + layoutInfo.TrailingHeight + Renderer.Tolerance) return true; } return false; }
/// <summary> /// Initializes a ParagraphRenderer object for rendering. /// </summary> /// <param name="gfx">The XGraphics object to render on.</param> /// <param name="renderInfo">The render info object containing information necessary for rendering.</param> /// <param name="fieldInfos">The field infos.</param> internal ParagraphRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { this.paragraph = (Paragraph)renderInfo.DocumentObject; }
internal TableRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { this.table = (Table)this.renderInfo.DocumentObject; }
internal ImageRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos) : base(gfx, renderInfo, fieldInfos) { this.image = (Image)renderInfo.DocumentObject; }
/// <summary> /// Formats the elements on the areas provided by the area provider. /// </summary> /// <param name="gfx">The graphics object to render on.</param> /// <param name="topLevel">if set to <c>true</c> formats the object is on top level.</param> public void FormatOnAreas(XGraphics gfx, bool topLevel) { _gfx = gfx; XUnit prevBottomMargin = 0; XUnit yPos = prevBottomMargin; RenderInfo prevRenderInfo = null; FormatInfo prevFormatInfo = null; List <RenderInfo> renderInfos = new List <RenderInfo>(); bool ready = _elements.Count == 0; bool isFirstOnPage = true; Area area = _areaProvider.GetNextArea(); XUnit maxHeight = area.Height; if (ready) { _areaProvider.StoreRenderInfos(renderInfos); return; } int idx = 0; while (!ready && area != null) { DocumentObject docObj = _elements[idx]; Renderer renderer = Renderer.Create(gfx, _documentRenderer, docObj, _areaProvider.AreaFieldInfos); if (renderer != null) // "Slightly hacked" for legends: see below { renderer.MaxElementHeight = maxHeight; } if (topLevel && _documentRenderer.HasPrepareDocumentProgress) { _documentRenderer.OnPrepareDocumentProgress(_documentRenderer.ProgressCompleted + idx + 1, _documentRenderer.ProgressMaximum); } // "Slightly hacked" for legends: they are rendered as part of the chart. // So they are skipped here. if (renderer == null) { ready = idx == _elements.Count - 1; if (ready) { _areaProvider.StoreRenderInfos(renderInfos); } ++idx; continue; } /////////////////////////////////////////// if (prevFormatInfo == null) { LayoutInfo initialLayoutInfo = renderer.InitialLayoutInfo; XUnit distance = prevBottomMargin; if (initialLayoutInfo.VerticalReference == VerticalReference.PreviousElement && initialLayoutInfo.Floating != Floating.None) { distance = MarginMax(initialLayoutInfo.MarginTop, distance); } area = area.Lower(distance); } renderer.Format(area, prevFormatInfo); _areaProvider.PositionHorizontally(renderer.RenderInfo.LayoutInfo); bool pagebreakBefore = _areaProvider.IsAreaBreakBefore(renderer.RenderInfo.LayoutInfo) && !isFirstOnPage; pagebreakBefore = pagebreakBefore || !isFirstOnPage && IsForcedAreaBreak(idx, renderer, area); if (!pagebreakBefore && renderer.RenderInfo.FormatInfo.IsEnding) { if (PreviousRendererNeedsRemoveEnding(prevRenderInfo, renderer.RenderInfo, area)) { prevRenderInfo.RemoveEnding(); renderer = Renderer.Create(gfx, _documentRenderer, docObj, _areaProvider.AreaFieldInfos); renderer.MaxElementHeight = maxHeight; renderer.Format(area, prevRenderInfo.FormatInfo); } else if (NeedsEndingOnNextArea(idx, renderer, area, isFirstOnPage)) { renderer.RenderInfo.RemoveEnding(); prevRenderInfo = FinishPage(renderer.RenderInfo, pagebreakBefore, ref renderInfos); if (prevRenderInfo != null) { prevFormatInfo = prevRenderInfo.FormatInfo; } else { prevFormatInfo = null; isFirstOnPage = true; } prevBottomMargin = 0; area = _areaProvider.GetNextArea(); maxHeight = area.Height; } else { renderInfos.Add(renderer.RenderInfo); isFirstOnPage = false; _areaProvider.PositionVertically(renderer.RenderInfo.LayoutInfo); if (renderer.RenderInfo.LayoutInfo.VerticalReference == VerticalReference.PreviousElement && renderer.RenderInfo.LayoutInfo.Floating != Floating.None) { prevBottomMargin = renderer.RenderInfo.LayoutInfo.MarginBottom; if (renderer.RenderInfo.LayoutInfo.Floating != Floating.None) { area = area.Lower(renderer.RenderInfo.LayoutInfo.ContentArea.Height); } } else { prevBottomMargin = 0; } prevFormatInfo = null; prevRenderInfo = null; ++idx; } } else { if (renderer.RenderInfo.FormatInfo.IsEmpty && isFirstOnPage) { area = area.Unite(new Rectangle(area.X, area.Y, area.Width, double.MaxValue)); renderer = Renderer.Create(gfx, _documentRenderer, docObj, _areaProvider.AreaFieldInfos); renderer.MaxElementHeight = maxHeight; renderer.Format(area, prevFormatInfo); prevFormatInfo = null; _areaProvider.PositionHorizontally(renderer.RenderInfo.LayoutInfo); _areaProvider.PositionVertically(renderer.RenderInfo.LayoutInfo); ready = idx == _elements.Count - 1; ++idx; } prevRenderInfo = FinishPage(renderer.RenderInfo, pagebreakBefore, ref renderInfos); if (prevRenderInfo != null) { prevFormatInfo = prevRenderInfo.FormatInfo; } else { prevFormatInfo = null; } isFirstOnPage = true; prevBottomMargin = 0; if (!ready) { area = _areaProvider.GetNextArea(); maxHeight = area.Height; } } if (idx == _elements.Count && !ready) { _areaProvider.StoreRenderInfos(renderInfos); ready = true; } } }
protected void RenderByInfos(RenderInfo[] renderInfos) { RenderByInfos(0, 0, renderInfos); }
/// <summary> /// Creates a fitting renderer for the render info to render and layout with. /// </summary> /// <param name="gfx">The XGraphics object to render on.</param> /// <param name="documentRenderer">The document renderer.</param> /// <param name="renderInfo">The RenderInfo object stored after a previous call of Format().</param> /// <param name="fieldInfos">The field infos.</param> /// <returns>The fitting Renderer.</returns> internal static Renderer Create(XGraphics gfx, DocumentRenderer documentRenderer, RenderInfo renderInfo, FieldInfos fieldInfos) { Renderer renderer = null; if (renderInfo.DocumentObject is Paragraph) { renderer = new ParagraphRenderer(gfx, renderInfo, fieldInfos); } else if (renderInfo.DocumentObject is Table) { renderer = new TableRenderer(gfx, renderInfo, fieldInfos); } else if (renderInfo.DocumentObject is PageBreak) { renderer = new PageBreakRenderer(gfx, renderInfo, fieldInfos); } else if (renderInfo.DocumentObject is TextFrame) { renderer = new TextFrameRenderer(gfx, renderInfo, fieldInfos); } else if (renderInfo.DocumentObject is Chart) { renderer = new ChartRenderer(gfx, renderInfo, fieldInfos); } //else if (renderInfo.DocumentObject is Chart) // renderer = new ChartRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is Image) { renderer = new ImageRenderer(gfx, renderInfo, fieldInfos); } if (renderer != null) { renderer._documentRenderer = documentRenderer; } return(renderer); }
/// <summary> /// Creates a fitting renderer for the render info to render and layout with. /// </summary> /// <param name="gfx">The XGraphics object to render on.</param> /// <param name="documentRenderer">The document renderer.</param> /// <param name="renderInfo">The RenderInfo object stored after a previous call of Format().</param> /// <param name="fieldInfos">The field infos.</param> /// <returns>The fitting Renderer.</returns> public static Renderer Create(XGraphics gfx, DocumentRenderer documentRenderer, RenderInfo renderInfo, FieldInfos fieldInfos) { Renderer renderer = null; if (renderInfo.DocumentObject is Paragraph) { renderer = new ParagraphRenderer(gfx, renderInfo, fieldInfos); } else if (renderInfo.DocumentObject is Table) { renderer = new TableRenderer(gfx, renderInfo, fieldInfos); } else if (renderInfo.DocumentObject is PageBreak) { renderer = new PageBreakRenderer(gfx, renderInfo, fieldInfos); } else if (renderInfo.DocumentObject is TextFrame) { renderer = new TextFrameRenderer(gfx, renderInfo, fieldInfos); } else if (renderInfo.DocumentObject is Chart) { renderer = new ChartRenderer(gfx, renderInfo, fieldInfos); } //else if (renderInfo.DocumentObject is Chart) // renderer = new ChartRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is Image) { renderer = new ImageRenderer(gfx, renderInfo, fieldInfos); } else if (GetRendererType != null) { System.Type rendererType = GetRendererType(renderInfo.DocumentObject); if (rendererType != null) { renderer = (Renderer)System.Activator.CreateInstance(rendererType, gfx, renderInfo, fieldInfos); } } if (renderer != null) { renderer._documentRenderer = documentRenderer; } return(renderer); }