Create my own font with lib VECTOR

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Create my own font with lib VECTOR

Post by Kwai chang caine »

Hello at all :D

I have a stupid question :oops: .....(Like usually !! Several members probably say) :mrgreen:

I want to know, if at your advice, it's possible to create my own font (pixel by pixel) in a canvas gadget and lib vector.
I don't want using DrawText, it's for just a matrix of 80 x 24 characters
But i wondering, if i write all my hundred characters, pixel by pixel i can resizing the canvas without have flickering ? :oops:

Someone have already do that ? or i'm again the only one donkey of the world who have this idea :mrgreen:

Have a good day
ImageThe happiness is a road...
Not a destination
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Create my own font with lib VECTOR

Post by walbus »

Hi KCC
You have posted in the Progressbar_EX thread
http://www.purebasic.fr/english/viewtop ... 12&t=68732

Looking, directly under your posting is a little code
This code make exactly this, you can extract simple what you want and also looking how its work
Not needed code parts you can simple delete, looking for "text$"
User avatar
mk-soft
Always Here
Always Here
Posts: 5336
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Create my own font with lib VECTOR

Post by mk-soft »

I found sprites font...
Link http://www.purebasic.fr/english/viewtop ... 92#p359614

Draw found on sprites...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Create my own font with lib VECTOR

Post by Kwai chang caine »

First, thanks at you two for your help 8)

@Walbus
The code you show me not really do what i search :|
Because you use LoadFont() and DrawRotatedText()
And i can't use this natives functions :cry:

In fact i have create a IBM 3270 simulator, with 80 collumns and 24 lines
The main function of this emulator, is to be resized, and the characters resized in the same time
I have try several method for do that, the EMF pictures and others i don't remember, but the top is the lib VECTOR and that run perfectly 8)
Except a problem, because they are always a problem :?
The lib VECTOR can't use font not registred, me and others members don't know why, probably a bug, but it's not sure :
RASHAD wrote:Hi KCC
Yes it is a bug with VectorFont()
If you installed the fonts using windows install the VectorFont() will work as expected
You can report it as a bug
You can install the fonts using code by coping the files direct to windows fonts directory then add some registry data
http://www.purebasic.fr/english/viewtop ... 52#p489452

After, i have try also several codes, using "AddFontMemResourceEx_()" or "AddFontResource_()" and that not works, the font is in windows, because WORDS and EXCEL see it, and i can writing with her, but not the libvector :|
And i have try "RegisterFontFile()" and here it's worst again, the code is locked at this line, on my machine :shock: :cry:
Surely the right administrator needed, or Active directory not allows the install for security :cry:

FRED never answer my question since 2016, so i have another time show the problem :|
http://www.purebasic.fr/english/viewtop ... 75#p510775

Then, i say to me, perhaps it's possible to jump the loading of font, drawing a copy of my favorite font, pixel by pixel, one time for all, like this, never i have again this problem like several years :cry:
My problem is what ?
For simulate the old IBM, i can't use ARIAL, or other font already installed on all windows machine, but a special font "*.fon"
Then, when i run my simuilator on new machine, i'm forcing to instal it before, and on all the machine i use, i'm not admin and the active directory is very restrictive, it's impossible to install fonts, without be administrator for a security problem.
I have search yesterday, and everybody say it's not possible, except if i use external soft, who perhaps can simulate the install, but i found it's not really a good solution :|

@Mk-Soft
It's interesting, but i'm not sure i can resize the windows and the characters is resizing in the same time ?
Furthermore, i'm not sure too, i can choose the font without load it :wink:
ImageThe happiness is a road...
Not a destination
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Create my own font with lib VECTOR

Post by walbus »

Hi KCC
You can replace the text call with any other things
This code give you a skeleton for flicker free animation any things on canvas
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Create my own font with lib VECTOR

Post by wilbert »

The easiest way might be to store the font as one bitmap image (like a sprite sheet) and copy the characters from there.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Create my own font with lib VECTOR

Post by Kwai chang caine »

Thanks WALBUS :wink:

This is my goal, in fact i believe i have my answer
This morning, i have write quickly this, for see if VECTOR is also fast for rewrite hundred characters in resizing, before try to spent much time to create pixel by pixel my own font
Apparently no problem... 8)

I hope if the characters is differents, it's the same thing :D

This is the A, i can now officially announce the creation of the first character of my first font :lol: :lol:

Code: Select all

Enumeration
 #Form
 #Canvas
EndEnumeration

Global StartX.f
Global StartY.f

Procedure A(x, y, SizeX, SizeY, Strong)
  
 MovePathCursor(x, y)
 AddPathLine(0, - SizeY, #PB_Path_Relative)
 AddPathLine(SizeX, 0, #PB_Path_Relative)
 AddPathLine(0, SizeY, #PB_Path_Relative)
 CursorY = SizeY/2
 MovePathCursor(PathCursorX(), PathCursorY() - CursorY)
 AddPathLine(- SizeX, 0, #PB_Path_Relative)
 StrokePath(Strong, #PB_Path_Default)
 
EndProcedure

Procedure WriteText(x.f = 0, y.f = 0, Couleur = 0)
 
 ClearGadgetItems(#Canvas)
 
 If StartVectorDrawing(CanvasVectorOutput(#Canvas))
  
  VectorSourceColor(RGBA(255,255,255,255))
  FillVectorOutput()
  VectorSourceColor(Couleur)
  ScaleCoordinates(x, y)
  
  For Lig = 1 To 300 Step 8
    
   For Col = 1 To 400 Step 8
    A(Col, Lig, 5, 5, 1)
   Next
   
  Next
  
  StopVectorDrawing()
  
 EndIf 
  
EndProcedure

Procedure WinCallback(WindowID, Message, wParam, lParam)
 
 Result = #PB_ProcessPureBasicEvents
      
 Select Message

  Case #WM_SIZE
   
   CoefX.f = WindowWidth(#Form) / StartX
   CoefY.f = WindowHeight(#Form) / StartY

   ResizeGadget(#Canvas, #PB_Ignore, #PB_Ignore, WindowWidth(#Form), WindowHeight(#Form))
   WriteText(CoefX, CoefY, RGBA(255, 0, 0, 255))
     
 EndSelect
 
 ProcedureReturn Result
 
EndProcedure


If OpenWindow(#Form, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
    
 SetWindowCallback(@WinCallback())
 CanvasGadget(#Canvas, 0, 0, 400, 200)
 StartX = WindowWidth(#Form) 
 StartY = WindowHeight(#Form)
 
 WriteText(0, 0, RGBA(255, 0, 0, 255))
 
 Repeat
  Event = WaitWindowEvent()
 Until Event = #PB_Event_CloseWindow
 
EndIf
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Create my own font with lib VECTOR

Post by Kwai chang caine »

WILBERT wrote:The easiest way might be to store the font as one bitmap image (like a sprite sheet) and copy the characters from there.
Hello WILBERT 8)

You mean, it's possible to capture the Font i need, letter by letter in BMP, and after show each BMP by the libvector, and the result is perfect even if i resize very large or very small the canvas :shock: :shock:
Are you sure i not lost in clearness ??
ImageThe happiness is a road...
Not a destination
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Create my own font with lib VECTOR

Post by walbus »

On the BucketFill_advanced download packet, you can found demo codes for output any sprite sheets directly on canvas
With alpha blending, resizing and flicker free
The function is named "Sprite_CSS_sheet_BF"
But, you must looking what you want exactely do, mostly it is not a good idea try creating self propietary fonts :wink:
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Create my own font with lib VECTOR

Post by wilbert »

Kwai chang caine wrote:You mean, it's possible to capture the Font i need, letter by letter in BMP, and after show each BMP by the libvector, and the result is perfect even if i resize very large or very small the canvas :shock: :shock:
Are you sure i not lost in clearness ??
I think I misunderstood you. I assumed you wanted the font to look pixelated even when resizing.
If you really want to use vectors, I recommend you take a look at the AddPathSegments(Segments$ [, Flags]) command and store the characters more like svg data.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Create my own font with lib VECTOR

Post by Kwai chang caine »

Walbus wrote:mostly it is not a good idea try creating self propietary fonts
I completely aggree with you, you don't know how much :lol: :lol:
My goal is to have the same font on all the machines, without load it, and mainly without passing all the futur night of my life with a pencil :lol:
I search the better and quick way for have a good result, without recreate the wheel :D

I take a look soon to the "BucketFill_advanced download packet", thanks a lot for the tips 8)
In fact, i have see this splendid work, but sometime, some librairies do so much things very well, that i not really understand what she do exactely :oops: :lol:
Wilbert wrote:If you really want to use vectors, I recommend you take a look at the AddPathSegments(Segments$ [, Flags]) command and store the characters more like svg data.
I have take a look to this function, effectively she are really more simply, for create what i search to do
So i'm when even forced to writing each characters, one by one, and like say WALBUS it's not sure it's the better way :|

But you give to me a very nice idea
Perhaps, they exist software, or a PB code to translate bmp to SVG for not have to all hand writing ? :idea:
Or better, cut each character, analyse the picture BMP and write automaticaly the AddPathSegments() you show to me :idea: 8)

Already, i have try like you say to me, and the result is not perfect, but not also ugly too ....
I think the better way, is capturing the letter, the most big possible, for not pixelise when the window is very big
Because i have see it's more simple for libvector to reduce than resize more big :wink:

The letter E
http://erdsjb.free.fr/purestorage/provisoires/E.bmp

Code: Select all

Enumeration
 #Form
 #Canvas
 #Image
EndEnumeration

Global StartX.f
Global StartY.f

Procedure WriteImage(x.f = 0, y.f = 0)
  
 If StartVectorDrawing(CanvasVectorOutput(#Canvas))
  
  VectorSourceColor(RGBA(0,0,0,255))
  FillVectorOutput()
  ScaleCoordinates(x, y)
  DrawVectorImage(ImageID(#Image), 255, ImageWidth(#Image), ImageHeight(#Image))
 
  StopVectorDrawing()
  
 EndIf 
  
EndProcedure

Procedure WinCallback(WindowID, Message, wParam, lParam)
 
 Result = #PB_ProcessPureBasicEvents
      
 Select Message

  Case #WM_SIZE
   
   CoefX.f = WindowWidth(#Form) / StartX
   CoefY.f = WindowHeight(#Form) / StartY

   ResizeGadget(#Canvas, #PB_Ignore, #PB_Ignore, WindowWidth(#Form), WindowHeight(#Form))
   WriteImage(CoefX, CoefY)
     
 EndSelect
 
 ProcedureReturn Result
 
EndProcedure

If OpenWindow(#Form, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
    
 SetWindowCallback(@WinCallback())
 CanvasGadget(#Canvas, 0, 0, 400, 200)
 StartX = WindowWidth(#Form) 
 StartY = WindowHeight(#Form)
 LoadImage(#Image, "E.bmp")
 WriteImage(0, 0)
 
 Repeat
  Event = WaitWindowEvent()
 Until Event = #PB_Event_CloseWindow
 
EndIf
ImageThe happiness is a road...
Not a destination
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Create my own font with lib VECTOR

Post by walbus »

Yep,
looking to this demo code "Sprite_using_CSS_Sheet_BF_delays_presetted.pb"
A other little code for creating sheets you found also

For BucketFill_advanced, a complete book, for handling all abilities is needed, but this is a lot of work and my english not good
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Create my own font with lib VECTOR

Post by Kwai chang caine »

Waooouuuh WALBUS !!!! :shock:

I have not all understand again :oops:
But i have found this code, my E is very perfect

Image

But the window can't be resized :|
I continue to search a resized window :wink:
ImageThe happiness is a road...
Not a destination
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Create my own font with lib VECTOR

Post by walbus »

This function handle your font picture as sprite

For other font colors it is available you must reduce or remove the function "SetColorDistanceSpriteMask_BF"

The function can handle also JPG compressed images

You must not have SVG for this, the function get automatically the image background color from pos 0,0 and make this color invisible

Enhance the code for resizing the window or canvas, BF handle internal all other full automatic, how ever you want

You found in the download packet code samples for output directly on images and on canvas

You can give the function simple a canvas ID for output or a image ID
Last edited by walbus on Wed Aug 23, 2017 1:05 pm, edited 2 times in total.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Create my own font with lib VECTOR

Post by Kwai chang caine »

@Wilbert

I continue also my search in your way :wink:
I have found a site for convert my E in SVG :D
https://convertio.co/fr/bmp-svg/

But i'm sad because, i have read the answer of KEYA :cry:
http://www.purebasic.fr/english/viewtop ... 73#p498773

I'm like a cunt with my E.svg now .... :lol: :lol:

In fact the TTF is a little bit like lib vector no ???
ImageThe happiness is a road...
Not a destination
Post Reply