Initial commit
This commit is contained in:
123
ThyBitmapFontCreator2.pb
Normal file
123
ThyBitmapFontCreator2.pb
Normal file
@@ -0,0 +1,123 @@
|
||||
Structure LoadedFont
|
||||
FontID.i
|
||||
AsciiStart.l
|
||||
AsciiEnd.l
|
||||
EndStructure
|
||||
|
||||
Global NewList LoadedFont.LoadedFont()
|
||||
|
||||
|
||||
Structure Output
|
||||
MaxSize.l
|
||||
MarginTop.l
|
||||
MarginRight.l
|
||||
MarginBottom.l
|
||||
MarginLeft.l
|
||||
ImageWidth.l
|
||||
ImageHeight.l
|
||||
EndStructure
|
||||
Global Output.Output
|
||||
|
||||
Procedure MyLoadFont(Font.l,Name.s,Size.l,Flag=0)
|
||||
Debug Name
|
||||
Taille=1;
|
||||
Img=CreateImage(#PB_Any,1,1);Creation d'une image pour travailler
|
||||
Repeat
|
||||
If IsFont(Font)
|
||||
FreeFont(Font)
|
||||
EndIf
|
||||
Taille+1
|
||||
Font=LoadFont(#PB_Any, Name, Taille,Flag)
|
||||
If IsFont(Font)
|
||||
StartDrawing(ImageOutput(Img))
|
||||
DrawingFont(FontID(Font))
|
||||
If TextHeight("@")>Size Or TextWidth("@")>Size
|
||||
Taille-1
|
||||
Quit=1
|
||||
EndIf
|
||||
StopDrawing()
|
||||
Else
|
||||
Debug "Error Load Font "+Name
|
||||
End
|
||||
EndIf
|
||||
Until Quit=1 Or Taille>500
|
||||
Debug "Taille="+Str(Taille)
|
||||
FreeImage(Img)
|
||||
ProcedureReturn Font
|
||||
EndProcedure
|
||||
|
||||
Procedure AddFont(Name.s,Size.l,Flag.l,AsciiStart.l,AsciiEnd.l)
|
||||
AddElement(LoadedFont())
|
||||
LoadedFont()\FontID=MyLoadFont(#PB_Any,Name.s,Size.l,Flag)
|
||||
LoadedFont()\AsciiStart=AsciiStart
|
||||
LoadedFont()\AsciiEnd=AsciiEnd
|
||||
EndProcedure
|
||||
|
||||
Structure myFontData
|
||||
x.l
|
||||
y.l
|
||||
Width.l
|
||||
Height.l
|
||||
EndStructure
|
||||
|
||||
Procedure ExportFont(Name.s)
|
||||
Protected Image.i=CreateImage(#PB_Any,Output\ImageWidth,Output\ImageHeight,32,#PB_Image_Transparent)
|
||||
StartDrawing(ImageOutput(Image))
|
||||
Protected.l a,x,y,ChrWidth,MaxHeight=Output\MaxSize
|
||||
Protected.c AsciiStart,AsciiEnd
|
||||
FirstElement(LoadedFont())
|
||||
AsciiStart=LoadedFont()\AsciiStart
|
||||
LastElement(LoadedFont())
|
||||
AsciiEnd=LoadedFont()\AsciiEnd
|
||||
Debug "AsciiStart="+Str(AsciiStart)
|
||||
Debug "AsciiEnd="+Str(AsciiEnd)
|
||||
Dim FontData.myFontData(AsciiEnd-AsciiStart)
|
||||
|
||||
ForEach LoadedFont()
|
||||
;Circle(x,y,5,RGBA(255,0,0,255))
|
||||
For a=LoadedFont()\AsciiStart To LoadedFont()\AsciiEnd
|
||||
ChrWidth=Output\MarginLeft+TextWidth(Chr(a))+Output\MarginRight
|
||||
If x+ChrWidth>ImageWidth(Image)
|
||||
x=0:y=y+MaxHeight
|
||||
EndIf
|
||||
Debug Chr(a)
|
||||
DrawingFont(FontID(LoadedFont()\FontID))
|
||||
DrawingMode(#PB_2DDrawing_Transparent|#PB_2DDrawing_AlphaBlend)
|
||||
FontData(a-AsciiStart)\x=x
|
||||
FontData(a-AsciiStart)\y=y
|
||||
FontData(a-AsciiStart)\Width=ChrWidth
|
||||
FontData(a-AsciiStart)\Height=MaxHeight
|
||||
DrawText(x+Output\MarginLeft,y+Output\MarginTop,Chr(a),RGBA(255,255,255,255))
|
||||
x=x+ChrWidth
|
||||
Next
|
||||
Next
|
||||
StopDrawing()
|
||||
SaveImage(Image,Name+".png",#PB_ImagePlugin_PNG)
|
||||
If CreateFile(0,Name+".dat")
|
||||
WriteCharacter(0,AsciiStart,#PB_Ascii)
|
||||
WriteCharacter(0,AsciiEnd,#PB_Ascii)
|
||||
WriteData(0,@FontData(),SizeOf(myFontData)*ArraySize(FontData()))
|
||||
CloseFile(0)
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
UsePNGImageEncoder()
|
||||
Output\MaxSize=20
|
||||
Output\MarginTop=2
|
||||
Output\MarginBottom=2
|
||||
Output\MarginLeft=2
|
||||
Output\MarginRight=2
|
||||
Output\ImageWidth=Output\MaxSize*10
|
||||
Output\ImageHeight=Output\MaxSize*10
|
||||
Size=Output\MaxSize-Output\MarginLeft-Output\MarginRight
|
||||
;AddFont("Langith RegPersonal",Size,0,32,43)
|
||||
;AddFont("MonoFonto",size,0,44,59)
|
||||
;AddFont("Langith RegPersonal",Size,0,60,122)
|
||||
AddFont("Alton Trial",size,0,32,122)
|
||||
ExportFont("AltonFont2")
|
||||
|
||||
; IDE Options = PureBasic 6.00 LTS (Windows - x64)
|
||||
; CursorPosition = 108
|
||||
; FirstLine = 45
|
||||
; Folding = -
|
||||
; EnableXP
|
Reference in New Issue
Block a user