Recent

Author Topic: Printing with Cocoa  (Read 4847 times)

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Printing with Cocoa
« on: May 13, 2018, 03:04:29 pm »
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)

« Last Edit: May 13, 2018, 03:07:08 pm by dbannon »
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Printing with Cocoa
« Reply #1 on: May 14, 2018, 01:52:21 pm »
Just a little more on this topic -

Code: Pascal  [Select][+][-]
  1.        Printer.BeginDoc;
  2.        Printer.Canvas.Font.Size := 48;
  3.        LineHeight := printer.canvas.TextHeight('I');  


Sets LineHeight to 1 when run under Cocoa.
Under carbon and same printer, its 237  !
 
Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

LazProgger

  • Full Member
  • ***
  • Posts: 103
Re: Printing with Cocoa
« Reply #2 on: May 17, 2018, 12:11:06 pm »
Is it not printing at all or is it printing in a wrong size?

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Printing with Cocoa
« Reply #3 on: May 17, 2018, 01:34:58 pm »
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
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

LazProgger

  • Full Member
  • ***
  • Posts: 103
Re: Printing with Cocoa
« Reply #4 on: May 17, 2018, 02:27:56 pm »
What if you set the font size to 1000 or whatever? Is it visible then?

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Printing with Cocoa
« Reply #5 on: May 19, 2018, 12:16:35 pm »
No, I have not tried 1000pt but I have a feeling it would produce the same result. Its just not returning a valid number ....
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Printing with Cocoa
« Reply #6 on: May 20, 2018, 04:48:27 am »
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][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   LineHeight, VMarg : integer;
  4. begin
  5.      try
  6.        Printer.BeginDoc;
  7.        Printer.Canvas.Font.Size := 48;
  8.        LineHeight := printer.canvas.TextHeight('I');
  9.        VMarg := 4 * LineHeight;
  10.        Printer.Canvas.TextOut(100, VMarg, 'This is some text');
  11.      finally
  12.        Printer.EndDoc;
  13.      end;
  14. end;  
   

If you want to save some paper, comment out the EndDoc and watch LineHeight, always comes back as 1 for me.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Printing with Cocoa
« Reply #7 on: December 24, 2019, 08:55:27 am »
Printing is not yet supported in Cocoa.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Printing with Cocoa
« Reply #8 on: December 24, 2019, 12:36:58 pm »
Printing 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
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Printing with Cocoa
« Reply #9 on: December 24, 2019, 04:26:02 pm »
Printing 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.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Printing with Cocoa
« Reply #10 on: December 24, 2019, 10:29:43 pm »
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.

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
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Printing with Cocoa
« Reply #11 on: December 26, 2019, 11:27:36 am »
Jwdietrich, just tested your code, worked perfectly, straight out of the box.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Printing with Cocoa
« Reply #12 on: December 26, 2019, 12:49:37 pm »
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.
<chomp>

Ok, having setup a printer this time, I put
Code: Pascal  [Select][+][-]
  1. ShowMessage('Line Height: ' + IntToStr(LineHeight));
in the finally clause and the answer was 56.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Printing with Cocoa
« Reply #13 on: December 26, 2019, 08:19:21 pm »
Jwdietrich, 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.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

 

TinyPortal © 2005-2018