This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ftrasterize issues with font name and spacing

I am trying to use a small 5x7 bitmap font in BDF format and when I use ftrasterize to convert it to a C file I have two problems:

the name of the bitmap array and font structure name have an invalid character (0x15) eg. if I use /ftrasterize.exe -v -f 5x7test -s F0 5x7.bdf then I get the names:

g_sFont[0x15]x7test0 and g_pui8[0x15]x7test0Data where [0x15] is the invalid character. Looking at the source code for ftrasterize, I can see that when I use the F0 option for the fixed font size it uses the pParams->iSize variable which for the fixed font option is the selected size index of 0. When the C file is created it uses this variable to create the font data array name with :

fprintf(pFile, "static const uint8_t g_pui8%s%d%s%sData[%d] =\n",
            pcCapFilename, pParams->iSize, pParams->bBold ? "b" : "",
            pParams->bItalic ? "i" : "", iOpt);

and the tFont name

fprintf(pFile, "const tFont g_sFont%s%d%s%s =\n", pcCapFilename,
                pParams->iSize, pParams->bBold ? "b" : "",
                pParams->bItalic ? "i" : "");

and reference to the data pointer at the bottom of the structure

fprintf(pFile, "    g_pui8%s%d%s%sData\n", pcCapFilename,
                pParams->iSize, pParams->bBold ? "b" : "",
                pParams->bItalic ? "i" : "");

Unfortunately the value of iSize is not the font width but rather the size index. I'm not sure why it converts this as the 0x15 character, but it is obviously a bug when you are using a fixed font index option.

The other issue I am having is when I use the C file and print a string of characters, there is no pixel space between them. The glyphs of the font are 5 pixels wide with each character being 4 pixels wide and the fifth column being blank to provide  a space between characters. However, it appears that the character encoding of ftrasterize doesn't allow for this unused pixel and the maximum width of the characters is spec'd as 4 not 5. I assume that this is why there is no space between them when they are displayed as a string. I have done a verbose listing :

ftrasterize.exe -v -f 5x7test -s F0 5x7.bdf
FTRasterize: Generate a TivaWare GrLib-compatible font.
Copyright 2008-2011 Texas Instruments Incorporated.

Command line arguments parsed.
Generating a narrow format font.
Encoding characters 32 to 126. Using tFont format.
Selected size index 0 (5 x 7).
Rendering individual character glyphs...
Forcing character 0x20 to be a space.
Character 0x21: 5 x 7, pitch 1, top 6
Character 0x21: xMin 2, xMax 2
Character 0x22: 5 x 7, pitch 1, top 6
Character 0x22: xMin 1, xMax 3
...

Character 0x7e: 5 x 7, pitch 1, top 6
Character 0x7e: xMin 0, xMax 3
Finding maximum character dimensions...
Maximum values - Width 4, YMax 0, YMin 6
Compressing glyphs...
Error compressing glyph. pucData 0x00000000, iMaxX 0
Error on compressing glyph 20!
Compressed glyph 0x21.  Width 1, 4 bytes of data.
Compressed glyph 0x22.  Width 3, 7 bytes of data.
Compressed glyph 0x23.  Width 5, 11 bytes of data.
...

Compressed glyph 0x7d.  Width 3, 9 bytes of data.
Compressed glyph 0x7e.  Width 4, 7 bytes of data.
Writing output file...
Finished.

When I use the -n option I get this:

ftrasterize.exe -v -n -f 5x7test -s F0 5x7.bdf
FTRasterize: Generate a TivaWare GrLib-compatible font.
Copyright 2008-2011 Texas Instruments Incorporated.

Command line arguments parsed.
Generating a narrow format font.
Encoding characters 32 to 126. Using tFont format.
Selected size index 0 (5 x 7).
Rendering individual character glyphs...
Character 0x20: 5 x 7, pitch 1, top 6
Character 0x20: xMin 1000000, xMax 0
Set char 0x20 width to 5 pixels.
Character 0x21: 5 x 7, pitch 1, top 6
Character 0x21: xMin 2, xMax 2
...

Character 0x7e: 5 x 7, pitch 1, top 6
Character 0x7e: xMin 0, xMax 3
Finding maximum character dimensions...
Maximum values - Width 5, YMax 0, YMin 6
Compressing glyphs...
Compressed glyph 0x20.  Width 6, 5 bytes of data.
Compressed glyph 0x21.  Width 1, 4 bytes of data.
Compressed glyph 0x22.  Width 3, 7 bytes of data.
...

Compressed glyph 0x7d.  Width 3, 9 bytes of data.
Compressed glyph 0x7e.  Width 4, 7 bytes of data.
Writing output file...
Finished.

This gives me a maximum font width of 6 in the C file, but I still don't get a space between characters. I don't understand the issue here unless, the encoding is incorrect. When I don't specify the -n option, I get a maximum width of 4 characters. I notice that after running this again after using the n option, the C file now says I have a maximum character width of 5 !

Can someone please explain how I can fix the problem of no space between the characters ?

Thanks.

Jeff

  • OK I managed to compile and debug ftrasterize and hence fix the two issues I was having. I managed to fix the missing intercharacter gap by adding the following code in line 1604 in CompressGlyph() of ftrasterize.c :

            if(pParams->bFixedSize)
            {
                iXMin = pGlyph->iMinX;
                iXMax = iWidth;                // set to the width of the font char set
            }
            else
            {
              //
              // For proportionally-spaced fonts, left-align the glyph in the
              // character cell and provide uniform inter-character padding on
              // the right side.
              //
              iXMin = pGlyph->iMinX;
              iXMax = pGlyph->iMaxX + 1 + (pParams->iSize / 10);
            }

    This prevents the fixed font from being treated like a proportional font and not including the pixel gap.

    The other issue of incorrect font naming was caused by removing the capitalization of the first character of the filename by subtracting 0x20 when the character was a number eg. 5x7 this meant that it printed 0x35 - 0x20 or 0x15 as the first character. I fixed this by using the following code at line 4482 :

        if((pcCapFilename[0] >= 'a') && (pParams->pcFilename[iX] <= 'z'))
        {
          pParams->pcFilename[0] += 0x20;
        }

    This ensures that numbers are not capitalised. Also this line previously was :

          pParams->pcFilename[0] -= 0x20;

    This was why the value 5 was converted to 0x15.

    Jeff

  • Hello Jeff,

    Do you want to report this as a bug in ftrasterize.c?

    Regards
    Amit
  • Hi Amit,


    It would probably be helpful to someone with a similar problem if it was notified as such. I'm not sure how to do that. I noticed when I compiled the program that there over 50 warning messages. They mostly related to unused variables and casting issues though. I have fixed all those issues and have attached the updated file, along with a print out of the warning messages. I also noticed that the fix I provided for the capitalization of the lower case file name should have decremented by 0x20 rather than incremented. I have put the correct code in the attached ftrasterize.c file.ftrasterize.c

    make all 
    Building file: ../ftrasterize.c
    Invoking: Cygwin C Compiler
    gcc -I"C:\ti\tirtos_tivac_2_14_00_10\products\TivaWare_C_Series-2.1.1.71b" -I"C:\bms\Component Datasheets\fonts\ftrasterize\freetype-2.4.0\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"ftrasterize.d" -MT"ftrasterize.d" -o "ftrasterize.o" "../ftrasterize.c"
    ../ftrasterize.c: In function 'DisplayGlyph':
    ../ftrasterize.c:1488:25: warning: unused variable 'iBytesPerLine' [-Wunused-variable]
         int iX, iY, iPixel, iBytesPerLine, iMaxPix;
                             ^
    ../ftrasterize.c: In function 'WriteBinaryBlocks':
    ../ftrasterize.c:1954:25: warning: unused variable 'iLoop' [-Wunused-variable]
         int iGlyph, iCount, iLoop, iX;
                             ^
    ../ftrasterize.c:1954:17: warning: variable 'iCount' set but not used [-Wunused-but-set-variable]
         int iGlyph, iCount, iLoop, iX;
                     ^
    ../ftrasterize.c: In function 'WriteRemappedBinaryBlocks':
    ../ftrasterize.c:2168:25: warning: unused variable 'iLoop' [-Wunused-variable]
         int iGlyph, iCount, iLoop;
                             ^
    ../ftrasterize.c:2168:17: warning: variable 'iCount' set but not used [-Wunused-but-set-variable]
         int iGlyph, iCount, iLoop;
                     ^
    ../ftrasterize.c:2165:22: warning: unused variable 'pBlock' [-Wunused-variable]
         tCodepointBlock *pBlock;
                          ^
    ../ftrasterize.c: In function 'WriteBinaryWideFont':
    ../ftrasterize.c:2271:16: warning: unused variable 'sBlock' [-Wunused-variable]
         tFontBlock sBlock;
                    ^
    ../ftrasterize.c:2265:29: warning: unused variable 'ulTemp' [-Wunused-variable]
         unsigned long ulOffset, ulTemp;
                                 ^
    ../ftrasterize.c:2265:19: warning: unused variable 'ulOffset' [-Wunused-variable]
         unsigned long ulOffset, ulTemp;
                       ^
    ../ftrasterize.c:2264:45: warning: unused variable 'iCount' [-Wunused-variable]
         int iX, iOpt, iFontSize, iGlyph, iLoop, iCount;
                                                 ^
    ../ftrasterize.c:2264:38: warning: unused variable 'iLoop' [-Wunused-variable]
         int iX, iOpt, iFontSize, iGlyph, iLoop, iCount;
                                          ^
    ../ftrasterize.c:2264:30: warning: unused variable 'iGlyph' [-Wunused-variable]
         int iX, iOpt, iFontSize, iGlyph, iLoop, iCount;
                                  ^
    ../ftrasterize.c:2263:22: warning: unused variable 'pGlyphBlockStart' [-Wunused-variable]
         tGlyph *pGlyph, *pGlyphBlockStart;
                          ^
    ../ftrasterize.c:2263:13: warning: unused variable 'pGlyph' [-Wunused-variable]
         tGlyph *pGlyph, *pGlyphBlockStart;
                 ^
    ../ftrasterize.c:2262:22: warning: unused variable 'pBlock' [-Wunused-variable]
         tCodepointBlock *pBlock;
                          ^
    ../ftrasterize.c: In function 'WriteRemappedASCIIBlocks':
    ../ftrasterize.c:2498:22: warning: unused variable 'pBlock' [-Wunused-variable]
         tCodepointBlock *pBlock;
                          ^
    ../ftrasterize.c: In function 'WriteASCIIWideFont':
    ../ftrasterize.c:2851:19: warning: unused variable 'ulOffset' [-Wunused-variable]
         unsigned long ulOffset;
                       ^
    ../ftrasterize.c:2850:45: warning: unused variable 'iCount' [-Wunused-variable]
         int iX, iOpt, iFontSize, iGlyph, iLoop, iCount;
                                                 ^
    ../ftrasterize.c:2850:38: warning: unused variable 'iLoop' [-Wunused-variable]
         int iX, iOpt, iFontSize, iGlyph, iLoop, iCount;
                                          ^
    ../ftrasterize.c:2850:30: warning: unused variable 'iGlyph' [-Wunused-variable]
         int iX, iOpt, iFontSize, iGlyph, iLoop, iCount;
                                  ^
    ../ftrasterize.c:2849:22: warning: unused variable 'pGlyphBlockStart' [-Wunused-variable]
         tGlyph *pGlyph, *pGlyphBlockStart;
                          ^
    ../ftrasterize.c:2849:13: warning: unused variable 'pGlyph' [-Wunused-variable]
         tGlyph *pGlyph, *pGlyphBlockStart;
                 ^
    ../ftrasterize.c:2848:22: warning: unused variable 'pBlock' [-Wunused-variable]
         tCodepointBlock *pBlock;
                          ^
    ../ftrasterize.c: In function 'ConvertWideFont':
    ../ftrasterize.c:3514:32: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'long unsigned int' [-Wformat=]
                                    ulCodePoint);
                                    ^
    ../ftrasterize.c:3514:32: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'long unsigned int' [-Wformat=]
    ../ftrasterize.c:3262:17: warning: unused variable 'eEncoding' [-Wunused-variable]
         FT_Encoding eEncoding;
                     ^
    ../ftrasterize.c:3261:16: warning: unused variable 'ppMap' [-Wunused-variable]
         FT_Bitmap *ppMap;
                    ^
    ../ftrasterize.c:3260:18: warning: unused variable 'pSlot' [-Wunused-variable]
         FT_GlyphSlot pSlot;
                      ^
    ../ftrasterize.c:3257:26: warning: unused variable 'iXMax' [-Wunused-variable]
         int iRetcode, iXMin, iXMax, iLoop, iMaxWidth;
                              ^
    ../ftrasterize.c:3257:19: warning: unused variable 'iXMin' [-Wunused-variable]
         int iRetcode, iXMin, iXMax, iLoop, iMaxWidth;
                       ^
    ../ftrasterize.c:3257:9: warning: unused variable 'iRetcode' [-Wunused-variable]
         int iRetcode, iXMin, iXMax, iLoop, iMaxWidth;
             ^
    ../ftrasterize.c: In function 'ShowFontCharacters':
    ../ftrasterize.c:3793:17: warning: unused variable 'eEncoding' [-Wunused-variable]
         FT_Encoding eEncoding;
                     ^
    ../ftrasterize.c:3792:16: warning: unused variable 'ppMap' [-Wunused-variable]
         FT_Bitmap *ppMap;
                    ^
    ../ftrasterize.c:3791:18: warning: unused variable 'pSlot' [-Wunused-variable]
         FT_GlyphSlot pSlot;
                      ^
    ../ftrasterize.c:3789:21: warning: unused variable 'bRetcode' [-Wunused-variable]
         bool bRendered, bRetcode;
                         ^
    ../ftrasterize.c:3788:26: warning: unused variable 'iXMax' [-Wunused-variable]
         int iRetcode, iXMin, iXMax, iLoop;
                              ^
    ../ftrasterize.c:3788:19: warning: unused variable 'iXMin' [-Wunused-variable]
         int iRetcode, iXMin, iXMax, iLoop;
                       ^
    ../ftrasterize.c:3788:9: warning: unused variable 'iRetcode' [-Wunused-variable]
         int iRetcode, iXMin, iXMax, iLoop;
             ^
    ../ftrasterize.c: In function 'ConvertNarrowFont':
    ../ftrasterize.c:4508:13: warning: pointer targets in passing argument 1 of 'sprintf' differ in signedness [-Wpointer-sign]
         sprintf(pucChar, "font%s%d%s%s.c", pParams->pcFilename, pParams->iSize,
                 ^
    In file included from /usr/include/string.h:10:0,
                     from C:\bms\Component Datasheets\fonts\ftrasterize\freetype-2.4.0\include/freetype/config/ftstdlib.h:76,
                     from C:\bms\Component Datasheets\fonts\ftrasterize\freetype-2.4.0\include/freetype/config/ftconfig.h:43,
                     from C:\bms\Component Datasheets\fonts\ftrasterize\freetype-2.4.0\include/freetype/freetype.h:34,
                     from ../ftrasterize.c:27:
    /usr/include/stdio.h:225:5: note: expected 'char *' but argument is of type 'unsigned char *'
     int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
         ^
    ../ftrasterize.c:4510:19: warning: pointer targets in passing argument 1 of 'fopen' differ in signedness [-Wpointer-sign]
         pFile = fopen(pucChar, "w");
                       ^
    In file included from /usr/include/string.h:10:0,
                     from C:\bms\Component Datasheets\fonts\ftrasterize\freetype-2.4.0\include/freetype/config/ftstdlib.h:76,
                     from C:\bms\Component Datasheets\fonts\ftrasterize\freetype-2.4.0\include/freetype/config/ftconfig.h:43,
                     from C:\bms\Component Datasheets\fonts\ftrasterize\freetype-2.4.0\include/freetype/freetype.h:34,
                     from ../ftrasterize.c:27:
    /usr/include/stdio.h:224:8: note: expected 'const char *' but argument is of type 'unsigned char *'
     FILE * _EXFUN(fopen, (const char *__restrict _name, const char *__restrict _type));
            ^
    ../ftrasterize.c:4197:16: warning: variable 'ppMap' set but not used [-Wunused-but-set-variable]
         FT_Bitmap *ppMap;
                    ^
    ../ftrasterize.c:4194:32: warning: unused variable 'uiIndex' [-Wunused-variable]
         FT_UInt uiChar, uiSrcChar, uiIndex;
                                    ^
    ../ftrasterize.c:4190:34: warning: unused variable 'iIndex' [-Wunused-variable]
         int iDisplayFont, iWideFont, iIndex, iNewStruct;
                                      ^
    ../ftrasterize.c:4190:23: warning: unused variable 'iWideFont' [-Wunused-variable]
         int iDisplayFont, iWideFont, iIndex, iNewStruct;
                           ^
    ../ftrasterize.c:4190:9: warning: unused variable 'iDisplayFont' [-Wunused-variable]
         int iDisplayFont, iWideFont, iIndex, iNewStruct;
             ^
    ../ftrasterize.c:4189:26: warning: unused variable 'iTranslateSource' [-Wunused-variable]
         int iTranslateStart, iTranslateSource;
                              ^
    ../ftrasterize.c:4189:9: warning: unused variable 'iTranslateStart' [-Wunused-variable]
         int iTranslateStart, iTranslateSource;
             ^
    ../ftrasterize.c:4188:32: warning: unused variable 'iOne' [-Wunused-variable]
         int iPrevBit, iBit, iZero, iOne;
                                    ^
    ../ftrasterize.c:4188:25: warning: unused variable 'iZero' [-Wunused-variable]
         int iPrevBit, iBit, iZero, iOne;
                             ^
    ../ftrasterize.c:4188:19: warning: unused variable 'iBit' [-Wunused-variable]
         int iPrevBit, iBit, iZero, iOne;
                       ^
    ../ftrasterize.c:4188:9: warning: unused variable 'iPrevBit' [-Wunused-variable]
         int iPrevBit, iBit, iZero, iOne;
             ^
    ../ftrasterize.c:4187:29: warning: unused variable 'iXMax' [-Wunused-variable]
         int iOpt, iXMin, iYMin, iXMax, iYMax, iX, iY, iWidth, iMaxWidth;
                                 ^
    ../ftrasterize.c:4187:15: warning: unused variable 'iXMin' [-Wunused-variable]
         int iOpt, iXMin, iYMin, iXMax, iYMax, iX, iY, iWidth, iMaxWidth;
                   ^
    ../ftrasterize.c: In function 'WriteRemappedASCIIBlocks':
    ../ftrasterize.c:2600:1: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
    ../ftrasterize.c: In function 'WriteASCIIBlocks':
    ../ftrasterize.c:2837:1: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
    Finished building: ../ftrasterize.c
     
    Building target: ftrasterize.exe
    Invoking: Cygwin C Linker
    gcc  -o "ftrasterize.exe"  ./font4x6b0.o ./ftrasterize.o   -lfreetype
    Finished building target: ftrasterize.exe
     
    
    10:29:38 Build Finished (took 2s.78ms)
    
    

  • Hello Jeff,

    OK. understood. Since the code base is compiled to ensure that no warnings are displayed during compilation, I would assume this was due to the modification done in your application.
    Thanks as well to bring in the updated code for reference.

    Regards
    Amit
  • Hi Amit,

    The warnings were in the code before I added my modifications. It may have been that they were because of the warning level settings not being the same as when it was compiled for release. Most of the warnings were due to variables which had been allocated but never used etc. Two of them were caused by functions being defined with a bool return variable which was not set on return. It looks like the code should have been checked a bit better before release, but they are not errors preventing the code from running.

    Regards,

    Jeff

  • Hello Jeff,

    The warning level settings is kept in the code. So if there a change of the same at the user end then we can't do much. Having said that the warning levels are not changed from test to release, but we will go back and check the same.

    Regards
    Amit