DrawVectorText() can also multiline output

Just starting out? Need help? Post your questions and find answers here.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

DrawVectorText() can also multiline output

Post by Saki »

Hello, everyone,
I notice,
DrawVectorText() can be multiline

This is wrong in the documentary :
"This function draws single lines of text only. Multiple calls must be made to draw multiple lines."

Code: Select all

Define window = OpenWindow(#PB_Any, 0, 0, 600, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define canvas = CanvasGadget(#PB_Any, 0, 0, 800, 600)

Define font = LoadFont(#PB_Any, "", 36, #PB_Font_Bold)

Define text$ = "DrawVectorText()"+#LF$+"can also multiline"+#LF$+"output !"+#LF$+"Best regards - Saki"

StartVectorDrawing(CanvasVectorOutput(canvas))

VectorFont(FontID(font))
VectorSourceColor($FFFF0000)

MovePathCursor (100, 10)
DrawVectorText(text$)
StopVectorDrawing()

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
地球上の平和
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: DrawVectorText() can also multiline output

Post by wombats »

It isn't on macOS.

Image
User avatar
skywalk
Addict
Addict
Posts: 3996
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: DrawVectorText() can also multiline output

Post by skywalk »

Interesting :idea:
Is this a bug or can we rely on this behavior?

wombats - Can you try #CR$ instead of #LF$?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: DrawVectorText() can also multiline output

Post by Shardik »

skywalk wrote:Can you try #CR$ instead of #LF$?
No, changing #CR$ to #LF$ or #CRLF$ doesn't change anything on MacOS (PB 5.72 x86 on High Sierra).
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: DrawVectorText() can also multiline output

Post by wombats »

skywalk wrote:Interesting :idea:
Is this a bug or can we rely on this behavior?

wombats - Can you try #CR$ instead of #LF$?
Same result.

On Linux, GTK is multiline and Qt is not (tested both #LF$ and #CR$).
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: DrawVectorText() can also multiline output

Post by freak »

Only single-line text is supported everywhere. If it works on some OS you cannot rely on it because this may change in the future.
quidquid Latine dictum sit altum videtur
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: DrawVectorText() can also multiline output

Post by Danilo »

For multiline:

Code: Select all

Procedure DrawVectorTextPro(text$)
    ;
    ; Multi-line DrawVectorText(). Lines separated by #LF$.
    ;
    Protected count = CountString(text$,#LF$)
    Protected height.d = VectorTextHeight(text$)
    Protected i, x = PathCursorX(), y = PathCursorY()
    For i = 0 To count
        MovePathCursor(x,y+(i*height))
        DrawVectorText(StringField(text$,i+1,#LF$))
    Next
EndProcedure

Define window = OpenWindow(#PB_Any, 0, 0, 600, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define canvas = CanvasGadget(#PB_Any, 0, 0, 800, 600)

Define font = LoadFont(#PB_Any, "", 36, #PB_Font_Bold)

Define text$ = "DrawVectorText()"+#LF$+"can also multiline"+#LF$+"output !"+#LF$+"Best regards - Saki"

StartVectorDrawing(CanvasVectorOutput(canvas))

VectorFont(FontID(font))
VectorSourceColor($FFFF0000)

MovePathCursor (100, 10)
RotateCoordinates(100, 10, 20)
DrawVectorTextPro(text$)
StopVectorDrawing()

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
mk-soft
Always Here
Always Here
Posts: 5398
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: DrawVectorText() can also multiline output

Post by mk-soft »

Now update my DrawTextBox to DrawVectorTextBox :wink:

Link: viewtopic.php?f=12&t=75341
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: DrawVectorText() kann auch mehrzeilige Ausgabe

Post by Saki »

Many thanks Danielo.
Its a little but important new function

@MK-Soft:
This is a very nice work
Replacing the line breaks is also amazing
地球上の平和
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: DrawVectorText() can also multiline output

Post by IdeasVacuum »

Multiline is very useful (Using Danilo's Procedure today!), thanks for sharing guys.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: DrawVectorText() kann auch mehrzeilige Ausgabe

Post by Saki »

You can do a lot more now

viewtopic.php?f=13&t=75332

Best regards Saki

Code: Select all

; By Danilo
Procedure.d VectorTextWidthPro(text$, flags=#PB_VectorText_Default)
  ; Returns the VectorTextWidth() of the longest line (separated by #LF$)
  ;
  Protected i, width.d, result.d = 0.0, count = CountString(text$,#LF$)
  For i = 0 To count
    width = VectorTextWidth(StringField(text$,i+1,#LF$),flags)
    If width > result
      result = width
    EndIf
  Next
  Debug result
  ProcedureReturn result
EndProcedure

; By Danilo
Procedure.d VectorTextHeightPro(text$, flags=#PB_VectorText_Default)
  ;
  ; Returns the VectorTextHeight() of all lines (separated by #LF$)
  ;
  ProcedureReturn VectorTextHeight(text$, flags) * (CountString(text$,#LF$) + 1)
EndProcedure

; By Danilo
Procedure DrawVectorTextPro(text$, x, y)
  ;
  ; Multi-line DrawVectorText(). Lines separated by #LF$.
  ;
  Protected count = CountString(text$,#LF$)
  Protected height.d = VectorTextHeight(text$)
  Protected i
  For i = 0 To count
    MovePathCursor(x,y+(i*height))
    DrawVectorText(StringField(text$,i+1,#LF$))
  Next
EndProcedure

Define window = OpenWindow(#PB_Any, 0, 0, 800, 600, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define canvas = CanvasGadget(#PB_Any, 0, 0, 800, 600)

Define font = LoadFont(#PB_Any, "", 21, #PB_Font_Bold)

Define text$ = "DrawVectorText()"+#LF$+"can also multiline"+#LF$+"output !"+#LF$+"Best regards - Saki"

Define x=200
Define y=0

StartVectorDrawing(CanvasVectorOutput(canvas))

VectorFont(FontID(font))

MovePathCursor (x, y)

RotateCoordinates(y, y, 20)

VectorSourceColor($FF00FFFF)

Define padding=VectorTextwidthPro(Space(6))

AddPathBox(x-padding, y - padding, VectorTextWidthPro(text$) + padding * 2, VectorTextHeightPro(text$))

FillPath()

VectorSourceColor($FF0000FF)

AddPathBox(x-padding, y - padding, VectorTextWidthPro(text$) + padding * 2, VectorTextHeightPro(text$))

StrokePath(6)

VectorSourceColor($FFFF0000)

DrawVectorTextPro(text$, x, y)

StopVectorDrawing()

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Last edited by Saki on Sat May 16, 2020 3:41 pm, edited 1 time in total.
地球上の平和
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: DrawVectorText() can also multiline output

Post by Danilo »

@Saki: You need to change

Code: Select all

AddPathBox(x-padding, y - padding, VectorTextWidthPro(text$) + padding * 2, VectorTextHeightPro(text$))
to

Code: Select all

AddPathBox(x-padding, y - padding, VectorTextWidthPro(text$) + padding * 2, VectorTextHeightPro(text$) + padding * 2)
(2 times)
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: DrawVectorText() kann auch mehrzeilige Ausgabe

Post by Saki »

Hi Danielo,
make a try, its because,
the height calculating is a litte strange
地球上の平和
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: DrawVectorText() kann auch mehrzeilige Ausgabe

Post by Danilo »

Saki wrote:Hi Danielo,
make a try, its because,
the height calculating is a litte strange
It works on macOS, but maybe you get strange results because you loaded font "". Try to use a font name like "Arial".
User avatar
mk-soft
Always Here
Always Here
Posts: 5398
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: DrawVectorText() can also multiline output

Post by mk-soft »

Unfortunately the font sizes fall differently to the OS.

Part of DrawVectorTextBox example ...

Code: Select all

Define hfont = LoadFont(0, "Arial", 12);, #PB_Font_Bold)
    
    If  StartVectorDrawing(output)
      
      ResetCoordinatesDPI()
      
      CompilerSelect #PB_Compiler_OS
        CompilerCase #PB_OS_Windows
          VectorFont(hfont, 13)
        CompilerCase #PB_OS_MacOS
          VectorFont(hfont, 16)
        CompilerCase #PB_OS_Linux
          VectorFont(hfont, 12)
      CompilerEndSelect
    
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply