Page 1 of 1

VectorLoadFont and VectorCatchFont

Posted: Sun Dec 22, 2019 9:18 pm
by User_Russian
I suggest adding functions.

Code: Select all

VectorLoadFont(#VectorFont, File.s)                 ; Load font from file.
VectorCatchFont(#VectorFont, *MemoryAddress , Size) ; Load font from memory.
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

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

Re: VectorLoadFont and VectorCatchFont

Posted: Tue Jun 28, 2022 7:15 am
by Michael Vogel
Hi, would like to use temporarly loaded true type fonts for DrawVectorText, but...
..your code doesn't work here, tried with multiple true type fonts.

I'll get a value for the FontCollection, but GdipCreateFont returns the value 2 and FontFamily is set to zero and the value for Font isn't changed.

Re: VectorLoadFont and VectorCatchFont

Posted: Tue Jun 28, 2022 8:24 am
by User_Russian
This is an example of loading a font from memory. But the font is not used in the VectorDrawing library due to missing access to the fonts internal variable. PB libraries are not open source.

Re: VectorLoadFont and VectorCatchFont

Posted: Tue Jun 28, 2022 8:13 pm
by Michael Vogel
Thanks, I am interested how the following font handles differ:

1. received by FontId(LoadFont(0,"Arial",123))
2. from LoadFontFromFileEx
3. by GdipNewPrivateFontCollection like in your example

ad 1 works for DrawText and DrawVectorText
ad 2 works for DrawText
ad 3 I wasn't able to use it for DrawText or DrawVectorText