Example #1
0
		/// <summary>
		/// Get the scale factor and the start location of an docoment onto a page.
		/// </summary>
		/// <param name="PageBounds">Bounds of the page in 1/100 inch.</param>
		/// <param name="MarginBounds">Margins of the page in 1/100 inch.</param>
		/// <param name="graphSize">Size of the document in 1/72 inch.</param>
		/// <param name="zoom">Returns the zoom factor to use for the document.</param>
		/// <param name="startLocationOnPage">Returns the start location onto the page in 1/100 inch.</param>
		/// <param name="usePrintingUnits">If <c>true</c> use printing units (1/100 inch) instead of points.</param>
		public void GetZoomAndStartLocation(RectangleF PageBounds, RectangleF MarginBounds, SizeF graphSize, out float zoom, out PointF startLocationOnPage, bool usePrintingUnits)
		{
			// First the size of the graph
			// if a fixed zoom factor is set, we use that

			if (usePrintingUnits) // recalculate everything in units of points (1/72 inch)
			{
				PageBounds = PageBounds.Scale(72.0 / 100);
				MarginBounds = MarginBounds.Scale(72.0 / 100);
			}

			zoom = 1;
			if (this.UseFixedZoomFactor)
			{
				zoom = (float)this.ZoomFactor;
			}
			else if (this.FitGraphToPrintIfSmaller || this.FitGraphToPrintIfLarger)
			{
				float zoomx = MarginBounds.Width / graphSize.Width;
				float zoomy = MarginBounds.Height / graphSize.Height;
				if (zoomx > 1 && zoomy > 1 && this.FitGraphToPrintIfSmaller)
				{
					zoom = Math.Min(zoomx, zoomy);
				}
				else if ((zoomx < 1 || zoomy < 1) && this.FitGraphToPrintIfLarger)
				{
					zoom = Math.Min(zoomx, zoomy);
				}
			}
			graphSize.Width *= zoom;
			graphSize.Height *= zoom;

			// First the location where to start from
			startLocationOnPage = PointF.Empty;
			switch (this.PrintLocation)
			{
				case SingleGraphPrintLocation.PrintableAreaLeftUpper:
					startLocationOnPage = MarginBounds.Location;
					break;

				case SingleGraphPrintLocation.PageLeftUpper:
					startLocationOnPage = new PointF(0, 0);
					break;

				case SingleGraphPrintLocation.PrintableAreaCenter:
					startLocationOnPage = MarginBounds.Center() - graphSize.Half();
					break;

				case SingleGraphPrintLocation.PageCenter:
					startLocationOnPage = PageBounds.Center() - graphSize.Half();
					break;
			}

			if (usePrintingUnits)
			{
				startLocationOnPage = startLocationOnPage.Scale(100.0 / 72);
			}
		}