Class: Fontconfig::FontSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/fontconfig/fc_fontset.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'ext/fontconfig/fc_fontset.c', line 40

static VALUE rb_oset_new(int argc, VALUE *argv, VALUE klass){
  VALUE optional = Qnil;
  rb_scan_args(argc, argv, "01", &optional);
  FcFontSet* set = FcFontSetCreate();
  if(!set)
    rb_raise(rb_eRuntimeError, "cannot create FcFontSet");

  VALUE self = object_set_wrap(set);
  if(optional != Qnil){
    ID each = rb_intern("each");
    if(!rb_respond_to(optional, each))
      rb_raise(rb_eArgError, "parameter must be enumerable");
    rb_block_call(optional, each, 0, 0, oset_add_i, self);
  }
  return self;
}

Instance Method Details

#<<(val) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'ext/fontconfig/fc_fontset.c', line 26

static VALUE rb_oset_add(VALUE self, VALUE val){
  if(!is_fc_pattern(val)){
    rb_raise(rb_eArgError, "argument must be a FcPattern");
  }
  if(!FcFontSetAdd(OSET_UNWRAP(self), pattern_unwrap(val))){
    rb_raise(rb_eRuntimeError, "cannot insert into FcFontSet");
  }
  return val;
}

#[](index) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'ext/fontconfig/fc_fontset.c', line 71

static VALUE rb_oset_at(VALUE self, VALUE index){

  int i = NUM2INT(index);
  FcFontSet* os = OSET_UNWRAP(self);

  if(i < 0 || i >= os->nfont)
    return Qnil;
  return pattern_wrap(os->fonts[i]);
}

#add(val) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'ext/fontconfig/fc_fontset.c', line 26

static VALUE rb_oset_add(VALUE self, VALUE val){
  if(!is_fc_pattern(val)){
    rb_raise(rb_eArgError, "argument must be a FcPattern");
  }
  if(!FcFontSetAdd(OSET_UNWRAP(self), pattern_unwrap(val))){
    rb_raise(rb_eRuntimeError, "cannot insert into FcFontSet");
  }
  return val;
}

#debug_printObject



81
82
83
84
# File 'ext/fontconfig/fc_fontset.c', line 81

static VALUE rb_oset_print(VALUE self){
  FcFontSetPrint(OSET_UNWRAP(self));
  return self;
}

#eachObject



58
59
60
61
62
63
64
65
# File 'ext/fontconfig/fc_fontset.c', line 58

static VALUE rb_oset_each(VALUE self){
  int i;
  FcFontSet* os = OSET_UNWRAP(self);
  for (i = 0; i < os->nfont; i++){
    rb_yield(pattern_wrap(os->fonts[i]));
  }
  return self;
}

#match_pattern(config, pattern) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'ext/fontconfig/fc_fontset.c', line 86

static VALUE rb_oset_match(VALUE self, VALUE config, VALUE pattern){
  FcFontSet* set = OSET_UNWRAP(self);
  FcConfig* conf = 0;
  if(RTEST(config) && is_fc_config(config))
    conf = CONFIG_UNWRAP(config);
  if(!RTEST(pattern) || !is_fc_pattern(pattern))
    rb_raise(rb_eArgError, "pattern must be Fontconfig::Pattern");
  FcResult res;
  FcPattern* result = FcFontSetMatch(conf, &set, 1, pattern_unwrap(pattern), &res);
  if(!result)
    return Qnil;
  return pattern_wrap(result);
}

#sizeObject



67
68
69
# File 'ext/fontconfig/fc_fontset.c', line 67

static VALUE rb_oset_size(VALUE self){
  return INT2NUM(OSET_UNWRAP(self)->nfont);
}