Re: How to use a custom font?
Posted: Thu Dec 19, 2024 11:25 am
Thank you, i tried it but it did not work for me.
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
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
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..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![]()