Pour afficher des fontes incluses dans le programme, voir ici :
Embed font in an application
Petit programme d'exemple :
Code : Tout sélectionner
Global.i hFont
OpenLibrary(0,"gdi32.dll")
hFont = CallFunction(0, "AddFontMemResourceEx", ?MyFont, ?EndSize - ?MyFont, 0, @"1")
CloseLibrary(0)
LoadFont(0, "Silubr", 12)
If hFont
If OpenWindow(0, 0, 0, 300, 200, "Font from memory", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0, 0, 0, 300, 200, "Purebasic with Font : Silubr.otf")
SetGadgetFont(0, FontID(0))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
EndIf
DataSection
MyFont: IncludeBinary "Silubr.otf"
EndSize:
EndDataSection
ou avec CallFunctionFast :
Code : Tout sélectionner
Enumeration
#LIB_GDI
#FONT_MEM
EndEnumeration
Global.i hFont
If OpenLibrary(#LIB_GDI, "gdi32.dll")
*AddFontMemResourceEx = GetFunction(#LIB_GDI, "AddFontMemResourceEx")
*RemoveFontMemResourceEx = GetFunction(#LIB_GDI, "RemoveFontMemResourceEx")
CloseLibrary(#LIB_GDI)
Else
End
EndIf
hFont = CallFunctionFast(*AddFontMemResourceEx, ?MyFont, ?EndSize - ?MyFont, 0, @"1")
If hFont
LoadFont(#FONT_MEM, "Silubr", 24)
If OpenWindow(0, 0, 0, 300, 200, "Font from memory", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 0, 0, 300, 200, #PB_Editor_WordWrap)
AddGadgetItem(0, 0, "Purebasic with Font : Silubr.otf")
SetGadgetFont(0, FontID(#FONT_MEM))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
CallFunctionFast(*RemoveFontMemResourceEx, hFont)
EndIf
DataSection
MyFont: IncludeBinary "Silubr.otf"
EndSize:
EndDataSection
Version sans LoadFont :
Code : Tout sélectionner
Enumeration
#LIB_GDI
#FONT_MEM
EndEnumeration
Global.i hFont
If OpenLibrary(#LIB_GDI, "gdi32.dll")
*AddFontMemResourceEx = GetFunction(#LIB_GDI, "AddFontMemResourceEx")
*RemoveFontMemResourceEx = GetFunction(#LIB_GDI, "RemoveFontMemResourceEx")
CloseLibrary(#LIB_GDI)
Else
End
EndIf
hFont = CallFunctionFast(*AddFontMemResourceEx, ?MyFont, ?EndSize - ?MyFont, 0, @"1")
If hFont
ID = CreateFont_(24, 0, 0, 0, 0, #False, #False, #False,
#DEFAULT_CHARSET, #OUT_RASTER_PRECIS, #CLIP_DEFAULT_PRECIS,
#ANTIALIASED_QUALITY, #FIXED_PITCH + #FF_DONTCARE, "Silubr")
If OpenWindow(0, 0, 0, 300, 200, "Font from memory", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 0, 0, 300, 200, #PB_Editor_WordWrap)
AddGadgetItem(0, 0, "Purebasic with Font : Silubr.otf")
SendMessage_(GadgetID(0), #WM_SETFONT, ID, #True)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
CallFunctionFast(*RemoveFontMemResourceEx, hFont)
EndIf
DataSection
MyFont: IncludeBinary "Silubr.otf"
EndSize:
EndDataSection
et une derniere, plus elegante :
Code : Tout sélectionner
Import "gdi32.lib"
AddFontMemResourceEx_(pbFont, ; font resource
cbFont, ; number of bytes in font resource
pdv, ; Reserved. Must be 0.
*pcFonts) As "_AddFontMemResourceEx" ; number of fonts installed
RemoveFontMemResourceEx_(hFont) As "_RemoveFontMemResourceEx"
EndImport
Enumeration
#FONT_MEM
EndEnumeration
Global.i hFont
hFont = AddFontMemResourceEx_(?MyFont, ?EndSize - ?MyFont, 0, @"1")
If hFont
LoadFont(#FONT_MEM, "Silubr", 24)
If OpenWindow(0, 0, 0, 300, 200, "Font from memory", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 0, 0, 300, 200, #PB_Editor_WordWrap)
AddGadgetItem(0, 0, "Purebasic with Font : Silubr.otf")
SetGadgetFont(0, FontID(#FONT_MEM))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
RemoveFontMemResourceEx_(hFont)
EndIf
DataSection
MyFont: IncludeBinary "Silubr.otf"
EndSize:
EndDataSection