July 17, 2024, 08:34:28 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Printing to printer

Started by ckoehn, April 09, 2018, 11:05:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ckoehn

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

ckoehn

April 10, 2018, 09:50:15 AM #1 Last Edit: April 10, 2018, 03:13:05 PM by ckoehn
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

Egil

Great work!
Thanks for sharing Clint.
Support Amateur Radio  -  Have a ham  for dinner!

ckoehn

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

billhsln

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
When all else fails, get a bigger hammer.

ckoehn

April 13, 2018, 06:28:29 AM #5 Last Edit: April 13, 2018, 07:00:22 AM by ckoehn
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

ckoehn

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

billhsln

Tried both new versions.  Attaching screen shot.  Still getting graphics chars.  I am running Win 10 Pro, 64-Bit.

Bill
When all else fails, get a bigger hammer.

ckoehn

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

fasecero

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

ckoehn

Thanks for the input fasecero.  Bill will have to try it because the other works for me.

Here is the update.

Later,
Clint

billhsln

It looks like that fixed it.

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

Thanks,
Bill
When all else fails, get a bigger hammer.

fasecero

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.

ckoehn

Thanks for your help. I only know enough to get myself in trouble.  :)

Later,
Clint

LarryMc

Good explanation fasecero.  Don't sell yourself short.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

ckoehn

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

ckoehn

April 18, 2018, 09:13:54 AM #16 Last Edit: April 18, 2018, 10:54:04 AM by ckoehn
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

ckoehn

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

ckoehn

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

ckoehn

April 19, 2018, 02:32:30 PM #19 Last Edit: April 22, 2018, 01:55:59 PM by ckoehn
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