Пример #1
0
        /// <summary>
        /// Gets a rectangle for the image
        /// </summary>
        RectangleF GetImageRect(Bounds bounds, Image image, TextStyle textStyle)
        {
            SizeF maxSize = bounds.GetSizeF();
            SizeF imgSize = new SizeF(ImageWidth, ImageHeight);

            return(bounds.GetRectangleF(imgSize,
                                        SectionText.ConvertAlign(textStyle.StringAlignment),
                                        textStyle.VerticalAlignment));
        }
Пример #2
0
        /// <summary>
        /// Gets the bounds used for the actual table, that is
        /// position is the top left corner of the table (after
        /// applying margins and alignments).
        /// The width is based on
        /// this.headerSize and the border size.  The height is the full
        /// height of the bounds.
        /// </summary>
        /// <param name="bounds">Maximum bounds allowed for the table</param>
        /// <param name="size">Size required for the table</param>
        /// <returns>The bounds that the table is printed into.</returns>
        Bounds GetTableBounds(Bounds bounds, SizeF size)
        {
            // size = this.borderPens.AddBorderSize (size);
            // Find the correct x and y to center
            RectangleF rect = bounds.GetRectangleF(size,
                                                   this.HorizontalAlignment, this.VerticalAlignment);

            // Create a new bounds with no margins at the correct location
            // (centered left to right and top to bottom).
            return(new Bounds(rect.Left, rect.Top, rect.Right, rect.Bottom));
        }
Пример #3
0
        /// <summary>
        /// Paints or measures the object passed in according
        /// to the formatting rules of this column.
        /// </summary>
        /// <param name="g">the graphics to paint the value onto</param>
        /// <param name="headerRow">True if this is a header row</param>
        /// <param name="alternatingRow">True if this row is an "alternating" row (even row most likely)</param>
        /// <param name="summaryRow">True if this row is a summary row</param>
        /// <param name="drv">DataRowView to grab the cell from</param>
        /// <param name="x">the x coordinate to start the paint</param>
        /// <param name="y">the y coordinate to start the paint</param>
        /// <param name="width">the width of the cell</param>
        /// <param name="height">The max height of this cell (when in sizeOnly mode)</param>
        /// <param name="sizeOnly">only calculate the sizes</param>
        /// <returns>A sizeF representing the measured size of the string + margins</returns>
        public override SizeF SizePaintCell
        (
            Graphics g, bool headerRow, bool alternatingRow, bool summaryRow,
            DataRowView drv, float x, float y, float width,
            float height, bool sizeOnly)
        {
            if (headerRow || summaryRow)
            {
                return(base.SizePaintCell(g, headerRow, alternatingRow, summaryRow, drv, x, y, width, height, sizeOnly));
            }

            // else it's a data row...
            // TODO: Update cell count and sum???
            SizeF     cellSize  = new SizeF(width, height);
            Image     image     = GetImage(drv);
            TextStyle textStyle = GetTextStyle(headerRow, alternatingRow, summaryRow);

            float  sideMargins      = textStyle.MarginNear + textStyle.MarginFar + RightPenWidth;
            float  topBottomMargins = textStyle.MarginTop + textStyle.MarginBottom;
            Bounds bounds           = new Bounds(x, y, x + width, y + height);
            Bounds innerBounds      = bounds.GetBounds(textStyle.MarginTop,
                                                       textStyle.MarginFar + RightPenWidth, textStyle.MarginBottom, textStyle.MarginNear);
            SizeF maxSize = innerBounds.GetSizeF();

            if (sizeOnly)
            {
                if (image == null)
                {
                    cellSize.Width  = 0;
                    cellSize.Height = 0;
                }
                else
                {
                    cellSize.Width  = ImageWidth;
                    cellSize.Height = ImageHeight;
                }
            }
            else
            {
                // draw background
                if (textStyle.BackgroundBrush != null)
                {
                    g.FillRectangle(textStyle.BackgroundBrush, bounds.GetRectangleF());
                }
                // draw image
                if (image != null)
                {
                    RectangleF cellLayout = GetImageRect(innerBounds, image, textStyle);
                    g.DrawImage(image, cellLayout);
                }
            }
            return(cellSize);
        }
Пример #4
0
        /// <summary>
        /// Gets the bounds used for the actual table, that is
        /// position is the top left corner of the table (after
        /// applying margins and alignments).  The width is based on
        /// this.headerSize and the border size.  The height is the full
        /// height of the bounds.
        /// </summary>
        /// <param name="bounds">Maximum bounds allowed for the table</param>
        /// <returns>The bounds that the table is printed into.</returns>
        Bounds GetTableBounds(Bounds bounds)
        {
            // Find the correct x to center by getting a rectangle that holds the header row.
            SizeF      size = this.borderPens.AddBorderSize(this.HeaderSize);
            RectangleF rect = bounds.GetRectangleF(size,
                                                   this.HorizontalAlignment, this.VerticalAlignment);

            // Create a new bounds with no margins at the correct location
            // (centered left to right).
            return(new Bounds(rect.Left, bounds.Position.Y,
                              rect.Right, bounds.Limit.Y));
        }
Пример #5
0
        /// <summary>
        /// Gets a rectangle for the image
        /// </summary>
        RectangleF GetImageRect(Bounds bounds)
        {
            SizeF maxSize = bounds.GetSizeF();
            float scaleW  = maxSize.Width / Image.Width;
            float scaleH  = maxSize.Height / Image.Height;

            if (PreserveAspectRatio)
            {
                float scale = Math.Min(scaleW, scaleH);
                scaleW = scale;
                scaleH = scale;
            }
            float width   = scaleW * Image.Width;
            float height  = scaleH * Image.Height;
            SizeF imgSize = new SizeF(width, height);

            return(bounds.GetRectangleF(imgSize, this.HorizontalAlignment, this.VerticalAlignment));
        }
Пример #6
0
        /// <summary>
        /// Paints or measures the object passed in according
        /// to the formatting rules of this column.
        /// </summary>
        /// <param name="g">the graphics to paint the value onto</param>
        /// <param name="headerRow">True if this is a header row</param>
        /// <param name="alternatingRow">True if this row is an "alternating" row (even row most likely)</param>
        /// <param name="summaryRow">True if this row is a summary row</param>
        /// <param name="drv">DataRowView to grab the cell from</param>
        /// <param name="x">the x coordinate to start the paint</param>
        /// <param name="y">the y coordinate to start the paint</param>
        /// <param name="width">the width of the cell</param>
        /// <param name="height">The max height of this cell (when in sizeOnly mode)</param>
        /// <param name="sizeOnly">only calculate the sizes</param>
        /// <returns>A sizeF representing the measured size of the string + margins</returns>
        public virtual SizeF SizePaintCell
        (
            Graphics g, bool headerRow, bool alternatingRow, bool summaryRow,
            DataRowView drv, float x, float y, float width,
            float height, bool sizeOnly)
        {
            // TODO: Break up this function
            SizeF        stringSize   = new SizeF(width, height);
            string       text         = GetString(headerRow, summaryRow, drv);
            TextStyle    textStyle    = GetTextStyle(headerRow, alternatingRow, summaryRow);
            Font         font         = textStyle.GetFont();
            StringFormat stringFormat = textStyle.GetStringFormat();

            float  sideMargins      = textStyle.MarginNear + textStyle.MarginFar + RightPenWidth;
            float  topBottomMargins = textStyle.MarginTop + textStyle.MarginBottom;
            Bounds bounds           = new Bounds(x, y, x + width, y + height);
            Bounds innerBounds      = bounds.GetBounds(textStyle.MarginTop,
                                                       textStyle.MarginFar + RightPenWidth, textStyle.MarginBottom, textStyle.MarginNear);
            SizeF maxSize = innerBounds.GetSizeF();

            if (sizeOnly)
            {
                // Find the height of the actual string to be drawn
                stringSize         = g.MeasureString(text, font, maxSize, stringFormat);
                stringSize.Width  += sideMargins;
                stringSize.Height += topBottomMargins;
                // Don't go bigger than maxHeight
                stringSize.Height = Math.Min(stringSize.Height, height);
            }
            else
            {
                // draw background & text
                if (textStyle.BackgroundBrush != null)
                {
                    g.FillRectangle(textStyle.BackgroundBrush, bounds.GetRectangleF());
                }
                RectangleF textLayout = innerBounds.GetRectangleF(stringSize,
                                                                  SectionText.ConvertAlign(textStyle.StringAlignment),
                                                                  textStyle.VerticalAlignment);
                g.DrawString(text, font, textStyle.Brush, textLayout, stringFormat);
            }
            return(stringSize);
        }
Пример #7
0
        /// <summary>
        /// Called to calculate the size that this section requires on
        /// the next call to Print.  This method will be called exactly once
        /// prior to each call to Print.  It must update the values Size and
        /// Continued of the ReportSection base class.
        /// </summary>
        /// <param name="reportDocument">Pparent ReportDocument that is printing.</param>
        /// <param name="g">Graphics object to print on.</param>
        /// <param name="bounds">Bounds of the area to print within.</param>
        /// <returns>SectionSizeValues</returns>
        protected override SectionSizeValues DoCalcSize(
            ReportDocument reportDocument,
            Graphics g,
            Bounds bounds
            )
        {
            SectionSizeValues retval = new SectionSizeValues();

            textFont   = this.TextStyle.GetFont();
            textLayout = bounds.GetRectangleF();
            if (CheckTextLayout(g))
            {
                // Get a new string starting from where-ever we left off on the last page
                textToPrint = GetText(reportDocument);
                retval      = SetTextSize(reportDocument, g, bounds);
            }
            else
            {
                retval.Fits = false;
            }
            return(retval);
        }
Пример #8
0
        /// <summary>
        /// Sets the TextLayout rectangle to the correct size
        /// Also sets size, itFits, and continued of the base class
        /// </summary>
        /// <param name="doc">The parent ReportDocument</param>
        /// <param name="g">Graphics object</param>
        /// <param name="bounds">Bounds to draw within</param>
        /// <returns>SectionSizeValues</returns>
        SectionSizeValues SetTextSize(ReportDocument doc, Graphics g, Bounds bounds)
        {
            SectionSizeValues retval = new SectionSizeValues();

            retval.Fits = true;

            // Find the height of the actual string + margins to be drawn
            SizeF requiredSize = g.MeasureString(textToPrint, textFont,
                                                 textLayout.Size, GetStringFormat(), out charsFitted, out linesFitted);

            if (charsFitted < textToPrint.Length)
            {
                // it doesn't all fit.
                if (this.KeepTogether)
                {
                    // try on the next page.
                    // HACK: This is bad if the whole section doesn't
                    // ever fit on a page, since it will end up in an infinite loop.
                    retval.Fits = false;
                    charsFitted = 0;
                    linesFitted = 0;
                    return(retval);
                }
                retval.Continued = true;
            }

            // Get a new rectangle aligned within the bounds and margins
            textLayout = bounds.GetRectangleF(requiredSize,
                                              this.HorizontalAlignment, this.VerticalAlignment);
            retval.RequiredSize = textLayout.Size;

            if (debugEnabled)
            {
                Console.WriteLine("Layout for string '" + textToPrint + "' is " + textLayout);
            }

            return(retval);
        }
Пример #9
0
 /// <summary>
 /// Draws a border inside the given bounds
 /// </summary>
 /// <param name="g">Graphics object to print on</param>
 /// <param name="bounds">Outer bounds of the border</param>
 public void DrawBorder(Graphics g, Bounds bounds)
 {
     RectangleF rect = bounds.GetRectangleF();
     DrawBorder (g, rect);
 }
Пример #10
0
        /// <summary>
        /// Sets the TextLayout rectangle to the correct size
        /// Also sets size, itFits, and continued of the base class
        /// </summary>
        /// <param name="doc">The parent ReportDocument</param>
        /// <param name="g">Graphics object</param>
        /// <param name="bounds">Bounds to draw within</param>
        /// <returns>SectionSizeValues</returns>
        SectionSizeValues SetTextSize(ReportDocument doc, Graphics g, Bounds bounds)
        {
            SectionSizeValues retval = new SectionSizeValues();
            retval.Fits = true;

            // Find the height of the actual string + margins to be drawn
            SizeF requiredSize = g.MeasureString(textToPrint, textFont,
                textLayout.Size, GetStringFormat(), out charsFitted, out linesFitted);

            if (charsFitted < textToPrint.Length)
            {
                // it doesn't all fit.
                if (this.KeepTogether)
                {
                    // try on the next page.
                    // HACK: This is bad if the whole section doesn't
                    // ever fit on a page, since it will end up in an infinite loop.
                    retval.Fits = false;
                    charsFitted = 0;
                    linesFitted = 0;
                    return retval;
                }
                retval.Continued = true;
            }

            if (this.HorizontalAlignment != HorizontalAlignment.Left)
                requiredSize.Width = textLayout.Size.Width;

            // Get a new rectangle aligned within the bounds and margins
            textLayout = bounds.GetRectangleF(requiredSize,
                this.HorizontalAlignment, this.VerticalAlignment);
            retval.RequiredSize = textLayout.Size;

            if (debugEnabled)
            {
                Console.WriteLine ("Layout for string '" + textToPrint + "' is " + textLayout);
            }

            return retval;
        }
Пример #11
0
 /// <summary>
 /// Called to calculate the size that this section requires on
 /// the next call to Print.  This method will be called exactly once
 /// prior to each call to Print.  It must update the values Size and
 /// Continued of the ReportSection base class.
 /// </summary>
 /// <param name="reportDocument">Pparent ReportDocument that is printing.</param>
 /// <param name="g">Graphics object to print on.</param>
 /// <param name="bounds">Bounds of the area to print within.</param>
 /// <returns>SectionSizeValues</returns>
 protected override SectionSizeValues DoCalcSize(
     ReportDocument reportDocument,
     Graphics g,
     Bounds bounds
     )
 {
     SectionSizeValues retval = new SectionSizeValues();
     textFont = this.TextStyle.GetFont();
     textLayout = bounds.GetRectangleF();
     if (CheckTextLayout(g))
     {
         // Get a new string starting from where-ever we left off on the last page
         textToPrint = GetText(reportDocument);
         retval = SetTextSize (reportDocument, g, bounds);
     }
     else
     {
         retval.Fits = false;
     }
     return retval;
 }
Пример #12
0
        /// <summary>
        /// Paints or measures the object passed in according 
        /// to the formatting rules of this column.
        /// </summary>
        /// <param name="g">the graphics to paint the value onto</param>
        /// <param name="text">the text to paint</param>
        /// <param name="textStyle">the textStyle to use to paint the text</param>
        /// <param name="x">the x coordinate to start the paint</param>
        /// <param name="y">the y coordinate to start the paint</param>
        /// <param name="width">the width of the cell</param>
        /// <param name="height">The max height of this cell (when in sizeOnly mode)</param>
        /// <param name="sizeOnly">only calculate the sizes</param>
        /// <returns>A sizeF representing the measured size of the string + margins</returns>
        public virtual SizeF SizePaintCell( 
			Graphics g, string text, TextStyle textStyle,
			float x, float y, float width,
			float height, bool sizeOnly)
        {
            SizeF stringSize = new SizeF(width, height);
            Font font = textStyle.GetFont();
            StringFormat stringFormat = textStyle.GetStringFormat();

            float sideMargins = textStyle.MarginNear + textStyle.MarginFar + RightPenWidth;
            float topBottomMargins = textStyle.MarginTop + textStyle.MarginBottom;
            Bounds bounds = new Bounds (x, y, x + width, y + height);
            Bounds innerBounds = bounds.GetBounds (textStyle.MarginTop,
                textStyle.MarginFar + RightPenWidth, textStyle.MarginBottom, textStyle.MarginNear);
            SizeF maxSize = innerBounds.GetSizeF();

            if (sizeOnly)
            {
                // Find the height of the actual string to be drawn
                stringSize = g.MeasureString(text, font, maxSize, stringFormat);
                stringSize.Width += sideMargins;
                stringSize.Height += topBottomMargins;
                // Don't go bigger than maxHeight
                stringSize.Height = Math.Min (stringSize.Height, height);
            }
            else
            {
                // draw background & text
                if (textStyle.BackgroundBrush != null)
                {
                    g.FillRectangle (textStyle.BackgroundBrush, bounds.GetRectangleF());
                }
                RectangleF textLayout = innerBounds.GetRectangleF (stringSize,
                    SectionText.ConvertAlign (textStyle.StringAlignment),
                    textStyle.VerticalAlignment);
                g.DrawString(text, font, textStyle.Brush, textLayout, stringFormat);
            }
            return stringSize;
        }
Пример #13
0
        /// <summary>
        /// Gets the bounds used for the actual table, that is
        /// position is the top left corner of the table (after
        /// applying margins and alignments).
        /// The width is based on
        /// this.headerSize and the border size.  The height is the full 
        /// height of the bounds.
        /// </summary>
        /// <param name="bounds">Maximum bounds allowed for the table</param>
        /// <param name="size">Size required for the table</param>
        /// <returns>The bounds that the table is printed into.</returns>
        Bounds GetTableBounds(Bounds bounds, SizeF size)
        {
            // size = this.borderPens.AddBorderSize (size);
            // Find the correct x and y to center
            RectangleF rect = bounds.GetRectangleF (size,
                this.HorizontalAlignment, this.VerticalAlignment);

            // Create a new bounds with no margins at the correct location
            // (centered left to right and top to bottom).
            return new Bounds (rect.Left, rect.Top, rect.Right, rect.Bottom);
        }
Пример #14
0
        /// <summary>
        /// Gets the bounds used for the actual table, that is
        /// position is the top left corner of the table (after
        /// applying margins and alignments).  The width is based on
        /// this.headerSize and the border size.  The height is the full 
        /// height of the bounds.
        /// </summary>
        /// <param name="bounds">Maximum bounds allowed for the table</param>
        /// <returns>The bounds that the table is printed into.</returns>
        Bounds GetTableBounds(Bounds bounds)
        {
            // Find the correct x to center by getting a rectangle that holds the header row.
            SizeF size = this.borderPens.AddBorderSize (this.HeaderSize);
            RectangleF rect = bounds.GetRectangleF (size,
                this.HorizontalAlignment, this.VerticalAlignment);

            // Create a new bounds with no margins at the correct location
            // (centered left to right).
            return new Bounds (rect.Left, bounds.Position.Y,
                rect.Right, bounds.Limit.Y);
        }
Пример #15
0
        /// <summary>
        /// Gets a rectangle for the image
        /// </summary>
        RectangleF GetImageRect(Bounds bounds, Image image, TextStyle textStyle)
        {
            SizeF maxSize = bounds.GetSizeF();
            SizeF imgSize = new SizeF (ImageWidth, ImageHeight);

            return bounds.GetRectangleF (imgSize,
                SectionText.ConvertAlign (textStyle.StringAlignment),
                textStyle.VerticalAlignment);
        }
Пример #16
0
        /// <summary>
        /// Paints or measures the object passed in according 
        /// to the formatting rules of this column.
        /// </summary>
        /// <param name="g">the graphics to paint the value onto</param>
        /// <param name="headerRow">True if this is a header row</param>
        /// <param name="alternatingRow">True if this row is an "alternating" row (even row most likely)</param>
        /// <param name="summaryRow">True if this row is a summary row</param>
        /// <param name="drv">DataRowView to grab the cell from</param>
        /// <param name="x">the x coordinate to start the paint</param>
        /// <param name="y">the y coordinate to start the paint</param>
        /// <param name="width">the width of the cell</param>
        /// <param name="height">The max height of this cell (when in sizeOnly mode)</param>
        /// <param name="sizeOnly">only calculate the sizes</param>
        /// <returns>A sizeF representing the measured size of the string + margins</returns>
        public override SizeF SizePaintCell( 
			Graphics g, bool headerRow, bool alternatingRow, bool summaryRow,
			DataRowView drv, float x, float y, float width,
			float height, bool sizeOnly)
        {
            if (headerRow || summaryRow)
            {
                return base.SizePaintCell (g, headerRow, alternatingRow, summaryRow, drv, x, y, width, height, sizeOnly);
            }

            // else it's a data row...
            // TODO: Update cell count and sum???
            SizeF cellSize = new SizeF(width, height);
            Image image = GetImage (drv);
            TextStyle textStyle = GetTextStyle (headerRow, alternatingRow, summaryRow);

            float sideMargins = textStyle.MarginNear + textStyle.MarginFar + RightPenWidth;
            float topBottomMargins = textStyle.MarginTop + textStyle.MarginBottom;
            Bounds bounds = new Bounds (x, y, x + width, y + height);
            Bounds innerBounds = bounds.GetBounds (textStyle.MarginTop,
                textStyle.MarginFar + RightPenWidth, textStyle.MarginBottom, textStyle.MarginNear);
            SizeF maxSize = innerBounds.GetSizeF();

            if (sizeOnly)
            {
                if (image == null)
                {
                    cellSize.Width = 0;
                    cellSize.Height = 0;
                }
                else
                {
                    cellSize.Width = ImageWidth;
                    cellSize.Height = ImageHeight;
                }
            }
            else
            {
                // draw background
                if (textStyle.BackgroundBrush != null)
                {
                    g.FillRectangle (textStyle.BackgroundBrush, bounds.GetRectangleF());
                }
                // draw image
                if (image != null)
                {
                    RectangleF cellLayout = GetImageRect (innerBounds, image, textStyle);
                    g.DrawImage (image, cellLayout);
                }
            }
            return cellSize;
        }
Пример #17
0
        /// <summary>
        /// Draws a border inside the given bounds
        /// </summary>
        /// <param name="g">Graphics object to print on</param>
        /// <param name="bounds">Outer bounds of the border</param>
        public void DrawBorder(Graphics g, Bounds bounds)
        {
            RectangleF rect = bounds.GetRectangleF();

            DrawBorder(g, rect);
        }
Пример #18
0
        /// <summary>
        /// Gets a rectangle for the image
        /// </summary>
        RectangleF GetImageRect(Bounds bounds)
        {
            SizeF maxSize = bounds.GetSizeF();
            float scaleW = maxSize.Width / Image.Width;
            float scaleH = maxSize.Height / Image.Height;
            if (PreserveAspectRatio)
            {
                float scale = Math.Min(scaleW, scaleH);
                scaleW = scale;
                scaleH = scale;
            }
            float width = scaleW * Image.Width;
            float height = scaleH * Image.Height;
            SizeF imgSize = new SizeF (width, height);

            return bounds.GetRectangleF (imgSize, this.HorizontalAlignment, this.VerticalAlignment);
        }