Ejemplo n.º 1
0
DTerr ImporterFontTTF::import(FontResource *target, std::string args)
{
    // Open up the stream for the font file
	BinaryFileStream *file = new BinaryFileStream();    // This pointer has to go through a C-API so no shared_ptr
	DTerr err = FileManager::open(*file, target->path(), true);
    if (err != DT3_ERR_NONE) {
        LOG_MESSAGE << "Unable to open font " << target->path().full_path();
        delete file;
        return DT3_ERR_FILE_OPEN_FAILED;
    }
    
    // Send the stream to freetype
    FT_Open_Args ftargs;

    ::memset((void *)&ftargs,0,sizeof(ftargs));
    
    ftargs.flags = FT_OPEN_STREAM;
    ftargs.stream=(FT_Stream)malloc(sizeof *(ftargs.stream));
    
    ftargs.stream->base = NULL;
    ftargs.stream->size = static_cast<DTuint>(file->length());
    ftargs.stream->pos = 0;
    ftargs.stream->descriptor.pointer = (void*) (file);
    ftargs.stream->pathname.pointer = NULL;
    ftargs.stream->read = &ImporterFontTTF::ft_io_func;
    ftargs.stream->close = &ImporterFontTTF::ft_close_func;

	FT_Error error = ::FT_Open_Face(FontResource::library(),
                                    &ftargs,
                                    0,
                                    &(target->typeface()));
    
    ::FT_Select_Charmap(target->typeface(),FT_ENCODING_UNICODE);
    
	return error == 0 ? DT3_ERR_NONE : DT3_ERR_FILE_OPEN_FAILED;
}