Ejemplo n.º 1
0
TTF_Font* TTF_OpenFontIndex( const char *file, int ptsize, long index )
{
	SDL_RWops *rw = SDL_RWFromFile(file, "rb");
	if ( rw == NULL ) {
		TTF_SetError(SDL_GetError());
		return NULL;
	}
	return TTF_OpenFontIndexRW(rw, 1, ptsize, index);
}
Ejemplo n.º 2
0
font font::open_font(istream& thefile,int ptsize,long index) {
    thefile.seekg(0,ios::end);
    int filesize=thefile.tellg();
    thefile.seekg(0,ios::beg);
    auto_ptr<vector<char> > filecont(new vector<char>(filesize));
    thefile.read(&(*filecont)[0],filesize);
    SDL_RWops* wop=SDL_RWFromConstMem(&(*filecont)[0],filesize);
    TTF_Font* thefont = TTF_OpenFontIndexRW(wop,true,ptsize,index);
    return font().build(thefont,filecont);
}
Ejemplo n.º 3
0
TTF_Font* TTF_OpenFontIndex( const char *file, int ptsize, long index )
{
	FILE* rw = fopen(file, "rb");
	if (rw){
#ifndef WIN32
	fcntl(fileno(rw), F_SETFD, FD_CLOEXEC);
#endif

		return TTF_OpenFontIndexRW(rw, 1, ptsize, index);
	}
	return NULL;
}
Ejemplo n.º 4
0
static mrb_value
mrb_sdl2_ttf_font_initialize(mrb_state *mrb, mrb_value self)
{
  TTF_Font *font = NULL;
  mrb_sdl2_ttf_font_data_t *data =
    (mrb_sdl2_ttf_font_data_t*)DATA_PTR(self);

  if (NULL == data) {
    data = (mrb_sdl2_ttf_font_data_t*)mrb_malloc(mrb, sizeof(mrb_sdl2_ttf_font_data_t));
    if (NULL == data) {
      mrb_raise(mrb, E_RUNTIME_ERROR, "insufficient memory.");
    }
    data->font = NULL;
  }

  if (2 == mrb->c->ci->argc) {
    SDL_RWops *rwops;
    mrb_value object;
    mrb_int size;
    mrb_get_args(mrb, "oi", &object, &size);

    if (mrb_obj_is_kind_of(mrb, object, mrb_class_get_under(mrb, mrb->object_class, "String"))) {
      font = TTF_OpenFont(RSTRING_PTR(object), size);
    } else if (mrb_obj_is_kind_of(mrb, object, mrb_class_get_under(mrb, mod_SDL2, "RWops"))) {
      rwops = mrb_sdl2_rwops_get_ptr(mrb, object);
      font = TTF_OpenFontRW(rwops, 0, size);
    }
  } else if (3 == mrb->c->ci->argc) {
    SDL_RWops *rwops;
    mrb_value object;
    mrb_int size, index;
    mrb_get_args(mrb, "oii", &object, &size, &index);
    if (mrb_obj_is_kind_of(mrb, object, mrb_class_get_under(mrb, mrb->object_class, "String"))) {
      font = TTF_OpenFontIndex(RSTRING_PTR(object), size, index);
    } else if (mrb_obj_is_kind_of(mrb, object, mrb_class_get_under(mrb, mod_SDL2, "RWops"))) {
      rwops = mrb_sdl2_rwops_get_ptr(mrb, object);
      font = TTF_OpenFontIndexRW(rwops, 0, size, index);
    }
  } else {
    mrb_free(mrb, data);
    mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments.");
  }
  if (NULL == font) {
    mrb_free(mrb, data);
    mruby_sdl2_raise_error(mrb);
  }

  data->font = font;

  DATA_PTR(self) = data;
  DATA_TYPE(self) = &mrb_sdl2_ttf_font_data_type;
  return self;
}
Ejemplo n.º 5
0
JNIEXPORT jlong JNICALL Java_sdljava_x_swig_SWIG_1SDLTTFJNI_TTF_1OpenFontIndexFromBuffer(JNIEnv *jenv, jclass jcls, jbyteArray dataArray, jint dataSize, jint ptsize, jint index) {
    
    jlong jresult = 0 ;
    TTF_Font *result;
    jint *data;
    
    data = (*jenv)->GetIntArrayElements(jenv, dataArray, 0);
    result = (TTF_Font *)TTF_OpenFontIndexRW(SDL_RWFromMem(data, dataSize), 1, ptsize, index);
    (*jenv)->ReleaseIntArrayElements(jenv, dataArray, data, 0);
    
    *(TTF_Font **)&jresult = result; 
    return jresult;
    
}
Ejemplo n.º 6
0
TTF_Font *
TTF_OpenFontRW(SDL_RWops * src, int freesrc, int ptsize)
{
    return TTF_OpenFontIndexRW(src, freesrc, ptsize, 0);
}
Ejemplo n.º 7
0
TTF_Font* TTF_OpenFontRW( FILE* src, int freesrc, int ptsize )
{
	return TTF_OpenFontIndexRW(src, freesrc, ptsize, 0);
}