| 38 | } |
| 39 | |
| 40 | FT_Stream open_stream(const std::string& utf8Filename) |
| 41 | { |
| 42 | FT_Stream stream = nullptr; |
| 43 | stream = (FT_Stream)malloc(sizeof(*stream)); |
| 44 | if (!stream) |
| 45 | return nullptr; |
| 46 | memset(stream, 0, sizeof(*stream)); |
| 47 | |
| 48 | LOG(VERBOSE, "FT: Loading font '%s'...", utf8Filename.c_str()); |
| 49 | |
| 50 | FILE* file = base::open_file_raw(utf8Filename, "rb"); |
| 51 | if (!file) { |
| 52 | free(stream); |
| 53 | LOG(VERBOSE, "FAIL\n"); |
| 54 | return nullptr; |
| 55 | } |
| 56 | |
| 57 | fseek(file, 0, SEEK_END); |
| 58 | stream->size = (unsigned long)ftell(file); |
| 59 | if (!stream->size) { |
| 60 | fclose(file); |
| 61 | free(stream); |
| 62 | LOG(VERBOSE, "FAIL\n"); |
| 63 | return nullptr; |
| 64 | } |
| 65 | fseek(file, 0, SEEK_SET); |
| 66 | |
| 67 | stream->descriptor.pointer = file; |
| 68 | stream->base = nullptr; |
| 69 | stream->pos = 0; |
| 70 | stream->read = ft_stream_io; |
| 71 | stream->close = ft_stream_close; |
| 72 | |
| 73 | LOG(VERBOSE, "OK\n"); |
| 74 | return stream; |
| 75 | } |
| 76 | |
| 77 | } // namespace ft |
no test coverage detected