FBTrueType static Win/Lin 32/64-bit

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FBTrueType static Win/Lin 32/64-bit

Post by fxm »

Compile with a FB version >= 1.04.0 (1.05.0 for example).
heisenberg
Posts: 4
Joined: May 04, 2018 18:42

Re: FBTrueType static Win/Lin 32/64-bit

Post by heisenberg »

The best solutions are the simple ones.
An update solved the problem.
The font looks great in my programs.

Thanks for the tip!

steve
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by D.J.Peters »

Hello Mr. Werner Karl Heisenberg :-)

"DrawStringCreateBitmap.bas" is only to create a bitmap font from TrueType font.

I added "DrawStringTestBitmap.bas" also.

Joshy
Last edited by D.J.Peters on May 06, 2018 13:29, edited 1 time in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by D.J.Peters »

I added LoadFontBitmap(), getFontInfo(), getFontHeight() and getTextWidth() see file "FBTrueType.bi"
and found out something goes wrong the lowercase letter "g" has some wrong pixels ?
Image
Is it "test06.bas" that create the bitmap or Draw String it's self ?

May be the wrong pixels comes from "f" letter in front of the"g" letter
inside the font bitmap I must do a deeper look on it.

Joshy
Last edited by D.J.Peters on Oct 12, 2022 18:13, edited 2 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by D.J.Peters »

I put LoadFontBitmap(), getFontInfo(), getFontHeight() and getTextWidth() in file: FBTrueType.bi
as a bad workaround I added one dummy pixel to the char width table.

Joshy
Last edited by D.J.Peters on May 06, 2018 13:29, edited 1 time in total.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by marcov »

Hmm. Mr. Heisenberg's post have timestamp, but not location. Hmm :-)

(*) https://en.wikipedia.org/wiki/Uncertainty_principle
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by D.J.Peters »

Image
I found and fixed the problem :-)
Image
Delete your old FBTrueType folder and download and extract the zip file again.

I gave the tests more meaningful names
GlyphIndex.bas
ShowBoundingBox.bas
LowLevel.bas
TTPrintString.bas
TTPrintWString.bas
DrawStringCreateBitmap.bas
DrawStringTestBitmap.bas

Joshy
Last edited by D.J.Peters on Oct 12, 2022 18:13, edited 1 time in total.
heisenberg
Posts: 4
Joined: May 04, 2018 18:42

Re: FBTrueType static Win/Lin 32/64-bit

Post by heisenberg »

Wow! Thanks, Joshy!
As always: Great work and support.
As a real rookie to FB, i really appreciate that.
(I learned to code with Turbo Pascal, ages ago)
Gonna update files and check it as soon as i find time.
Damn real life :)

@marcov: Lol!
But in fact, i'm more a fan of LaPlace and his determinism theory.
https://en.wikipedia.org/wiki/Laplace%27s_demon

steve
heisenberg
Posts: 4
Joined: May 04, 2018 18:42

Re: FBTrueType static Win/Lin 32/64-bit

Post by heisenberg »

@joshy:

Something off-topic:
I'm a musician/guitarist, and the reason i start to try working with FB is to
write some kind of "composing tools" (for easier re-harmonizing, for example).
Since you seem to be a musician too: Did you ever work on something like this?
I mean something music related?
Just curious.

steve
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by D.J.Peters »

@Steve I wrote Paganini a MIDI sequencer with some audio tracks 20 years ago, yes I'm old ;-)

Currently I try to fix a bug in FBSound V1.0 section DSP effects fbs_PitchShifter()
my optimized 32-bit assembler version is OK but the devil are in 64-bit mode.

Looks like I have to rewrite a none optimized version
and make it faster and faster step by step in 64-bit mode.

With other words after all the years I self don't understand
my optimized version any more and lost the original code of the slow version :-)

In your case for a composing tool I self would use FLTK-c as a fast GUI and FBSound for audio playback.

Joshy
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: FBTrueType static Win/Lin 32/64-bit

Post by paul doe »

Hi, Joshy

When I run the 'DrawStringTestBitmap.bas' file, my OS is reporting a modest ~2 GB memory usage =D:

Image

LOL!

Can you confirm it, or is it just my craptop doing funny things again? Thanks.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by D.J.Peters »

Hello paul good find width height in LoadFontBitmap was wrong
must be long not integer (32 vs 64-bit)

Joshy

Code: Select all

function LoadFontBitmap(byref fontbmpfile as string) as any ptr
  dim as long w,h ' <-- changed from integer 32/64bit to 32bit long
  ...
  ...
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by owen »

Thanks Joshy for this contribution.
I want to experiment with this a bit. How can i re-use the available ttf files i have on my laptop?
Say for example the ttf files that comes with win10.

My goal is to avoid having to include ttf files along with my source code files.

I suppose the solution is that my program would do a directory search for ttf files in commonly known win folders.
I'm guessing that these directories are not the same for all versions of windows.
Or if the user of my programs are running linux then that would be even more locations to search.

I guess my question is: how do you do it? Ie. in FbEdit if you want to change the code font it opens a font selection dialog.
How does fbedit know the fonts i have available?
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by owen »

i get some errors saying error: loading: whatever.ttf no free font id
also is there a way to not have to copy the ttf files to the directory?

Code: Select all

#include once "FBTrueType.bi"
screenres 800,80,32

Dim As String fontfile,fontfiles(),fontfiletemp,errors
Dim As Integer font_c,errors_c

fontfiletemp=Dir("c:\windows\fonts\*.ttf")
Do
	If fontfiletemp="" Then
		Exit Do
	Else
		font_c+=1
		ReDim Preserve fontfiles(font_c)
		fontfiles(font_c)=fontfiletemp
		fontfiletemp=Dir()
	EndIf
Loop
If font_c>0 Then
	Shell "copy c:\windows\fonts\*.ttf"
	Dim As Long font
	For i As Integer = 1 To font_c
		font = FontLoad(fontfiles(i))
		If font<0 Then
			errors_c+=1
			errors += "error: loading: " & fontfiles(i) & " " & ErrorText(font) & Chr(10) & Chr(13)
		Else
			TTPrint font,10,10, fontfiles(i) ,rgb(255,255,255),33
			Sleep 100
			Cls
		End if
	Next
	If errors_c>0 Then
		Print errors_c;" errors"
		Print "error data saved in errors.txt"
		Open "errors.txt" For Output As #1
		Print #1, errors
		Close #1
	Else
		Print "no errors"
	EndIf
Else
	Print "no fonts found in c:\windows\fonts"
End If
Sleep
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: FBTrueType static Win/Lin 32/64-bit

Post by owen »

there must be a max of 64 fonts

Code: Select all

#include once "FBTrueType.bi"
screenres 800,100,32

Dim As String fontfile,fontfiles(),fontfiletemp,errors
Dim As Integer font_c,errors_c

fontfiletemp=Dir("c:\windows\fonts\*.ttf")
Do
	If fontfiletemp="" Then
		Exit Do
	Else
		font_c+=1
		ReDim Preserve fontfiles(font_c)
		fontfiles(font_c)=fontfiletemp
		fontfiletemp=Dir()
	EndIf
Loop
Dim As Long font(font_c)
If font_c>0 Then
	Shell "copy c:\windows\fonts\*.ttf"
	For i As Integer = 1 To font_c
		font(i) = FontLoad(fontfiles(i))
		If font(i)<0 Then
			errors_c+=1
			errors += "error: loading: " & fontfiles(i) & " " & ErrorText(font(i)) & Chr(10) & Chr(13)
		End if
	Next
	If errors_c>0 Then
		Print errors_c;" errors"
		Print "error data saved in errors.txt"
		Open "errors.txt" For Output As #1
		Print #1, errors
		Close #1
	Else
		Print "no errors"
	EndIf
Else
	Print "no fonts found in c:\windows\fonts"
End If
Sleep 1000
Dim As Integer c
For i As Integer = 1 To font_c
	If font(i)<>0 Then
		Cls
		c+=1
		Print fontfiles(i)
		Print c
		TTPrint font(i),10,20, fontfiles(i) ,rgb(255,255,255),33
		Sleep 500
	EndIf
Next
Post Reply