It is currently Tue Mar 31, 2020 8:42 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: VectorLoadFont and VectorCatchFont
PostPosted: Sun Dec 22, 2019 9:18 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1090
Location: Russia
I suggest adding functions.
Code:
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:
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

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye