freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft] Help finding glyphs in TTF files


From: Michael Franklin
Subject: Re: [ft] Help finding glyphs in TTF files
Date: Sat, 30 Mar 2013 17:57:21 -0700 (PDT)

Yes, I tried the following:

while (text[i] != '\0')
{
    FT_UInt glyph_index = FT_Get_Char_Index(face, text[i]);
    if (glyph_index == 0)
    {
        printf("Missing Glyph for char %c: %d\r\n", text[i], error);
    }
    
    error = FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT );
    if (error)
    {
        printf("FT_Load_Glyph char %c: %d\r\n", text[i], error);
    }
    else
    {
        error = FT_Render_Glyph( face->glyph, FT_RENDER_MODE_NORMAL );
        if (error)
        {
            printf("FT_Load_Glyph char %c: %d\r\n", text[i], error);
        }
        else
        {
            printf("FT_Render_Glyph[%c] succeeded\r\n", text[i]);
            FT_Draw_Bitmap(&face->glyph->bitmap, face->glyph->bitmap_left + x, 
y - face->glyph->bitmap_top);
            
            //Move cursor to position for next character
            x += (face->glyph->advance.x >> 6);  //int 1/64th units, so shift 
by 6
            y += (face->glyph->advance.y >> 6);
            
            printf("%d,%d\r\n", x, y);
        }
    }
                    
    i++;
}


FreeMono.ttf:  FT_Get_Char_Index returns 0 whether I subtract 29 or not, but 
correctly displays the "unknown" glyph for each character
Verdana.ttf: FT_Get_Char_Index return 0 whether I subtract 29 or not, and 
FT_Load_Glyph returns FT_Err_Nested_DEFS
Arial.ttf: FT_Get_Char_Index return 0, and FT_Load_Glyph returns 
FT_Err_Invalid_Opcode

I'm guessing there's something wrong in my build, like maybe on of my types is 
defined incorrectly.  I'm using the CodeLite IDE with Sourcery Codebench 
arm-none-eabi (GCC 4.7.2).  I imported the .h and .c files excluded all but the 
main .c files in each module (because they #include the other .c files) and 
built using the following flags:

arm-none-eabi-gcc -MD -mthumb -mcpu=cortex-m4 -mtune=cortex-m4  
-mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mlittle-endian -ffunction-sections 
-fsingle-precision-constant -fmessage-length=0 -Wa,-EL


My computer is Windows 8 Pro.  It builds without any warnings.  With this 
approach, is there something I need to consider?

Thanks for all the help so far.

Mike
________________________________
From: Gregor Mückl <address@hidden>
To: Michael Franklin <address@hidden> 
Sent: Sunday, March 31, 2013 7:31 AM
Subject: Re: [ft] Help finding glyphs in TTF files


Have you tried translating your strings to glyph indices using 
FT_Get_Char_Index? 

Gregor


Michael Franklin <address@hidden> wrote:
Well, I my test text is "1234abcdEFGH".  But what I see on my screen is "NOPQ~ 
??bcde".  Looking at an ASCII table I can see that what I want and what I see 
are off by 29.  
>
>
>Mike
>
>
>>________________________________
>
>From: Wojciech Mamrak <address@hidden>
>To: suzuki toshiya <address@hidden> 
>Cc: Michael Franklin <address@hidden>; "address@hidden" <address@hidden> 
>Sent: Sunday, March 31, 2013 1:02 AM
>Subject: Re: [ft] Help finding glyphs in TTF files
>
>
>Hi,
>
>how did you come up with that -29? :)
>
>regards
>
>
>
>
>2013/3/30 suzuki toshiya <address@hidden>
>
>Hi,
>
>
>What kind of text[] is passed  to
FT_Load_Char()?
>>And what kind of the error is returned?
>>
>>Regards,
>>mpsuzuki
>>
>>
>>Michael Franklin wrote:
>>
>>
>>Hello,
>>>
>>>First of all, let me say thanks for FreeType.  I was thrilled when text 
>>>first appeared (clean and crisp) on my embedded system for the fist time 
>>>even if it wasn't the text I hoped for.  And I'm hoping you can help me with 
>>>that.
>>>
>>>I'm creating an embedded system using a Cortex-M4 processor and the Sourcery 
>>>Codebench Lite (GCC 4.7.2) toolchain.
>>>
>>>I'm trying to do a simple glyph to bitmap rendering as demonstrated in the 
>>>FreeType Tutorial 1.  I have successfully displayed glyphs from Verdana.ttf 
>>>(stolen from my Windows 8 computer) and FreeMono.ttf (stolen from my Mint 
>>>Linux computer).  However, with both of these fonts, I can't get the correct 
>>>glyphs unless I subtract 29 from the
character code as shown below.
>>>
>>>error = FT_Load_Char(face, text[i] - 29, FT_LOAD_RENDER);   //this works
>>>error = FT_Load_Char(face, text[i], FT_LOAD_RENDER);   //this doesn't work
>>>
>>>Verdana.ttf reports 1 charmap (platform: 0, encoding: 1) and Mono.ttf 
>>>reports 0 charmaps, which also seems strange.
>>>
>>>I also tried a few other fonts (Arial.ttf from my Windows 8 computer and a 
>>>few others), but they all return various errors after calling FT_Load_Char.  
>>>Sometimes FT_Err_Invalid_Opcode and sometimes FT_Err_ENDF_In_Exec_Stream 
>>>depending on the file.
>>>
>>>At first I suspected my disk I/O routines, but these have all been working 
>>>well in my libpng port, so I'm fairly confident they are working well.  
>>>Also,  FT_New_Face doesn't give me any errors.
>>>
>>>Here's my source code.  Please let me know if you have any suggestions.
>>>
>>>Thanks.
>>>
>>>DrawText(const Point& p, const uint8_t size, const File& file, const Color&am
p;
color, const char* text, ...)
>>>{
>>>    FT_Library library;
>>>
>>>    FT_Error error = FT_Init_FreeType(&library);
>>>    if (error)
>>>    {
>>>        printf("FT_Init_FreeType failed\r]n");
>>>        return;
>>>    }
>>>
>>>    printf("FT_Init_FreeType finished\r\n");
>>>
>>>    FT_Face face;
>>>    error = FT_New_Face( library, "/arialbi.ttf", 0, &face );
>>>    if ( error == FT_Err_Unknown_File_Format )
>>>    {
>>>        printf("FT_New_Face failed\r\n");
>>>        //... the font file could be opened and read, but it appears
>>>        //... that its font format is unsupported
>>>    }
>>>    else if ( error )
>>>    {
>>>        printf("FT_New_Face failed 2: %d\r\n", error);
>>>        //... another error code means that the font file could not
>>>        //... be opened or read, or simply that it is broken...
>>>    }
>>>    else
>>>    { 
>>>        printf("FT_New_Face finished\r\n");
>>>
>>>        printf("%d charmaps exist\r\n", face->num_charmaps);
>>>        for (int n = 0; n < face->num_charmaps; n++ )
>>>        {
>>>            FT_CharMap charmap = face->charmaps[n];
>>>            printf("charmap: %d, %d\r\n", charmap->platform_id, 
>>>charmap->encoding_id);
>>>        }
>>>
>>>        error = FT_Set_Char_Size(
>>>            face,      // handle to face object
>>>            0,         // char_width in 1/64th of points
>>>            size << 6, // char_height in 1/64th of points
>>>            72,        // horizontal device resolution in dots per inch
>>>            72);       // vertical device resolution
>>>
>>>        if (error)
>>>        {
>>>            printf("FT_Set_Char_Size failed\r\n");
>>>        }
>>>        else
>>>       
  {
>>>            printf("FT_Set_Char_Size finished\r\n");
>>>
>>>            int i = 0;
>>>            int16_t x = 200;
>>>            int16_t y = 200;
>>>            while (text[i] != '\0')
>>>            {
>>>                error = FT_Load_Char(face, text[i] - 29, FT_LOAD_RENDER);
>>>                if (error)
>>>                {
>>>                    printf("Missing Glyph for char %c: %d\r\n", text[i], 
>>>error);
>>>                }
>>>                else
>>>                {
>>>                    printf("FT_Load_Char[%c] succeeded\r\n", text[i]);
>>>                    FT_Draw_Bitmap(&face->glyph->bitmap, 
>>>face->glyph->bitmap_left + x, y - face->glyph->bitmap_top);
>>>
>>>                    //Move cursor to position for next character
>>>                    x +=
(face->glyph->advance.x >> 6);  //int 1/64th units, so shift by 6
>>>                    y += (face->glyph->advance.y >> 6);
>>>
>>>                    printf("%d,%d\r\n", x, y);
>>>                }
>>>
>>>                i++;
>>>            }
>>>        }
>>>
>>>        error = FT_Done_Face(face);
>>>        if (error)
>>>        {
>>>            printf("FT_Done_Face failed\r\n");
>>>        }
>>>    }
>>>
>>>    error = FT_Done_FreeType(library);
>>>    if (error)
>>>    {
>>>        printf("FT_Done_FreeType failed\r\n");
>>>    }
>>>}
>>>
>>>void FT_Draw_Bitmap( FT_Bitmap*  bitmap, FT_Int x, FT_Int y)
>>>{
>>>    FT_Int  i, j, p, q;
>>>    FT_Int  x_max = x + bitmap->width;
>>>    FT_Int  y_max = y + bitmap->rows;
>>>
>>>    for ( i = x, p = 0; i < x_max; i++, p++ )
>>>    {
>>>  

  for ( j = y, q = 0; j < y_max; j++, q++ )
>>>        {
>>>            uint8_t alpha = bitmap->buffer[q * bitmap->width + p];
>>>            SetPixel({i, j}, Color(alpha, alpha, alpha));
>>>        }
>>>    }
>>>}
>>>
>>>>>>________________________________
>>>
>>>Freetype mailing list
>>>address@hidden
>>>https://lists.nongnu.org/mailman/listinfo/freetype
>>
>>>>________________________________
>>
>>Freetype mailing list
>>address@hidden
>>https://lists.nongnu.org/mailman/listinfo/freetype
>
>>________________________________
>
>Freetype mailing list
>address@hidden
>https://lists.nongnu.org/mailman/listinfo/freetype
>
-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]