Handle cards with different DPI

This commit is contained in:
GenevensiS
2025-02-15 16:02:52 +01:00
parent cfe308f38f
commit 6ac93dc6ab
2 changed files with 12 additions and 9 deletions
+10 -8
View File
@@ -29,7 +29,8 @@ void PageLayout::init(const StyleSheet& stylesheet, PageLayoutType type, const R
this->page_size = page_size; this->page_size = page_size;
margin_left = margin_right = margin_top = margin_bottom = 0; margin_left = margin_right = margin_top = margin_bottom = 0;
card_size.width = stylesheet.card_width * 25.4 / stylesheet.card_dpi; card_size.width = stylesheet.card_width * 25.4 / stylesheet.card_dpi;
card_size.height = stylesheet.card_height * 25.4 / stylesheet.card_dpi; card_size.height = stylesheet.card_height * 25.4 / stylesheet.card_dpi;
card_dpi = stylesheet.card_dpi;
card_landscape = card_size.width > card_size.height; card_landscape = card_size.width > card_size.height;
cols = int(floor(page_size.width / card_size.width)); cols = int(floor(page_size.width / card_size.width));
rows = int(floor(page_size.height / card_size.height)); rows = int(floor(page_size.height / card_size.height));
@@ -119,13 +120,15 @@ 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);
// determine dpi factor for this card
double dpi_factor = stylesheet.card_dpi / job->layout.card_dpi;
// 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 RealPoint pos((job->layout.margin_left + (job->layout.card_size.width + job->layout.card_spacing.width) * col) * dpi_factor
, job->layout.margin_top + (job->layout.card_size.height + job->layout.card_spacing.height) * row); ,(job->layout.margin_top + (job->layout.card_size.height + job->layout.card_spacing.height) * row) * dpi_factor);
// determine rotation // determine rotation
const StyleSheet& stylesheet = job->set->stylesheetFor(card);
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) {
rotation = rad90; rotation = rad90;
@@ -143,8 +146,7 @@ void CardsPrintout::drawCard(DC& dc, const CardP& card, int card_nr) {
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
bool isPreview = IsPreview(); double zoom = 4;
double zoom = isPreview ? 1 : 4;
wxBitmap buffer(w*zoom,h*zoom,32); wxBitmap buffer(w*zoom,h*zoom,32);
wxMemoryDC bufferDC; wxMemoryDC bufferDC;
bufferDC.SelectObject(buffer); bufferDC.SelectObject(buffer);
@@ -156,9 +158,9 @@ void CardsPrintout::drawCard(DC& dc, const CardP& card, int card_nr) {
// render buffer to device // render buffer to device
double px_per_mm = zoom * stylesheet.card_dpi / 25.4; 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(int(scale_x * pos.x), int(scale_y * pos.y)); dc.SetDeviceOrigin(0, 0);
bufferDC.SelectObject(wxNullBitmap); bufferDC.SelectObject(wxNullBitmap);
dc.DrawBitmap(buffer, isPreview ? 0 : int(scale_x * pos.x), isPreview ? 0 : int(scale_y * pos.y)); dc.DrawBitmap(buffer, int(scale_x * pos.x), int(scale_y * pos.y));
} }
// ----------------------------------------------------------------------------- : PrintWindow // ----------------------------------------------------------------------------- : PrintWindow
+2 -1
View File
@@ -26,7 +26,8 @@ public:
// layout // layout
RealSize page_size; ///< Size of a page (in millimetres) RealSize page_size; ///< Size of a page (in millimetres)
RealSize card_size; ///< Size of a card (in millimetres) RealSize card_size; ///< Size of a card (in millimetres)
RealSize card_spacing; ///< Spacing between cards (in millimetres) RealSize card_spacing; ///< Spacing between cards (in millimetres)
double card_dpi; ///< Dots per inch of the default stylesheet
double margin_left, margin_right, margin_top, margin_bottom; ///< Page margins (in millimetres) double margin_left, margin_right, margin_top, margin_bottom; ///< Page margins (in millimetres)
int rows, cols; ///< Number of rows/columns of cards int rows, cols; ///< Number of rows/columns of cards
bool card_landscape; ///< Are cards rotated to landscape orientation? bool card_landscape; ///< Are cards rotated to landscape orientation?