Printing TextGadget with NewLine

Just starting out? Need help? Post your questions and find answers here.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Printing TextGadget with NewLine

Post by VB6_to_PBx »

Printing TextGadget with NewLine

the TextGadget correctly displays 2 lines of Text
but it only prints 1 line of Text

how can i Print the 2 lines of text like it shows in the TextGadget ??

Code: Select all

;        TextGadget_with_NewLine_Math_Printing__v1

LoadFont(1,"Verdana",10)
SetGadgetFont(#PB_Default,FontID(1))

CrLf$ = Chr(13)+ Chr(10)

X.D = 123.456 * 2


txt$ = "TextGadget " + CrLf$ + StrD(X.D,5)

OpenWindow(0, 0, 0, 270, 160, "TextGadget_with_NewLine", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(1, 30,  10, 250, 40, txt$)

PrintRequester()
StartPrinting("")
LoadFont(2, "Arial", 80)
StartDrawing(PrinterOutput())
DrawingFont(FontID(2))
DrawText(100, 800, txt$,RGB(0,0,255),RGB(255,255,255))
StopDrawing()
StopPrinting()

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
HeX0R
Addict
Addict
Posts: 1187
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Printing TextGadget with NewLine

Post by HeX0R »

You have to do it on your own, like this:

Code: Select all

;        TextGadget_with_NewLine_Math_Printing__v1

Procedure MyDrawText(x, y, Text$, FrontColor, BackColor)
	Protected i, yPosAdd
	
	For i = 0 To CountString(Text$, #LF$)
		DrawText(x, y + yPosAdd, StringField(Text$, i + 1, #LF$), FrontColor, BackColor)
		yPosAdd + TextHeight(StringField(Text$, i + 1, #LF$))
	Next i
EndProcedure


LoadFont(1,"Verdana",10)
SetGadgetFont(#PB_Default,FontID(1))

X.D = 123.456 * 2


txt$ = "TextGadget " + #LF$ + StrD(X.D,5)

OpenWindow(0, 0, 0, 270, 160, "TextGadget_with_NewLine", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(1, 30,  10, 250, 40, txt$)

PrintRequester()
StartPrinting("")
LoadFont(2, "Arial", 80)
StartDrawing(PrinterOutput())
DrawingFont(FontID(2))
MyDrawText(100, 800, txt$,RGB(0,0,255),RGB(255,255,255))
StopDrawing()
StopPrinting()

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
hichem
User
User
Posts: 26
Joined: Sun Sep 04, 2005 4:18 pm

Re: Printing TextGadget with NewLine

Post by hichem »

something like this :

Code: Select all

LoadFont(1,"Verdana",10)
SetGadgetFont(#PB_Default,FontID(1))

; CrLf$ = Chr(13)+ Chr(10)

X.D = 123.456 * 2


txt$ = "TextGadget " + #CRLF$ + StrD(X.D,5)

OpenWindow(0, 0, 0, 270, 160, "TextGadget_with_NewLine", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(1, 30,  10, 250, 40, txt$)

PrintRequester()
StartPrinting("")
LoadFont(2, "Arial", 80)
StartDrawing(PrinterOutput())
DrawingFont(FontID(2))
For ii = 1 To CountString(txt$,#CRLF$)+1
  DrawText(100, 800+((ii-1)*TextHeight("gM")), StringField(txt$,ii,#CRLF$),RGB(0,0,255),RGB(255,255,255))
Next  
StopDrawing()
StopPrinting()

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
haven't seen your replay HeX0R sorry.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Printing TextGadget with NewLine

Post by IdeasVacuum »

I think you have to send the text as two printable lines.

If you want to do any serious amount of printing on Windows, use ABBKlaus's lib: Printer Lib

However, I tested your example in the lib and two lines of output are still required:

Code: Select all

sOPT.s = "Orientation=" + Str(#DMORIENT_PORTRAIT) + ","
sOPT + "Papersize="   + Str(#DMPAPER_A4)

If Print_OpenPrinter("",sOPT)

      Print_StartPrinting("My Print")
      Print_Font("Arial",14,#PB_Font_HighQuality + 1)
      Print_SetTextColor(RGB(0,0,255))
      Print_Text(100,100,"TextGadget")
      Print_Text(100,106,StrD(X.D,5))
      Print_StopPrinting()

EndIf
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: Printing TextGadget with NewLine

Post by VB6_to_PBx »

thanks IdeasVacuum, for Link to Printer library

also thanks :
HeX0R
hichem

for solutions !
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
Post Reply