18# include FT_FREETYPE_H
28# define STREAM_FILE(stream) static_cast<FILE *>(stream->descriptor.pointer)
29# define FT_THROW(e) -1
31static void ft_ansi_stream_close(FT_Stream stream)
33 fclose(STREAM_FILE(stream));
35 stream->descriptor.pointer =
nullptr;
47 if (!
count && offset > stream->size) {
51 FILE *file = STREAM_FILE(stream);
53 if (stream->pos != offset) {
57 return fread(buffer, 1,
count, file);
60static FT_Error FT_Stream_Open__win32_compat(FT_Stream stream,
const char *filepathname)
64 stream->descriptor.pointer =
nullptr;
65 stream->pathname.pointer = (
char *)filepathname;
68 stream->read =
nullptr;
69 stream->close =
nullptr;
71 FILE *file =
BLI_fopen(filepathname,
"rb");
75 "could not open `%s'\n",
77 return FT_THROW(Cannot_Open_Resource);
81 stream->size = ftell(file);
85 "opened `%s' but zero-sized\n",
88 return FT_THROW(Cannot_Open_Stream);
93 stream->descriptor.pointer =
file;
94 stream->read = ft_ansi_stream_io;
95 stream->close = ft_ansi_stream_close;
100FT_Error FT_New_Face__win32_compat(FT_Library library,
101 const char *pathname,
107 FT_Stream stream =
static_cast<FT_Stream
>(
MEM_callocN(
sizeof(*stream), __func__));
109 open.flags = FT_OPEN_STREAM;
110 open.stream = stream;
112 stream->pathname.pointer = (
void *)pathname;
114 err = FT_Stream_Open__win32_compat(stream, pathname);
120 err = FT_Open_Face(library, &open, face_index, aface);
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_fseek(FILE *stream, int64_t offset, int whence)
Read Guarded memory(de)allocation.
void MEM_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)