Ejemplo n.º 1
0
        /// <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 TableRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos)
     :
     base(gfx, renderInfo, fieldInfos)
 {
     this.table = (Table)this.renderInfo.DocumentObject;
 }
Ejemplo n.º 3
0
 internal TextFrameRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos)
     : base(gfx, renderInfo, fieldInfos)
 {
     this.textframe = (TextFrame)renderInfo.DocumentObject;
 }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
 internal ChartRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos)
     : base(gfx, renderInfo, fieldInfos)
 {
     this.chart = (Chart)renderInfo.DocumentObject;
 }
Ejemplo n.º 6
0
 internal ImageRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos)
     : base(gfx, renderInfo, fieldInfos)
 {
     this.image = (Image)renderInfo.DocumentObject;
 }
Ejemplo n.º 7
0
 /// <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)
 {
     this.renderInfo = renderInfo;
 }
Ejemplo n.º 8
0
        /// <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)
        {
            this.gfx = gfx;
            XUnit      prevBottomMargin = 0;
            XUnit      yPos             = prevBottomMargin;
            RenderInfo prevRenderInfo   = null;
            FormatInfo prevFormatInfo   = null;
            ArrayList  renderInfos      = new ArrayList();
            bool       ready            = this.elements.Count == 0;
            bool       isFirstOnPage    = true;
            Area       area             = this.areaProvider.GetNextArea();
            XUnit      maxHeight        = area.Height;

            if (ready)
            {
                this.areaProvider.StoreRenderInfos(renderInfos);
                return;
            }
            int idx = 0;

            while (!ready && area != null)
            {
                DocumentObject docObj   = this.elements[idx];
                Renderer       renderer = Renderer.Create(gfx, this.documentRenderer, docObj, this.areaProvider.AreaFieldInfos);
                if (renderer != null) // "Slightly hacked" for legends: see below
                {
                    renderer.MaxElementHeight = maxHeight;
                }

                if (topLevel && this.documentRenderer.HasPrepareDocumentProgress)
                {
                    this.documentRenderer.OnPrepareDocumentProgress(this.documentRenderer.ProgressCompleted + idx + 1,
                                                                    this.documentRenderer.ProgressMaximum);
                }

                // "Slightly hacked" for legends: they are rendered as part of the chart.
                // So they are skipped here.
                if (renderer == null)
                {
                    ready = idx == this.elements.Count - 1;
                    if (ready)
                    {
                        this.areaProvider.StoreRenderInfos(renderInfos);
                    }
                    ++idx;
                    continue;
                }
                ///////////////////////////////////////////
                if (prevFormatInfo == null)
                {
                    LayoutInfo initialLayoutInfo = renderer.InitialLayoutInfo;
                    XUnit      distance          = prevBottomMargin;
                    if (initialLayoutInfo.VerticalReference == VerticalReference.PreviousElement &&
                        initialLayoutInfo.Floating != Floating.None) //Added KlPo 12.07.07
                    {
                        distance = MarginMax(initialLayoutInfo.MarginTop, distance);
                    }

                    area = area.Lower(distance);
                }
                renderer.Format(area, prevFormatInfo);
                this.areaProvider.PositionHorizontally(renderer.RenderInfo.LayoutInfo);
                bool pagebreakBefore = this.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, this.documentRenderer, docObj, this.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             = this.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)//Added KlPo 12.07.07
                        {
                            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, this.documentRenderer, docObj, this.areaProvider.AreaFieldInfos);
                        renderer.MaxElementHeight = maxHeight;
                        renderer.Format(area, prevFormatInfo);
                        prevFormatInfo = null;

                        //Added KlPo 12.07.07
                        this.areaProvider.PositionHorizontally(renderer.RenderInfo.LayoutInfo);
                        this.areaProvider.PositionVertically(renderer.RenderInfo.LayoutInfo);
                        //Added End
                        ready = idx == this.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 false
                    area = this.areaProvider.GetNextArea();
#else
                    if (!ready) //!!!newTHHO 19.01.2007: korrekt? oder GetNextArea immer ausführen???
                    {
                        area      = this.areaProvider.GetNextArea();
                        maxHeight = area.Height;
                    }
#endif
                }
                if (idx == this.elements.Count && !ready)
                {
                    this.areaProvider.StoreRenderInfos(renderInfos);
                    ready = true;
                }
            }
        }