Class: OpenCV::CvFont

Inherits:
Object
  • Object
show all
Defined in:
ext/opencv/cvfont.cpp,
ext/opencv/cvfont.cpp

Overview

Font structure that can be passed to text rendering functions. see CvMat#put_text, CvMat#put_text!

Constant Summary collapse

FACE =
face
FONT_OPTION =
default_option

Instance Method Summary collapse

Constructor Details

#new(face, font_option = nil) ⇒ Object

Create font object

Examples:

Create Font

OpenCV::CvFont.new(:simplex, :hscale => 2, :vslace => 2, :italic => true)# create 2x bigger than normal, italic type font.

Parameters:

  • face (Symbol)

    Font name identifier. Only a subset of Hershey fonts (sources.isc.org/utils/misc/hershey-font.txt) are supported now:

    • :simplex - normal size sans-serif font

    • :plain - small size sans-serif font

    • :duplex - normal size sans-serif font (more complex than :simplex)

    • :complex - normal size serif font

    • :triplex - normal size serif font (more complex than :complex)

    • :complex_small - smaller version of :complex

    • :script_simplex - hand-writing style font

    • :script_complex - more complex variant of :script_simplex

  • font_option (Hash)

    should be Hash include these keys.


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'ext/opencv/cvfont.cpp', line 76

VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE face, font_option;
  rb_scan_args(argc, argv, "11", &face, &font_option);
  Check_Type(face, T_SYMBOL);
  face = rb_hash_lookup(rb_const_get(cCvFont::rb_class(), rb_intern("FACE")), face);
  if (NIL_P(face)) {
    rb_raise(rb_eArgError, "undefined face.");
  }
  font_option = FONT_OPTION(font_option);

  int font_face = NUM2INT(face);
  if (FO_ITALIC(font_option)) {
    font_face |= CV_FONT_ITALIC;
  }
  try {
    cvInitFont(CVFONT(self),
	       font_face,
	       FO_HSCALE(font_option),
	       FO_VSCALE(font_option),
	       FO_SHEAR(font_option),
	       FO_THICKNESS(font_option),
	       FO_LINE_TYPE(font_option));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }

  return self;
}

Instance Method Details

#faceFixnum

Returns font face

Returns:

  • (Fixnum)

    Font face


113
114
115
116
117
# File 'ext/opencv/cvfont.cpp', line 113

VALUE
rb_face(VALUE self)
{
  return INT2FIX(CVFONT(self)->font_face);
}

#hscaleNumber

Returns hscale

Returns:

  • (Number)

    hscale


124
125
126
127
128
# File 'ext/opencv/cvfont.cpp', line 124

VALUE
rb_hscale(VALUE self)
{
  return rb_float_new(CVFONT(self)->hscale);
}

#italicBoolean

Returns italic or not

Returns:

  • (Boolean)

    self is italic or not


179
180
181
182
183
# File 'ext/opencv/cvfont.cpp', line 179

VALUE
rb_italic(VALUE self)
{
  return ((CVFONT(self)->font_face & CV_FONT_ITALIC) > 0) ? Qtrue : Qfalse;
}

#line_typeFixnum

Returns line type

Returns:

  • (Fixnum)

    line_type


168
169
170
171
172
# File 'ext/opencv/cvfont.cpp', line 168

VALUE
rb_line_type(VALUE self)
{
  return INT2FIX(CVFONT(self)->line_type);
}

#shearNumber

Returns shear

Returns:

  • (Number)

    shear


146
147
148
149
150
# File 'ext/opencv/cvfont.cpp', line 146

VALUE
rb_shear(VALUE self)
{
  return rb_float_new(CVFONT(self)->shear);
}

#thicknessFixnum

Returns thickness

Returns:

  • (Fixnum)

    thickness


157
158
159
160
161
# File 'ext/opencv/cvfont.cpp', line 157

VALUE
rb_thickness(VALUE self)
{
  return INT2FIX(CVFONT(self)->thickness);
}

#vscaleNumber

Returns vscale

Returns:

  • (Number)

    vscale


135
136
137
138
139
# File 'ext/opencv/cvfont.cpp', line 135

VALUE
rb_vscale(VALUE self)
{
  return rb_float_new(CVFONT(self)->vscale);
}