Load a font from file (like AddFontResource_)

Mac OSX specific forum
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

Load a font from file (like AddFontResource_)

Post 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.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Load a font from file (like AddFontResource_)

Post 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.
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

Re: Load a font from file (like AddFontResource_)

Post by glomph »

Any hope for a snippet? :idea:
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Load a font from file (like AddFontResource_)

Post 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
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

Re: Load a font from file (like AddFontResource_)

Post by glomph »

Thank you very much for that.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Load a font from file (like AddFontResource_)

Post by luis »

Thank you Danilo, could be useful :)
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply