Hello,

I am running the attached program in linux as 64 bit program.
Using below command.
g++ -g -m64 -I/ freetype-2.10.0/include  -lfreetype -o freetypetest 
freetypeTest.cpp.

After running I am not getting the correct value for HoriHeader version value. 
It display as 5692055178828579072(should be 256 if it reads 4 bytes).
Version is of type FT_Fixed which is long so it is reading the 8 bytes. But if 
try to read 4 bytes it give me correct value and next 2 byte will give correct 
value of
for the member of structure and so on.

Due to this the data is not placed correctly in memory
A snapshot
p *m_pHoriHeader
$2 = {Version = 5692055178828579072, Ascender = 17152, Descender = 16, Line_Gap 
= -20486, advance_Width_Max = 31482, min_Left_Side_Bearing = 16,
  min_Right_Side_Bearing = 256, xMax_Extent = 0, caret_Slope_Rise = 0, 
caret_Slope_Run = 0, caret_Offset = 0, Reserved = {0, 0, 0, -27119},
  metric_Data_Format = 0, number_Of_HMetrics = 0, long_metrics = 0x4671, 
short_metrics = 0x10006}

ideally version should be 256,Ascender should be 15879 and so on.

Windows OS will not replicate this problem as both int and long types are 4 
bytes.

Appreciate any help to get these value correct for 64 bit. Let me know if you 
have any questions.

Thanks
Ankit
The information contained in this message is proprietary and/or confidential. 
If you are not the intended recipient, please: (i) delete the message and all 
copies; (ii) do not disclose, distribute or use the message in any manner; and 
(iii) notify the sender immediately. In addition, please be aware that any 
message addressed to our domain is subject to archiving and review by persons 
other than the intended recipient. Thank you.
#include <iostream>
#include <fstream>
//using namespace std;
#include<iostream>
#include "ft2build.h"
#include FT_FREETYPE_H
#include FT_LIST_H


#include "freetype/internal/internal.h"
#include FT_INTERNAL_TRUETYPE_TYPES_H
#include FT_TRUETYPE_TAGS_H

#include "freetype/winfnt.h"
#include FT_INTERNAL_SFNT_H

#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_SFNT_H

#include FT_TRUETYPE_TABLES_H 

#include FT_TRUETYPE_IDS_H
#include FT_SFNT_NAMES_H
#include FT_TRUETYPE_TABLES_H


struct FT_FaceRec_;


#include <freetype/internal/tttypes.h>

bool GetTable(SFNT_Interface * pSfntInterface, 
                  TT_Face TTFace,
                  TT_TableRec & tableDirEntry,
                  FT_Byte *& puchTable,
                  FT_ULong & ftuSize)
{
        if (pSfntInterface->load_any( TTFace, tableDirEntry.Tag, 0, puchTable, 
&ftuSize))
        {
                return false;
         }
        //std::cout << "size is: " << ftuSize << std::endl;
        puchTable = new FT_Byte[ftuSize];
        if (pSfntInterface->load_any( TTFace, tableDirEntry.Tag, 0, puchTable, 
&ftuSize))
        {
        delete [] puchTable;
        puchTable = 0;
        return false;
        }
        return true;
}

int main(int     argc,
        char**  argv)
{
        FT_Library    library;
        struct FT_FaceRec_    * m_ftfcFace;
        //FT_Face       face;

        int error = FT_Init_FreeType(&library);
        if (error)
        {
                std::cout << "an error occurred during library initialization" 
<< std::endl;
        }
        char*                   m_FontBuffer;
        unsigned int                    m_FontBufferLen = 100000;
        FILE * pFile = fopen("Arial.ttf", "rb");

        fseek(pFile, 0, SEEK_END);
        unsigned int uiSize = ftell(pFile) + 1;
        fseek(pFile, 0, SEEK_SET);
        
        if (uiSize >= m_FontBufferLen)
        {
                m_FontBufferLen = uiSize;
        }
        m_FontBuffer = new char[m_FontBufferLen];
        memset(m_FontBuffer, 0, m_FontBufferLen);
        fread(m_FontBuffer, 1, uiSize, pFile);
        fclose(pFile);
        
        

        error = FT_New_Memory_Face(library,
                        (u_char *)m_FontBuffer,
                        uiSize,
                        0,
                        &m_ftfcFace);
        if (error == FT_Err_Unknown_File_Format)
        {
                std::cout << "the font file could be opened and read, but it 
appears\
                        that its font format is unsupported" << std::endl;
        }
        else if (error)
        {
                std::cout << "another error code means that the font file could 
not\
                        ... be opened or read, or that it is broken" << 
std::endl;
        }

        std::cout << "module_name: " << 
m_ftfcFace->driver->root.clazz->module_name <<
                        "  Address  " << m_ftfcFace->driver->root.clazz << 
std::endl;

        TT_Face TTFace = (TT_Face) m_ftfcFace;  
        std::cout << "No of tables" <<TTFace->num_tables << std::endl;


        int             nTempCount =TTFace->num_tables;

        TT_TableRec        tableDirectory;
        FT_Byte * puchTable       = 0;
        FT_Byte  *              m_puchHhea;
        FT_ULong        ftuSize         = 0;

        SFNT_Interface * pSfntInterface;
        pSfntInterface = (SFNT_Interface*)FT_Get_Module_Interface(library, 
"sfnt" );
        for (int i = 0; i < nTempCount; i++) 
        {
                tableDirectory = TTFace->dir_tables[i];
                ftuSize = 0;
                if (!GetTable(pSfntInterface, TTFace, tableDirectory, 
puchTable, ftuSize))
                 {
                         continue;
                 }
                if (tableDirectory.Tag == TTAG_hhea)
                {
                        std::cout<<"found header table" << std::endl;
                        m_puchHhea = puchTable;         
                        
                        
                }
        
        }

                        
        TT_HoriHeader * m_pHoriHeader;

        m_pHoriHeader     = (TT_HoriHeader *)m_puchHhea;
        if(m_pHoriHeader)
        {

                std::cout << "Version is : " << m_pHoriHeader->Version << 
std::endl;
        
        }


}
         

Reply via email to