Initial commit
This commit is contained in:
95
Fontcreator.pb
Normal file
95
Fontcreator.pb
Normal file
@@ -0,0 +1,95 @@
|
||||
UsePNGImageEncoder()
|
||||
UsePNGImageDecoder()
|
||||
font.i= LoadFont(#PB_Any,"Arial",96)
|
||||
|
||||
|
||||
Structure myFontData
|
||||
x.l
|
||||
y.l
|
||||
Width.l
|
||||
Height.l
|
||||
EndStructure
|
||||
|
||||
Dim myFontData.myFontData(256)
|
||||
AsciiStart.c=33
|
||||
AsciiEnd.c=122
|
||||
;Repeat
|
||||
|
||||
;Until
|
||||
If IsFont(font)
|
||||
MaxWidth=0
|
||||
MaxHeight=0
|
||||
CreateImage(0,1024,1024,32,#PB_Image_Transparent)
|
||||
StartDrawing(ImageOutput(0))
|
||||
DrawingFont(FontID(font))
|
||||
|
||||
For a=AsciiStart To AsciiEnd
|
||||
myFontData(a)\Width=TextWidth(Chr(a))
|
||||
myFontData(a)\Height=TextHeight(Chr(a))
|
||||
If myFontData(a)\Width>MaxWidth:MaxWidth=myFontData(a)\Width:EndIf
|
||||
If myFontData(a)\Height>MaxHeight:MaxHeight=myFontData(a)\Height:EndIf
|
||||
Next
|
||||
StopDrawing()
|
||||
FreeImage(0)
|
||||
|
||||
;Classique ;
|
||||
|
||||
If MaxWidth>MaxHeight
|
||||
Max=MaxWidth
|
||||
Else
|
||||
Max=MaxHeight
|
||||
EndIf
|
||||
Debug "Size="+Str(Max)
|
||||
Marg=4
|
||||
CreateImage(0,(Max+Marg*2)*10,(Max+Marg*2)*10,32,#PB_Image_Transparent)
|
||||
StartDrawing(ImageOutput(0))
|
||||
DrawingFont(FontID(font))
|
||||
x.l=0:y.l=0
|
||||
For a=AsciiStart To AsciiEnd
|
||||
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Outlined )
|
||||
Box(x,y,Max+Marg*2,Max+Marg*2,RGBA(0,255,0,128))
|
||||
|
||||
DrawingMode(#PB_2DDrawing_Transparent|#PB_2DDrawing_AlphaBlend)
|
||||
DrawText(x+Marg,y+Marg,Chr(a),RGBA(255,255,255,255))
|
||||
Line(x+Marg+myFontData(a)\Width,y,1,Max,RGBA(255,0,0,200))
|
||||
Debug Chr(a)+" width="+Str(myFontData(a)\Width)
|
||||
x=x+Max+Marg*2
|
||||
If x+Max+Marg*2>ImageWidth(0):x=0:y=y+Max+Marg*2:EndIf
|
||||
|
||||
Next
|
||||
StopDrawing()
|
||||
SaveImage(0,"Fonts.png",#PB_ImagePlugin_PNG)
|
||||
FreeImage(0)
|
||||
;optimized
|
||||
CreateImage(0,(Max+Marg*2)*10,(Max+Marg*2)*10,32,#PB_Image_Transparent)
|
||||
StartDrawing(ImageOutput(0))
|
||||
DrawingFont(FontID(font))
|
||||
x.l=0:y.l=0
|
||||
Dim finalFont.myFontData(90)
|
||||
For a=AsciiStart To 122
|
||||
DrawingMode(#PB_2DDrawing_Transparent|#PB_2DDrawing_AlphaBlend)
|
||||
If x+myFontData(a)\Width+Marg*2>ImageWidth(0)
|
||||
x=0:Y=Y+MaxHeight+Marg*2
|
||||
EndIf
|
||||
DrawText(x+Marg,y+Marg,Chr(a),RGBA(255,255,255,255))
|
||||
finalFont(a-33)\x=x
|
||||
finalFont(a-33)\y=y
|
||||
finalFont(a-33)\Width=myFontData(a)\Width+Marg*2
|
||||
finalFont(a-33)\Height=MaxHeight+Marg*2
|
||||
x=x+myFontData(a)\Width+Marg*2
|
||||
Next
|
||||
Y=Y+MaxHeight+Marg*2
|
||||
Line(0,Y,ImageWidth(0),1,RGBA(255,0,0,255))
|
||||
StopDrawing()
|
||||
SaveImage(0,"FontsCompress.png",#PB_ImagePlugin_PNG)
|
||||
If CreateFile(0,"FontsCompress.dat")
|
||||
WriteCharacter(0,AsciiStart,#PB_Ascii)
|
||||
WriteCharacter(0,AsciiEnd,#PB_Ascii)
|
||||
WriteData(0,@finalFont(),SizeOf(myFontData)*ArraySize(finalFont()))
|
||||
CloseFile(0)
|
||||
EndIf
|
||||
EndIf
|
||||
; IDE Options = PureBasic 6.00 Beta 5 (Windows - x64)
|
||||
; CursorPosition = 85
|
||||
; FirstLine = 18
|
||||
; EnableXP
|
Reference in New Issue
Block a user