Esempio n. 1
0
        bool PositionHorizontallyToMargin(LayoutInfo layoutInfo)
        {
            Rectangle rect = CalcContentRect(_currentPage);
            ElementAlignment align = GetCurrentAlignment(layoutInfo.HorizontalAlignment);


            switch (align)
            {
                case ElementAlignment.Near:
                    if (layoutInfo.Left != 0)
                    {
                        layoutInfo.ContentArea.X += layoutInfo.Left;
                        return true;
                    }
                    if (layoutInfo.MarginLeft != 0)
                    {
                        layoutInfo.ContentArea.X += layoutInfo.MarginLeft;
                        return true;
                    }
                    return false;

                case ElementAlignment.Far:
                    XUnit xPos = rect.X + rect.Width;
                    xPos -= layoutInfo.ContentArea.Width;
                    xPos -= layoutInfo.MarginRight;
                    layoutInfo.ContentArea.X = xPos;
                    return true;

                case ElementAlignment.Center:
                    xPos = rect.Width;
                    xPos -= layoutInfo.ContentArea.Width;
                    xPos = rect.X + xPos / 2;
                    layoutInfo.ContentArea.X = xPos;
                    return true;
            }
            return false;
        }
Esempio n. 2
0
        bool PositionHorizontallyToPage(LayoutInfo layoutInfo)
        {
            XUnit xPos;
            ElementAlignment align = GetCurrentAlignment(layoutInfo.HorizontalAlignment);
            switch (align)
            {
                case ElementAlignment.Near:
#if true
                    // Attempt to make it compatible with MigraDoc CPP.
                    // Ignore layoutInfo.Left if absolute position is specified in layoutInfo.MarginLeft.
                    // Use layoutInfo.Left if layoutInfo.MarginLeft is 0.
                    // TODO We would need HasValue for XUnit to determine whether a value was assigned.
                    if (layoutInfo.HorizontalReference == HorizontalReference.Page ||
                      layoutInfo.HorizontalReference == HorizontalReference.PageMargin)
                        xPos = layoutInfo.MarginLeft != 0 ? layoutInfo.MarginLeft : layoutInfo.Left;
                    else
                        xPos = Math.Max(layoutInfo.MarginLeft, layoutInfo.Left);
#else
                    if (layoutInfo.HorizontalReference == HorizontalReference.Page ||
                      layoutInfo.HorizontalReference == HorizontalReference.PageMargin)
                        xPos = layoutInfo.MarginLeft; // ignore layoutInfo.Left if absolute position is specified
                    else
                        xPos = Math.Max(layoutInfo.MarginLeft, layoutInfo.Left);
#endif
                    layoutInfo.ContentArea.X = xPos;
                    break;

                case ElementAlignment.Far:
                    xPos = _currentSection.PageSetup.EffectivePageWidth.Point;
                    xPos -= layoutInfo.ContentArea.Width;
                    xPos -= layoutInfo.MarginRight;
                    layoutInfo.ContentArea.X = xPos;
                    break;

                case ElementAlignment.Center:
                    xPos = _currentSection.PageSetup.EffectivePageWidth.Point;
                    xPos -= layoutInfo.ContentArea.Width;
                    xPos /= 2;
                    layoutInfo.ContentArea.X = xPos;
                    break;
            }
            return true;
        }
Esempio n. 3
0
 bool IAreaProvider.PositionHorizontally(LayoutInfo layoutInfo)
 {
     return false;
 }
Esempio n. 4
0
        bool IAreaProvider.PositionHorizontally(LayoutInfo layoutInfo)
        {
            switch (layoutInfo.HorizontalReference)
            {
                case HorizontalReference.PageMargin:
                case HorizontalReference.AreaBoundary:
                    return PositionHorizontallyToMargin(layoutInfo);

                case HorizontalReference.Page:
                    return PositionHorizontallyToPage(layoutInfo);
            }
            return false;
        }
 bool IAreaProvider.IsAreaBreakBefore(LayoutInfo layoutInfo)
 {
     return false;
 }
Esempio n. 6
0
        bool IAreaProvider.PositionHorizontally(LayoutInfo layoutInfo)
        {
            Rectangle rect = CalcContentRect();
            switch (layoutInfo.HorizontalAlignment)
            {
                case ElementAlignment.Near:
                    if (layoutInfo.Left != 0)
                    {
                        layoutInfo.ContentArea.X += layoutInfo.Left;
                        return true;
                    }
                    return false;

                case ElementAlignment.Far:
                    XUnit xPos = rect.X + rect.Width;
                    xPos -= layoutInfo.ContentArea.Width;
                    xPos -= layoutInfo.MarginRight;
                    layoutInfo.ContentArea.X = xPos;
                    return true;

                case ElementAlignment.Center:
                    xPos = rect.Width;
                    xPos -= layoutInfo.ContentArea.Width;
                    xPos = rect.X + xPos / 2;
                    layoutInfo.ContentArea.X = xPos;
                    return true;
            }
            return false;
        }
Esempio n. 7
0
        bool PositionHorizontallyToPage(LayoutInfo layoutInfo)
        {
            XUnit xPos;
              ElementAlignment align = GetCurrentAlignment(layoutInfo.HorizontalAlignment);
              switch (align)
              {
            case ElementAlignment.Near:
            #if true
              // Allow negative offsets (supporting "Anschnitt" for images)
              if (layoutInfo.HorizontalReference == HorizontalReference.Page ||
            layoutInfo.HorizontalReference == HorizontalReference.PageMargin)
            xPos = layoutInfo.MarginLeft; // Ignore layoutInfo.Left if absolute position is specified
              else
            xPos = Math.Max(layoutInfo.MarginLeft, layoutInfo.Left);
            #else
              //!!!delTHHO 22.10.2008
              xPos = Math.Max(layoutInfo.MarginLeft, layoutInfo.Left);
            #endif
              layoutInfo.ContentArea.X = xPos;
              break;

            case ElementAlignment.Far:
              xPos = this.currentSection.PageSetup.PageWidth.Point;
              xPos -= layoutInfo.ContentArea.Width;
              xPos -= layoutInfo.MarginRight;
              layoutInfo.ContentArea.X = xPos;
              break;

            case ElementAlignment.Center:
              xPos = this.currentSection.PageSetup.PageWidth.Point;
              xPos -= layoutInfo.ContentArea.Width;
              xPos /= 2;
              layoutInfo.ContentArea.X = xPos;
              break;
              }
              return true;
        }
Esempio n. 8
0
        bool IAreaProvider.PositionVertically(LayoutInfo layoutInfo)
        {
            switch (layoutInfo.VerticalReference)
            {
                case VerticalReference.PreviousElement:
                    return false;

                case VerticalReference.AreaBoundary:
                case VerticalReference.PageMargin:
                    return PositionVerticallyToMargin(layoutInfo);

                case VerticalReference.Page:
                    return PositionVerticallyToPage(layoutInfo);
            }
            return false;
        }
Esempio n. 9
0
 bool IAreaProvider.PositionHorizontally(LayoutInfo layoutInfo)
 {
     return(false);
 }
Esempio n. 10
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)
        {
            _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;
                }
            }
        }
Esempio n. 11
0
 bool IAreaProvider.PositionVertically(LayoutInfo layoutInfo)
 {
     return(false);
 }
Esempio n. 12
0
 bool IAreaProvider.IsAreaBreakBefore(LayoutInfo layoutInfo)
 {
     return(false);
 }
Esempio n. 13
0
        bool IAreaProvider.PositionHorizontally(LayoutInfo layoutInfo)
        {
            IAreaProvider formattedDoc = _documentRenderer.FormattedDocument;

            return(formattedDoc.PositionHorizontally(layoutInfo));
        }
Esempio n. 14
0
        bool PositionVerticallyToMargin(LayoutInfo layoutInfo)
        {
            Rectangle rect = CalcContentRect(_currentPage);
            XUnit yPos;
            switch (layoutInfo.VerticalAlignment)
            {
                case ElementAlignment.Near:
                    yPos = rect.Y;
                    if (layoutInfo.Top == 0)
                        yPos += layoutInfo.MarginTop;
                    else
                        yPos += layoutInfo.Top;
                    layoutInfo.ContentArea.Y = yPos;
                    break;

                case ElementAlignment.Far:
                    yPos = rect.Y + rect.Height;
                    yPos -= layoutInfo.ContentArea.Height;
                    yPos -= layoutInfo.MarginBottom;
                    layoutInfo.ContentArea.Y = yPos;
                    break;

                case ElementAlignment.Center:
                    yPos = rect.Height;
                    yPos -= layoutInfo.ContentArea.Height;
                    yPos = rect.Y + yPos / 2;
                    layoutInfo.ContentArea.Y = yPos;
                    break;
            }
            return true;
        }
Esempio n. 15
0
        bool PositionVerticallyToMargin(LayoutInfo layoutInfo)
        {
            Rectangle rect = CalcContentRect(this.currentPage);
              XUnit yPos;
              switch (layoutInfo.VerticalAlignment)
              {
            case ElementAlignment.Near:
              yPos = rect.Y;
              //Added KlPo 12.07.07:
              if (layoutInfo.Top == 0)
            yPos += layoutInfo.MarginTop;
              else
            yPos += layoutInfo.Top;
              //Removed KlPo 12.07.07
              //yPos += Math.Max(layoutInfo.Top, layoutInfo.MarginTop);

              layoutInfo.ContentArea.Y = yPos;
              break;

            case ElementAlignment.Far:
              yPos = rect.Y + rect.Height;
              yPos -= layoutInfo.ContentArea.Height;
              yPos -= layoutInfo.MarginBottom;
              layoutInfo.ContentArea.Y = yPos;
              break;

            case ElementAlignment.Center:
              yPos = rect.Height;
              yPos -= layoutInfo.ContentArea.Height;
              yPos = rect.Y + yPos / 2;
              layoutInfo.ContentArea.Y = yPos;
              break;
              }
              return true;
        }
Esempio n. 16
0
        bool PositionVerticallyToPage(LayoutInfo layoutInfo)
        {
            XUnit yPos;
            switch (layoutInfo.VerticalAlignment)
            {
                case ElementAlignment.Near:
                    yPos = Math.Max(layoutInfo.MarginTop, layoutInfo.Top);
                    layoutInfo.ContentArea.Y = yPos;
                    break;

                case ElementAlignment.Far:
                    yPos = _currentSection.PageSetup.EffectivePageHeight.Point;
                    yPos -= layoutInfo.ContentArea.Height;
                    yPos -= layoutInfo.MarginBottom;
                    layoutInfo.ContentArea.Y = yPos;
                    break;

                case ElementAlignment.Center:
                    yPos = _currentSection.PageSetup.EffectivePageHeight.Point;
                    yPos -= layoutInfo.ContentArea.Height;
                    yPos /= 2;
                    layoutInfo.ContentArea.Y = yPos;
                    break;
            }
            return true;
        }
Esempio n. 17
0
 bool IAreaProvider.PositionHorizontally(LayoutInfo layoutInfo)
 {
     IAreaProvider formattedDoc = _documentRenderer.FormattedDocument;
     return formattedDoc.PositionHorizontally(layoutInfo);
 }
Esempio n. 18
0
 bool IAreaProvider.IsAreaBreakBefore(LayoutInfo layoutInfo)
 {
     return layoutInfo.PageBreakBefore;
 }
Esempio n. 19
0
 bool IAreaProvider.PositionVertically(LayoutInfo layoutInfo)
 {
     return false;
 }
Esempio n. 20
0
 bool IAreaProvider.PositionVertically(LayoutInfo layoutInfo)
 {
     IAreaProvider formattedDoc = (IAreaProvider)this.documentRenderer.FormattedDocument;
       return formattedDoc.PositionVertically(layoutInfo);
 }
 bool IAreaProvider.IsAreaBreakBefore(LayoutInfo layoutInfo)
 {
     return(layoutInfo.PageBreakBefore);
 }