/// <summary> /// Handle a PrintPage event. /// </summary> protected override void PrintPage(object sender, PrintPageEventArgs e) { ItemLayout currentItem; PointF startPosition; MetricHInch hInch = new MetricHInch(); if (marginTop + items[0].Size.Height <= marginBottom) throw new Exception("Cannot start to print page! Item's size + top margin exceeds bottom margin!"); startPosition = new PointF(marginLeft, marginTop); e.Graphics.PageUnit = GraphicsUnit.Millimeter; do { object element = objects[_elementCount]; GroupObjects group = element as GroupObjects; // Check if element is a group of objects if (group != null) { element = group.Next; currentItem = (ItemLayout) group.Layout; if (!group.HasNext) _elementCount++; } else { _elementCount++; currentItem = items[0]; } currentItem.Print(e.Graphics, element, startPosition); startPosition.X += gapHorizontal + currentItem.Size.Width; if (startPosition.X + currentItem.Size.Width >= hInch.Reverse(paperSize.Width) - marginRight) { startPosition.X = marginLeft; startPosition.Y += gapVertical + currentItem.Size.Height; } } while (_elementCount < objects.Count && startPosition.Y + currentItem.Size.Height <= hInch.Reverse(paperSize.Height) - marginBottom); e.HasMorePages = _elementCount < objects.Count; }
/// <summary> /// Setup page settings /// </summary> protected override void QueryPageSettings(object sender, QueryPageSettingsEventArgs e) { MetricHInch hInch = new MetricHInch(); e.PageSettings.PaperSize = paperSize; e.PageSettings.Margins.Left = (int) Math.Round(hInch.Reverse(marginLeft)); e.PageSettings.Margins.Top = (int) Math.Round(hInch.Reverse(marginTop)); //e.PageSettings.Margins.Right = (int) Math.Round(hInch.Reverse(marginRight)); //e.PageSettings.Margins.Bottom = (int) Math.Round(hInch.Reverse(marginBottom)); }
/// <summary> /// Creates a PaperSize from Xml /// </summary> internal static PaperSize CreatePaperSizeFromXml(XmlElement root, Metric metric) { MetricHInch hInch = new MetricHInch(); float width, height; PaperSize paper; if (root.HasAttribute("Metric")) metric = Metric.GetMetricParser(root.GetAttribute("Metric")); else metric = new MetricCentimeter(); width = hInch.Reverse(metric.Parse(root.GetAttribute("Width"))); height = hInch.Reverse(metric.Parse(root.GetAttribute("Height"))); paper = new PaperSize( "Custom", (int) Math.Round(width), (int) Math.Round(height)); #if DEBUG if (paper.Width < Math.Round(width) || paper.Height < Math.Round(height)) throw new Exception("DEBUG: Invalid paper size!"); #endif return paper; }