Take a look at the PrintRotatedText() procedure in the following code. I took an example of printing rotated text on an image and modified it to use the printer instead.
Code: Select all
;- draw rotated text on specified image
Procedure DrawRotatedText(Image.l, Text.s, X.l, Y.l, FontName.s, Size.l, Angle.l, Weight.l, Italic.l, Underline.l, StrikeOut.l, Color.l)
PrevFont.l
hFont.l
ImageDC.l
; get image device context for API calls
UseImage(Image)
ImageDC.l = StartDrawing(ImageOutput())
; font size is in pixels and negative
; if you are specifying the character height
lfHeight.l = Size * GetDeviceCaps_(ImageDC, #LOGPIXELSY) / 72
; create rotated font and select into image DC
hFont = CreateFont_(lfHeight, 0, Angle * 10, 0, Weight, Italic, Underline, StrikeOut, #ANSI_CHARSET, #OUT_TT_PRECIS, #CLIP_LH_ANGLES, #PROOF_QUALITY, #DEFAULT_PITCH|#FF_DONTCARE, FontName)
PrevFont = SelectObject_(ImageDC, hFont)
; set position
Locate(X, Y)
; transparent background
DrawingMode(1)
; draw text in specified color
FrontColor(Red(Color), Green(Color), Blue(Color))
DrawText(Text)
StopDrawing()
; clean up by restoring original font
SelectObject_(ImageDC, PrevFont)
DeleteObject_(hFont)
EndProcedure
;- draw rotated text on printer
Procedure PrintRotatedText(Text.s, X.l, Y.l, FontName.s, Size.l, Angle.l, Weight.l, Italic.l, Underline.l, StrikeOut.l, Color.l)
PrevFont.l
hFont.l
PrinterDC.l
; get printer device context for API calls
PrinterDC.l = StartDrawing(PrinterOutput())
; font size is in pixels and negative
; if you are specifying the character height
lfHeight.l = Size * GetDeviceCaps_(PrinterDC, #LOGPIXELSY) / 72
; create rotated font and select into printer DC
hFont = CreateFont_(lfHeight, 0, Angle * 10, 0, Weight, Italic, Underline, StrikeOut, #ANSI_CHARSET, #OUT_TT_PRECIS, #CLIP_LH_ANGLES, #PROOF_QUALITY, #DEFAULT_PITCH|#FF_DONTCARE, FontName)
PrevFont = SelectObject_(PrinterDC, hFont)
; set position
Locate(X, Y)
; transparent background
DrawingMode(1)
; draw text in specified color
FrontColor(Red(Color), Green(Color), Blue(Color))
DrawText(Text)
StopDrawing()
; clean up by restoring original font
SelectObject_(PrinterDC, PrevFont)
DeleteObject_(hFont)
EndProcedure
OpenWindow(0, 0, 0, 400, 300, #PB_Window_ScreenCentered|#PB_Window_SystemMenu, "Rotated Text Test")
CreateGadgetList(WindowID())
ImageGadget(1, 10, 10, 380, 280, 0)
CreateImage(2, 380, 280)
StartDrawing(ImageOutput())
Box(0, 0, ImageWidth(), ImageHeight(), RGB(128, 128, 128))
StopDrawing()
; rotated text on image
DrawRotatedText(2, "Rotated Text?", 190, 140, "Arial", 12, 0, #FW_SEMIBOLD, #False, #False, #False, RGB(255, 0, 0))
DrawRotatedText(2, "Rotated Text?", 190, 140, "Arial", 12, 90, #FW_SEMIBOLD, #False, #False, #False, RGB(0, 255, 0))
DrawRotatedText(2, "Rotated Text?", 190, 140, "Arial", 12, 180, #FW_SEMIBOLD, #False, #False, #False, RGB(0, 0, 255))
DrawRotatedText(2, "Rotated Text?", 190, 140, "Arial", 12, 270, #FW_SEMIBOLD, #False, #False, #False, RGB(255, 255, 255))
SetGadgetState(1, ImageID())
; rotated text on printer
If DefaultPrinter()
StartPrinting("Rotated Text")
PrintRotatedText("Rotated Text?", 1000, 2000, "Arial", 12, 0, #FW_SEMIBOLD, #False, #False, #False, RGB(255, 0, 0))
PrintRotatedText("Rotated Text?", 1000, 2000, "Arial", 12, 90, #FW_SEMIBOLD, #False, #False, #False, RGB(0, 255, 0))
PrintRotatedText("Rotated Text?", 1000, 2000, "Arial", 12, 180, #FW_SEMIBOLD, #False, #False, #False, RGB(0, 0, 255))
PrintRotatedText("Rotated Text?", 1000, 2000, "Arial", 12, 270, #FW_SEMIBOLD, #False, #False, #False, RGB(0, 0, 0))
StopPrinting()
EndIf
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow