public ItemRectangle(ImagePrintItem item, int verticalSpacing, int horizontalSpacing) { if (item == null) { throw new ArgumentNullException("item"); } _horizontalSpacing = horizontalSpacing; _verticalSpacing = verticalSpacing; _item = item; Size size = _item.GetSize(); size.Width += _horizontalSpacing + 1 /*shared border*/; size.Height += _verticalSpacing + 1 /*shared border*/; _rect = new Rectangle(new Point(0, 0), size); _square = _rect.Width * _rect.Height; _neighbours = new ArrayList(); _hostedPositions = new ArrayList(); }
public override void FillPage(PrintPageEventArgs e, System.Collections.ArrayList items, System.Collections.ArrayList coords) { System.Diagnostics.Debug.Assert(items != null, "pItems should be allocated by caller"); System.Diagnostics.Debug.Assert(coords != null, "pCoords should be allocated by caller"); ImagePrintItem item = GetNextItem(e); if (e.Cancel == true || item == null) { e.HasMorePages = HasMorePages(); return; } int printerResolutionX, printerResolutionY; GetValidatedResolution(e, out printerResolutionX, out printerResolutionY); int pageWidth = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Width, printerResolutionX), pageHeight = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Height, printerResolutionY), marginX = PrintUtils.InchHundredthsToPixels(e.MarginBounds.X, printerResolutionX), marginY = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Y, printerResolutionY); Size pageSize = new Size(pageWidth, pageHeight); item.FitSize(pageSize, _printOptions.PlaceholderAutoRotate); Size itemSize = item.GetSize(); Point coord = new Point(); coord.X = marginX + (pageWidth - itemSize.Width) / 2; coord.Y = marginY + (pageHeight - itemSize.Height) / 2; items.Add(item); coords.Add(coord); e.HasMorePages = HasMorePages(); }
public override void FillPage(PrintPageEventArgs e, System.Collections.ArrayList items, System.Collections.ArrayList coords) { System.Diagnostics.Debug.Assert(items != null, "pItems should be allocated by caller"); System.Diagnostics.Debug.Assert(coords != null, "pCoords should be allocated by caller"); int printerResolutionX, printerResolutionY; GetValidatedResolution(e, out printerResolutionX, out printerResolutionY); ConvertSpacings(printerResolutionX, printerResolutionY); int curX = 0, curY = 0, leftMargin = PrintUtils.InchHundredthsToPixels(e.MarginBounds.X, printerResolutionX), topMargin = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Y, printerResolutionY), maxHeight = -1, pageWidth = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Width, printerResolutionX), pageHeight = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Height, printerResolutionY); Size pageSize = new Size(pageWidth, pageHeight); bool isPageFilled = false; while (!isPageFilled) { bool isRowFilled = false; maxHeight = -1; while (!isRowFilled) { ImagePrintItem item = GetNextItem(e); if (e.Cancel == true) { return; } if (item == null) { isPageFilled = true; break; } item.FitSize(pageSize, _printOptions.PlaceholderAutoRotate); Size itemSize = item.GetSize(); Size rotatedSize = item.GetSizeOfRotated(); // Trying to insert (maybe with rotation, if it allowed) int freeSpaceWidth = pageWidth - curX, freeSpaceHeight = pageHeight - curY; if (itemSize.Width <= freeSpaceWidth && itemSize.Height <= freeSpaceHeight) { // Item placed successfully items.Add(item); coords.Add(new Point(curX + leftMargin, curY + topMargin)); curX += itemSize.Width; if (itemSize.Height > maxHeight) { maxHeight = itemSize.Height; } } else if (_printOptions.PlaceholderAutoRotate && (rotatedSize.Width <= freeSpaceWidth && rotatedSize.Height <= freeSpaceHeight)) { // Item placed successfully after a 90-degree rotate. items.Add(item); coords.Add(new Point(curX + leftMargin, curY + topMargin)); item.SetSize(rotatedSize); curX += rotatedSize.Width; if (rotatedSize.Height > maxHeight) { maxHeight = rotatedSize.Height; } } else { // Item cannot be inserted into current row - putting it into // NonPlacedItems queue for trying to insert into next rows. AddToNonPlacedItems(item); isRowFilled = true; } curX += _horizontalSpacing; if (curX >= pageWidth) { isRowFilled = true; } } // Shifting to next row. If intMaxHeight == -1 - this means that // no one Item has been inserted on current step => current Item // of the queue can be placed only on next page => this page is filled. if (maxHeight == -1) { isPageFilled = true; } else { curX = 0; curY += maxHeight + _verticalSpacing; if (curY > pageHeight) { isPageFilled = true; } } } e.HasMorePages = HasMorePages(); }