VectorLoadFont and VectorCatchFont
Posted: Sun Dec 22, 2019 9:18 pm
I suggest adding functions. This is a very useful function for VectorDrawing.
They are easy to add to PB, but this is impossible without access to the library source.
For example, I load a font from memory, but VectorFont does not accept it.
Code: Select all
VectorLoadFont(#VectorFont, File.s) ; Load font from file.
VectorCatchFont(#VectorFont, *MemoryAddress , Size) ; Load font from memory.
They are easy to add to PB, but this is impossible without access to the library source.
For example, I load a font from memory, but VectorFont does not accept it.
Code: Select all
Import "gdiplus.lib"
GdiplusStartup(*gdiplusToken, *input, *output)
GdipNewPrivateFontCollection(*privateFontCollection)
GdipPrivateAddMemoryFont(*privateFontCollection, *FontData, Size)
GdipCreateFontFamilyFromName(fontName.s,*fontCollection, *fontFamily)
GdipCreateFont(*fontFamily, emSize.f, style, unit, *font)
EndImport
Structure GdiplusStartupInput
GdiPlusVersion.l
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 ; ALIGN next pointer to 8
PB_Alignment.b[4]
CompilerEndIf
*DebugEventCallback.DebugEventProc
SuppressBackgroundThread.i
SuppressExternalCodecs.i
EndStructure
#FontStyleBold = 1
#UnitPixel = 2
gdiplusStartupInput.GdiplusStartupInput
gdiplusStartupInput\GdiplusVersion = 1
gdiplusStartupInput\DebugEventCallback = #Null
gdiplusStartupInput\SuppressBackgroundThread = #False
gdiplusStartupInput\SuppressExternalCodecs = #True
gdiplusToken=0
FontCollection=0
FontFamily=0
Font=0
GdiplusStartup(@gdiplusToken, @gdiplusStartupInput, 0)
GdipNewPrivateFontCollection(@FontCollection)
GdipPrivateAddMemoryFont(FontCollection, ?f, ?ef-?f)
GdipCreateFontFamilyFromName("FontName",FontCollection, @FontFamily)
Debug "GdipCreateFont = "+GdipCreateFont(FontFamily, 10, #FontStyleBold, #UnitPixel, @Font)
Debug "Font = "+Font
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
If StartVectorDrawing(CanvasVectorOutput(0))
Debug "VectorFont "+VectorFont(Font)
MovePathCursor(50, 25)
AddPathText("1234")
VectorSourceColor(RGBA(255, 0, 0, 255))
DashPath(3, 6)
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
DataSection
f:
IncludeBinary "MyFont.ttf"
ef:
EndDataSection