IonicWind Software

IWBasic => General Questions => Topic started by: ckoehn on April 09, 2018, 11:05:57 AM

Title: Printing to printer
Post by: ckoehn on April 09, 2018, 11:05:57 AM
I had a little time to play around with printing to a printer.  These are the files LarryMc posted and also Peter.  Without them this wouldn't have been possible.  There is room for more functionality.

Put all these files under the same directory.

When you open with a SelectPrinter and select a printer you must always close with an EndPrint.

Later,
Clint
Title: Re: Printing to printer
Post by: ckoehn on April 10, 2018, 09:50:15 AM
Changed SetPrinterFont so you could add whatever weight you wanted to.

Added PrintBMP.

Put all these files under the same directory.

EDIT: forgot the DELETEIMAGE(bmpSource) on the PrintBMP sub.
Later,
Clint
Title: Re: Printing to printer
Post by: Egil on April 10, 2018, 11:36:04 AM
Great work!
Thanks for sharing Clint.
Title: Re: Printing to printer
Post by: ckoehn on April 12, 2018, 09:50:54 AM
This is a work in progress, sorry.  I found a few errors and changed FillRectangle to include round corners.

Still calling it "Printing with Windows 2".

Later,
Clint
Title: Re: Printing to printer
Post by: billhsln on April 12, 2018, 12:56:13 PM
Funny thing and I don't understand it.  The original EXE works fine with the sample and prints text normal.  However, when I recompile, the text is all symbols.  I did not change any of the program, just unzipped 'Printing With Windows 2.zip' and 'prtdialog255.zip' into a directory where that is all that is in it and recompiled and executed.

Bill
Title: Re: Printing to printer
Post by: ckoehn on April 13, 2018, 06:28:29 AM
That is a little strange. ???

I have a windows 10 that this was compiled on.

Empty that directory out and just unzip the file below, which should have everything you need, and let me know how it goes. I'm guessing it will do the same thing.

I do have an idea what the problem is. I did struggle a little with the SetPrinterFont.  Windows has both ANSI (8 bit) and Wide Character (16 bit) fonts.  I had to change the last line in the LOGFONT to ISTRING instead of CHAR to get it to work on my computer.  If anyone has suggestions, let's hear them.  :)

EDIT:  Remarked out logfont to use sapero's.  Try this.
EDIT2: Found out sapero did the same thing I did.  I'll try to explain.

This is the windows LOGFONT structure or in IWBASIC the TYPE.
typedef struct tagLOGFONT {
  LONG  lfHeight;
  LONG  lfWidth;
  LONG  lfEscapement;
  LONG  lfOrientation;
  LONG  lfWeight;
  BYTE  lfItalic;
  BYTE  lfUnderline;
  BYTE  lfStrikeOut;
  BYTE  lfCharSet;
  BYTE  lfOutPrecision;
  BYTE  lfClipPrecision;
  BYTE  lfQuality;
  BYTE  lfPitchAndFamily;
  TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT, *PLOGFONT;

The last item "TCHAR lfFaceName[LF_FACESIZE]" is an array that holds LF_FACESIZE chars, which currently is 32 chars.  TCHAR is a "macro", that makes it an ANSI or UNIICODE (Wide Character) array.  Sapero defined a LOGFONTA and a LOGFONTW and then defined LOGFONT to LOGFONTA.  If Bills system is set up for UNICODE, that needs to be redfined as LOGFONT is LOGFONTW.

LarryMc, is there a way to determine if a system is using ANSI or UNICODE?  Or am I on the wrong track?

Later,
Clint
Title: Re: Printing to printer
Post by: ckoehn on April 13, 2018, 07:19:17 AM
Sorry about this.  I'm to impulsive I guess.  I have always had to just dive in to learn.  I probably need to spend a little more time in meditation and testing. :-[

Here is another one that checks unicode (I think).

Later,
Clint
Title: Re: Printing to printer
Post by: billhsln on April 13, 2018, 10:57:16 AM
Tried both new versions.  Attaching screen shot.  Still getting graphics chars.  I am running Win 10 Pro, 64-Bit.

Bill
Title: Re: Printing to printer
Post by: ckoehn on April 13, 2018, 03:09:54 PM
I appreciate your feedback Bill. I guess I'll have to dig a little deeper.

Anyone have any idea why this is happening?

Later,
Clint
Title: Re: Printing to printer
Post by: fasecero on April 13, 2018, 05:27:00 PM
The LOGFONT structure could be the cause of the issue


sub SetPrinterFont(string name,int pointa, OPT int angle=0, OPT int font_weight = 400, opt int DoStyle=0),int
$ifdef UNICODE
LOGFONTW fnt
fnt.lfFaceName = S2W(name)
$else
LOGFONTA fnt
fnt.lfFaceName = name
$ENDIF


Try with


sub SetPrinterFont(string name,int pointa, OPT int angle=0, OPT int font_weight = 400, opt int DoStyle=0),int
$ifdef UNICODE
LOGFONTW fnt
ZeroMemory(fnt,LEN(fnt))
fnt.lfFaceName = S2W(name)
$else
LOGFONTA fnt
ZeroMemory(fnt,LEN(fnt))
fnt.lfFaceName = name
$ENDIF


Or just


sub SetPrinterFont(string name,int pointa, OPT int angle=0, OPT int font_weight = 400, opt int DoStyle=0),int
LOGFONTA fnt
ZeroMemory(fnt,LEN(fnt))
fnt.lfFaceName = name
Title: Re: Printing to printer
Post by: ckoehn on April 13, 2018, 07:35:59 PM
Thanks for the input fasecero.  Bill will have to try it because the other works for me.

Here is the update.

Later,
Clint
Title: Re: Printing to printer
Post by: billhsln on April 13, 2018, 09:07:27 PM
It looks like that fixed it.

I really like your grid with the rounded edges.  Very cool.

Thanks,
Bill
Title: Re: Printing to printer
Post by: fasecero on April 13, 2018, 10:41:06 PM
Just for the record, Larry could explain it much better, he doesn't seem to be around so I'll try. If $DEFINE UNICODE isn't called explicitly by you, you will always get ANSI by default. So the ANSI block will always be executed regardless of where the program is being executed (Win10, Win7, Xp... 64-Bit, 32-Bit... or whatever).

LOGFONTA fnt
ZeroMemory(fnt,LEN(fnt))
fnt.lfFaceName = name


Only when you explicitly define an unicode build with the command preprocessor at the top of your own code: $DEFINE UNICODE

you'll get (compiled and executed) the other part instead.

LOGFONTW fnt
ZeroMemory(fnt,LEN(fnt))
fnt.lfFaceName = S2W(name)


Neither the operating system nor the amount of bits defines whether unicode is used or not, only your own choise.
Title: Re: Printing to printer
Post by: ckoehn on April 14, 2018, 05:09:55 AM
Thanks for your help. I only know enough to get myself in trouble.  :)

Later,
Clint
Title: Re: Printing to printer
Post by: LarryMc on April 14, 2018, 10:41:21 AM
Good explanation fasecero.  Don't sell yourself short.
Title: Re: Printing to printer
Post by: ckoehn on April 14, 2018, 07:59:23 PM
I hope this is it.  I made quite a few changes.  Fixed some bugs, changed some names, added some functionality, Slapped a pdf manual in there, very basic.

Added a polygon and made it so polygons, rectangles, and ellipses could be transparent.

I need to turn this thing into a library.  Another one of those things I don't understand real well.

As usual, put everything under the same directory.

Later,
Clint
Title: Re: Printing to printer
Post by: ckoehn on April 18, 2018, 09:13:54 AM
I'm having problems with this last file.  It prints fine when going to a PDF printer, which is how I have been testing it.  But when printing to a real printer the PrintBMP and SetPenColor doesn't seem to work.  But the one that is prior to this one works fine.  Why?  The first one uses printer pixels,  the other one converts to printer pixels, yet this last one woks on on a PDF printer.

I hope I can figure it out, and it may take a while.

EDIT: This is the one that works, but it is missing a lot of my changes.

Later,
Clint
Title: Re: Printing to printer
Post by: ckoehn on April 19, 2018, 07:20:51 AM
Just a quick update.

This quote is so true: "When you know the answer, the question isn't hard"

On the pdf printer there was no "printer offset".  On the printer there was.  Something like 78 ppx which gives a negative number sometimes.  I'm having to modify the code to accommodate that.  One set of routines for position and another for distance.

Be back when I get it finished.

Later,
Clint
Title: Re: Printing to printer
Post by: ckoehn on April 19, 2018, 08:07:48 AM
Ok, give it a try.  If anyone finds something wrong, either fix it or let me know.  I haven't given the PRINTER_UNIT_MM a good test yet since I'm not use to using mm.

I did place in the main program a couple of sub's that I thought would be interesting. "PrintArrow" and "rotate_point" which "PrintArrow" uses.

Later,
Clint
Title: Re: Printing to printer
Post by: ckoehn on April 19, 2018, 02:32:30 PM
Having so much fun I can't quit.  ;D

Added PrintFilledText.  It Draws the outline with the current pen and fills it with the current brush.  Look at SetPenColor and SetBrushColor.  Added this to the pdf manual.

It uses the BeginPath/EndPath api calls.  You can do all kind of neat stuff with them.

Just including the printer.iwb and pdf manual this time.

Later,
Clint