Skip to content

Commit 43c52cf

Browse files
Copilotlaeubi
andcommitted
Extract POINTS_PER_INCH constant and improve comments
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
1 parent a69c15b commit 43c52cf

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

  • bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing

bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PDFDocument.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public final class PDFDocument extends Device {
7878
/** The name of the Microsoft Print to PDF printer */
7979
private static final String PDF_PRINTER_NAME = "Microsoft Print to PDF";
8080

81+
/** Points per inch - the standard PDF coordinate system uses 72 points per inch */
82+
private static final double POINTS_PER_INCH = 72.0;
83+
8184
/** Helper class to represent a paper size with orientation */
8285
private static class PaperSize {
8386
int paperSizeConstant;
@@ -138,9 +141,9 @@ private static PaperSize findBestPaperSize(double widthInPoints, double heightIn
138141
}
139142
}
140143

141-
// Default to Letter if no match found (requested size is larger than all standard sizes)
144+
// Default to largest available size if no standard size fits
142145
if (bestMatch == null) {
143-
// Use the largest standard size that fits the aspect ratio best
146+
// Choose TABLOID (largest standard size) in the orientation that matches the requested aspect ratio
144147
if (widthInPoints > heightInPoints) {
145148
bestMatch = new PaperSize(OS.DMPAPER_TABLOID, OS.DMORIENT_LANDSCAPE, 1224, 792);
146149
} else {
@@ -449,9 +452,9 @@ public Rectangle getClientArea() {
449452
int offsetX = OS.GetDeviceCaps(handle, OS.PHYSICALOFFSETX);
450453
int offsetY = OS.GetDeviceCaps(handle, OS.PHYSICALOFFSETY);
451454

452-
// Convert from device units to points (72 DPI)
453-
double scaleX = 72.0 / dpi.x;
454-
double scaleY = 72.0 / dpi.y;
455+
// Convert from device units to points
456+
double scaleX = POINTS_PER_INCH / dpi.x;
457+
double scaleY = POINTS_PER_INCH / dpi.y;
455458

456459
int x = (int) (offsetX * scaleX);
457460
int y = (int) (offsetY * scaleY);
@@ -495,14 +498,14 @@ public long internal_new_GC(GCData data) {
495498
data.font = getSystemFont();
496499
}
497500

498-
// Set up coordinate system scaling to work in points (72 DPI)
501+
// Set up coordinate system scaling to work in points
499502
// The printer has its own DPI, so we scale to make 1 user unit = 1 point
500503
int printerDpiX = OS.GetDeviceCaps(handle, OS.LOGPIXELSX);
501504
int printerDpiY = OS.GetDeviceCaps(handle, OS.LOGPIXELSY);
502505

503-
// Scale factor: printer_dpi / 72 (since we want 1 unit = 1 point = 1/72 inch)
504-
float scaleX = printerDpiX / 72.0f;
505-
float scaleY = printerDpiY / 72.0f;
506+
// Scale factor: printer_dpi / POINTS_PER_INCH (since we want 1 unit = 1 point = 1/72 inch)
507+
float scaleX = (float)(printerDpiX / POINTS_PER_INCH);
508+
float scaleY = (float)(printerDpiY / POINTS_PER_INCH);
506509

507510
OS.SetGraphicsMode(handle, OS.GM_ADVANCED);
508511
float[] transform = new float[] {scaleX, 0, 0, scaleY, 0, 0};

0 commit comments

Comments
 (0)