public void TestDrawHorizontalLine() { var image = new IndexedImage { Size = new Size(5, 5) }; ImagePainter.DrawHorizontalLine(image, 1, 1, 5, 1, 2); AssertImage( new[] { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, image); ImagePainter.DrawHorizontalLine(image, 0, 3, 4, 2, 1); AssertImage( new[] { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0 }, image); }
void IPainter.DrawHorizontalLine(int x, int y, int length, int argb, int width) { x += Shift.Width; y += Shift.Height; if (y >= ClipRect.Top && y < ClipRect.BottomExclusive) { x = Math.Max(x, ClipRect.Left); length = Math.Min(length, ClipRect.RightExclusive - x); if (length > 0) { ImagePainter.DrawHorizontalLine(Canvas, x, y, length, argb, SupportLineWidth ? width : 1); } } }
protected override void UpdateVisualImageCore() { base.UpdateVisualImageCore(); VisualImage.Size = ImageBoxSize; ImagePainter.FillRect(VisualImage, new Rectangle(0, 0, VisualImage.Size.Width, VisualImage.Size.Height), BlackColorArgb); if (PagePrintSize.Width <= 0 || PagePrintSize.Height <= 0 || PrintSchemePagesCount.Width <= 0 || PrintSchemePagesCount.Height <= 0 || pageThumbnailSize.Width <= 0 || pageThumbnailSize.Height <= 0) { return; } var imageVisualPartSize = new Size(pageThumbnailSize.Width - PreviewPageBorder * 2, pageThumbnailSize.Height - PreviewPageBorder * 2); var pageWithMarginHeight = pageThumbnailSize.Height + PreviewPagesMargin; var startY = (VisualImage.Size.Height - pageWithMarginHeight * PrintSchemePagesCount.Height + PreviewPagesMargin) / 2; var pageWithMarginWidth = pageThumbnailSize.Width + PreviewPagesMargin; var palettePagesColumns = (PrintPalettePagesCount + PrintSchemePagesCount.Height - 1) / PrintSchemePagesCount.Height; var actualColumnsCount = PrintSchemePagesCount.Width + palettePagesColumns; var startX = (VisualImage.Size.Width - pageWithMarginWidth * actualColumnsCount) / 2; if (startX < 0) { startX = 0; } var schemePagesCount = PrintSchemePagesCount.Width * PrintSchemePagesCount.Height; for (int row = 0, y = startY, srcY = 0; row < PrintSchemePagesCount.Height; row++, y += pageWithMarginHeight, srcY += PageCellsSize.Height) { for (int col = 0, x = startX, srcX = 0; col < actualColumnsCount; col++, x += pageWithMarginWidth, srcX += PageCellsSize.Width) { var actualX = x; if (col >= PrintSchemePagesCount.Width) { actualX += PreviewPageBorder * 2; } if (col < PrintSchemePagesCount.Width && imageVisualPartSize.Width > 0 && imageVisualPartSize.Height > 0) { ImagePainter.FillRect(VisualImage, new Rectangle(actualX, y, pageThumbnailSize.Width, pageThumbnailSize.Height), WhiteColorArgb); var sourceCropRect = new Rectangle(srcX, srcY, PageCellsSize.Width, PageCellsSize.Height); if (sourceCropRect.RightExclusive > SourceImage.Size.Width) { sourceCropRect.Width = SourceImage.Size.Width - srcX; } if (sourceCropRect.BottomExclusive > SourceImage.Size.Height) { sourceCropRect.Height = SourceImage.Size.Height - srcY; } var croppedImage = ImageCropper.Crop(SourceImage, sourceCropRect); var zoomSize = new Size(sourceCropRect.Width * imageVisualPartSize.Width / PageCellsSize.Width, sourceCropRect.Height * imageVisualPartSize.Height / PageCellsSize.Height); var zoomedPartImage = new ImageResampler().Resample(croppedImage, zoomSize, ImageResampler.FilterType.Box); ImageCopier.Copy(zoomedPartImage, VisualImage, new Point(actualX + PreviewPageBorder, y + PreviewPageBorder)); PaintPageNumber(row * PrintSchemePagesCount.Width + col + 1, actualX, y); } else if (row * palettePagesColumns + col - PrintSchemePagesCount.Width + schemePagesCount < PagesCount) { ImagePainter.FillRect(VisualImage, new Rectangle(actualX, y, pageThumbnailSize.Width, pageThumbnailSize.Height), WhiteColorArgb); var lineX = actualX + PreviewPageBorder; var lineLength = pageThumbnailSize.Width / 2; var lastLineY = y + pageThumbnailSize.Height - PreviewPageBorder * 2; for (int lineY = y + PreviewPageBorder; lineY < lastLineY; lineY += 3) { ImagePainter.DrawHorizontalLine(VisualImage, lineX, lineY, lineLength, BlackColorArgb); } PaintPageNumber(schemePagesCount + row + (col - PrintSchemePagesCount.Width) * PrintSchemePagesCount.Height + 1, actualX, y); } } } }