Code : Tout sélectionner
; Auteur : Le Soldat Inconnu
; Version de PB : 3.9
;
; Explication du programme :
Structure TextTableInfo
Width.l
Height.l
ImageID.l
EndStructure
Procedure.l TextTable(Table.l, Police.s, Taille.l, Style.l)
Protected Image.l, Font.l, FontID.l, Txt.s, Couleur.l , n, i, ii, Win, Progress, Text
Win = OpenWindow(#PB_Any, 0, 0, 200, 35, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, Police + " (" + Str(Taille) + ")")
If Win
If CreateGadgetList(WindowID())
Text = TextGadget(#PB_Any, 0, 0, 200, 15, "")
Progress = ProgressBarGadget(#PB_Any, 0, 15, 200, 20, 0, 255 - 32)
#TextTableZoom = 6
#Bordure = 1
; On charge la police
Font = LoadFont(#PB_Any, Police, Taille * #TextTableZoom, Style)
FontID = FontID()
For n = 32 To 255
Txt = Chr(n)
SetGadgetText(Text, Txt)
SetGadgetState(Progress, n - 32)
UpdateWindow_(WindowID())
While WindowEvent()
Wend
; on calcul la taille du caractère
Image.l = CreateImage(#PB_Any, 10, 10)
hdc = StartDrawing(ImageOutput())
DrawingFont(FontID())
GetTextExtentPoint32_(hdc, @Txt, 1, Size.SIZE)
StopDrawing()
FreeImage(Image)
; on ajoute une bordure
Size\cx + #Bordure * #TextTableZoom * 2
Size\cy + #Bordure * #TextTableZoom * 2
; on dessine le caractère
Image.l = CreateImage(#PB_Any, Size\cx, Size\cy)
StartDrawing(ImageOutput())
DrawingFont(FontID)
DrawingMode(1)
FrontColor($FF, $FF, $FF)
Locate(#Bordure * #TextTableZoom, #Bordure * #TextTableZoom)
DrawText(Txt)
StopDrawing()
; On récupère l'image sous forme de tableau pour travailler plus vite
Dim TableTemp.l(Size\cx - 1, Size\cy - 1)
GetImageBits(UseImage(Image), @TableTemp())
; On pixellise la police pour travailler facilement dessus
For i = 0 To Size\cx - 1
For ii = 0 To Size\cy - 1
Couleur = TableTemp(i, ii)
If Couleur > 0 And Couleur < $FFFFFF
If Couleur > 127
TableTemp(i, ii) = $FFFFFF
Else
TableTemp(i, ii) = 0
EndIf
EndIf
Next
Next
; On dessine la bordure externe
For i = 0 To Size\cx - 1
For ii = 0 To Size\cy - 1
If TableTemp(i, ii) = 0
For j = -#Bordure * #TextTableZoom To #Bordure * #TextTableZoom
For jj = -#Bordure * #TextTableZoom To #Bordure * #TextTableZoom
If i + j >= 0 And i + j <= Size\cx - 1 And ii + jj >= 0 And ii + jj <= Size\cy - 1
If TableTemp(i + j, ii + jj) = $FFFFFF
Longueur = j * j + jj * jj
If Longueur <= #Bordure * #Bordure * #TextTableZoom * #TextTableZoom
TableTemp(i, ii) = $FF
Break 2
EndIf
EndIf
EndIf
Next
Next
EndIf
Next
Next
SetImageBits(UseImage(Image), @TableTemp())
Size\cx / #TextTableZoom
Size\cy / #TextTableZoom
ResizeImage(Image, Size\cx, Size\cy, #PB_Image_Smooth)
PokeL(Table + SizeOf(TextTableInfo) * n, Size\cx)
PokeL(Table + SizeOf(TextTableInfo) * n + 4, Size\cy)
PokeL(Table + SizeOf(TextTableInfo) * n + 8, Image)
Next
CloseFont(Font)
Dim TableTemp(0, 0)
EndIf
CloseWindow(Win)
EndIf
EndProcedure
Procedure DrawTextTable(Table.l, x.l, y.l, Txt.s)
Protected n.l, nn.l, Pos.l, Image.l, cx.l
Pos = 0
For n = 1 To Len(Txt)
nn = Asc(Mid(Txt, n, 1))
Image = PeekL(Table + SizeOf(TextTableInfo) * nn + 8)
cx = PeekL(Table + SizeOf(TextTableInfo) * nn)
DrawImage(UseImage(Image), x + Pos, y)
Pos + cx
Next
EndProcedure
; On crée la police sous forme de BMP
Dim Text.TextTableInfo(255)
TextTable(@Text(), "tahoma", 16, #PB_Font_HighQuality)
; On dessine la police sur une image
CreateImage(0, 300, 200)
StartDrawing(ImageOutput())
DrawTextTable(@Text(), 0, 0, "Bonjour les zamis !")
DrawTextTable(@Text(), 0, Text(100)\Height, "Comment ça va bien ?")
DrawTextTable(@Text(), 0, Text(100)\Height * 2, "0123456789")
StopDrawing()
; Text(100)\Height
; je prends un carac au pif et je la hauteur (tous les carac ont la même hauteur)
; Création de la fenêtre principale
UseImage(0)
OpenWindow(0, 0, 0, ImageWidth(), ImageHeight(), #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "TextTable")
CreateGadgetList(WindowID())
ImageGadget(0, 0, 0, 0, 0, UseImage(0))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_EventCloseWindow
End