Charset2FBFont

User projects written in or related to FreeBASIC.
Muttonhead
Posts: 139
Joined: May 28, 2009 20:07

Charset2FBFont

Post by Muttonhead »

a new version of my truetype font to bitmap converter now available

Image

http://www.freebasic-portal.de/download ... nt-88.html

Mutton
Last edited by Muttonhead on May 01, 2016 8:37, edited 2 times in total.
chung
Posts: 648
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Re: Charset2FBFont

Post by chung »

good job ! i like it
Muttonhead
Posts: 139
Joined: May 28, 2009 20:07

Re: Charset2FBFont

Post by Muttonhead »

some minor changes :) v.2.02
squall4226
Posts: 284
Joined: Dec 21, 2008 15:08
Contact:

Re: Charset2FBFont

Post by squall4226 »

Oh, this is sweet. Glad I stumbled on this.
Rens
Posts: 256
Joined: Jul 06, 2005 21:09

Re: Charset2FBFont

Post by Rens »

Thanx,

Works fine under Linux Lite 1.0.6 - kernel 3.2.0-40-generic-pae (i686)

Dependencies (checked with shell command: ldd ./CharSet2FBFont):

linux-gate.so.1 => (0xb77d5000)
libfreetype.so.6 => /usr/lib/i386-linux-gnu/libfreetype.so.6 (0xb7703000)
libX11.so.6 => /usr/lib/i386-linux-gnu/libX11.so.6 (0xb75cf000)
libXext.so.6 => /usr/lib/i386-linux-gnu/libXext.so.6 (0xb75bc000)
libXpm.so.4 => /usr/lib/i386-linux-gnu/libXpm.so.4 (0xb75aa000)
libXrandr.so.2 => /usr/lib/i386-linux-gnu/libXrandr.so.2 (0xb75a1000)
libXrender.so.1 => /usr/lib/i386-linux-gnu/libXrender.so.1 (0xb7597000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb757c000)
libtinfo.so.5 => /lib/i386-linux-gnu/libtinfo.so.5 (0xb755c000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7530000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb752b000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7382000)
/lib/ld-linux.so.2 (0xb77d6000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb736c000)
libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0xb734a000)
libXau.so.6 => /usr/lib/i386-linux-gnu/libXau.so.6 (0xb7346000)
libXdmcp.so.6 => /usr/lib/i386-linux-gnu/libXdmcp.so.6 (0xb733f000)

If the program does not work then check if libfreetype6-dev is installed!
Muttonhead
Posts: 139
Joined: May 28, 2009 20:07

Re: Charset2FBFont

Post by Muttonhead »

@Rens: thanks for testing under Linux.

Mutton
Muttonhead
Posts: 139
Joined: May 28, 2009 20:07

Re: Charset2FBFont

Post by Muttonhead »

a minor change: the latest version should create codepage 437 compatible bitmap fonts, if the font support the needed glyphs

Mutton
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Charset2FBFont

Post by leopardpm »

Very nice, Mutton! I have wondered, but not researched, how to use different fonts in FB... seemed to be quite a pain (why can't FB just directly access the windows OTF, TTF, etc fonts with a command?)... I ran some tests and your utilities provide a pretty easy method for using any font I want to.

Question: You provide two different methods to draw the font: (1) your PRINT command, and, (2) Draw String. Which one is faster?

Also, it appears that changing the color that the font is drawn is easier by using your custom print routine (I am not very familiar with draw string, so i could be wrong).
Muttonhead
Posts: 139
Joined: May 28, 2009 20:07

Re: Charset2FBFont

Post by Muttonhead »

@leopardpm: i have never made any kind of speedtests but i think my own plotting routine is much slower than DRAW STRING, many many PSETs inside :).
generally I would recommend DRAW STRING to use. But the methods for manipulation have their problems with anti-aliased bitmaps, these methods work best with real 2-color-bitmaps.
for my own plot routine are the colors in the bitmap uninteresting(!). only the alpha value is needed. alpha value, pencolor and background color gives the new color.

...and yes, with my plot routine it is more convenient to change the pencolor

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

Re: Charset2FBFont

Post by D.J.Peters »

leopardpm wrote:(why can't FB just directly access the windows OTF, TTF, etc fonts with a command?)
Normaly you can use the Freetype rendered font glyph (it's a 8-bit alphachannel bitmap) perfectly with the put() command.

The problem are in fbgfx a width of a bitmap row must be a multiply of 16 bytes.

Freetype can render for examlple an "I" truetype glyph with 5x8 pixels and 5 isn't a multiply of 16.

You know ?

Joshy
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Charset2FBFont

Post by leopardpm »

D.J.Peters wrote:
leopardpm wrote:(why can't FB just directly access the windows OTF, TTF, etc fonts with a command?)
Normaly you can use the Freetype rendered font glyph (it's a 8-bit alphachannel bitmap) perfectly with the put() command.

The problem are in fbgfx a width of a bitmap row must be a multiply of 16 bytes.

Freetype can render for examlple an "I" truetype glyph with 5x8 pixels and 5 isn't a multiply of 16.

You know ?

Joshy
I guess what I am not understanding is that the font information is just basically mathematical descriptions of arcs and curves in a shape (and I think there is also additional 'hint' info for particular letters/numbers) - isn't it possible to render this data on the fly? I gather Mutton's code must do that to convert the font to a bitmap, why not skip the step of making a bitmap which needs to be saved and just render directly?

I imagine that a command would look like this:

DrawFont (fontid,fontsize,fontColor,"text to be drawn",xpos,ypos)...

or perhaps two commands, the first one just to set the font/size/color and second one to provide the pos and text...

I do notice that in the high-end graphics programs I use (FlexiSign, Adobe InDesign, Photoshop, etc), there is a period of time where the system fonts are 'loaded', so maybe they all load up the font math definitions at start, but they seem to render directly on the fly because any font point size can be used.

I guess it is not that important as I would probably only use one or two fonts and different sizes max, so it is easy enough just to use the pre-rendered bitmaps like his program creates... sure seems clunky though!
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Charset2FBFont

Post by leopardpm »

looking through Muttons code, I am guessing that it is in the FreeType DLL that the font is actually rendered to a bitmap, right? Though I can't discern exactly what it is rendered to.... because my FB knowledge is so poor... I do not understand what this "->" operator does, which he uses everywhere... just recently I believe someone told me where to find it in the FB help... but I have forgotten.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Charset2FBFont

Post by BasicCoder2 »

NOTE: The text below is copied from this web page:
http://www.petesqbsite.com/sections/exp ... nters.html
Pointers aren't limited to just the standard FreeBASIC data types. You can also define a pointer to point to a UDT (User Defined Type). To do this you simply use the name of the UDT for the type in the pointer definition.

Code: Select all

  type myUDT
    var1 as integer
    var2 as integer
    var3 as integer
  end type

  dim myType as myUDT     'create UDT in memory
  dim myPtr  as myUDT ptr 'create a pointer of type myUDT

  myPtr = @myType 'point to our UDT
Remember the pointer type just indicates how much memory the pointer can address at one time. So, we must first create our UDT in memory and then have our pointer point to it, before we can start using the pointer. Now that we have a pointer to our UDT, how do we access it's elements through the pointer? Your first thought might be to use the standard dot notation.

Code: Select all

  myPtr.var1 = value 'assign value to var1 using myPtr???
However, this is incorrect. The dot notation is only used for variables, not pointers. With a pointer we need to use the "->" symbol.

Code: Select all

  myPtr->var1 = value 'correct pointer notation to assign value to var1
It might seem odd, at first, to have two different symbols ("." and "->") which essentially do the same thing. With two symbols, though, we can quickly determine how we are accessing our information. The "->" symbol tells us immediately that we're working with a pointer. Otherwise we're working directly with a variable.
Last edited by BasicCoder2 on Jun 01, 2016 21:18, edited 3 times in total.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Charset2FBFont

Post by leopardpm »

wow.. thanks BasicCoder... that was a VERY clear description and examples... I understand exactly what is happening now... of course, need to actually put it to use to help burn it into my brain, or I will undoubtedly forget again..
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Charset2FBFont

Post by D.J.Peters »

BasicCoder2 wrote:...However, this is incorrect. The dot notation is only used for variables, not pointers. With a pointer we need to use the "->" symbol.
You are right but this are only the half of the story :-)

Joshy

Code: Select all

*myPtr.value = xyz
or

Code: Select all

with *myPtr
  .value = xyz
end with
Post Reply