User projects written in or related to FreeBASIC.
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Charset2FBFont

Postby leopardpm » May 02, 2016 0:43

hmmm gets crazy fast... but understanding these different methods will help my code be more modular...
Posts: 3739
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Charset2FBFont

Postby BasicCoder2 » May 02, 2016 0:46

D.J.Peters wrote:You are right but this are only the half of the story :-)

Sorry I didn't make it clear the text was copied word for word from, ... nters.html
to save the reader having to search for the relevant part themselves.
Posts: 137
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: Charset2FBFont

Postby wallyg » Jun 01, 2016 20:11

Thank you for this fine product.

I am going to use it for one of the projects I am working on. I see you include the zlib and freetype license. Do you have a license I should include for this library or is the zlib and freetype license enough.
Posts: 134
Joined: May 28, 2009 20:07

Re: Charset2FBFont

Postby Muttonhead » Jun 02, 2016 9:52

Hm... as long as you want to use the only and a bitmap, howsoever(thanks2googletransltr) it was created,... feel free to use it and earn a lot of money with it! :D
I think no license needed

The created Bitmap...
I'm not a lawyer, the most fonts are copyrighted, take a look at the (c)'s before you use a bitmap of this font.

Posts: 137
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: Charset2FBFont

Postby wallyg » Jun 02, 2016 10:28

Thanks, I was not planning on selling anything, just putting together a library for some friends to use.

Thanks for the list. I was planning on doing some research to find a couple of fonts that were in the public domain for use. If anyone knows of fonts that can be used with your software that are in the public domain, I would appreciate finding out about them.
Posts: 137
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Charset2FBFont - Thank You and simple request

Postby wallyg » Jun 11, 2021 0:04

I appreciate your software and it works great. Thank you for providing it for general use.

I was wondering how hard it would be to remove the GUI software of your Fontmaker and make it a standalone function that I could call with some options( like font name, size, ... ) and have the files generated with a specified base filename that I could then read and use with my homebrew design software as needed.

Or maybe a standalone batch program that I could EXEC that would allow options to be specified as command arguments.

This would allow me not to have to generate and store hundreds of files for different fonts in different heights and options.

Thank you for your consideration and advice.

Gratefully yours, Wally
Posts: 134
Joined: May 28, 2009 20:07

Re: Charset2FBFont

Postby Muttonhead » Jun 12, 2021 16:33

This would allow me not to have to generate and store hundreds of files for different fonts in different heights and options.

;) thats why vector font was invented, but seriously:
under these circumstances, there are good reasons for using the Freetype library directly for the output,
and not to take the diversions via a BitmapFont.By the way, there is a good code example that explains the
basic use of the Freetype library: compiler directory\examples\graphics\FreeType\

Please download the latest version of Charset2FBFont. It contains some small fixes: latest compilerversion(v1.08.0) and 64Bit are supported.

Based on this package try this:

Code: Select all

#include "freetype2/"
#include ""
#include ""

'all parameter
dim as string p_SourcePath, p_VectorFontFile, p_DestinationPath, p_BitmapFontFile
dim as integer p_size,p_res,p_rangestart,p_rangeend,p_bitmaptype,p_plottype, p_spacewidth
dim as integer p_pencolor,p_bgcolor,p_pthreshold,p_bgthreshold
dim as single p_gamma

'to create a cp437 bitmap
dim as integer unicodetable(255)

'ft library stuff
dim as FT_Library library
dim as FT_Face face
dim as FT_Bitmap ptr FTbitmap
dim as integer FT_BitmapPitch,FTRenderFlag

'own bitmap font stuff
dim as BitmapFont ptr BMPFont

'dim as integer pt,dpi,p_spacewidth,gammafactor
dim as uinteger PixelColor
dim as ubyte ftoutput,bmpinput
dim as integer tmpheight,raiserange,index,ucval,ff
dim as string row

screen 19,32'we need a FB screen to create fb images

if (FT_Init_FreeType(@library) <> 0) then print "FT_Init_FreeType() failed": End 1
BMPFont=new BitmapFont
if BMPFont=0 then print "FT_Init_FreeType() failed": End 1

'read cp437
if fileexists ("CodePage.cfg") then
  open "CodePage.cfg" for input as ff
      line input # ff, row
      if left (row,1)<>"#" then
        index= val( "&H" & mid(row,3,2) )
        ucval= val( "&H" & mid(row,8,4) )
      end if
    loop until eof(ff)
  close ff
  for i as integer=0 to 255
  next i
end if

p_BitmapFontFile=left(p_VectorFontFile, len(p_VectorFontFile)-4) + ".bmp"
p_size=15'font size in Pt
p_res=96'Resolution (dpi)
p_bitmaptype=1'1=DRAW STRING compatible 2=smallest Bitmap
p_plottype=1'1=proportional 2=monospaced
p_spacewidth=1'additional space between chars or fixed char width
p_pthreshold=255' contrast tool parameters

if FT_New_Face(library, p_VectorFontFile, 0, @face) = 0 then 'if the font file was opened by freetype library

  if BMPFont->firstchar<0 then BMPFont->firstchar=0
  if BMPFont->firstchar>255 then BMPFont->firstchar=255
  if BMPFont->lastchar<0 then BMPFont->lastchar=0
  if BMPFont->lastchar>255 then BMPFont->lastchar=255
  if BMPFont->firstchar>BMPFont->lastchar then swap BMPFont->firstchar,BMPFont->lastchar
  if p_size<1 then p_size=1
  if p_spacewidth<0 then p_spacewidth=0
  if p_plottype=2 then if p_spacewidth<1 then p_spacewidth=1


  '1. alle Größen zu jedem Zeichen auslesen, Höhe BaseLine berechnen
  if FT_Set_Char_Size( face, 0, p_size*64,p_res,p_res)=0 then
    for i as integer=BMPFont->firstchar to BMPFont->lastchar
      if FT_Load_Char(face, unicodetable(i), FTRenderFlag)=0 then
        BMPFont->CharSet(i).OffsetX       =BMPFont->imgwidth
        BMPFont->CharSet(i).AdvanceX      =face->glyph->advance.x shr 6
        BMPFont->CharSet(i).GlyphWidth    =face->glyph->bitmap.width
        BMPFont->CharSet(i).GlyphHeight   =face->glyph->bitmap.rows
        BMPFont->CharSet(i).GlyphLeft     =face->glyph->bitmap_left
        BMPFont->CharSet(i).GlyphTop      =face->glyph->bitmap_top
        'Baseline... eigentlich nur Suche nach größter Enfernung nach oben
        if BMPFont->BaseLine < BMPFont->CharSet(i).GlyphTop then BMPFont->BaseLine = BMPFont->CharSet(i).GlyphTop

        select case p_bitmaptype
          case 1'DRAW STRING
            if p_plottype=1 then'proportional
              if BMPFont->CharSet(i).GlyphWidth>0 then BMPFont->CharSet(i).AdvanceX = BMPFont->CharSet(i).GlyphWidth
              BMPFont->CharSet(i).AdvanceX +=p_spacewidth
              BMPFont->CharSet(i).GlyphLeft=cint(p_spacewidth/2)  'cint((BMPFont->CharSet(i).AdvanceX - BMPFont->CharSet(i).GlyphWidth)/2)
              BMPFont->imgwidth += BMPFont->CharSet(i).AdvanceX
            else                                   'monospaced
              BMPFont->CharSet(i).AdvanceX =p_spacewidth
              if BMPFont->CharSet(i).GlyphWidth>p_spacewidth then BMPFont->CharSet(i).GlyphWidth=p_spacewidth
              BMPFont->CharSet(i).GlyphLeft=cint((p_spacewidth - BMPFont->CharSet(i).GlyphWidth)/2)
              BMPFont->imgwidth += p_spacewidth
            end if
          case 2'smallest bitmap
            BMPFont->imgwidth += BMPFont->CharSet(i).GlyphWidth
        end select
      end if
    next i

    '2.ausgehend von der nun bekannten BaseLine die Gesamthöhe des Fonts ermitteln
    '.GlyphTop steht noch im Bezug zur BaseLine, Umrechnung auf "Abstand von oben"
    'damit gilt jetzt bei allen Werten das Screen/Image Koordinatensystem
    for i as integer=BMPFont->firstchar to BMPFont->lastchar
      'GlyphTop "umrechnen"
      BMPFont->CharSet(i).GlyphTop = BMPFont->BaseLine - BMPFont->CharSet(i).GlyphTop
      tmpheight =BMPFont->CharSet(i).GlyphTop + BMPFont->CharSet(i).GlyphHeight
      if BMPFont->imgheight < tmpheight then BMPFont->imgheight=tmpheight
    next i


    line BMPFont->img,(0,0)-(BMPFont->imgwidth-1,BMPFont->imgheight-1),BMPFont->Background,BF

    '3. alle Zeichen ins Image plotten
    for i as integer=BMPFont->firstchar to BMPFont->lastchar
      if FT_Load_Char(face,unicodetable(i),FTRenderFlag)=0 then'flag 256 anitialias/ monochrom
        FTbitmap = @face->glyph->bitmap
        for y As integer = 0 To (FTbitmap->rows - 1)
          for x As integer = 0 To (FTbitmap->width - 1)

            ftoutput = FTbitmap->buffer[y * FTbitmap->pitch + x]

            if p_bgthreshold > p_pthreshold then swap p_bgthreshold,p_pthreshold
            raiserange=p_pthreshold - p_bgthreshold

            if ftoutput<=p_bgthreshold then bmpinput=0
            if ftoutput>p_bgthreshold and ftoutput<=p_pthreshold then bmpinput=(ftoutput-p_bgthreshold)/raiserange * 255
            if ftoutput>p_pthreshold then bmpinput=255
            bmpinput=((bmpinput / 255) ^ p_gamma) * 255
            PixelColor=MixColor(BMPFont->Background, BMPFont->PenColor, bmpinput)

            select case  BMPFont->PlotType
              case 1
                pset BMPFont->img, (BMPFont->CharSet(i).OffsetX + BMPFont->CharSet(i).GlyphLeft + x, BMPFont->CharSet(i).GlyphTop + y),PixelColor
              case 2
                pset BMPFont->img, (BMPFont->CharSet(i).OffsetX + x, y),PixelColor
            end select

          next x
        next y
      end if
    next i

  end if

  chdir p_DestinationPath
  BMPFont->SaveFont(p_BitmapFontFile)'a Drawer will created
  print "File not opened"
end if

delete BMPFont

a kind of stand alone converter.
all p_* variables are Parameter to feed the converting process.
its your turn to build a command line tool :)
remark: you need allways an open fb screen to handle with bitmaps.

greets Mutton
Posts: 137
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: Charset2FBFont

Postby wallyg » Jun 12, 2021 19:17

Thank you. Especially thank you for helping and trying to educate the rest of us.
Posts: 134
Joined: May 28, 2009 20:07

Re: Charset2FBFont

Postby Muttonhead » Jun 13, 2021 16:17

I am neither able nor do I want to educate anyone here :)
maybe i've misunderstand you

Posts: 137
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: Charset2FBFont

Postby wallyg » Jun 13, 2021 19:13

Your willingness to respond and answer questions together with examples and impart your knowledge to others is the true sign of an educator.

Thank you for all you have done for me and the community as a whole.

Posts: 237
Joined: Mar 12, 2006 16:25

Re: Charset2FBFont

Postby RockTheSchock » Jun 19, 2021 18:02

Some time ago I wrote / ported a routine to use Draw String with FreeType2 lib to output UTF8 strings.

Using a font like Google Noto Mono might be cool but I did not test it.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 9 guests