[Top][All Lists]

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

[ft] About using FT_Open_Face with std::ifstream

From: Patrick Cheung
Subject: [ft] About using FT_Open_Face with std::ifstream
Date: Thu, 27 Jul 2006 16:49:42 +0800

Dear all,
I would like to create a face by calling FT_OpenFace with std::istream, but error 2 returns. Here are my codes.
unsigned long stream_load(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count) {
    std::ifstream* is = reinterpret_cast<std::ifstream*>(stream->descriptor.pointer);
    if (count == 0) return 0;
    is->read((char*)buffer, count);
    return is->gcount();

void stream_close(FT_Stream stream) {
    // Nothing to do


// ...

std::ifstream ifs;"C:\\WINDOWS\\Fonts\\arial.ttf", std::ios::in | std::ios::binary);
FT_StreamDesc desc;
desc.pointer = (void*)&ifs;

FT_StreamRec stream;
memset(&stream, 0, sizeof(FT_StreamRec));
stream.base = 0;
stream.size = 367112; // I dun't know how to get size from std::ifstream, i just view it in file properties
stream.pos = 0;
stream.descriptor = desc; = stream_load;
stream.close = stream_close;

FT_Open_Args args;
memset(&args, 0, sizeof(FT_Open_Args));
args.flags = FT_OPEN_STREAM; = &stream;
error = FT_Open_Face(library, &args, 0, &face);

// got error 2 ???


What is the error about? Anything I have missed? Sorry for the question if someone has asked this before.

Thank you for your attention.


Patrick Cheung


reply via email to

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