Page 1 of 1
LoadFont Current Name?
Posted: Sun Jan 31, 2021 7:21 am
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)
Re: LoadFont Current Name?
Posted: Sun Jan 31, 2021 3:02 pm
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.
Re: LoadFont Current Name?
Posted: Sun Jan 31, 2021 5:04 pm
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.
Re: LoadFont Current Name?
Posted: Sun Jan 31, 2021 5:18 pm
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().
Re: LoadFont Current Name?
Posted: Sun Jan 31, 2021 6:18 pm
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
Re: LoadFont Current Name?
Posted: Sun Jan 31, 2021 7:10 pm
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))
Re: LoadFont Current Name?
Posted: Sun Jan 31, 2021 7:20 pm
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>")
Re: LoadFont Current Name?
Posted: Mon Feb 01, 2021 3:01 am
by useful
Thank you all.
Both in SB and PB I am missing next to (loadfont,setfont) GETFONT.