Page 1 of 1

Different font style , size & color in same line

Posted: Wed Aug 18, 2021 4:39 pm
by RASHAD
Hi

Code: Select all

LoadFont(0, "Arial", 12)
LoadFont(1, "Times New Roman", 12, #PB_Font_Italic)
LoadFont(2, "Georgia", 12,#PB_Font_StrikeOut)

If OpenWindow(0, 0, 0, 600, 100, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 600, 100)
  
  If StartVectorDrawing(CanvasVectorOutput(0))
    VectorFont(FontID(0), 50)
    hb1 = VectorTextHeight("Hi",#PB_VectorText_Baseline)
    VectorSourceColor(RGBA(0, 255, 255, 255))
    MovePathCursor(10 ,10)
    DrawVectorText("Hi")
    x = PathCursorX()
    
    VectorFont(FontID(1), 12)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    hb2 = VectorTextHeight("from PB",#PB_VectorText_Baseline)
    MovePathCursor(x+4 ,10 + hb1 - hb2)
    DrawVectorText("from PB")
    x = PathCursorX()
    
    VectorFont(FontID(2), 30)
    VectorSourceColor(RGBA(0, 0, 255, 255))
    hb3 = VectorTextHeight("ShadowStorm",#PB_VectorText_Baseline)
    MovePathCursor(x+4,10 + hb1 - hb3)
    DrawVectorText("ShadowStorm")
        
    StopVectorDrawing()
    FreeFont(0)
    FreeFont(1)
    FreeFont(2)
  EndIf
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf




Re: Different font style , size & color in same line

Posted: Wed Aug 18, 2021 6:54 pm
by davido
@RASHAD,
Nice example. Thank you for sharing :D
Works on my MacBook, too.

Re: Different font style , size & color in same line

Posted: Thu Aug 19, 2021 7:24 pm
by mk-soft
Very nice :wink:

As small function VectorPrint

Code: Select all

LoadFont(0, "Arial", 12)
LoadFont(1, "Times New Roman", 12, #PB_Font_Italic)
LoadFont(2, "Georgia", 12,#PB_Font_StrikeOut)


Procedure VectorPrint(Text.s, x.d = #PB_Ignore, y.d = #PB_Ignore)
  Static pos_x.d, pos_y.d
  Protected height.d
  If x >= 0.0
    pos_x = x
  EndIf
  If y >= 0.0
    pos_y = y
  EndIf
  height = VectorTextHeight(Text,#PB_VectorText_Baseline)
  MovePathCursor(pos_x, pos_y - height)
  DrawVectorText(Text)
  pos_x = PathCursorX()
EndProcedure


If OpenWindow(0, 0, 0, 600, 100, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 600, 100)
  
  If StartVectorDrawing(CanvasVectorOutput(0))
    VectorFont(FontID(0), 50)
    VectorSourceColor(RGBA(0, 255, 255, 255))
    VectorPrint("Hi", 20, 50)
    
    VectorFont(FontID(1), 12)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    VectorPrint(" from PB ")
    
    VectorFont(FontID(2), 30)
    VectorSourceColor(RGBA(0, 0, 255, 255))
    VectorPrint("ShadowStorm")
        
    StopVectorDrawing()
    FreeFont(0)
    FreeFont(1)
    FreeFont(2)
  EndIf
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

Re: Different font style , size & color in same line

Posted: Fri Aug 20, 2021 12:13 am
by ShadowStorm
Thanks, I'm working on a function like this, but I can't do it right now, see my topic in beginner :)

I would like something like:

AddVectorText(Text.s, Font.s, Style.i, Size, TextColor.i, TextBackColor.i)

Each call of this function will calculate the text, positions, etc.
Each text will be put next to each other.

You have to think of a function or an option to change the line.
For example: AddVectorTextNewLine()

Then a function to draw the text on the surface I want
For example something like:

If StartVectorDrawing(CanvasVectorOutput(0))
DrawVectorText()
StopVectorDrawing()
EndIf

This is just an idea, but I would like to make it very easy to use, I have a lot of trouble with vectors, even more with text!

Thank you!

Re: Different font style , size & color in same line

Posted: Sat Aug 21, 2021 6:08 am
by RASHAD
@Davido,mk-soft
Thanks guys