* * *

Author Topic: Printing with Cocoa  (Read 1067 times)

dbannon

  • Sr. Member
  • ****
  • Posts: 291
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 1.8, Linux (and reluctantly Win10, OSX)

dbannon

  • Sr. Member
  • ****
  • Posts: 291
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 1.8, Linux (and reluctantly Win10, OSX)

LazProgger

  • New member
  • *
  • Posts: 33
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

  • Sr. Member
  • ****
  • Posts: 291
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 1.8, Linux (and reluctantly Win10, OSX)

LazProgger

  • New member
  • *
  • Posts: 33
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

  • Sr. Member
  • ****
  • Posts: 291
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 1.8, Linux (and reluctantly Win10, OSX)

dbannon

  • Sr. Member
  • ****
  • Posts: 291
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 1.8, Linux (and reluctantly Win10, OSX)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus