/// <summary> /// Called to calculate the size that this section requires on /// the next call to Print. This method will be called once /// prior to each call to Print. /// </summary> /// <param name="reportDocument">The parent ReportDocument that is printing.</param> /// <param name="g">Graphics object to print on.</param> /// <param name="bounds">Bounds of the area to print within. /// The bounds passed already takes the margins into account - so you cannot /// print or do anything within these margins. /// </param> /// <returns>The values for RequireSize, Fits and Continues for this section.</returns> protected override SectionSizeValues DoCalcSize( ReportDocument reportDocument, Graphics g, Bounds bounds ) { // Take offset into account... bounds.Position.X += OffsetLeft; bounds.Position.Y += OffsetTop; SectionSizeValues retval = new SectionSizeValues(); // need to determine what to do with these values... retval.Fits = true; retval.Continued = false; SizeF contentSize = new SizeF(0, 0); if (CurrentSection != null) { CurrentSection.CalcSize(reportDocument, g, GetMaxContentBounds(bounds)); contentSize = CurrentSection.Size; // or could use RequiredSize? } this.borderBounds = GetBorderBounds(bounds, contentSize); this.paddingBounds = border.GetInnerBounds(this.borderBounds); this.contentBounds = paddingBounds.GetBounds(PaddingTop, PaddingRight, PaddingBottom, PaddingLeft); retval.RequiredSize = this.borderBounds.GetSizeF(); return(retval); }
/// <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); }
/// <summary> /// Limits a bounds down to MaxWidth and MaxHeight /// </summary> Bounds LimitBounds(Bounds bounds) { if ((this.MaxWidth > 0) && (bounds.Width > this.MaxWidth)) { bounds.Limit.X = bounds.Position.X + this.MaxWidth; } if ((this.MaxHeight > 0) && (bounds.Height > this.MaxHeight)) { bounds.Limit.Y = bounds.Position.Y + this.MaxHeight; } // Take margins into account bounds = bounds.GetBounds(this.MarginTop, this.MarginRight, this.MarginBottom, this.MarginLeft); return(bounds); }
/// <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); }
/// <summary> /// Called to actually print this section. /// The DoCalcSize method will be called exactly once prior to each /// call of DoPrint. /// It should obey the value or Size and Continued as set by /// DoCalcSize(). /// </summary> /// <param name="reportDocument">The parent 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> protected override void DoPrint( ReportDocument reportDocument, Graphics g, Bounds bounds ) { SizeF mySize = new SizeF(0, 0); if (ShowDividerFirst && (Divider != null)) { divider.Print(reportDocument, g, bounds); AdvancePointers(divider.Size, ref bounds, ref mySize); } // size first SectionSizeValues oneCall = SizePrintLine(reportDocument, g, bounds, true, false); bool fits = oneCall.Fits; while (oneCall.Fits) { Bounds printBounds = bounds.GetBounds(oneCall.RequiredSize); SizePrintLine(reportDocument, g, printBounds, false, true); // print AdvancePointers(oneCall.RequiredSize, ref bounds, ref mySize); // if this section is not continued, quit now if (!oneCall.Continued) { break; } if (Divider != null) { divider.Print(reportDocument, g, bounds); AdvancePointers(divider.Size, ref bounds, ref mySize); } oneCall = SizePrintLine(reportDocument, g, bounds, true, false); // size } SetSize(mySize, bounds); SetFits(fits); SetContinued(oneCall.Continued); }
/// <summary> /// Gets the BorderBounds based on the bounds inside /// the margins, /// using Width and Height, UseFullWidth and UseFullHeight, /// and optinally the contentSize (if non-zero) /// </summary> Bounds GetBorderBounds(Bounds bounds, SizeF contentSize) { SizeF borderSize = bounds.GetSizeF(); if (SizeToContentsWidth) { borderSize.Width = contentSize.Width + PaddingLeft + PaddingRight + this.border.LeftWidth + this.border.RightWidth; } else { float widthToUse = Width; if (WidthPercent > 0) { widthToUse = bounds.Width * (WidthPercent / 100); } borderSize.Width = widthToUse - MarginLeft - MarginRight; } if (SizeToContentsHeight) { borderSize.Height = contentSize.Height + PaddingTop + PaddingBottom + this.border.LeftWidth + this.border.RightWidth; } else { float heightToUse = Height; if (HeightPercent > 0) { heightToUse = bounds.Height * (HeightPercent / 100); } borderSize.Height = heightToUse - MarginTop - MarginBottom; } Bounds borderBounds = bounds.GetBounds(borderSize, this.HorizontalAlignment, this.VerticalAlignment); return(borderBounds); }
/// <summary> /// Limits a bounds down to MaxWidth and MaxHeight /// </summary> Bounds LimitBounds(Bounds bounds) { if ((this.MaxWidth > 0) && (bounds.Width > this.MaxWidth)) { bounds.Limit.X = bounds.Position.X + this.MaxWidth; } if ((this.MaxHeight > 0) && (bounds.Height > this.MaxHeight)) { bounds.Limit.Y = bounds.Position.Y + this.MaxHeight; } // Take margins into account bounds = bounds.GetBounds (this.MarginTop, this.MarginRight, this.MarginBottom, this.MarginLeft); return bounds; }
/// <summary> /// Called to actually print this section. /// The DoCalcSize method will be called exactly once prior to each /// call of DoPrint. /// It should obey the value or Size and Continued as set by /// DoCalcSize(). /// </summary> /// <param name="reportDocument">The parent 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> protected override void DoPrint( ReportDocument reportDocument, Graphics g, Bounds bounds ) { SizeF mySize = new SizeF (0,0); if (ShowDividerFirst && (Divider != null)) { divider.Print (reportDocument, g, bounds); AdvancePointers (divider.Size, ref bounds, ref mySize); } // size first SectionSizeValues oneCall = SizePrintLine (reportDocument, g, bounds, true, false); bool fits = oneCall.Fits; while (oneCall.Fits) { Bounds printBounds = bounds.GetBounds (oneCall.RequiredSize); SizePrintLine (reportDocument, g, printBounds, false, true); // print AdvancePointers (oneCall.RequiredSize, ref bounds, ref mySize); // if this section is not continued, quit now // or if this was the last column/row on this page, quit now if (!oneCall.Continued || bounds.IsEmpty()) { break; } oneCall = SizePrintLine (reportDocument, g, bounds, true, false); // size if ( oneCall.Fits && Divider != null) { divider.Print (reportDocument, g, bounds); AdvancePointers (divider.Size, ref bounds, ref mySize); } } SetSize (mySize, bounds); SetFits (fits); SetContinued (oneCall.Continued); }
/// <summary> /// Gets the BorderBounds based on the bounds inside /// the margins, /// using Width and Height, UseFullWidth and UseFullHeight, /// and optinally the contentSize (if non-zero) /// </summary> Bounds GetBorderBounds(Bounds bounds, SizeF contentSize) { SizeF borderSize = bounds.GetSizeF(); if (SizeToContentsWidth) { borderSize.Width = contentSize.Width + PaddingLeft + PaddingRight + this.border.LeftWidth + this.border.RightWidth; } else { float widthToUse = Width; if (WidthPercent > 0) { widthToUse = bounds.Width * (WidthPercent / 100); } borderSize.Width = widthToUse - MarginLeft - MarginRight; } if (SizeToContentsHeight) { borderSize.Height = contentSize.Height + PaddingTop + PaddingBottom + this.border.LeftWidth + this.border.RightWidth; } else { float heightToUse = Height; if (HeightPercent > 0) { heightToUse = bounds.Height * (HeightPercent / 100); } borderSize.Height = heightToUse - MarginTop - MarginBottom; } Bounds borderBounds = bounds.GetBounds (borderSize, this.HorizontalAlignment, this.VerticalAlignment); return borderBounds; }
/// <summary> /// Called to calculate the size that this section requires on /// the next call to Print. This method will be called once /// prior to each call to Print. /// </summary> /// <param name="reportDocument">The parent ReportDocument that is printing.</param> /// <param name="g">Graphics object to print on.</param> /// <param name="bounds">Bounds of the area to print within. /// The bounds passed already takes the margins into account - so you cannot /// print or do anything within these margins. /// </param> /// <returns>The values for RequireSize, Fits and Continues for this section.</returns> protected override SectionSizeValues DoCalcSize( ReportDocument reportDocument, Graphics g, Bounds bounds ) { // Take offset into account... bounds.Position.X += OffsetLeft; bounds.Position.Y += OffsetTop; SectionSizeValues retval = new SectionSizeValues(); // need to determine what to do with these values... retval.Fits = true; retval.Continued = false; SizeF contentSize = new SizeF (0,0); if (CurrentSection != null) { CurrentSection.CalcSize (reportDocument, g, GetMaxContentBounds(bounds)); contentSize = CurrentSection.Size; // or could use RequiredSize? } this.borderBounds = GetBorderBounds (bounds, contentSize); this.paddingBounds = border.GetInnerBounds (this.borderBounds); this.contentBounds = paddingBounds.GetBounds (PaddingTop, PaddingRight, PaddingBottom, PaddingLeft); retval.RequiredSize = this.borderBounds.GetSizeF(); return retval; }
/// <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; }
/// <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; }
/// <summary> /// The actual method to print a page /// </summary> /// <param name="e">PrintPageEventArgs</param> /// <param name="sizeOnly">Indicates that only sizing is done</param> /// <returns>True if there are more pages</returns> protected virtual bool PrintAPage(PrintPageEventArgs e, bool sizeOnly) { #if BYPASS_PRINTABLE_AREA_LOGIC Graphics g = e.Graphics; g.PageUnit = DocumentUnit; // Define page bounds (margins are always in inches) float scale = GetScale() / 100; // Bypass "tricky" page margins that take into account printer limits float leftMargin = e.MarginBounds.Left * scale; float topMargin = e.MarginBounds.Top * scale; float rightMargin = e.MarginBounds.Right * scale; float bottomMargin = e.MarginBounds.Bottom * scale; Bounds pageBounds = new Bounds(leftMargin, topMargin, rightMargin, bottomMargin); #else Graphics g = e.Graphics; g.PageUnit = DocumentUnit; // Define page bounds (margins are always in inches) float scale = GetScale() / 100; IntPtr hDc = e.Graphics.GetHdc(); PrinterMarginInfo mi = new PrinterMarginInfo(hDc.ToInt32()); e.Graphics.ReleaseHdc(hDc); Bounds pageBounds = mi.GetBounds(e.PageBounds, e.MarginBounds, scale); #endif // Header if (this.PageHeader != null) { Bounds headerBounds = pageBounds; if (this.PageHeaderMaxHeight > 0) { headerBounds.Limit.Y = headerBounds.Position.Y + this.PageHeaderMaxHeight; } this.PageHeader.Print(this, g, headerBounds); pageBounds.Position.Y += this.PageHeader.Size.Height; } // Footer if (this.PageFooter != null) { Bounds footerBounds = pageBounds; if (this.PageFooterMaxHeight > 0) { footerBounds.Position.Y = footerBounds.Limit.Y - this.PageFooterMaxHeight; } this.PageFooter.CalcSize(this, g, footerBounds); footerBounds = footerBounds.GetBounds(this.PageFooter.Size, this.PageFooter.HorizontalAlignment, this.PageFooter.VerticalAlignment); this.PageFooter.Print(this, g, footerBounds); pageBounds.Limit.Y -= this.PageFooter.Size.Height; } // Body if (this.Body != null) { this.Body.Print(this, g, pageBounds); e.HasMorePages = this.Body.Continued; } else { e.HasMorePages = false; } return(e.HasMorePages); } // OnPrintPage