Different font style , size & color in same line

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Different font style , size & color in same line

Post 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



Egypt my love
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

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

Post by davido »

@RASHAD,
Nice example. Thank you for sharing :D
Works on my MacBook, too.
DE AA EB
User avatar
mk-soft
Always Here
Always Here
Posts: 5398
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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
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
ShadowStorm
Enthusiast
Enthusiast
Posts: 237
Joined: Tue Feb 14, 2017 12:07 pm

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

Post 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!
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

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

Post by RASHAD »

@Davido,mk-soft
Thanks guys
Egypt my love
Post Reply