right now, i'm trying to port over Steve Hanov's ttf parser in to c++ but ran in to a issue trying to convert char* to uintN_t.
when putting ComicSans.ttf, and arial.ttf, scarlar type should out put as 65536, but it turns out as 256
even changing the sizeof(x)
in fi.read((char*)&x, sizeof(x));
under getUInt32 to some random number like fi.read((char*)&x, 3621);
it still turns out as 256
class BinaryReader{
private:
ifstream fi;
streampos fileSize;
public:
int position = 0;
void open(string fname){
fi.open(fname, ios::binary);
fi.seekg(0, ios::end);
fileSize = fi.tellg();
fi.seekg(0, ios::beg);
}
void close(){
fi.close();
}
int getUInt8(){
fi.seekg(position, ios::beg);
uint8_t x;
fi.read((char*)&x, sizeof(x));
position+=sizeof(x);
return (int)x;
}
int getUInt16(){
fi.seekg(position, ios::beg);
uint16_t x;
fi.read((char*)&x, sizeof(x));
position+=sizeof(x);
return (int)x;
}
int getUInt32(){
fi.seekg(position, ios::beg);
uint32_t x = 0;
fi.read((char*)&x, sizeof(x));
position+=sizeof(x);
return x;
}
};
int main(int argc, char* argv[]) {
BinaryReader fontie;
fontie.open("./fonts/ComicSans.ttf");
cout << "scarlar type: " << fontie.getUInt32() << endl;
cout << "numTables: " << fontie.getUInt16() << endl;
cout << "searchRange: " << fontie.getUInt16() << endl;
cout << "entrySelector: " << fontie.getUInt16() << endl;
cout << "rangeShift: " << fontie.getUInt16() << endl;
cout << "pose: " << fontie.position << endl;
fontie.close();
}