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.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBTrueType Windows and Linux (32/64-bit)

Post by D.J.Peters »

srvaldez wrote:only test04 and test05 give the expected output
You have to read the source code to know what are expected :-)
test01 print the glyph numbers of some ascii codes (the glyph has a shape and it's number is not the same as the ASCII nor unicode it's a position inside the TT Font)

test02 draws some glyph bounding boxes (if you will use TT Fonts with your own drawing stuff you have to know the size of any glyph)

test03 shows glyphs with unicodes in range of 0-2550 (if any of this unicodes has a shape)

Not more not less.

How ever thank you for testing.

Joshy
Last edited by D.J.Peters on Sep 30, 2016 22:20, edited 1 time in total.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: FBTrueType Windows and Linux (32/64-bit)

Post by srvaldez »

hi Joshy
tested on my Mac with same result.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: FBTrueType Windows and Linux (32/64-bit)

Post by MrSwiss »

@Joshy,

FBC WIN 64 (on WIN10) - is OK now.

However, I've had to make some changes in the FBTrueType.bi:
The changes made are only for WIN, if one wants to put the .bi into \inc\ and
the .a files into \lib\[OS]\

Code: Select all

#ifndef __FBTrueType_bi__
#define __FBTrueType_bi__

#include once "crt.bi"

#ifdef __FB_WIN32__
# ifndef __FB_64BIT__
#  libpath "lib/win32"
# else
#  libpath "lib/win64"
# endif '__FB_64BIT__
#else
# libpath "lib/lin"
#endif '__FB_WIN32__

#ifndef __FB_64BIT__
# inclib "FBTrueType-32-static"
#else
# inclib "FBTrueType-64-static"
#endif
As said, only changed for WINDOWS (for LIN maybe also some changes needed!) ...
fxm
Moderator
Posts: 12083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FBTrueType Windows and Linux (32/64-bit)

Post by fxm »

fxm
Moderator
Posts: 12083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FBTrueType Windows and Linux (32/64-bit)

Post by fxm »

Kwabbernoot
Posts: 79
Joined: Apr 19, 2010 18:23
Location: NL

Re: FBTrueType Windows and Linux (32/64-bit)

Post by Kwabbernoot »

This looks great. I can use any font I like by taking a font in: C:\Windows\Fonts.
The letters look beautiful.
This is very much better than the Xfont routines.
http://www.freebasic.net/forum/viewtopi ... =8&t=12078
Good job.
sgaba
Posts: 31
Joined: Aug 15, 2005 19:18
Location: Czech Republic

Re: FBTrueType Windows and Linux (32/64-bit)

Post by sgaba »

Hi D.J.Peters
I did recompile FBImage-src on Raspberry PI 3. (I can send .a file you if you want).

make.sh

Code: Select all

gcc -c -o FBTrueType.o FBTrueType.c
ar rcs libFBTrueType-armv7a-hf-static.a FBTrueType.o
rm FBTrueType.o
and I changed the code in FBTrueType.bi which makes selection of   Library depending on architecture

FBTrueType.bi

Code: Select all

#ifndef __FBTrueType_bi__
#define __FBTrueType_bi__

#include once "crt.bi"

#ifdef __FB_WIN32__
# libpath "lib/win"
	#Ifdef __FB_64BIT__
		# inclib "FBTrueType-64-static"
	#Else
		# inclib "FBTrueType-32-static"
	#EndIf
#EndIf

#ifdef __FB_LINUX__
	# libpath "lib/lin"
	#Ifdef __FB_64BIT__
		# inclib "FBTrueType-64-static"
	#Else
		#ifdef __FB_ARM__
  			# inclib "FBTrueType-armv7a-hf-static"
		#Else
  			# inclib "FBTrueType-32-static"
		#EndIf 
	#EndIf
#endif

' error codes (<0) returned by FontLoad()
#define FONT_NOT_LOADED    (-1)
#define FONT_NOT_SUPPORTED (-2)
' maximal 64 font ids can be used at once (should be enough)
#define NO_FREE_FONTID     (-3)
' error code if a font id are not legal (not in range of 0-63 or font was not loaded before)
#define WRONG_FONTID       (-4)
' error code if a value are out of range (e.g. pixelheight <=0 ...)
#define WRONG_VALUE        (-5)
' error code if a unicode char was not found in font
#define GLYPH_NOT_FOUND    (-6)

function ErrorText(byval errcode as long) as string
  select case errcode
  case FONT_NOT_LOADED    : return "font not loaded"
  case FONT_NOT_SUPPORTED : return "font not supported" 
  case NO_FREE_FONTID     : return "no free font id (64 fonts in use)"
  case WRONG_FONTID       : return "font id is illegal"
  case WRONG_VALUE        : return "wrong value (parameter out of range)"
  case GLYPH_NOT_FOUND    : return "no glyph for unicode in font"
  case else               : return "no error"
  end select
end function


' font properties
type FontProps
  as single scale
  as long   advanceHeight ' space to the next cursor y position (ascent - descent + linegap)
  as long   ascent        ' the space between base line to top of the font
  as long   descent       ' space from bottom of the font to base line (negativ)
  as long   linegap       ' space from bottom of the font to next font top line
end type

' glyph properties
type GlyphProps
  as long advanceWidth    ' the space to the next cursor x position
  as long kernAdvance     ' the kerning can be added to advanceWidth if the glyph has a neighbor glyph
  as long leftSideBearing ' the space from current x position to the most left of the glyph
  as long y               ' the absolute y position of the glyph (from font ascent)
  as long w,h             ' width and height of the visibe part of the glyph
end type


extern "C"

' init the library and prepare 64 font id's (it's not strictly required)
declare sub      FontInit()
' free all loaded fonts at once (not strictly required)
declare sub      FontDestroy()

' ########
' # Font #
' ########
' load a *.ttf file from memory (returns a new font id or error code)
declare function FontCopy(byval filedata as any ptr) as long
' load a *.ttf file from filesystem (returns a new font id or error code)
declare function FontLoad(byval filename as const zstring ptr) as long
' free a loaded font (mark the font ID as illegal WRONG_FONTID)
declare sub      FontFree(byref font as long)

' get the bounding box of all possible characters (return 0 on success or error code)
declare function FontBoundingBox(byval font as long,byref x0 as long,byref y0 as long,byref x1 as long,byref y1 as long) as long

' get font properties based on height in pixels (return 0 on success or error code)
declare function FontPorperties(byval font as long, byval HeightInPixel as long, byref pops as FontProps) as long

' #########
' # Glyph #
' #########
' get glyph index return the glyph position inside the font 
declare function GlyphIndex(byval font as long, byval char as long) as long
' returns true if the glyph has a renderable shape
declare function GlyphHasShape(byval font as long, byval gindex as long) as boolean
' get the bounding box of the visible shape of a glyph (return 0 on success or error code)
declare function GlyphBoundingBox(byval font as long, byval glyphIndex as long, byref x0 as long, byref y0 as long, byref x1 as long, byref y1 as long) as long

' get glyph properties based on glyph index 1 and optional the neighbor glyph index 2
' fill the glypprops members (return 0 on success or error code)
declare function GlyphProperties(byval font as long, byref fProps as const FontProps, byref gProps as GlyphProps, byval glyphIndex1 as long, byval glyphIndex2 as long=0) as long
' render the glyph antialias return a 8-bit FBGFX image or NULL on error
declare function GlyphImageCreate(byval font as long, byref fProps as const FontProps, byref gProps as const GlyphProps,byval glyphindex as long) as any ptr
' you can use ImageDestroy also
declare sub      GlyphImageDestroy(byref img as any ptr)

end extern

#endif ' __FBTrueType_bi__

I tested it on:
Intel:
Windows 10 64-bit gcc32
Windows 10 64-bit gcc64
Windows 10 64-bit GAS32
Ubuntu 16.10 64-bit gcc64
ARM:
Ubumtu Mate 16.04 armv7a-hf RPI3 gcc

I think it will work on all armv7a-hf machines.
I plan to test tegra2 (Toshiba ac100 and Asus tf101)
WQ1980
Posts: 48
Joined: Sep 25, 2015 12:04
Location: Russia

Re: FBTrueType Windows and Linux (32/64-bit)

Post by WQ1980 »

Is possible to create such a font? (second row)

http://s012.radikal.ru/i320/1509/cc/97458bb58bed.png
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FBTrueType Windows and Linux (32/64-bit)

Post by VANYA »

Hi Joshy!

Is it properly freed AlphaChannel in this way? :

Code: Select all

ImageDestroy AlphaChannel
Or it is necessary so:

Code: Select all

GlyphImageDestroy AlphaChannel
In the examples everywhere like this:

Code: Select all

         
         ......
          var AlphaChannel = GlyphImageCreate(font, fProps, gProps,index1)
          if AlphaChannel then
            var glyph = ImageCreate(gProps.w,gProps.h,col)
            put glyph,(0,0),AlphaChannel,ALPHA
            put (cx,cy + gProps.y),glyph,ALPHA
            ImageDestroy glyph
            ImageDestroy AlphaChannel
            ........
            
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBTrueType Windows and Linux (32/64-bit)

Post by D.J.Peters »

Because of malware on alice-dsl.net domain I moved all content to my new shiny3d.de server.

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

Re: FBTrueType Windows and Linux (32/64-bit)

Post by D.J.Peters »

Added free font "DejaVuSans-Oblique.ttf"
"DrawStringCreateBitmap.bas" and "DrawStringTestBitmap.bas"

With DrawStringCreateBitmap.bas you can create from any ttf file draw string command compatible bitmap fonts.

Joshy
Last edited by D.J.Peters on May 06, 2018 13:27, edited 3 times in total.
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: FBTrueType Windows and Linux (32/64-bit)

Post by lizard »

Again all tests are working here on Mint 18 64bit, including the new test06.bas.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBTrueType Windows and Linux (32/64-bit)

Post by D.J.Peters »

Again thank you for testing :-)

Joshy
Roland Chastain
Posts: 993
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: FBTrueType Windows and Linux (32/64-bit)

Post by Roland Chastain »

Great code. Thank you Joshy.

I could create a bitmap and load the font from the bitmap. :)

Your latest code example is doing more or less the same job as CharSet2FBFont.
heisenberg
Posts: 4
Joined: May 04, 2018 18:42

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

Post by heisenberg »

First of all: Thanks to EVERYONE who contribute their stuff to this forum! Great work!

I was looking for an easy way of using ttf's in FB for a long time.
So i was really happy finding this one.

But i get an error in FBTrueType.bi :

error 14: Expected identifier, found 'boolean' in 'declare function GlyphHasShape(byval font as long, byval gindex as long) as boolean'

Do i miss something here?
Maybe compiler options?
Any clue?

Thanx in advance!

steve
Post Reply