1

This engine is dedicated to manipulate different font on the Ti. At the basis, the Ti as three sorts of font: the little, the medium and the large. Now, with this engine, you will be able to make your own font. Then you will be able to load the font of your choice and draw a string with this font. Some special format are included (or will be included) in the drawing routines, as bold and italic format.

Another feature of this engine is that it draws string faster than Ti-OS routines does. So, even if you don't use special font, you can use the HibDLL routines to draw string fast.

The datas

The datas of the font are stored in variables of the Ti, with the extension "FONT". One of this variable will describe only one size of font. In consequence, to describe the three Ti-OS fonts, three variables will be necessary.

The format of the variable is quite simple:
2B: the size of the variable (as for every variables)
2B: the version of description of the font variable format
1B: the maximum width of a caracter
1B: the maximum height of a caracter
1B: the width of the space between two caracters
1B: the code of the first described caracter
the table of width of caracter: table of 256-FisrtChar elements of 1B
the table of picture of caracter: table of 256-FisrtChar elements of ( height * (width / 8) ) Bytes
a string which describe the font (for example "TI-OS Font 1")
a string of the name of the author (for example "Me")
the FONT tag: "FONT\0\xF8"

Load a font

Before using a font, you have to load the font. In fact, it simply search the FONT variable, gets its handle, locks it, and fills the h_Font structure.

typedef struct {
  HANDLE h;
  unsigned char filename[18];
  unsigned char * name;
  unsigned char x;
  unsigned char y;
  unsigned char charSpace;
  unsigned char firstChar;
  unsigned char * xTable;
  unsigned char * spriteTable;
} h_Font;


So, because it locks the handle, you have to unload a font before leaving your software: use the macro \TiC{h_unloadFont(font)} to do it.

Load every font

Another way to load font is to use the h_loadAllFont function. It search in the Ti every FONT variable and store the h_Font structures in a table. Then when you want a specific font, you just have to use h_findFont which return the index of the table of the font you want.

The table is described by the folowing structure:

typedef struct {
  h_Font * tab;
  short nb;
} h_FontTab;


By this way too, you have to unload every FONT by using the macro h_unloadAllFont(fonttab).

2

The caracter drawing routine


short h_drawChar(h_Font * font, short x, short y, unsigned char caract, h_Mode mode, unsigned char * screen) {  
  short decal;
  short j;

  short charsize=h_getFontCharSize(font,caract)+((mode & HMODE_BOLD)!=0)+((mode & HMODE_ITALIC)!=0);
  unsigned char * sprite=(font->spriteTable+font->y*(caract-font->firstChar+1)-1);

  screen+=(y+font->y-1)*30+(x>>3);
  decal=x&7;
  
  for (j=0;j<font->y;j++) {
    (*screen)|=((*sprite)>>decal);
    (*(screen+1))|=((*sprite)<<(8-decal));
    if ((mode & HMODE_BOLD)!=0) {
      (*screen)|=((*sprite)>>(decal+1));
      (*(screen+1))|=((*sprite)<<(8-decal-1));
    }
    if ((mode & HMODE_ITALIC)!=0 && j%3==2)
      decal++;
    screen-=30;
    sprite--;
  }
  
  return charsize;
}

3

I continue to develop HibView. To improve it, I have added the possibility to change the current font. To do so, I had to specify a FONT variable.
The goal is twice : have several different fonts on the Ti and have fast drawing routines.
Then, to be generic, I would like that this format to become used by other programmer. So, what do you think of this ?

In my test (not bench) the speed of the routine I have implemented is sufficient for HibView.

Note : I haven't worked a lot on it, knowing that I will do mistakes. For exemple, I have doubt about the utility of the 'FirstChar' field in the structure.

4

You said your system can be used to render strings faster, even when using the standard TI fonts (in fact AMS'rendering functions work in a dynamically resizable window which introduces a lot of complex calculations that dramatically slow down the process, so I don't doubt you are alot faster happy).
When doing so, does one have to have a copy of the font in a file, or you have a special feature available to make direct use of the fonts in AMS?

Not that I will use it: I won't probably make the kind of program that require speed or different fonts. Still, I'm curious about it and always willing to give suggestions as to how things could be improved cheeky.

5

spectras :
You said your system can be used to render strings faster, even when using the standard TI fonts (in fact AMS'rendering functions work in a dynamically resizable window which introduces a lot of complex calculations that dramatically slow down the process, so I don't doubt you are alot faster happy). When doing so, does one have to have a copy of the font in a file, or you have a special feature available to make direct use of the fonts in AMS?
I use three TiOS files for the three fonts. For the engine, there is no difference in drawing a TiOS font or a custum font.
Not that I will use it: I won't probably make the kind of program that require speed or different fonts. Still, I'm curious about it and always willing to give suggestions as to how things could be improved cheeky.
you're welcome ! wink

6

There is one suggestion I have...
If you want to use 2 fonts (for instance), you have to have two files on your TI ?
That's a bit much, I think.
Couldn't it be possible to have several fontes in only one file ? (for example, a file like a ttarchive (or any other system that works the same way), which consists of differents indepedant sections) ?)
Or, at least, wouldn't it be a good idea to have an initialization function to which one can pass a pointer to a block in memory containing the data of a font ? that would allow users to put a font in their external file, and use it with your library, without the need of adding one more external file to their program smile
avatarTutorial C (TI-89/92+/v200) - Articles Développement Web (PHP, Javascript, ...)
« What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against? » - Larry Wall

7

squale92 :
There is one suggestion I have... If you want to use 2 fonts (for instance), you have to have two files on your TI ?
yes
That's a bit much, I think. Couldn't it be possible to have several fontes in only one file ? (for example, a file like a ttarchive (or any other system that works the same way), which consists of differents indepedant sections) ?)
yes, that's a good idea, I have thought about it. For exemple for the 3 TiOS fonts, there will be a unique big variable which will contain the 3 group of datas, this big variable being compressed.
This functionnality could be added later as an upper layer.
Or, at least, wouldn't it be a good idea to have an initialization function to which one can pass a pointer to a block in memory containing the data of a font ? that would allow users to put a font in their external file, and use it with your library, without the need of adding one more external file to their program smile
good idea too. In fact the programmer can already do it.
Here is the code for loading a font :

char h_loadFont(h_Font * font, const unsigned char * filename) {
  SYM_ENTRY * SymPtr;
  unsigned char * data;
  unsigned short size;
  short version;
  
  SymPtr=DerefSym(SymFind(SYMSTR(filename)));
  if (SymPtr==NULL)
    return h_ERR_NOT_FOUND;
  
  data=HLock((font->h=SymPtr->handle));
  if (data==NULL)
    return h_ERR_MEM;
  
//verify it is FONT File  
  size=*(unsigned short *)data;
  if (strncmp("\0FONT\0\xF8",data+size-5,7)!=0) {
    HeapUnlock(font->h);
    return h_ERR_NOT_FONT_FILE;
  }

  strcpy(font->filename,filename);
  data+=2;
  version=*(unsigned short *)data;
  data+=2;

  if (version>1) { //the version of the FONT file is unknown
    HeapUnlock(font->h);
    return h_ERR_WRONG_VERSION;
  }

  font->x=*(data++);
  font->y=*(data++);
  font->charSpace=*(data++);
  font->firstChar=*(data++);
  font->xTable=data;
  font->spriteTable=(data+=256-font->firstChar);
  font->name=(data+=(256-font->firstChar)*font->y);

  return h_NO_ERR;

}


The programmer can use the end of this code to do as he wants with his own datas. In fact he will fill the h_Font structure and that's all.

8

ok smile
avatarTutorial C (TI-89/92+/v200) - Articles Développement Web (PHP, Javascript, ...)
« What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against? » - Larry Wall