QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Juanjogomez on November 19, 2018, 01:28:28 pm

Title: Turn page 90 degrees
Post by: Juanjogomez on November 19, 2018, 01:28:28 pm
Hi guys,
I want to print a page in landscape format but I do not know how to turn the page 90 degrees.
What I do is create a page with the width of the A4 length and the width of the A4 length. I write the corresponding text, but to send it to the printer I have to rotate it.
With _PUTIMAGE I can reverse it, but I do not think I can rotate it. Could someone tell me how to do it?
Thank you
Title: Re: Turn page 90 degrees
Post by: Petr on November 19, 2018, 03:35:05 pm
Hi. Try ROTOZOOM way (with this you can rotating images for all angles, this demo show 45)

Code: QB64: [Select]
  1. CLS , _RGB32(255, 255, 255)
  2.  
  3. image& = _SCREENIMAGE 'or LOADIMAGE....
  4. RotoZoom _WIDTH / 2, _HEIGHT / 2, image&, _WIDTH, _HEIGHT, 1, 1, 1, 45
  5. _PRINTIMAGE 0 'print current screen
  6.  
  7.  
  8. SUB RotoZoom (X AS INTEGER, Y AS INTEGER, Image AS LONG, startx AS INTEGER, starty AS INTEGER, xoffset AS INTEGER, yoffset AS INTEGER, Scale AS SINGLE, Rotation AS SINGLE)
  9.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  10.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  11.     px(0) = (-xoffset + startx) / 2: py(0) = (-yoffset + starty) / 2: px(1) = (-xoffset + startx) / 2: py(1) = (yoffset - starty) / 2
  12.     px(2) = (xoffset - startx) / 2: py(2) = (yoffset - starty) / 2: px(3) = (xoffset - startx) / 2: py(3) = (-yoffset + starty) / 2
  13.     sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
  14.     FOR i& = 0 TO 3
  15.         x2& = Scale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = Scale * (py(i&) * cosr! - px(i&) * sinr!) + Y
  16.         px(i&) = x2&: py(i&) = y2&
  17.     NEXT
  18.     _MAPTRIANGLE (startx, starty)-(startx, yoffset - 1)-(xoffset - 1, yoffset - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  19.     _MAPTRIANGLE (startx, starty)-(xoffset - 1, starty)-(xoffset - 1, yoffset - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  20.  
Title: Re: Turn page 90 degrees
Post by: Pete on November 19, 2018, 04:29:55 pm
I don't work with graphics and I don't know enough about the orientation of color, hue, pixel 0 or 1, etc., to make a real gif, png example, etc. If this was SCREEN 0, you would find the color and character and use loops to re-orient the object. Anyway, just to demonstrate the concept. Maybe something like this could be implemented to work with _PRINTSTRING. Of course, the other elements in an image, hue, etc., would have to be mapped and the algorithms adjusted accordingly, but this was fun...

Code: QB64: [Select]
  1. ' Portrait to Landscape pseudosimulation.
  2. DATA This is a phony gif header
  3. DATA 1A1B1C1D1E
  4. DATA 2F2G2H2I2J
  5. DATA 3K3L3M3N3O
  6.  
  7. ' Get height and width
  8. DO UNTIL a$ = "EOF"
  9.     i = i + 1
  10.     READ a$
  11.     IF i > 1 THEN
  12.         IF i = 2 THEN ' Get width
  13.             gifwidth = LEN(a$)
  14.         END IF
  15.     END IF
  16. gifheight = i - 2 ' Subtract 2 for header and EOF
  17.  
  18. ' Draw a portrait orientation pic.
  19. i = 0
  20.     i = i + 1
  21.     READ a$
  22.     IF a$ = "EOF" THEN EXIT DO
  23.     IF i > 1 THEN
  24.         pic$ = pic$ + a$
  25.     END IF
  26.  
  27. PRINT "Portrait Orientation": PRINT
  28. FOR i = 1 TO LEN(pic$) / 2
  29.     a = VAL(MID$(pic$, i * 2 - 1, 1))
  30.     a$ = MID$(pic$, i * 2, 1)
  31.     COLOR a
  32.     PRINT CHR$((ASC(UCASE$(a$)) - 65 + 127));
  33.     IF i MOD gifwidth / 2 = 0 THEN PRINT
  34. COLOR 7, 0
  35.  
  36. REDIM a$(gifwidth) ' This will be the new height when rotated.
  37. i = 0
  38.  
  39.     h = h + 1
  40.     READ a$
  41.     IF a$ = "EOF" THEN EXIT DO
  42.     IF h > 1 THEN
  43.         j = j + 1
  44.         FOR i = 1 TO gifwidth / 2
  45.             x$ = MID$(a$, i * 2 - 1, 2)
  46.             a$(i) = x$ + a$(i)
  47.         NEXT
  48.     END IF
  49.  
  50. 'PRINT
  51. 'FOR i = 1 TO gifwidth
  52. 'PRINT i, a$(i)
  53. 'NEXT
  54.  
  55. FOR i = 1 TO gifwidth
  56.     newpic$ = newpic$ + a$(i)
  57.  
  58. PRINT: PRINT "Landscape Orientation": PRINT
  59. FOR i = 1 TO LEN(newpic$) / 2
  60.     a = VAL(MID$(newpic$, i * 2 - 1, 1))
  61.     a$ = MID$(newpic$, i * 2, 1)
  62.     COLOR a
  63.     PRINT CHR$((ASC(UCASE$(a$)) - 65 + 127));
  64.     IF i MOD gifheight = 0 THEN PRINT
  65. COLOR 7, 0


Pete
Title: Re: Turn page 90 degrees
Post by: doppler on November 20, 2018, 11:43:33 am
If you are still using a CRT monitor it's possible to turn the yoke on the monitor neck to achieve the effect you want.
If you are using a led monitor just flip it on it's side.

K.I.S.S. no need for complex programs.
Title: Re: Turn page 90 degrees
Post by: Pete on November 20, 2018, 12:03:13 pm
Yeah, but he wants to PRINT it. Oh that's right, just turn the printer on its side, right? I'm guilty of making this same joke on a similar QBasic thread, some 15 years ago. I think back then I recommended using printer escape codes, to tell the printer to switch the orientation to landscape, but I'm pretty sure that was for a text document, not a graphic.

Pete
Title: Re: Turn page 90 degrees
Post by: Juanjogomez on November 20, 2018, 02:29:43 pm
Thanks Petr, I did not know the function _MAPTRIANGLE
I have already been able to do it.
Title: Re: Turn page 90 degrees
Post by: Pete on November 20, 2018, 03:58:59 pm
What values did you use to get it to go from 45% to 90%? Also, it looked to me like Rotozoom when taking a full screen image let the corners get chopped off, instead of truncating the image to fit on the screen.

Pete
Title: Re: Turn page 90 degrees
Post by: TempodiBasic on November 21, 2018, 09:04:53 am
Well
QB64 let use the default printer that results from settings of OS.
But is there some statement to access to the settings of default printer?

Try just Galleon example in the wiki about printing and making a preview.
It is not clear how to change direction of the output in printing.... yes you can workaround
rotating the  image to print but how it fits on the paper?
Mixing RotoZoom with the above talked example in the wiki I get no good results.
Title: Re: Turn page 90 degrees
Post by: Pete on November 21, 2018, 11:51:39 am
Well the ESC sequence for landscape printing would be...

LPRINT CHR$(27)&l1O ' Which is sending the sequence [ESC] & l 1O (el one Oh) to the printer. I hope I have that coded right, it's been 12 years since I used this with QB45. By coded right, I mean I can't recall if a "+" sign is needed after the CHR$(27) or not. i think the "&" sign combines it properly, but I just can no longer recall.

As far as how to access the default printer with QB64, I believe someone once pointed out you needed to make a library to access the Windows API in Windows. I don't even want to guess about how to do it in Linux or Mac.

Pete
Title: Re: Turn page 90 degrees
Post by: Juanjogomez on November 21, 2018, 12:25:30 pm
With this sentences works perfectly. A4 landscape to A4 in printer.

Page& = _NEWIMAGE(2970, 2100, 32) '---A4 landscape
NewPage& = _NEWIMAGE(2100, 2970, 32) '---A4 normal
_DEST NewPage&
 CLS , _RGB(255, 255, 255)'make background white to save ink!
_DEST Page&
 CLS , _RGB(255, 255, 255) 'make background white to save ink!
_DEST 0

´´´´´´print text in Page&

_MAPTRIANGLE (2970, 2100)-(2970, 0)-(0, 0), Page& TO(0, 2970)-(2100, 2970)-(2100, 0), NewPage&
_MAPTRIANGLE (2970, 2100)-(0, 2100)-(0, 0), Page& TO(0, 2970)-(0, 0)-(2100, 0), NewPage&
_PRINTIMAGE NewPage&
Title: Re: Turn page 90 degrees
Post by: Petr on November 21, 2018, 12:34:40 pm
Juanjogomez:
Quote
Thanks Petr, I did not know the function _MAPTRIANGLE
I have already been able to do it.

I am glad, it helped you

Pete:
Quote
Well the ESC sequence for landscape printing would be...

LPRINT CHR$(27)&l1O ' Which is sending the sequence [ESC] & l 1O (el one Oh) to the printer. I hope I have that coded right, it's been 12 years since I used this with QB45. By coded right, I mean I can't recall if a "+" sign is needed after the CHR$(27) or not. i think the "&" sign combines it properly, but I just can no longer recall.

As far as how to access the default printer with QB64, I believe someone once pointed out you needed to make a library to access the Windows API in Windows. I don't even want to guess about how to do it in Linux or Mac.

Pete

I'm afraid I've read somewhere that QB64 does not support these print control codes.
Title: Re: Turn page 90 degrees
Post by: Pete on November 21, 2018, 12:43:27 pm
I haven't used LPRINT in years so I checked the Wiki and...

"Note: Printer escape codes starting with CHR$(27) will not work with LPRINT and may produce text printing errors."

That's a shame. I'm going to read up a bit on Windows print settings, next.

OK, I modified this, from the Wiki article, to find the default printer...

Code: QB64: [Select]
  1. ' WARNING: Be sure you don't already have "default.txt" as a text file in your directory or running this will overwrite that file.
  2. SHELL _HIDE "CMD /C" + "wmic printer get name,default > default.txt"
  3. OPEN "default.txt" FOR INPUT AS #1
  4.     LINE INPUT #1, a$
  5.     PRINT a$


The word "True" will appear before the default printer device. There is another example that allows you to change the default printer in a similar manner, which leads me to wonder if the command window has a sequence that would change the orientation setting to landscape and back.

Well, I suppose it depends on the printers. Some helpful articles online to send escape codes via the command line:

https://stackoverflow.com/questions/30255647/print-a-file-in-landscape-from-windows-command-line-or-powershell

https://groups.google.com/forum/#!topic/microsoft.public.word.pagelayout/wXJoer4u1Eg


Pete


Title: Re: Turn page 90 degrees
Post by: SMcNeill on November 21, 2018, 01:17:36 pm
For Windows, you can change printer settings with powershell:  https://docs.microsoft.com/en-us/powershell/module/printmanagement/set-printconfiguration?view=win10-ps
Title: Re: Turn page 90 degrees
Post by: Pete on November 21, 2018, 01:33:31 pm
I read that Powershell does not effect orientation settings.

https://powershell.org/forums/topic/changing-printer-output-to-landscape/

Pete
Title: Re: Turn page 90 degrees
Post by: SMcNeill on November 21, 2018, 03:35:15 pm
I read that Powershell does not effect orientation settings.

https://powershell.org/forums/topic/changing-printer-output-to-landscape/

Pete

Try this command and see if it doesn't work for you:

Code: QB64: [Select]
  1. SetPrinter "” 8 pDevMode=dmOrientation=1

The "" basically says to apply orientation changes to ALL your printers.  Feel free to use the specific name of one, if you don't want to change them all.  (Such as "EPSON1BF169 (WF-3640 Series)" on my machine.)

dmOrientation is 1 for Landscape, 2 for Portrait.  (If I remember correctly...)

There's a boatload of things that SetPrinter can change for you, so my advice would be to go to your command line and just type:   SetPrinter /?

Once you get a basic list of things, give the inbuilt examples a go:   
SetPrinter /examples 0
SetPrinter /examples 8



Code: QB64: [Select]
  1. SetPrinter -show "" 8

The above will give you a list of all the level 8 options which you can change with SetPrinter.  Not all printers/devices allow changes to orientation, so make certain that the device you want to work with allows that.
Title: Re: Turn page 90 degrees
Post by: Pete on November 21, 2018, 03:44:06 pm
Actually, my Win 10 command prompt does not recognize SetPrinter.

GoFigure /?

Anyway, no worries. I don't need this for any of my projects. I was just hunting a bit for alternatives, since esc codes are no longer supported. I suppose being able to print over a network or USB printer is just compensation for the loss.

Pete
Title: Re: Turn page 90 degrees
Post by: SMcNeill on November 21, 2018, 03:54:34 pm
SetPrinter has been around since Win Server 2000; it should definitely be in your Win 10 machine.  https://docs.microsoft.com/en-us/windows/desktop/printdocs/setprinter

Try opening a cmd prompt with admin privileges and let me know what happens.  I'm using Win10 and have no issues with it.  I'd love to sort out what the differences might be.
Title: Re: Turn page 90 degrees
Post by: Pete on November 21, 2018, 04:07:29 pm
Nope. Opened as admin and it still can't find it. BTW, just to be absolutely sure, I not only typed SetPrinter /? but I also copied and pasted it from your post, so no typos.

Pete
Title: Re: Turn page 90 degrees
Post by: TempodiBasic on November 21, 2018, 05:14:21 pm
Hi Pete
from the link posted https://docs.microsoft.com/en-us/powershell/module/printmanagement/set-printer?view=win10-ps (https://docs.microsoft.com/en-us/powershell/module/printmanagement/set-printer?view=win10-ps)
I can understand that after opening a cmd window you must type before "Powershell"   and then set-printer...
yes be careful to put the - between set and printer.
More than Set-Printer in PowerShell you can use
Set-printerconfiguration
https://docs.microsoft.com/en-us/powershell/module/printmanagement/set-printconfiguration?view=win10-ps (https://docs.microsoft.com/en-us/powershell/module/printmanagement/set-printconfiguration?view=win10-ps)
and
Set-Printerproperty
https://docs.microsoft.com/en-us/powershell/module/printmanagement/set-printerproperty?view=win10-ps (https://docs.microsoft.com/en-us/powershell/module/printmanagement/set-printerproperty?view=win10-ps)
....
ok and in Linux or Macos? How is possible to change from landscape to protrait and viceversa?
Title: Re: Turn page 90 degrees
Post by: Pete on November 21, 2018, 07:19:57 pm
OK, I'll try set-printer /? instead of SetPrinter /?

I'm in Powershell...

PS C:\Windows\System32>set-printer /?

No help info is generated. It just immediately goes back to the prompt, so...

PS C:\Windows\System32>set-printer /?
PS C:\Windows\System32>

That's what I get.

Usually Microsoft includes a help screen but maybe there isn't one for this command.

Pete
Title: Re: Turn page 90 degrees
Post by: SMcNeill on November 21, 2018, 08:01:10 pm
Looking on my machine, SetPrinter is in a "Windows Resource Kit" folder, so it may have been something I downloaded in a package in the past.  I think all that's needed to use it is the exe itself, so give it a try and see what you get.