FBTrueType static Win/Lin 32/64-bit

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 7659
Joined: May 28, 2005 3:28

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

Postby D.J.Peters » Sep 30, 2016 21:52

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: 1834
Joined: Sep 25, 2005 21:54

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

Postby srvaldez » Sep 30, 2016 22:06

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

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

Postby MrSwiss » Oct 01, 2016 0:04

@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
Posts: 8680
Joined: Apr 22, 2009 12:46
Location: Paris (suburbs), FRANCE

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

Postby fxm » Oct 01, 2016 6:47

fxm
Posts: 8680
Joined: Apr 22, 2009 12:46
Location: Paris (suburbs), FRANCE

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

Postby fxm » Oct 01, 2016 9:07

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

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

Postby Kwabbernoot » Oct 03, 2016 19:51

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.
viewtopic.php?f=8&t=12078
Good job.
sgaba
Posts: 28
Joined: Aug 15, 2005 19:18
Location: Czech Republic

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

Postby sgaba » Dec 06, 2016 13:33

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: 40
Joined: Sep 25, 2015 12:04
Location: Russia

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

Postby WQ1980 » Feb 16, 2017 19:23

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

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

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

Postby VANYA » Jun 30, 2017 18:22

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: 7659
Joined: May 28, 2005 3:28

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

Postby D.J.Peters » Sep 25, 2017 17:14

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

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

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

Postby D.J.Peters » Apr 24, 2018 9:42

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)

Postby lizard » Apr 24, 2018 10:06

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

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

Postby D.J.Peters » Apr 24, 2018 10:13

Again thank you for testing :-)

Joshy
Roland Chastain
Posts: 851
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

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

Postby Roland Chastain » Apr 24, 2018 20:49

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

Postby heisenberg » May 04, 2018 18:54

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

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 2 guests