LoadFont and line-height

Just starting out? Need help? Post your questions and find answers here.
Dirk Geppert
Posts: 333
Joined: Fri Sep 22, 2017 7:02 am

LoadFont and line-height

Post by Dirk Geppert »

Hello, is there a way to adjust the properties of the loaded font?

I need more line-height..

Cya Dirk
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: LoadFont and line-height

Post by Peter »

Can you provide a small piece of code that illustrates your problem?
plouf
Posts: 295
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: LoadFont and line-height

Post by plouf »

i dont think he has a problem, i think he is asking how to change line-height of a font
this is a css atribute , and long as i know you can not do with spiderbasci commands
have to tweak css directly
Christos
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: LoadFont and line-height

Post by Peter »

plouf wrote:i think he is asking how to change line-height of a font this is a css atribute
line-height always refers to the element that uses the font; not to the font itself.

As there are many gadgets, I asked for a concrete example.

Furthermore, a sample code makes it easier for us to help.
plouf wrote:and long as i know you can not do with spiderbasci commands have to tweak css directly
yes, that is correct
munfraid
Posts: 135
Joined: Sat Mar 24, 2018 1:33 pm

Re: LoadFont and line-height

Post by munfraid »

Last time I needed this I just used this:

Code: Select all

OpenWindow(0, 100, 100, 400, 400, "Line-Height")
LoadFont(0, "Arial", 50)
SetGadgetFont(#PB_Default, FontID(0))
TextGadget(0, 10, 10, 380, 380, "<div style='line-height:150%'>Lorem ipsum dolor sit amet, consetetur sadipscing elitr</div>")
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: LoadFont and line-height

Post by Peter »

munfraid wrote:Last time I needed this I just used this:

Code: Select all

[...]
TextGadget(0, 10, 10, 380, 380, "<div style='line-height:150%'>Lorem ipsum dolor sit amet, consetetur sadipscing elitr</div>")
That's OK, but remember that you are adding an unnecessary div element to the TextGadget (span element). When changing text with SetGadgetText() you must always remember that the div element is included.

For this reason I find the following solution more appropriate:

Code: Select all

EnableExplicit

Procedure SetGadgetLineHeight(Gadget, LineHeight.s)
  
  If IsGadget(Gadget) = 0 : ProcedureReturn : EndIf
  
  Protected GID = GadgetID(Gadget)
  
  Select GadgetType(Gadget)
    Case #PB_GadgetType_Text
      ! $(v_gid.gadget).css("line-height", v_lineheight);
  EndSelect
  
EndProcedure

OpenWindow(0, 100, 100, 400, 400, "Line-Height")
LoadFont(0, "Arial", 50)
SetGadgetFont(#PB_Default, FontID(0))
TextGadget(0, 10, 10, 380, 380, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr")

SetGadgetLineHeight(0, "150%")
Greetings ... Peter
munfraid
Posts: 135
Joined: Sat Mar 24, 2018 1:33 pm

Re: LoadFont and line-height

Post by munfraid »

That's much better indeed. Thanks, Peter!
Dirk Geppert
Posts: 333
Joined: Fri Sep 22, 2017 7:02 am

Re: LoadFont and line-height

Post by Dirk Geppert »

Hello Peter, great, thank you very much! This is exactly what I need.

I use a textgadget to display some text. When I use my own font (bigger than the standard 13px font) the line height stays at 13px and the text is squeezed too much.
Post Reply