Page 1 of 1

Load a font from file (like AddFontResource_)

Posted: Tue Feb 25, 2014 12:35 pm
by Lebostein
Hi,

how I can load a font file in PureBasic on Mac OS X? On Windows I use "AddFontResource_()" to do that.
http://www.purebasic.fr/english/viewtop ... 05#p257005

Thanks.

Re: Load a font from file (like AddFontResource_)

Posted: Tue Feb 25, 2014 7:01 pm
by Danilo
See Custom font in a Cocoa application and ATSApplicationFontsPath and
Embedding Fonts in an Application.

Just adding ATSApplicationFontsPath key to your Info.plist seems the way to go to
import your own fonts from Resources directory within your .app file.

Re: Load a font from file (like AddFontResource_)

Posted: Thu Feb 27, 2014 11:10 pm
by glomph
Any hope for a snippet? :idea:

Re: Load a font from file (like AddFontResource_)

Posted: Fri Feb 28, 2014 7:33 am
by Danilo
Example: Embedded_font_in_app.zip (51KB)

Code: Select all

;
; 1.) Compile your .app
;
; 2.) Create the "Resources" directory within your .app/Contents/ directory
;
; 3.) Create a "fonts" directory within the Resources directory and copy your fonts there
;
; 4.) Add the following key and string to your Info.plist:
;     <key>ATSApplicationFontsPath</key>
;     <string>fonts</string>
;
;     the string "fonts" is the name of the directory
;     within your Resources folder, where your fonts are located
;
;
;
; The embedded font is „Crystal“ by Allen R Walden:
; http://www.fontspace.com/allen-r-walden/crystal
;
crystal = LoadFont(#PB_Any,"Crystal", 100, #PB_Font_HighQuality)
image   = CreateImage(#PB_Any, 800,600, 32, RGB(255,255,255))

If StartDrawing( ImageOutput(image) )
    DrawingFont( FontID(crystal) )
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(10,10,"CRYSTAL FONT",RGB(0,0,0))
    StopDrawing()
EndIf

OpenWindow(0,0,0,800,600,"Load embedded font from .app",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,800,600,ImageID(image))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: Load a font from file (like AddFontResource_)

Posted: Fri Feb 28, 2014 3:51 pm
by glomph
Thank you very much for that.

Re: Load a font from file (like AddFontResource_)

Posted: Fri Feb 28, 2014 9:31 pm
by luis
Thank you Danilo, could be useful :)