Printing with Cocoa lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- dbannon · 2018-05-13 13:04 Anyone familiar with printing (as in to a piece of paper) from a Cocoa app ? I have some pretty simple printing code that just does Printer.Canvas.TextOut(X, Y, Text) that works fine on Linux, Windows and Carbon but on Cocoa we see a message box saying "No Pages from the Document were selected to be printed" when it hits Printer.EndDoc Should I keep trying or is printing not yet been addressed in Cocoa ? Davo (and, no, I am not trying to save printer toner by using Cocoa) ---------------------------------------------------------------------- dbannon · 2018-05-14 11:52 Just a little more on this topic - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i        Printer.BeginDoc;       Printer.Canvas.Font.Size := 48;       LineHeight := printer.canvas.TextHeight('I');   Sets LineHeight to 1 when run under Cocoa. Under carbon and same printer, its 237  !   Davo ---------------------------------------------------------------------- LazProgger · 2018-05-17 10:11 Is it not printing at all or is it printing in a wrong size? ---------------------------------------------------------------------- dbannon · 2018-05-17 11:34 Its not printing at all. Blank pages come out of the printer. I mentioned the size issue as its an indication that the canvas is clearly not working as it should. No matter how bit a font you use, its all one pixel high. Maybe, if I looked closely, I could see all the text in that one pixel .... Davo ---------------------------------------------------------------------- LazProgger · 2018-05-17 12:27 What if you set the font size to 1000 or whatever? Is it visible then? ---------------------------------------------------------------------- dbannon · 2018-05-19 10:16 No, I have not tried 1000pt but I have a feeling it would produce the same result. Its just not returning a valid number .... ---------------------------------------------------------------------- dbannon · 2018-05-20 02:48 be nice if someone could please confirm this please. I don't want to put a bug report in if its just me being silly.... Trunk, using 64bit Cocoa. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  LineHeight, VMarg : integer;begin     try       Printer.BeginDoc;       Printer.Canvas.Font.Size := 48;       LineHeight := printer.canvas.TextHeight('I');       VMarg := 4 * LineHeight;       Printer.Canvas.TextOut(100, VMarg, 'This is some text');     finally       Printer.EndDoc;     end;end;      If you want to save some paper, comment out the EndDoc and watch LineHeight, always comes back as 1 for me. Davo ---------------------------------------------------------------------- jwdietrich · 2019-12-24 07:55 Printing is not yet supported in Cocoa. ---------------------------------------------------------------------- dbannon · 2019-12-24 11:36 Quote from: jwdietrich on December 24, 2019, 08:55:27 amPrinting is not yet supported in Cocoa. Er, don't think it was working back when this thread started but it works perfectly for me now. Davo ---------------------------------------------------------------------- jwdietrich · 2019-12-24 15:26 Quote from: dbannon on December 24, 2019, 12:36:58 pmQuote from: jwdietrich on December 24, 2019, 08:55:27 amPrinting is not yet supported in Cocoa. Er, don't think it was working back when this thread started but it works perfectly for me now. Davo Do you use a trunk version of Lazarus? In the official distribution, the attached project works well with the Carbon widgetset, but it generates an empty page with Cocoa. ---------------------------------------------------------------------- dbannon · 2019-12-24 21:29 Quote from: jwdietrich on December 24, 2019, 04:26:02 pmDo you use a trunk version of Lazarus? In the official distribution, the attached project works well with the Carbon widgetset, but it generates an empty page with Cocoa. I am using fixes, I think all the printing and a huge batch of other cocoa fixes made it  into 2.0.6 but maybe wrong.  But I think fixes has had working cocoa printing since before 2.0.6 Its Christmas day here Jwdietrich, if I get caught playing with the IDE I'll be in big trouble. Here is how I print, text only, works across Windows, Linux and Mac (carbon and Cocoa) - https://github.com/tomboy-notes/tomboy- ng/blob/master/tomboy-ng/k_prn.pas  It takes the text content of a KMemo and renders it on paper. I think, from memory, there was a problem dumping an existing canvas to the printer, my words, probably incorrect terms. My code draws the text on the printers canvas.  I'll fire up your code tonight if I get a chance, maybe its a printer specific issue ?  (I have not had an reports of my app not printing on Cocoa from end users but don't have a lot of Mac users ....) Davo ---------------------------------------------------------------------- dbannon · 2019-12-26 10:27 Jwdietrich, just tested your code, worked perfectly, straight out of the box. Davo ---------------------------------------------------------------------- trev · 2019-12-26 11:49 Quote from: dbannon on May 20, 2018, 04:48:27 ambe nice if someone could please confirm this please. I don't want to put a bug report in if its just me being silly.... Trunk, using 64bit Cocoa. Ok, having setup a printer this time, I put Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ShowMessage('Line Height: ' + IntToStr(LineHeight)); in the finally clause and the answer was 56. ---------------------------------------------------------------------- jwdietrich · 2019-12-26 19:19 Quote from: dbannon on December 26, 2019, 11:27:36 amJwdietrich, just tested your code, worked perfectly, straight out of the box. Davo OK, in the official distribution (Lazarus 2.0.6) the output is only correct in Carbon (see attachment). So there seems to be some prospect for the next version.