"Delphi" fixes the proportion problem of Quick Report preview printing

Quick Report in 1920*1080 resolution plus 125% When the above display setting environment is,The proportion of "Preview Print" will be incorrect.(too big or too small),But the actual printing is normal.,If you want to correct,It is necessary to modify the qrprntr.pas file of Quick Report in the compilation environment,There are two ways to correct it。

 

◎ File location
C:\Program Files (x86)\EmbarcaderoStudio16.0Quickrep506qrprntr.pas

 

◎ Method 1
Add a scaleToNativeDeskRes Function to be called by FMetafile.Width and FMetafile.Height。

procedure TQRPrinter.CreateMetafileCanvas;

  function scaleToNativeDeskRes(pVal: Integer): Integer;
  var
   tTemp: HDC;
  begin
    tTemp := GetDC(0);
    try
      Result := Round((pVal * GetDeviceCaps(tTemp, VERTRES)) / GetDeviceCaps(tTemp, DESKTOPVERTRES));
    finally
      ReleaseDC(0, tTemp);
    end;
  end;

begin
...
  FMetafile.Width := scaleToNativeDeskRes(XSize(PaperWidthValue));
  FMetafile.Height := scaleToNativeDeskRes(YSize(PaperLengthValue));
  FCanvas := TMetafileCanvas.Create(FMetafile, 0);
  FCanvas.Font.PixelsPerInch := MetafileDPI;
...
end;

 

The complete example is as follows

procedure TQRPrinter.CreateMetafileCanvas;

// 解決 Windows 字型放大到 125% 以上時,預覽列印的比例會異常的問題。
 function scaleToNativeDeskRes(pVal: Integer): Integer;
  var
    tTemp: HDC;
  begin
    tTemp := GetDC(0);
    try
      Result := Round((pVal * GetDeviceCaps(tTemp, VERTRES)) / GetDeviceCaps(tTemp, DESKTOPVERTRES));
    finally
      ReleaseDC(0, tTemp);
    end;
  end;

begin
  FMetafile := TMetafile.Create;
  // {$define HIRES}
{$IFDEF HIRES}
  // try a high res canvas
  XFactor := GetDeviceCaps(aPrinter.Handle, LogPixelsX) / 254;
  YFactor := GetDeviceCaps(aPrinter.Handle, LogPixelsY) / 254;
  FMetafile.Width := XSize(PaperWidthValue);
  FMetafile.Height := YSize(PaperLengthValue);
  FCanvas := TMetafileCanvas.Create(FMetafile, aprinter.Handle);
  FCanvas.Font.PixelsPerInch := GetDeviceCaps(aprinter.Handle, LOGPIXELSY);
{$ELSE}
  // dpi fix ? suggested by David Martin
  FMetafile.Width := scaleToNativeDeskRes(XSize(PaperWidthValue)); // add // 在此處調用 scaleToNativeDeskRes。
  FMetafile.Height := scaleToNativeDeskRes(YSize(PaperLengthValue)); // add // 在此處調用 scaleToNativeDeskRes。
  FCanvas := TMetafileCanvas.Create(FMetafile, 0); // add
  FCanvas.Free; // add
  if FMetafile.Width > XSize(PaperWidthValue) then // add
    FMetafile.Inch := (96 * FMetafile.Width) div XSize(PaperWidthValue); // add
  // end fix

  FMetafile.Width := XSize(PaperWidthValue);
  FMetafile.Height := YSize(PaperLengthValue);
  FCanvas := TMetafileCanvas.Create(FMetafile, 0);
  YFactor := Screen.PixelsPerInch / 254;
  XFactor := YFactor;
  SetGraphicsMode(FCanvas.handle, GM_ADVANCED); // disable this line
{$ENDIF}
  // FHyperlinks := TList.Create;
end;

 

◎Method 2

In fact, in Quick Report 5.06 In version,A fix has been provided,write on {$IFDEF HIRES} under,It's just that the program is not there {$define HIRES} Define what constitutes high resolution,So the program will not run into the correction program。
Therefore, the second method is to {$IFDEF HIRES} Move the program in {$ELSE} under,Just replace the original writing。

procedure TQRPrinter.CreateMetafileCanvas;

begin
  FMetafile := TMetafile.Create;
  // {$define HIRES}
{$IFDEF HIRES}

{$ELSE}
  // try a high res canvas
  // 解決 Windows 字型放大到 125% 以上時,預覽列印的比例會異常的問題。
  XFactor := GetDeviceCaps(aPrinter.Handle, LogPixelsX) / 254;
  YFactor := GetDeviceCaps(aPrinter.Handle, LogPixelsY) / 254;
  FMetafile.Width := XSize(PaperWidthValue);
  FMetafile.Height := YSize(PaperLengthValue);
  FCanvas := TMetafileCanvas.Create(FMetafile, aprinter.Handle);
  FCanvas.Font.PixelsPerInch := GetDeviceCaps(aprinter.Handle, LOGPIXELSY);

  // dpi fix ? suggested by David Martin
  FMetafile.Width := scaleToNativeDeskRes(XSize(PaperWidthValue)); // add
  FMetafile.Height := scaleToNativeDeskRes(YSize(PaperLengthValue)); // add
  FCanvas := TMetafileCanvas.Create(FMetafile, 0); // add
  FCanvas.Free; // add
  if FMetafile.Width > XSize(PaperWidthValue) then // add
    FMetafile.Inch := (96 * FMetafile.Width) div XSize(PaperWidthValue); // add
  // end fix

  FMetafile.Width := XSize(PaperWidthValue);
  FMetafile.Height := YSize(PaperLengthValue);
  FCanvas := TMetafileCanvas.Create(FMetafile, 0);
  YFactor := Screen.PixelsPerInch / 254;
  XFactor := YFactor;
  SetGraphicsMode(FCanvas.handle, GM_ADVANCED); // disable this line
{$ENDIF}
  // FHyperlinks := TList.Create;
end;

 

【參考連結】

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.