This commit is contained in:
haru-s 2024-03-03 00:53:29 +09:00
parent 44dc15f382
commit 1f1b854251

View file

@ -1,6 +1,6 @@
// printing.d // printing.d
// //
// Copyright (C) 2024 haru-s/Rayerd // Written by haru-s/Rayerd in 2024.
/// ///
module dfl.printing; module dfl.printing;
@ -404,7 +404,6 @@ class PrintPageEventArgs : EventArgs
Rect marginBounds; Rect marginBounds;
Rect pageBounds; Rect pageBounds;
PageSettings pageSettings; PageSettings pageSettings;
HDC hDC; // TODO: Remove.
int currentPage; int currentPage;
/// ///
@ -414,7 +413,6 @@ class PrintPageEventArgs : EventArgs
this.marginBounds = marginBounds; this.marginBounds = marginBounds;
this.pageBounds = pageBounds; this.pageBounds = pageBounds;
this.pageSettings = pageSettings; this.pageSettings = pageSettings;
this.hDC = graphics.handle; // TODO: Remove.
this.currentPage = currentPage; this.currentPage = currentPage;
} }
} }
@ -478,14 +476,14 @@ class StandardPrintController : PrintController
/// ///
override Graphics onStartPage(PrintDocument document, PrintPageEventArgs e) override Graphics onStartPage(PrintDocument document, PrintPageEventArgs e)
{ {
StartPage(e.hDC); StartPage(e.graphics.handle);
return e.graphics; return e.graphics;
} }
/// ///
override void onEndPage(PrintDocument document, PrintPageEventArgs e) override void onEndPage(PrintDocument document, PrintPageEventArgs e)
{ {
EndPage(e.hDC); EndPage(e.graphics.handle);
} }
} }
@ -539,12 +537,10 @@ class PrintDocument
printPageArgs = new PrintPageEventArgs(originGraphics, marginBounds, pageBounds, ps, pageCounter); printPageArgs = new PrintPageEventArgs(originGraphics, marginBounds, pageBounds, ps, pageCounter);
printPageArgs.graphics = printController.onStartPage(this, printPageArgs); // Call StartPage() API printPageArgs.graphics = printController.onStartPage(this, printPageArgs); // Call StartPage() API
printPageArgs.hDC = printPageArgs.graphics.handle; // TODO: Remove.
if(!printPageArgs.cancel) if(!printPageArgs.cancel)
this.onPrintPage(printPageArgs); this.onPrintPage(printPageArgs);
printPageArgs.hDC = hDC; // TODO: Remove.
printPageArgs.graphics = originGraphics; printPageArgs.graphics = originGraphics;
printController.onEndPage(this, printPageArgs); // Call EndPage() API printController.onEndPage(this, printPageArgs); // Call EndPage() API
@ -2206,7 +2202,7 @@ class PrintPreviewControl : Control
{ {
if (this.autoZoom) if (this.autoZoom)
{ {
const Rect screenRect = Rect(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); // NOTE: Gets MemoryGraphics size as the background DC. const Rect screenRect = Rect(0, 0, _background.width, _background.height);
const Rect paperRect = _toRect(document.printerSettings.defaultPageSettings); const Rect paperRect = _toRect(document.printerSettings.defaultPageSettings);
uint h0 = height; uint h0 = height;
@ -2522,7 +2518,7 @@ class PrintPreviewDialog : Form
class PreviewPrintController : PrintController class PreviewPrintController : PrintController
{ {
private PrintPreviewControl _previewControl; /// private PrintPreviewControl _previewControl; ///
private Graphics _pageGraphics; /// private MemoryGraphics _pageGraphics; ///
/// ///
this(PrintPreviewControl previewControl) this(PrintPreviewControl previewControl)
@ -2560,9 +2556,9 @@ class PreviewPrintController : PrintController
_pageGraphics = { _pageGraphics = {
// Be dispose() called in onEntPage(). // Be dispose() called in onEntPage().
if (e.pageBounds.width <= e.pageBounds.height) if (e.pageBounds.width <= e.pageBounds.height)
return new MemoryGraphics(paperRect.width, paperRect.height, e.hDC); return new MemoryGraphics(paperRect.width, paperRect.height, e.graphics.handle);
else else
return new MemoryGraphics(paperRect.height, paperRect.width, e.hDC); // TODO: Implement correctly. return new MemoryGraphics(paperRect.height, paperRect.width, e.graphics.handle); // TODO: Implement correctly.
}(); }();
// Draw the form of paper. // Draw the form of paper.
_pageGraphics.fillRectangle(Color.white, paperRect); _pageGraphics.fillRectangle(Color.white, paperRect);
@ -2581,7 +2577,7 @@ class PreviewPrintController : PrintController
_pageGraphics.drawText(currentPageString, font, Color.black, Rect(0, 0, 1000, 1000)); _pageGraphics.drawText(currentPageString, font, Color.black, Rect(0, 0, 1000, 1000));
// Draw the main image. // Draw the main image.
const Rect screenRect = Rect(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); // NOTE: Gets MemoryGraphics size as the background DC. const Rect screenRect = Rect(0, 0, _pageGraphics.width, _pageGraphics.height);
const Rect paperRect = _toRect(document.printerSettings.defaultPageSettings); const Rect paperRect = _toRect(document.printerSettings.defaultPageSettings);
const uint row = (e.currentPage - _previewControl.startPage - 1) % _previewControl.rows; const uint row = (e.currentPage - _previewControl.startPage - 1) % _previewControl.rows;
const uint col = (e.currentPage - _previewControl.startPage - 1) / _previewControl.rows; const uint col = (e.currentPage - _previewControl.startPage - 1) / _previewControl.rows;
@ -2626,7 +2622,7 @@ class PreviewPrintController : PrintController
SetStretchBltMode(_pageGraphics.handle, STRETCH_DELETESCANS); // SRC SetStretchBltMode(_pageGraphics.handle, STRETCH_DELETESCANS); // SRC
StretchBlt( StretchBlt(
e.hDC, // DST e.graphics.handle, // DST
PrintPreviewControl.LEFT_MARIGIN + row * (w0 + PrintPreviewControl.HORIZONTAL_SPAN), PrintPreviewControl.LEFT_MARIGIN + row * (w0 + PrintPreviewControl.HORIZONTAL_SPAN),
PrintPreviewControl.TOP_MARGIN + col * (h0 + PrintPreviewControl.VERTICAL_SPAN), PrintPreviewControl.TOP_MARGIN + col * (h0 + PrintPreviewControl.VERTICAL_SPAN),
w0, w0,