1

Just recently we got a bug report regarding high dpi system (e.g. 4k screens with a resoltion higher than 200dpi) that our printed graphics are not properly scaled - they do not take the whole width on the screen.

Following code should show the situation:

procedure TForm1.Button1Click(Sender : TObject);
var mf : TMetafile;
begin
     Printer.BeginDoc;

     mf := TMetafile.Create;
     mf.SetSize(10, 10);

     with TMetafileCanvas.Create(mf, 0) do
     try
        MoveTO(0, 0);
        LineTo(10, 10);
     finally
            Free;
     end;


     Printer.Canvas.StretchDraw( Rect( 0, 0, Printer.PageWidth,  Printer.PageHeight ), mf  );

     mf.Free;


     Printer.EndDoc;
end;

That code should stretch the 10x10 metafile on a whole page - this fails on a high dpi system. The code works if the Font/Item scaling is set to a 100% in Windows and also the application has no manifest in it that tells windows that it is dpi aware. I'm using Delphi 2010.

mrabat
  • 802
  • 7
  • 15
  • Is your process DPI aware? – David Heffernan Sep 29 '15 at 14:00
  • @David: Darn you were fast.... not it is not - it is a plain VCL project with a button on it (no manifist nor calling the SetProcessDPIAwareness – mrabat Sep 29 '15 at 14:06
  • That's the usual place to start looking when your app misbehaves under high DPI conditions. Slap in a call to `SetProcessDPIAwareness` at startup and see what happens. – David Heffernan Sep 29 '15 at 14:09
  • @DavidHeffernan: I tried that on our main application and tada the printing worked again but nevertheless the application is not usable any more since in fact it is not dpi aware (thus the fonts are way too small). Anyway why does the above code fail if the app it is not dpi aware? I know we have to update our software for such usage but now I'm simly curious why that above code fails (it also helps me to understand the scaling... msdn is not very helpfull here) – mrabat Sep 29 '15 at 14:15
  • I can't explain why your code fails when the process is not DPI aware. I don't have any experience of working with programs that are not DPI aware. – David Heffernan Sep 29 '15 at 14:18
  • @mrabat, you tried to add a "Aware.manifest" : true PerMonitorV2 – antonio May 16 '23 at 04:17

0 Answers0