wxWidgets icon indicating copy to clipboard operation
wxWidgets copied to clipboard

Print preview too small at high DPI

Open taler21 opened this issue 1 year ago • 5 comments

As can be seen in the printing sample, the print preview is too small at 200% DPI scaling.

If running the sample DPI unaware and DPI aware, the preview should have the same size on the screen in both cases. But currently, in case of DPI awareness, the preview is too small by the DPI scaling factor.

print-preview-DPI-unaware-vs-aware

It seems that the size of wxPreviewFrame can be easily fixed as follows

diff --git "a/src/common/prntbase.cpp" "b/src/common/prntbase.cpp"
index 408c4b6336..54b12ea20b 100644
--- "a/src/common/prntbase.cpp"
+++ "b/src/common/prntbase.cpp"
@@ -940,7 +940,7 @@ wxScrolledWindow(parent, wxID_ANY, pos, size, style | wxFULL_REPAINT_ON_RESIZE,
 
     // Use some reasonable default size for this window, roughly proportional
     // to the paper sheet.
-    SetInitialSize(wxSize(600, 750));
+    SetInitialSize(FromDIP(wxSize(600, 750)));
 }
 
 wxPreviewCanvas::~wxPreviewCanvas()

print-preview-DPI-unaware-vs-aware-with-patched-frame

but I have no idea how to fix the size of its content (the preview of the page).

Platform and version information

  • wxWidgets version you use: 3.2.5
  • wxWidgets port you use: wxMSW
  • OS and its version: Windows 10

taler21 avatar Jul 02 '24 05:07 taler21

See https://github.com/dsa-t/wxWidgets/commit/c9cfb7f85f27d9b3a37208a9c87098a7ffd3b362

Might be wrong, but seems to be working. Also not tested on other operating systems.

I noticed that window sizing can be wrong when moving between screens for some reason (unrelated bug).

dsa-t avatar Jul 03 '24 16:07 dsa-t

I can confirm that with your changes it looks correct with wxMSW. But your changes have side effects with wxGTK, where the preview of the page becomes too large on a high-resolution monitor (at 200% scaling).

taler21 avatar Jul 04 '24 10:07 taler21

The changes (backported to 3.2.5) also cause my actual application with wxGTK to crash.

Call stack:

#0 0x7ffff734a384	cairo_translate() (/lib/x86_64-linux-gnu/libcairo.so.2:??)
#1 0x7ffff7765eb1	???() (/lib/x86_64-linux-gnu/libgtk-3.so.0:??)
#2 0x7ffff7604388	gtk_main_do_event() (/lib/x86_64-linux-gnu/libgtk-3.so.0:??)
#3 0x7ffff7c62407	???() (/lib/x86_64-linux-gnu/libgdk-3.so.0:??)
#4 0x7ffff7c74769	???() (/lib/x86_64-linux-gnu/libgdk-3.so.0:??)
#5 0x7ffff7c78e35	???() (/lib/x86_64-linux-gnu/libgdk-3.so.0:??)
#6 0x7ffff7c79041	???() (/lib/x86_64-linux-gnu/libgdk-3.so.0:??)
#7 0x1a465c5	wxWindow::Update(this=0x3582e40) (./src/gtk/window.cpp:5339)
#8 0x1a6df34	wxStatusBar::DoUpdateStatusText(this=0x3582e40, number=0) (./src/generic/statusbr.cpp:166)
#9 0x1b8b077	wxStatusBarBase::SetStatusText(this=0x3582e40, text=..., number=0) (./src/common/statbar.cpp:262)
#10 0x1b054d0	wxFrameBase::SetStatusText(this=0x3b23dd0, text=..., number=0) (./src/common/framecmn.cpp:409)
#11 0x1b73f33	wxPrintPreviewBase::RenderPage(this=0x38726f0, pageNum=1) (./src/common/prntbase.cpp:2137)
#12 0x1b73026	wxPrintPreviewBase::UpdatePageRendering(this=0x38726f0) (./src/common/prntbase.cpp:2003)
#13 0x1b74981	wxPrintPreview::UpdatePageRendering(this=0x387d0a0) (./src/common/prntbase.cpp:2290)
#14 0x1b6f111	wxPreviewCanvas::OnPaint(this=0x3a8c380) (./src/common/prntbase.cpp:952)

taler21 avatar Jul 04 '24 13:07 taler21

Created PR: https://github.com/wxWidgets/wxWidgets/pull/24681

Latest commit seems to solve the scaling issue on wxGTK.

Not sure about the crash though.

dsa-t avatar Jul 05 '24 23:07 dsa-t

Yes, it solved the scaling issue, but unfortunately the crash still occurs.

The crash is caused by the added m_printPreview->UpdatePageRendering(); call in void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)), and finally occurs in void wxWindowGTK::Update(), when calling gdk_window_process_updates(window, true);. See the call stack above.

taler21 avatar Jul 08 '24 07:07 taler21