In Cocoa 64bit, Printer.XDPI and Printer.YDPI always return 72 dpi resolution for all printers
Original Reporter info from Mantis: gabriemarcelo
-
Reporter name: Gabrie Marcelo
Original Reporter info from Mantis: gabriemarcelo
- Reporter name: Gabrie Marcelo
Description:
In Cocoa 64bit, Printer.XDPI and Printer.YDPI always return 72 dpi resolution for all printers.
The same code in Carbon works as expected
I've investigated a bit about what others do on this matter and found these:
-
https://bugs.eclipse.org/bugs/show_bug.cgi?id=219133
- https://code.woboq.org/qt5/qtbase/src/plugins/platforms/cocoa/qcocoaprintdevice.mm.html
On both sources, they tried to solve the issue by using almost the same approach which is look for all the resolutions supported by the printer by calling PMPrinterGetPrinterResolutionCount and PMPrinterGetIndexedPrinterResolution functions. In source #1 (closed), they opted for looking for the greatest dpi supported values while in source #2 (closed) they opted for returning the lowest supported dpi
I've modified the TCocoaPrinter.GetOutputResolution in cocoaprinters.inc based on source #1 (closed) and it works but because it returns the greatest dpi value for each printer, it does not return the "default" dpi as Carbon code does on the same macOS system.
function TCocoaPrinter.GetOutputResolution: PMResolution;
var
curPrinter : PMPrinter;
res: OSStatus;
pInfo: NSPrintInfo;
resCount:UInt32;
tempRes, pmRes : PMResolution;
i:integer;
begin
pInfo := NSPrintInfo.sharedPrintInfo;
curPrinter := GetCurrentPrinter();
res := PMPrinterGetOutputResolution(curPrinter, pInfo.PMPrintSettings, result{%H-});
if res <> noErr then
begin
resCount := 0;
res := PMPrinterGetPrinterResolutionCount(curPrinter, resCount);
if res <> noErr then
begin
Result.vRes := 72;
Result.hRes := 72;
end else begin
tempRes.hRes:=0;
tempRes.vRes:=0;
i := 1;
while i <= resCount do begin
res := PMPrinterGetIndexedPrinterResolution(curPrinter, i, pmRes);
if res = noErr then begin
if((pmRes.vRes > tempRes.vRes) and (pmRes.hRes > tempRes.hRes)) then
tempRes := pmRes;
end else begin
tempRes.hRes:=72;
tempRes.vRes:=72;
end;
inc(i);
end;
Result.vRes:=tempRes.vRes;
Result.hRes:=tempRes.hRes;
end;
end;
end;
Mantis conversion info:
- Mantis ID: 36063
- Version: 2.0.4
- Fixed in revision: 62184 (#a11d2db8)