LoadFont Current Name?

Just starting out? Need help? Post your questions and find answers here.
User avatar
useful
Posts: 116
Joined: Tue Feb 25, 2014 1:15 pm

LoadFont Current Name?

Post by useful »

Result = LoadFont(#Font, Name$, Height [, Flags])
How to change the Size and Bold or Italic without changing the Name?
For example
LoadFont(#Font, "", 32 , #PB_Font_Bold) or LoadFont(#Font, #PB_Ignore, 32 , #PB_Font_Bold)
2B or not 2B = FF
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: LoadFont Current Name?

Post by Peter »

Code: Select all

EnableExplicit

Procedure AdjustFont(Font, Height, Flags)
  
  If IsFont(Font) = 0 : ProcedureReturn : EndIf
  
  ! var font = spider.font.objects.Get(v_font);
  ! var fontFamily = font.family;
  ! spider_FreeFont(v_font);
  ! spider_LoadFont(v_font, fontFamily, v_height, v_flags);
  
EndProcedure

OpenWindow(0, 0, 0, 222, 130, "SetGadgetFont", #PB_Window_ScreenCentered)
LoadFont(0, "Arial", 16)

ButtonGadget(0, 10, 10, 200, 30, "Arial 16")
SetGadgetFont(0, FontID(0))

AdjustFont(0, 32, #PB_Font_Italic | #PB_Font_Bold) ; adjust Font 0
SetGadgetFont(0, FontID(0)) ; reassign font to the gadget
// Edit: there was a different (more cumbersome) code here before. I think this one is better.
User avatar
useful
Posts: 116
Joined: Tue Feb 25, 2014 1:15 pm

Re: LoadFont Current Name?

Post by useful »

I probably didn't describe the question correctly
In your example:
LoadFont(0, "Arial", 16)
. i.e. you have already defined the font.family "Arial"

And I don't want to know. I want to change the size and attributes of the font that in each case has already been defined by someone before.
2B or not 2B = FF
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: LoadFont Current Name?

Post by Peter »

Maybe I'm still misunderstanding you, but if you want to change a font(-style), you must have the font number. And if you have it, then you can call AdjustFont().
User avatar
useful
Posts: 116
Joined: Tue Feb 25, 2014 1:15 pm

Re: LoadFont Current Name?

Post by useful »

Code: Select all

OpenWindow(0, 0, 0, 222, 130, "SetGadgetFont", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 30, "default font")

;??????????
MyLoadFont(1,#PB_Ignore, #PB_Ignore , #PB_Font_Bold)
;??????????

ButtonGadget(1, 10, 40, 200, 30, "default font bold")
SetGadgetFont(1, FontID(1))
how to leave the default family font, and only change the size and bold or(and) italic
2B or not 2B = FF
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: LoadFont Current Name?

Post by Peter »

something like this?

Code: Select all

OpenWindow(0, 0, 0, 222, 130, "SetGadgetFont", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 30, "default font")

Define GID
Define FontName.s
Define FontHeight

GID = GadgetID(0)

! v_fontname = $(v_gid.div).css("fontFamily");
! v_fontheight = $(v_gid.div).css("fontSize");

LoadFont(1, FontName, FontHeight, #PB_Font_Bold)

ButtonGadget(1, 10, 40, 200, 30, "default font bold")
SetGadgetFont(1, FontID(1))
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: LoadFont Current Name?

Post by plouf »

spiderbasic itself do not support directly what you are trying to achieve
you have to mess your self with page's css

changing globally will affect everything.
The "trick" is to explicit use span element inside button text to trick it, you also change text later to alter this
an example of this

Code: Select all

OpenWindow(0, 0, 0, 222, 130, "SetGadgetFont", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 30, "global size font 150%")

; Following javascrtipt command changes size GLOBALLY to all of yous page, no matter before or after
! document.body.style.fontSize = "150%";

ButtonGadget(1, 10, 40, 200, 30, "<span style='font-size:22px'> fixed 22px</span>")
ButtonGadget(2, 10, 80, 200, 30, "<span style='font-size:50%'> fixed 50%</span>") 
SetGadgetText(2,"<span style='font-size:20%'> fixed 20%</span>")
Christos
User avatar
useful
Posts: 116
Joined: Tue Feb 25, 2014 1:15 pm

Re: LoadFont Current Name?

Post by useful »

Thank you all.
Both in SB and PB I am missing next to (loadfont,setfont) GETFONT.
2B or not 2B = FF
Post Reply