From a11d2db8f4d1de45b2a86ab8b9b3b762d996eca3 Mon Sep 17 00:00:00 2001 From: dmitry Date: Sun, 3 Nov 2019 23:54:51 +0000 Subject: [PATCH] Printers: update Cocoa resolution information. #36063 git-svn-id: trunk@62184 - --- components/printers/cocoa/cocoaprinters.inc | 34 +++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/components/printers/cocoa/cocoaprinters.inc b/components/printers/cocoa/cocoaprinters.inc index 1996215012..90dce4c2b7 100644 --- a/components/printers/cocoa/cocoaprinters.inc +++ b/components/printers/cocoa/cocoaprinters.inc @@ -380,12 +380,40 @@ end; function TCocoaPrinter.GetOutputResolution: PMResolution; var - res: OSStatus; pInfo: NSPrintInfo; + prn : PMPrinter; + cnt : UInt32; + i : UInt32; + rs : PMResolution; begin + Result.vRes := 0; + Result.hRes := 0; + cnt := 0; pInfo := NSPrintInfo.sharedPrintInfo; - res := PMPrinterGetOutputResolution(GetCurrentPrinter(), pInfo.PMPrintSettings, result{%H-}); - if res <> noErr then + prn := GetCurrentPrinter(); + // todo: the code has been changed to mirror Carbon implementation + // for some drivers PMPrinterGetOutputResolution() returns failure at all times + // (even if printer dialog has been called). + // Enumeration of resolution doesn't return all possible values either. + // (i.e. Brother MFC 7860DW only gives 300x300 resolution + // while it actually supports 300, 600 and HQ1200 (2400x600) dpis) + // CUPS properties do indicate the actual resoltuion, BUT there's no standard + // way of reading the resolution. + // (i.e. the same Brother printer reports via "lpoptions -l": + // BRResolution/Resolution: 300dpi *600dpi 2400x600dpi) + if (PMPrinterGetOutputResolution(prn, pInfo.PMPrintSettings, rs{%H-}) = noErr) then + Result := rs + else if PMPrinterGetPrinterResolutionCount(prn, cnt) = noErr then + begin + for i:=1 to cnt do + begin + if (PMPrinterGetIndexedPrinterResolution(prn, i, rs) = noErr) + and ((rs.vRes > Result.vRes) or (rs.hRes > Result.hRes)) then + Result := rs; + end; + end; + + if (Result.vRes = 0) or (Result.hRes = 0) then begin Result.vRes := 72; Result.hRes := 72;