void Font::load_ttf_font_rage_file(VALUE r_file, char *filename, int size, int flags) { RAGE_CHECK_DISPOSED(disposed); if (font != nullptr) al_destroy_font(font); Filesystem::BaseFile *fl; Data_Get_Struct(r_file, Filesystem::BaseFile, fl); if (fl->disposed) { rb_raise(rb_eException, RAGE_ERROR_FS_DISPOSED_RAGE_FILE_READ); return; } if (fl->file == nullptr) { rb_raise(rb_eException, RAGE_ERROR_FS_RAGE_FILE_NOT_LOADED); return; } rage_file = r_file; font = al_load_ttf_font_f(fl->file, filename, size, flags); if (font == nullptr) { rb_raise(rb_eException, RAGE_ERROR_FONT_LOAD_FAIL, RAGE_BASE_FILE); return; } }
ALLEGRO_FONT * load_packed_font(unsigned char *mem, int mem_size, int font_size) { ALLEGRO_FILE *mem_file = al_open_memfile(mem, mem_size, "r"); /* "The filename (second arg) is only used to find possible additional files next to a font file." ? But works with just a blank string */ ALLEGRO_FONT *font = al_load_ttf_font_f(mem_file, "", font_size, 0); /* last variable flags */ /* https://www.allegro.cc/manual/5/al_load_ttf_font_f "The file handle is owned by the returned ALLEGRO_FONT object and must not be freed by the caller, as FreeType expects to be able to read from it at a later time." */ return font; }
/** TTF font constructor from file. @param file file. @param size size in points. @param flags font flags. */ Font(const File &file, int size, int flags = 0) : Shared(al_load_ttf_font_f(file.get(), nullptr, size, flags), al_destroy_font) { }
/** TTF font constructor from file. @param file file. @param filename used for additional files. @param size size in points. @param flags font flags. */ Font(const File &file, const char *filename, int size, int flags = 0) : Shared(al_load_ttf_font_f(file.get(), filename, size, flags), al_destroy_font) { }
/** loads a true-type font from a file. @param file file to load the font from. @param filename used for additional files. @param size size in points. @param flags font flags. @return true on success. */ bool load(const File &file, const char *filename, int size, int flags = 0) { reset(al_load_ttf_font_f(file.get(), filename, size, flags), al_destroy_font); return (bool)(*this); }