How to use a custom font?

Just starting out? Need help? Post your questions and find answers here.
Mijikai
Posts: 33
Joined: Sun Sep 17, 2017 9:59 am

Re: How to use a custom font?

Post by Mijikai »

Thank you, i tried it but it did not work for me.
User avatar
Caronte3D
Posts: 187
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: How to use a custom font?

Post 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
Mijikai
Posts: 33
Joined: Sun Sep 17, 2017 9:59 am

Re: How to use a custom font?

Post 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 :)
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: How to use a custom font?

Post by Fred »

There is so many way to secure codes across drive/cloud/git etc, that's sad to hear in 2024
Mijikai
Posts: 33
Joined: Sun Sep 17, 2017 9:59 am

Re: How to use a custom font?

Post by Mijikai »

Was a brand new Laptop did not expect it to die within 2 weeks.
tj1010
Posts: 218
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: How to use a custom font?

Post 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..
Post Reply