Author Topic: Turn page 90 degrees  (Read 3903 times)

0 Members and 1 Guest are viewing this topic.

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Turn page 90 degrees
« 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

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Turn page 90 degrees
« Reply #1 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.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Turn page 90 degrees
« Reply #2 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Turn page 90 degrees
« Reply #3 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.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Turn page 90 degrees
« Reply #4 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Turn page 90 degrees
« Reply #5 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.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Turn page 90 degrees
« Reply #6 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Turn page 90 degrees
« Reply #7 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.
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Turn page 90 degrees
« Reply #8 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Turn page 90 degrees
« Reply #9 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&
« Last Edit: November 21, 2018, 12:31:21 pm by Juanjogomez »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Turn page 90 degrees
« Reply #10 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.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Turn page 90 degrees
« Reply #11 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


« Last Edit: November 21, 2018, 01:04:12 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Turn page 90 degrees
« Reply #12 on: November 21, 2018, 01:17:36 pm »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Turn page 90 degrees
« Reply #13 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Turn page 90 degrees
« Reply #14 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.
« Last Edit: November 21, 2018, 03:41:14 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!