Page 2 of 2

Re: How to use a custom font?

Posted: Thu Dec 19, 2024 11:25 am
by Mijikai
Thank you, i tried it but it did not work for me.

Re: How to use a custom font?

Posted: Thu Dec 19, 2024 1:37 pm
by Caronte3D
Try it, but anyway I think you should separate the load of a font and the assign to a gadget:

Code: Select all

Procedure.i LoadCustomFont(gadget_id,FFamily.s="Arial", FPath.s="", FSize=10, Font_id=#PB_Any);<- would be nice to have the font family and path as parameters
  !var font = new FontFace(v_ffamily,'url('+v_fpath+')');
  !font.load().then(function(loadedFont) {
  !document.fonts.add(loadedFont);
  !$(v_gadget_id.gadget).css('font-family',v_ffamily+', sans-serif');
  !}).catch(function(error) {
  !return 0;
  !})  
  ProcedureReturn LoadFont(Font_id,FFamily,FSize,#PB_Font_HighQuality)
EndProcedure

 
  If OpenWindow(0, 0, 0, 270, 190, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    Define textwithfont=TextGadget(0, 10,  10, 250, 20, "TextGadget Standard (Left)")
    TextGadget(1, 10,  70, 250, 20, "TextGadget Center", #PB_Text_Center)
    TextGadget(2, 10,  40, 250, 20, "TextGadget Right", #PB_Text_Right)
    TextGadget(3, 10, 100, 250, 20, "TextGadget Border", #PB_Text_Border)
    TextGadget(4, 10, 130, 250, 20, "TextGadget Center + Border", #PB_Text_Center | #PB_Text_Border)
    TextGadget(5, 10, 160, 250, 20, "<b>Bold</b> TextGadget") ; Using HTML markup
    
    ; Load font on the first button
    Define FontZector=LoadCustomFont(textwithfont,"Zector","./resources/Fonts/Zector.ttf",10)  
  EndIf

Re: How to use a custom font?

Posted: Mon Dec 23, 2024 4:21 pm
by Mijikai
Thanks @Caronte3D and sorry for the late reply.
I lost the harddrive with the sources for two games in SB.
My original plan was to finish one of the games during the holidays.
When i get my motivation back i will definitely give this a try :)

Re: How to use a custom font?

Posted: Tue Dec 24, 2024 5:43 pm
by Fred
There is so many way to secure codes across drive/cloud/git etc, that's sad to hear in 2024

Re: How to use a custom font?

Posted: Thu Dec 26, 2024 12:59 am
by Mijikai
Was a brand new Laptop did not expect it to die within 2 weeks.

Re: How to use a custom font?

Posted: Sun Dec 29, 2024 6:26 am
by tj1010
Caronte3D wrote: Thu Dec 19, 2024 1:37 pm Try it, but anyway I think you should separate the load of a font and the assign to a gadget:

Code: Select all

Procedure.i LoadCustomFont(gadget_id,FFamily.s="Arial", FPath.s="", FSize=10, Font_id=#PB_Any);<- would be nice to have the font family and path as parameters
  !var font = new FontFace(v_ffamily,'url('+v_fpath+')');
  !font.load().then(function(loadedFont) {
  !document.fonts.add(loadedFont);
  !$(v_gadget_id.gadget).css('font-family',v_ffamily+', sans-serif');
  !}).catch(function(error) {
  !return 0;
  !})  
  ProcedureReturn LoadFont(Font_id,FFamily,FSize,#PB_Font_HighQuality)
EndProcedure

 
  If OpenWindow(0, 0, 0, 270, 190, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    Define textwithfont=TextGadget(0, 10,  10, 250, 20, "TextGadget Standard (Left)")
    TextGadget(1, 10,  70, 250, 20, "TextGadget Center", #PB_Text_Center)
    TextGadget(2, 10,  40, 250, 20, "TextGadget Right", #PB_Text_Right)
    TextGadget(3, 10, 100, 250, 20, "TextGadget Border", #PB_Text_Border)
    TextGadget(4, 10, 130, 250, 20, "TextGadget Center + Border", #PB_Text_Center | #PB_Text_Border)
    TextGadget(5, 10, 160, 250, 20, "<b>Bold</b> TextGadget") ; Using HTML markup
    
    ; Load font on the first button
    Define FontZector=LoadCustomFont(textwithfont,"Zector","./resources/Fonts/Zector.ttf",10)  
  EndIf

Works here on Windows 11>Brave and Debian>Firefox
Mijikai wrote: Mon Dec 23, 2024 4:21 pm Thanks @Caronte3D and sorry for the late reply.
I lost the harddrive with the sources for two games in SB.
My original plan was to finish one of the games during the holidays.
When i get my motivation back i will definitely give this a try :)
Similar issue.. Two years worth of PB coding around AI and poker, and a massive library of other text files and code, on a mSATA that has passive-component damage and possible dead NAND chip.. I haven't had the magnification to do surface-mount solder on the weird through-hole PGA it uses..

I've also had issues with Alienware laptops; the only thing not soldered anymore is the SSD..

I now have five USB 3.1 1000MBps/900MBps 1TB drives I basically use in a RAID 1 fashion with f2fs and encryption.. I don't really use cloud stuff because questionable encryption and telemetry.. I hear mega.io isn't too bad..