FBTrueType static Win/Lin 32/64-bit
Re: FBTrueType static Win/Lin 32/64-bit
i see it is not necessary to copy fonts to the folder of the source code.
specifying the path is possible.
font = FontLoad("c:\windows\fonts\" & fontfilename)
specifying the path is possible.
font = FontLoad("c:\windows\fonts\" & fontfilename)
Re: FBTrueType static Win/Lin 32/64-bit
Code: Select all
#include once "FBTrueType.bi"
screenres 1000,400,32
Dim As String fontfile,fontfiles()
Dim As Integer font_c
Dim As Long font
fontfile=Dir("c:\windows\fonts\*.ttf")
Do
If fontfile="" Then
Exit Do
Else
font = FontLoad("c:\windows\fonts\" & fontfile)
If font>0 Then
font_c+=1
ReDim Preserve fontfiles(font_c)
fontfiles(font_c)=fontfile
FontDestroy()
EndIf
fontfile=Dir()
EndIf
Loop
For i As Integer = 1 To font_c
fontfile = Mid(fontfiles(i),1,Len(fontfiles(i))-4)
font = FontLoad("c:\windows\fonts\" & fontfiles(i))
TTPrint font,10,20*i-20, fontfile,rgb(255,255,255),20
FontDestroy()
Next
Dim As Integer mr,mx,my,myp,mw,mwp,mb,mc
Dim As Integer wy
Dim As Integer selected_font,selected_font_p
Do
Select Case InKey
Case Chr(27),Chr(255)+"k"
Exit Do
End Select
mr=GetMouse(mx,my,mw,mb,mc)
If mr=0 And mw<>mwp Then
If mw>mwp Then
wy+=20
Else
wy-=20
EndIf
If wy>0 Then wy=0
If wy<font_c*20*-1+400 Then wy=font_c*20*-1+400
mwp=mw
EndIf
mw=0
selected_font=(my+10)/20+Abs(wy)/20
If selected_font<>selected_font_p Then
selected_font_p=selected_font
ScreenLock
Cls
For i As Integer = 1 To font_c
Select Case 20*i-20+wy
Case -20 To 400
fontfile = Mid(fontfiles(i),1,Len(fontfiles(i))-4)
font = FontLoad("c:\windows\fonts\" & fontfiles(i))
If i=selected_font Then
TTPrint font,10,20*i-20+wy, fontfile,rgb(255,0,255),20
Else
TTPrint font,10,20*i-20+wy, fontfile,rgb(255,255,255),20
EndIf
FontDestroy()
End Select
Next
font = FontLoad("c:\windows\fonts\" & fontfiles(selected_font))
TTPrint font,500,20, "Hello World",rgb(255,255,255),80
FontDestroy()
ScreenUnLock
End If
Sleep 1
Loop
Re: FBTrueType static Win/Lin 32/64-bit
this is really a great contribution to fb.
i never knew what was involved in ttf and now we have otf to look forward to.
fonts are all about kerning and white space and a whole lot more so i'm finding out.
i never knew what was involved in ttf and now we have otf to look forward to.
fonts are all about kerning and white space and a whole lot more so i'm finding out.
Re: FBTrueType static Win/Lin 32/64-bit
any ideas how i can handle thing anyone knows someone dont have C in their boot partion drive label? more than likely my mother for example has E in such device.
Re: FBTrueType static Win/Lin 32/64-bit
@jupe
are you a BOT ?
are you a BOT ?
-
- Posts: 165
- Joined: Apr 19, 2019 19:03
Re: FBTrueType static Win/Lin 32/64-bit
Here is the linux version:owen wrote:Code: Select all
#include once "FBTrueType.bi" screenres 1000,400,32 Dim As String fontfile,fontfiles() Dim As Integer font_c Dim As Long font fontfile=Dir("c:\windows\fonts\*.ttf") Do If fontfile="" Then Exit Do Else font = FontLoad("c:\windows\fonts\" & fontfile) If font>0 Then font_c+=1 ReDim Preserve fontfiles(font_c) fontfiles(font_c)=fontfile FontDestroy() EndIf fontfile=Dir() EndIf Loop For i As Integer = 1 To font_c fontfile = Mid(fontfiles(i),1,Len(fontfiles(i))-4) font = FontLoad("c:\windows\fonts\" & fontfiles(i)) TTPrint font,10,20*i-20, fontfile,rgb(255,255,255),20 FontDestroy() Next Dim As Integer mr,mx,my,myp,mw,mwp,mb,mc Dim As Integer wy Dim As Integer selected_font,selected_font_p Do Select Case InKey Case Chr(27),Chr(255)+"k" Exit Do End Select mr=GetMouse(mx,my,mw,mb,mc) If mr=0 And mw<>mwp Then If mw>mwp Then wy+=20 Else wy-=20 EndIf If wy>0 Then wy=0 If wy<font_c*20*-1+400 Then wy=font_c*20*-1+400 mwp=mw EndIf mw=0 selected_font=(my+10)/20+Abs(wy)/20 If selected_font<>selected_font_p Then selected_font_p=selected_font ScreenLock Cls For i As Integer = 1 To font_c Select Case 20*i-20+wy Case -20 To 400 fontfile = Mid(fontfiles(i),1,Len(fontfiles(i))-4) font = FontLoad("c:\windows\fonts\" & fontfiles(i)) If i=selected_font Then TTPrint font,10,20*i-20+wy, fontfile,rgb(255,0,255),20 Else TTPrint font,10,20*i-20+wy, fontfile,rgb(255,255,255),20 EndIf FontDestroy() End Select Next font = FontLoad("c:\windows\fonts\" & fontfiles(selected_font)) TTPrint font,500,20, "Hello World",rgb(255,255,255),80 FontDestroy() ScreenUnLock End If Sleep 1 Loop
Code: Select all
' show_ttf_linux.bas
#include once "FBTrueType.bi"
screenres 1000,400,32
Dim As String fontfile,fontfiles()
Dim As Integer font_c
Dim As Long font
fontfile=dir("/usr/share/fonts/truetype/dejavu/*.ttf")
Do
If fontfile="" Then
Exit Do
Else
font = FontLoad("/usr/share/fonts/truetype/dejavu/" & fontfile)
If font>0 Then
font_c+=1
ReDim Preserve fontfiles(font_c)
fontfiles(font_c)=fontfile
FontDestroy()
EndIf
fontfile=Dir()
EndIf
Loop
For i As Integer = 1 To font_c
fontfile = Mid(fontfiles(i),1,Len(fontfiles(i))-4)
font = FontLoad("/usr/share/fonts/truetype/dejavu/" & fontfiles(i))
TTPrint font,10,20*i-20, fontfile,rgb(255,255,255),20
FontDestroy()
Next
Dim As Integer mr,mx,my,myp,mw,mwp,mb,mc
Dim As Integer wy
Dim As Integer selected_font,selected_font_p
Do
Select Case InKey
Case Chr(27),Chr(255)+"k"
Exit Do
End Select
mr=GetMouse(mx,my,mw,mb,mc)
If mr=0 And mw<>mwp Then
If mw>mwp Then
wy+=20
Else
wy-=20
EndIf
If wy>0 Then wy=0
If wy<font_c*20*-1+400 Then wy=font_c*20*-1+400
mwp=mw
EndIf
mw=0
selected_font=(my+10)/20+Abs(wy)/20
If selected_font<>selected_font_p Then
selected_font_p=selected_font
ScreenLock
Cls
For i As Integer = 1 To font_c
Select Case 20*i-20+wy
Case -20 To 400
fontfile = Mid(fontfiles(i),1,Len(fontfiles(i))-4)
font = FontLoad("/usr/share/fonts/truetype/dejavu/" & fontfiles(i))
If i=selected_font Then
TTPrint font,10,20*i-20+wy, fontfile,rgb(255,0,255),20
Else
TTPrint font,10,20*i-20+wy, fontfile,rgb(255,255,255),20
EndIf
FontDestroy()
End Select
Next
font = FontLoad("/usr/share/fonts/truetype/dejavu/" & fontfiles(selected_font))
TTPrint font,500,20, "Hello World",rgb(255,255,255),80
FontDestroy()
ScreenUnLock
End If
Sleep 1
Loop
-
- Posts: 231
- Joined: Apr 10, 2010 11:41
- Location: Japan
- Contact:
Re: FBTrueType static Win/Lin 32/64-bit
Dear D.J.Peters;
Dear owen;
I have learned that FBTrueType allows me to use Japanese fonts to display Japanese characters on drawing screens.
I would like to add Japanese comments to your program examples and introduce them on my site to FreeBASIC fans in Japan.
Thank you for your understanding.
Dear owen;
I have learned that FBTrueType allows me to use Japanese fonts to display Japanese characters on drawing screens.
I would like to add Japanese comments to your program examples and introduce them on my site to FreeBASIC fans in Japan.
Thank you for your understanding.
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: FBTrueType static Win/Lin 32/64-bit
I edit the include file "FBTrueType.bi" this fixed the trouble with fbc 1.8.0 !
(unused parameters with ImageInfo())
Joshy
(unused parameters with ImageInfo())
Joshy
-
- Posts: 231
- Joined: Apr 10, 2010 11:41
- Location: Japan
- Contact:
Re: FBTrueType static Win/Lin 32/64-bit
Dear Kwabbernoot;
Thank you for telling me about FBTrueType.
With FreeBASIC 1.08.0, I can display Japanese characters on drawing screens using Japanese fonts.
I am very grateful to you.
Thank you for telling me about FBTrueType.
With FreeBASIC 1.08.0, I can display Japanese characters on drawing screens using Japanese fonts.
I am very grateful to you.
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: FBTrueType static Win/Lin 32/64-bit
I fixed a tiny bug (integer vs long) and added for testing some free TrueType Fonts.
(see first post for download)
Joshy
(see first post for download)
Joshy
Re: FBTrueType static Win/Lin 32/64-bit
Great work thank you for sharing this library,
even better I, at least i think, read somewhere
on the forum that there is a good chance that
this will become a standard lib for FB!
I've made a small sample with the following code:
viewtopic.php?p=295676&hilit=fb+lib+ttf#p295676
There a some small issues I came across that might
be worthwhile looking into:
a) a kerning issue with the letter 'j' (lowercase)
try 'dj jd' with the sample code note how j sticks to d
used 'TTPrintString.bas'
actually more letters are effectd w, m Q etc....
b) regrettably there is no support for text styles aka attributes
similar to sdl_ttf see:
https://wiki.libsdl.org/SDL_ttf/TTF_SetFontStyle
TTF_SetFontStyle(font, TTF_STYLE_BOLD)
c) getTextWidth seems only to work with images(.bmp)?
made a work around in the above mentioned code
'fb_querytexture' but it is a bit wasteful and not so
scale able.
d) text orientation is not supported.
granted with sdl_ttf the work around is
by using SDL_RenderCopyEx, see
example in above mentioned code maybe
something similar is possible with this library.
e) there is a very small but still noticeable memory leak
specifacly when using TTPrint in a do ... loop
Hope this helps.
even better I, at least i think, read somewhere
on the forum that there is a good chance that
this will become a standard lib for FB!
I've made a small sample with the following code:
viewtopic.php?p=295676&hilit=fb+lib+ttf#p295676
There a some small issues I came across that might
be worthwhile looking into:
a) a kerning issue with the letter 'j' (lowercase)
try 'dj jd' with the sample code note how j sticks to d
used 'TTPrintString.bas'
actually more letters are effectd w, m Q etc....
b) regrettably there is no support for text styles aka attributes
similar to sdl_ttf see:
https://wiki.libsdl.org/SDL_ttf/TTF_SetFontStyle
TTF_SetFontStyle(font, TTF_STYLE_BOLD)
c) getTextWidth seems only to work with images(.bmp)?
made a work around in the above mentioned code
'fb_querytexture' but it is a bit wasteful and not so
scale able.
d) text orientation is not supported.
granted with sdl_ttf the work around is
by using SDL_RenderCopyEx, see
example in above mentioned code maybe
something similar is possible with this library.
e) there is a very small but still noticeable memory leak
specifacly when using TTPrint in a do ... loop
Hope this helps.