Ejemplo n.º 1
0
 /// <summary>
 /// Returns the max of the given Margins, if both are positive or 0, the sum otherwise.
 /// </summary>
 /// <param name="prevBottomMargin">The bottom margin of the previous element.</param>
 /// <param name="nextTopMargin">The top margin of the next element.</param>
 /// <returns></returns>
 private XUnit MarginMax(XUnit prevBottomMargin, XUnit nextTopMargin)
 {
     if (prevBottomMargin >= 0 && nextTopMargin >= 0)
         return Math.Max(prevBottomMargin, nextTopMargin);
     else
         return prevBottomMargin + nextTopMargin;
 }
Ejemplo n.º 2
0
 public static XGraphics NewPage(PdfDocument document, XUnit width, XUnit height)
 {
     var page = document.AddPage();
     page.Width = width;
     page.Height = height;
     return XGraphics.FromPdfPage(page);
 }
Ejemplo n.º 3
0
        internal void Render(XUnit x, XUnit y, XUnit width, XUnit height)
        {
            if (_shading == null || _brush == null)
                return;

            _gfx.DrawRectangle(_brush, x.Point, y.Point, width.Point, height.Point);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Create new page
 /// </summary>
 void CreatePage()
 {
     Page = _document.AddPage();
     Page.Size = PageSize.A4;
     Gfx = XGraphics.FromPdfPage(Page);
     _currentPosition = _topPosition;
 }
Ejemplo n.º 5
0
 public Cell(string text, XUnit width, XFont font, Alignment alignment)
 {
     this.Text = text;
     this.width = width;
     this.font = font;
     this.alignment = alignment;
     this.height = XUnit.Zero;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="document">Pdf Document object</param>
 /// <param name="topPosition">Top positon for the PDF write start position</param>
 /// <param name="bottomMargin">Bottom margin for the PDF</param>
 public PDFLayoutHelper(PdfDocument document, XUnit topPosition, XUnit bottomMargin)
 {
     _document = document;
     _topPosition = topPosition;
     _bottomMargin = bottomMargin;
     // Set a value outside the page - a new page will be created on the first request.
     _currentPosition = bottomMargin + 10000;
 }
Ejemplo n.º 7
0
 internal FormattedCell(Cell cell, DocumentRenderer documentRenderer, Borders cellBorders, FieldInfos fieldInfos, XUnit xOffset, XUnit yOffset)
 {
   this.cell = cell;
   this.fieldInfos = fieldInfos;
   this.yOffset = yOffset;
   this.xOffset = xOffset;
   this.bordersRenderer = new BordersRenderer(cellBorders, null);
   this.documentRenderer = documentRenderer;
 }
Ejemplo n.º 8
0
    internal void Render(XUnit x, XUnit y, XUnit width, XUnit height)
    {
      XBrush brush = GetBrush();

      if (brush == null)
        return;

      this.gfx.DrawRectangle(brush, x.Point, y.Point, width.Point, height.Point);
    }
Ejemplo n.º 9
0
 internal void Render(XUnit xPosition, XUnit yPosition, XUnit width, XUnit height)
 {
     XUnit lineWidth = GetWidth();
     if (lineWidth > 0)
     {
         XPen pen = GetPen(lineWidth);
         _gfx.DrawRectangle(pen, xPosition, yPosition, width, height);
     }
 }
Ejemplo n.º 10
0
 internal FormattedCell(Cell cell, DocumentRenderer documentRenderer, Borders cellBorders, FieldInfos fieldInfos, XUnit xOffset, XUnit yOffset)
 {
     _cell = cell;
     _fieldInfos = fieldInfos;
     _yOffset = yOffset;
     _xOffset = xOffset;
     _bordersRenderer = new BordersRenderer(cellBorders, null);
     _documentRenderer = documentRenderer;
 }
Ejemplo n.º 11
0
        public OHS_Page(PdfPage page, ProfileInfo userProfile, List<Parameter> userParameters)
        {
            this.page = page;
            this.userProfile = userProfile;

            foreach (Parameter p in userParameters)
                this.userParameters.Add(p.Name, p);

            quaterWidth = page.Width / 4;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Get line positon for current write position
        /// </summary>
        /// <param name="requestedHeight">Requested height for next line</param>
        /// <param name="requiredHeight">Required height for next line</param>
        /// <returns></returns>
        public XUnit GetLinePosition(XUnit requestedHeight, XUnit requiredHeight)
        {
            XUnit required = requiredHeight == -1f ? requestedHeight : requiredHeight;

            // Check if new line position will exceed the page limit, if then create a new page
            if (_currentPosition + required > _bottomMargin)
                CreatePage();

            XUnit result = _currentPosition;
            _currentPosition += requestedHeight;
            return result;
        }
Ejemplo n.º 13
0
        FormattedTextArea GetFormattedTextArea(TextArea area, XUnit width)
        {
            if (area == null)
                return null;

            FormattedTextArea formattedTextArea = new FormattedTextArea(_documentRenderer, area, _fieldInfos);

            if (!double.IsNaN(width))
                formattedTextArea.InnerWidth = width;

            formattedTextArea.Format(_gfx);
            return formattedTextArea;
        }
Ejemplo n.º 14
0
        void GetLeftRightVerticalPosition(out XUnit top, out XUnit bottom)
        {
            //REM: Line width is still ignored while layouting charts.
            Area contentArea = _renderInfo.LayoutInfo.ContentArea;
            ChartFormatInfo formatInfo = (ChartFormatInfo)_renderInfo.FormatInfo;
            top = contentArea.Y;

            if (formatInfo.FormattedHeader != null)
                top += formatInfo.FormattedHeader.InnerHeight;

            bottom = contentArea.Y + contentArea.Height;
            if (formatInfo.FormattedFooter != null)
                bottom -= formatInfo.FormattedFooter.InnerHeight;
        }
Ejemplo n.º 15
0
        /// <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;
            }
        }
Ejemplo n.º 16
0
        internal void Render(XUnit x, XUnit y, XUnit width, XUnit height, RoundedCorner roundedCorner)
        {
            // If there is no rounded corner, we can use the usual Render method.
            if (roundedCorner == RoundedCorner.None)
            {
                Render(x, y, width, height);
                return;
            }

            if (_shading == null || _brush == null)
                return;

            XGraphicsPath path = new XGraphicsPath();

            switch (roundedCorner)
            {
                case RoundedCorner.TopLeft:
                    path.AddArc(new XRect(x, y, width * 2, height * 2), 180, 90); // Error in CORE: _corePath.AddArc().
                    path.AddLine(new XPoint(x + width, y), new XPoint(x + width, y + height));
                    break;
                case RoundedCorner.TopRight:
                    path.AddArc(new XRect(x - width, y, width * 2, height * 2), 270, 90); // Error in CORE: _corePath.AddArc().
                    path.AddLine(new XPoint(x + width, y + height), new XPoint(x, y + height));
                    break;
                case RoundedCorner.BottomRight:
                    path.AddArc(new XRect(x - width, y - height, width * 2, height * 2), 0, 90); // Error in CORE: _corePath.AddArc().
                    path.AddLine(new XPoint(x, y + height), new XPoint(x, y));
                    break;
                case RoundedCorner.BottomLeft:
                    path.AddArc(new XRect(x, y - height, width * 2, height * 2), 90, 90); // Error in CORE: _corePath.AddArc().
                    path.AddLine(new XPoint(x, y), new XPoint(x + width, y));
                    break;
            }

            path.CloseFigure();
            _gfx.DrawPath(_brush, path);
        }
Ejemplo n.º 17
0
 void RestoreAfterProbing(ParagraphIterator paragraphIter, int blankCount, XUnit wordsWidth, XUnit xPosition, XUnit lineWidth, XUnit blankWidth)
 {
   this.currentLeaf = paragraphIter;
   this.currentBlankCount = blankCount;
   this.currentXPosition = xPosition;
   this.currentLineWidth = lineWidth;
   this.currentWordsWidth = wordsWidth;
   this.savedBlankWidth = blankWidth;
 }
Ejemplo n.º 18
0
 void SaveBeforeProbing(out ParagraphIterator paragraphIter, out int blankCount, out XUnit wordsWidth, out XUnit xPosition, out XUnit lineWidth, out XUnit blankWidth)
 {
   paragraphIter = this.currentLeaf;
   blankCount = this.currentBlankCount;
   xPosition = this.currentXPosition;
   lineWidth = this.currentLineWidth;
   wordsWidth = this.currentWordsWidth;
   blankWidth = this.savedBlankWidth;
 }
Ejemplo n.º 19
0
    /// <summary>
    /// Probes the paragraph elements after a right aligned tab stop and returns the vertical text position to start at.
    /// </summary>
    /// <param name="tabStopPosition">Position of the tab to probe.</param>
    /// <param name="notFitting">Out parameter determining whether the tab causes a line break.</param>
    /// <returns>The new x-position to restart behind the tab.</returns>
    XUnit ProbeAfterDecimalAlignedTab(XUnit tabStopPosition, out bool notFitting)
    {
      notFitting = false;
      ParagraphIterator savedLeaf = this.currentLeaf;

      //Extra for auto tab after list symbol
      if (IsTab(this.currentLeaf.Current))
        this.currentLeaf = this.currentLeaf.GetNextLeaf();
      if (this.currentLeaf == null)
      {
        this.currentLeaf = savedLeaf;
        return this.currentXPosition + tabStopPosition;
      }
      VerticalLineInfo newVerticalInfo = CalcCurrentVerticalInfo();
      Rectangle fittingRect = this.formattingArea.GetFittingRect(this.currentYPosition, newVerticalInfo.height);
      if (fittingRect == null)
      {
        notFitting = true;
        this.currentLeaf = savedLeaf;
        return this.currentXPosition;
      }

      if (IsPlainText(this.currentLeaf.Current))
      {
        Text text = (Text)this.currentLeaf.Current;
        string word = text.Content;
        int lastIndex = text.Content.LastIndexOfAny(new char[] { ',', '.' });
        if (lastIndex > 0)
          word = word.Substring(0, lastIndex);

        XUnit wordLength = MeasureString(word);
        notFitting = this.currentXPosition + wordLength >= formattingArea.X + formattingArea.Width + Tolerance;
        if (!notFitting)
          return this.formattingArea.X + tabStopPosition - wordLength;

        else
          return this.currentXPosition;
      }
      this.currentLeaf = savedLeaf;
      return ProbeAfterRightAlignedTab(tabStopPosition, out notFitting);
    }
Ejemplo n.º 20
0
 internal TabOffset(TabLeader leader, XUnit offset)
 {
   this.leader = leader;
   this.offset = offset;
 }
Ejemplo n.º 21
0
    /// <summary>
    /// Probes the paragraph elements after a right aligned tab stop and returns the vertical text position to start at.
    /// </summary>
    /// <param name="tabStopPosition">Position of the tab to probe.</param>
    /// <param name="notFitting">Out parameter determining whether the tab causes a line break.</param>
    /// <returns>The new x-position to restart behind the tab.</returns>
    XUnit ProbeAfterCenterAlignedTab(XUnit tabStopPosition, out bool notFitting)
    {
      //--- Save ---------------------------------
      ParagraphIterator iter;
      int blankCount;
      XUnit xPosition;
      XUnit lineWidth;
      XUnit wordsWidth;
      XUnit blankWidth;
      SaveBeforeProbing(out iter, out blankCount, out wordsWidth, out xPosition, out lineWidth, out blankWidth);
      //------------------------------------------

      XUnit xPositionAfterTab = xPosition;
      notFitting = ProbeAfterTab();

      if (!notFitting)
      {
        if (xPosition + this.currentLineWidth / 2.0 <= this.formattingArea.X + tabStopPosition)
        {
          Rectangle rect = this.formattingArea.GetFittingRect(this.currentYPosition, this.currentVerticalInfo.height);
          if (this.formattingArea.X + tabStopPosition + this.currentLineWidth / 2.0 > rect.X + rect.Width - this.RightIndent)
          {
            //the text is too long on the right hand side of the tabstop => align to right indent.
            xPositionAfterTab = rect.X +
              rect.Width -
              this.RightIndent -
              this.currentLineWidth;
          }
          else
            xPositionAfterTab = this.formattingArea.X + tabStopPosition - this.currentLineWidth / 2;
        }
      }

      //--- Restore ------------------------------
      RestoreAfterProbing(iter, blankCount, wordsWidth, xPosition, lineWidth, blankWidth);
      //------------------------------------------
      return xPositionAfterTab;
    }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XForm"/> class that represents a page of a PDF document.
 /// </summary>
 /// <param name="document">The PDF document.</param>
 /// <param name="width">The width of the page.</param>
 /// <param name="height">The height of the page</param>
 public XForm(PdfDocument document, XUnit width, XUnit height)
     : this(document, new XRect(0, 0, width, height))
 {
 }
Ejemplo n.º 23
0
 internal void Format(XGraphics gfx)
 {
     this.gfx = gfx;
       this.isFirstArea = true;
       this.formatter = new TopDownFormatter(this, this.documentRenderer, this.headerFooter.Elements);
       this.formatter.FormatOnAreas(gfx, false);
       this.contentHeight = RenderInfo.GetTotalHeight(GetRenderInfos());
 }
Ejemplo n.º 24
0
 void StartUnderline(XUnit xPosition)
 {
   this.underlineStartPos = xPosition;
 }
Ejemplo n.º 25
0
    void RenderUnderline(XUnit width, bool isWord)
    {
      XPen pen = GetUnderlinePen(isWord);

      bool penChanged = UnderlinePenChanged(pen);
      if (penChanged)
      {
        if (this.currentUnderlinePen != null)
          EndUnderline(this.currentUnderlinePen, this.currentXPosition);

        if (pen != null)
          StartUnderline(this.currentXPosition);

        this.currentUnderlinePen = pen;
      }

      if (this.currentLeaf.Current == this.endLeaf.Current)
      {
        if (this.currentUnderlinePen != null)
          EndUnderline(this.currentUnderlinePen, this.currentXPosition + width);

        this.currentUnderlinePen = null;
      }
    }
Ejemplo n.º 26
0
    VerticalLineInfo CalcVerticalInfo(XFont font)
    {
      ParagraphFormat paragraphFormat = this.paragraph.Format;
      LineSpacingRule spacingRule = paragraphFormat.LineSpacingRule;
      XUnit lineHeight = 0;

      XUnit descent = FontHandler.GetDescent(font);
      descent = Math.Max(this.currentVerticalInfo.descent, descent);

      XUnit singleLineSpace = font.GetHeight();
      RenderInfo imageRenderInfo = this.CurrentImageRenderInfo;
      if (imageRenderInfo != null)
        singleLineSpace = singleLineSpace - FontHandler.GetAscent(font) + imageRenderInfo.LayoutInfo.ContentArea.Height;

      XUnit inherentLineSpace = Math.Max(this.currentVerticalInfo.inherentlineSpace, singleLineSpace);
      switch (spacingRule)
      {
        case LineSpacingRule.Single:
          lineHeight = singleLineSpace;
          break;

        case LineSpacingRule.OnePtFive:
          lineHeight = 1.5 * singleLineSpace;
          break;

        case LineSpacingRule.Double:
          lineHeight = 2.0 * singleLineSpace;
          break;

        case LineSpacingRule.Multiple:
          lineHeight = this.paragraph.Format.LineSpacing * singleLineSpace;
          break;

        case LineSpacingRule.AtLeast:
          lineHeight = Math.Max(singleLineSpace, paragraph.Format.LineSpacing);
          break;

        case LineSpacingRule.Exactly:
          lineHeight = new XUnit(paragraph.Format.LineSpacing);
          inherentLineSpace = paragraph.Format.LineSpacing.Point;
          break;
      }
      lineHeight = Math.Max(this.currentVerticalInfo.height, lineHeight);
      if (this.MaxElementHeight > 0)
        lineHeight = Math.Min(this.MaxElementHeight - Renderer.Tolerance, lineHeight);

      return new VerticalLineInfo(lineHeight, descent, inherentLineSpace);
    }
Ejemplo n.º 27
0
    /// <summary>
    /// Stores all line information.
    /// </summary>
    void StoreLineInformation()
    {
      PopSavedBlankWidth();

      XUnit topBorderOffset = TopBorderOffset;
      Area contentArea = this.renderInfo.LayoutInfo.ContentArea;
      if (topBorderOffset > 0)//May only occure for the first line.
        contentArea = this.formattingArea.GetFittingRect(this.formattingArea.Y, topBorderOffset);

      if (contentArea == null)
      {
        contentArea = this.formattingArea.GetFittingRect(this.currentYPosition, this.currentVerticalInfo.height);
      }
      else
        contentArea = contentArea.Unite(this.formattingArea.GetFittingRect(this.currentYPosition, this.currentVerticalInfo.height));

      XUnit bottomBorderOffset = this.BottomBorderOffset;
      if (bottomBorderOffset > 0)
        contentArea = contentArea.Unite(this.formattingArea.GetFittingRect(this.currentYPosition + this.currentVerticalInfo.height, bottomBorderOffset));

      LineInfo lineInfo = new LineInfo();
      lineInfo.vertical = this.currentVerticalInfo;

      if (this.startLeaf != null && this.startLeaf == this.currentLeaf)
        HandleNonFittingLine();

      lineInfo.lastTab = this.lastTab;
      this.renderInfo.LayoutInfo.ContentArea = contentArea;

      lineInfo.startIter = this.startLeaf;

      if (this.currentLeaf == null)
        lineInfo.endIter = new ParagraphIterator(this.paragraph.Elements).GetLastLeaf();
      else
        lineInfo.endIter = this.currentLeaf.GetPreviousLeaf();

      lineInfo.blankCount = this.currentBlankCount;

      lineInfo.wordsWidth = this.currentWordsWidth;

      lineInfo.lineWidth = this.currentLineWidth;
      lineInfo.tabOffsets = this.tabOffsets;
      lineInfo.reMeasureLine = this.reMeasureLine;

      this.savedWordWidth = 0;
      this.reMeasureLine = false;
      ((ParagraphFormatInfo)this.renderInfo.FormatInfo).AddLineInfo(lineInfo);
    }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the XForm class such that it can be drawn on the specified graphics
 /// object.
 /// </summary>
 /// <param name="gfx">The graphics object that later is used to draw this form.</param>
 /// <param name="width">The width of the form.</param>
 /// <param name="height">The height of the form.</param>
 public XForm(XGraphics gfx, XUnit width, XUnit height)
     : this(gfx, new XSize(width, height))
 {
 }
Ejemplo n.º 29
0
        /// <summary>
        /// This member is intended to be used by XmlDomainObjectReader only.
        /// </summary>
        public static XUnit Parse(string value)
        {
            XUnit unit = value;

            return(unit);
        }
Ejemplo n.º 30
0
        XPen GetPen(XUnit width)
        {
            if (width == 0)
                return null;

            XPen pen = new XPen(GetColor(), width);
            switch (_lineFormat.DashStyle)
            {
                case DashStyle.Dash:
                    pen.DashStyle = XDashStyle.Dash;
                    break;

                case DashStyle.DashDot:
                    pen.DashStyle = XDashStyle.DashDot;
                    break;

                case DashStyle.DashDotDot:
                    pen.DashStyle = XDashStyle.DashDotDot;
                    break;

                case DashStyle.Solid:
                    pen.DashStyle = XDashStyle.Solid;
                    break;

                case DashStyle.SquareDot:
                    pen.DashStyle = XDashStyle.Dot;
                    break;
            }
            return pen;
        }
Ejemplo n.º 31
0
    void EndUnderline(XPen pen, XUnit xPosition)
    {
      //Removed KlPo 06.06.07
      //XUnit yPosition = this.currentYPosition + this.currentVerticalInfo.height + pen.Width / 2;
      //yPosition -= 0.66 * this.currentVerticalInfo.descent;

      //New KlPo 
      XUnit yPosition = CurrentBaselinePosition;
      yPosition += 0.33 * this.currentVerticalInfo.descent;
      this.gfx.DrawLine(pen, this.underlineStartPos, yPosition, xPosition, yPosition);
    }
Ejemplo n.º 32
0
 Size GetSizeOfPage(int page, out XUnit width, out XUnit height)
 {
     PageInfo pageInfo = _renderer.FormattedDocument.GetPageInfo(page);
     if (pageInfo.Orientation == PdfSharp.PageOrientation.Portrait)
     {
         width = pageInfo.Width;
         height = pageInfo.Height;
     }
     else
     {
         width = pageInfo.Height;
         height = pageInfo.Width;
     }
     return new Size(width.Presentation, height.Presentation);
 }
Ejemplo n.º 33
0
    /// <summary>
    /// Probes the paragraph elements after a right aligned tab stop and returns the vertical text position to start at.
    /// </summary>
    /// <param name="tabStopPosition">Position of the tab to probe.</param>
    /// <param name="notFitting">Out parameter determining whether the tab causes a line break.</param>
    /// <returns>The new x-position to restart behind the tab.</returns>
    XUnit ProbeAfterRightAlignedTab(XUnit tabStopPosition, out bool notFitting)
    {
      //--- Save ---------------------------------
      ParagraphIterator iter;
      int blankCount;
      XUnit xPosition;
      XUnit lineWidth;
      XUnit wordsWidth;
      XUnit blankWidth;
      SaveBeforeProbing(out iter, out blankCount, out wordsWidth, out xPosition, out lineWidth, out blankWidth);
      //------------------------------------------

      XUnit xPositionAfterTab = xPosition;

      notFitting = ProbeAfterTab();
      if (!notFitting && xPosition + this.currentLineWidth <= this.formattingArea.X + tabStopPosition)
        xPositionAfterTab = this.formattingArea.X + tabStopPosition - this.currentLineWidth;

      //--- Restore ------------------------------
      RestoreAfterProbing(iter, blankCount, wordsWidth, xPosition, lineWidth, blankWidth);
      //------------------------------------------
      return xPositionAfterTab;
    }