Page 1 of 1

LoadFont and line-height

Posted: Fri Oct 02, 2020 1:00 pm
by Dirk Geppert
Hello, is there a way to adjust the properties of the loaded font?

I need more line-height..

Cya Dirk

Re: LoadFont and line-height

Posted: Fri Oct 02, 2020 1:45 pm
by Peter
Can you provide a small piece of code that illustrates your problem?

Re: LoadFont and line-height

Posted: Sat Oct 03, 2020 9:13 am
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

Re: LoadFont and line-height

Posted: Sat Oct 03, 2020 10:12 am
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

Re: LoadFont and line-height

Posted: Sat Oct 03, 2020 1:12 pm
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>")

Re: LoadFont and line-height

Posted: Sat Oct 03, 2020 1:40 pm
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

Re: LoadFont and line-height

Posted: Sat Oct 03, 2020 2:44 pm
by munfraid
That's much better indeed. Thanks, Peter!

Re: LoadFont and line-height

Posted: Mon Oct 05, 2020 10:02 am
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.