better print bug fix

This commit is contained in:
GenevensiS
2025-06-01 23:00:29 +02:00
parent 2e48c5e868
commit 0d1b5a6be0
+8 -11
View File
@@ -103,7 +103,7 @@ void CardsPrintout::OnPreparePrinting() {
bool CardsPrintout::OnPrintPage(int page) { bool CardsPrintout::OnPrintPage(int page) {
DC& dc = *GetDC(); DC& dc = *GetDC();
// scale factors // scale factors (pixels per mm)
int pw_mm, ph_mm; int pw_mm, ph_mm;
GetPageSizeMM(&pw_mm, &ph_mm); GetPageSizeMM(&pw_mm, &ph_mm);
int pw_px, ph_px; int pw_px, ph_px;
@@ -122,12 +122,12 @@ bool CardsPrintout::OnPrintPage(int page) {
void CardsPrintout::drawCard(DC& dc, const CardP& card, int card_nr) { void CardsPrintout::drawCard(DC& dc, const CardP& card, int card_nr) {
const StyleSheet& stylesheet = job->set->stylesheetFor(card); const StyleSheet& stylesheet = job->set->stylesheetFor(card);
// determine dpi factor for this card // determine dpi factor for this card
double dpi_factor = stylesheet.card_dpi / job->layout.card_dpi; double px_per_mm = stylesheet.card_dpi / 25.4;
// determine position // determine position
int col = card_nr % job->layout.cols; int col = card_nr % job->layout.cols;
int row = card_nr / job->layout.cols; int row = card_nr / job->layout.cols;
RealPoint pos((job->layout.margin_left + (job->layout.card_size.width + job->layout.card_spacing.width) * col) * dpi_factor RealPoint pos((job->layout.margin_left + (job->layout.card_size.width + job->layout.card_spacing.width) * col) / scale_x * px_per_mm
,(job->layout.margin_top + (job->layout.card_size.height + job->layout.card_spacing.height) * row) * dpi_factor); ,(job->layout.margin_top + (job->layout.card_size.height + job->layout.card_spacing.height) * row) / scale_y * px_per_mm);
// determine rotation // determine rotation
Radians rotation = 0; Radians rotation = 0;
if ((stylesheet.card_width > stylesheet.card_height) != job->layout.card_landscape) { if ((stylesheet.card_width > stylesheet.card_height) != job->layout.card_landscape) {
@@ -137,28 +137,25 @@ void CardsPrintout::drawCard(DC& dc, const CardP& card, int card_nr) {
// size of this particular card (in mm) // size of this particular card (in mm)
RealSize card_size( stylesheet.card_width * 25.4 / stylesheet.card_dpi RealSize card_size( stylesheet.card_width * 25.4 / stylesheet.card_dpi
, stylesheet.card_height * 25.4 / stylesheet.card_dpi); , stylesheet.card_height * 25.4 / stylesheet.card_dpi);
if (is_rad90(rotation)) swap(card_size.width, card_size.height); if (is_rad90(rotation)) swap(card_size.width, card_size.height);
// adjust card size, to center card in the available space (from job->layout.card_size)? // adjust card size, to center card in the available space (from job->layout.card_size)?
// TODO: deal with different sized cards in general // TODO: deal with different sized cards in general
*/ */
// create buffers // create buffers
int w = int(stylesheet.card_width), h = int(stylesheet.card_height); // in pixels int w = int(stylesheet.card_width), h = int(stylesheet.card_height); // in pixels
if (is_rad90(rotation)) swap(w,h); if (is_rad90(rotation)) swap(w,h);
// Draw using text buffer // Draw using text buffer
double zoom = 4; wxBitmap buffer(w,h,32);
wxBitmap buffer(w*zoom,h*zoom,32);
wxMemoryDC bufferDC; wxMemoryDC bufferDC;
bufferDC.SelectObject(buffer); bufferDC.SelectObject(buffer);
clearDC(bufferDC,*wxWHITE_BRUSH); clearDC(bufferDC,*wxWHITE_BRUSH);
RotatedDC rdc(bufferDC, rotation, stylesheet.getCardRect(), zoom, QUALITY_AA, ROTATION_ATTACH_TOP_LEFT); RotatedDC rdc(bufferDC, rotation, stylesheet.getCardRect(), 1.0, QUALITY_AA, ROTATION_ATTACH_TOP_LEFT);
// render card to dc // render card to dc
viewer.setCard(card); viewer.setCard(card);
viewer.draw(rdc, *wxWHITE); viewer.draw(rdc, *wxWHITE);
// render buffer to device // render buffer to device
double px_per_mm = zoom * stylesheet.card_dpi / 25.4;
dc.SetUserScale(scale_x / px_per_mm, scale_y / px_per_mm); dc.SetUserScale(scale_x / px_per_mm, scale_y / px_per_mm);
dc.SetDeviceOrigin(0, 0);
bufferDC.SelectObject(wxNullBitmap); bufferDC.SelectObject(wxNullBitmap);
dc.DrawBitmap(buffer, int(scale_x * pos.x), int(scale_y * pos.y)); dc.DrawBitmap(buffer, int(scale_x * pos.x), int(scale_y * pos.y));
} }