mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add documents of CvFont
This commit is contained in:
parent
6f7a251112
commit
5348bf91de
3 changed files with 100 additions and 80 deletions
|
@ -39,48 +39,6 @@ rb_class()
|
||||||
return rb_klass;
|
return rb_klass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
define_ruby_class()
|
|
||||||
{
|
|
||||||
if (rb_klass)
|
|
||||||
return;
|
|
||||||
/*
|
|
||||||
* opencv = rb_define_module("OpenCV");
|
|
||||||
*
|
|
||||||
* note: this comment is used by rdoc.
|
|
||||||
*/
|
|
||||||
VALUE opencv = rb_module_opencv();
|
|
||||||
|
|
||||||
rb_klass = rb_define_class_under(opencv, "CvFont", rb_cObject);
|
|
||||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
|
||||||
VALUE face = rb_hash_new();
|
|
||||||
rb_define_const(rb_klass, "FACE", face);
|
|
||||||
rb_hash_aset(face, ID2SYM(rb_intern("simplex")), INT2FIX(CV_FONT_HERSHEY_SIMPLEX));
|
|
||||||
rb_hash_aset(face, ID2SYM(rb_intern("plain")), INT2FIX(CV_FONT_HERSHEY_PLAIN));
|
|
||||||
rb_hash_aset(face, ID2SYM(rb_intern("duplex")), INT2FIX(CV_FONT_HERSHEY_DUPLEX));
|
|
||||||
rb_hash_aset(face, ID2SYM(rb_intern("triplex")), INT2FIX(CV_FONT_HERSHEY_TRIPLEX));
|
|
||||||
rb_hash_aset(face, ID2SYM(rb_intern("complex_small")), INT2FIX(CV_FONT_HERSHEY_COMPLEX_SMALL));
|
|
||||||
rb_hash_aset(face, ID2SYM(rb_intern("script_simplex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_SIMPLEX));
|
|
||||||
rb_hash_aset(face, ID2SYM(rb_intern("script_complex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_COMPLEX));
|
|
||||||
|
|
||||||
VALUE default_option = rb_hash_new();
|
|
||||||
rb_define_const(rb_klass, "FONT_OPTION", default_option);
|
|
||||||
rb_hash_aset(default_option, ID2SYM(rb_intern("hscale")), rb_float_new(1.0));
|
|
||||||
rb_hash_aset(default_option, ID2SYM(rb_intern("vscale")), rb_float_new(1.0));
|
|
||||||
rb_hash_aset(default_option, ID2SYM(rb_intern("shear")), INT2FIX(0));
|
|
||||||
rb_hash_aset(default_option, ID2SYM(rb_intern("thickness")), INT2FIX(1));
|
|
||||||
rb_hash_aset(default_option, ID2SYM(rb_intern("line_type")), INT2FIX(8));
|
|
||||||
|
|
||||||
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
|
||||||
rb_define_method(rb_klass, "face", RUBY_METHOD_FUNC(rb_face), 0);
|
|
||||||
rb_define_method(rb_klass, "hscale", RUBY_METHOD_FUNC(rb_hscale), 0);
|
|
||||||
rb_define_method(rb_klass, "vscale", RUBY_METHOD_FUNC(rb_vscale), 0);
|
|
||||||
rb_define_method(rb_klass, "shear", RUBY_METHOD_FUNC(rb_shear), 0);
|
|
||||||
rb_define_method(rb_klass, "thickness", RUBY_METHOD_FUNC(rb_thickness), 0);
|
|
||||||
rb_define_method(rb_klass, "line_type", RUBY_METHOD_FUNC(rb_line_type), 0);
|
|
||||||
rb_define_method(rb_klass, "italic", RUBY_METHOD_FUNC(rb_italic), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_allocate(VALUE klass)
|
rb_allocate(VALUE klass)
|
||||||
{
|
{
|
||||||
|
@ -88,46 +46,32 @@ rb_allocate(VALUE klass)
|
||||||
return Data_Make_Struct(klass, CvFont, 0, -1, ptr);
|
return Data_Make_Struct(klass, CvFont, 0, -1, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* Create font object
|
||||||
* CvFont.new(<i>face[,font_option]</i>) -> font
|
* @overload new(face, font_option = nil)
|
||||||
|
* @param face [Symbol] Font name identifier. Only a subset of Hershey fonts (http://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
|
||||||
*
|
*
|
||||||
* Create font object.
|
* @param font_option [Hash] should be Hash include these keys.
|
||||||
* <i>face</i> is font name identifier.
|
* @option font_option [Number] :hscale Horizontal scale. If equal to 1.0, the characters have the original width depending on the font type. If equal to 0.5, the characters are of half the original width.
|
||||||
*
|
* @option font_option [Number] :vscale Vertical scale. If equal to 1.0, the characters have the original height depending on the font type. If equal to 0.5, the characters are of half the original height.
|
||||||
* Only a subset of Hershey fonts (http://sources.isc.org/utils/misc/hershey-font.txt) are supported now:
|
* @option font_option [Number] :shear Approximate tangent of the character slope relative to the vertical line. Zero value means a non-italic font, 1.0f means ~45 degree slope, etc.
|
||||||
* * :simplex - normal size sans-serif font
|
* @option font_option [Number] :thickness Thickness of the text strokes.
|
||||||
* * :plain - small size sans-serif font
|
* @option font_option [Number] :line_type Type of the strokes, see CvMat#Line description.
|
||||||
* * :duplex - normal size sans-serif font (more complex than :simplex)
|
* @option font_option [Number] :italic If value is not nil or false that means italic or oblique font.
|
||||||
* * :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
|
|
||||||
*
|
*
|
||||||
* <i>font_option</i> should be Hash include these keys.
|
* @example Create Font
|
||||||
* :hscale
|
|
||||||
* Horizontal scale. If equal to 1.0, the characters have the original width depending on the font type.
|
|
||||||
* If equal to 0.5, the characters are of half the original width.
|
|
||||||
* :vscale
|
|
||||||
* Vertical scale. If equal to 1.0, the characters have the original height depending on the font type.
|
|
||||||
* If equal to 0.5, the characters are of half the original height.
|
|
||||||
* :shear
|
|
||||||
* Approximate tangent of the character slope relative to the vertical line.
|
|
||||||
* Zero value means a non-italic font, 1.0f means ~45degree slope, etc.
|
|
||||||
* :thickness
|
|
||||||
* Thickness of the text strokes.
|
|
||||||
* :line_type
|
|
||||||
* Type of the strokes, see CvMat#Line description.
|
|
||||||
* :italic
|
|
||||||
* If value is not nil or false that means italic or oblique font.
|
|
||||||
*
|
|
||||||
* note: <i>font_option</i>'s default value is CvFont::FONT_OPTION.
|
|
||||||
*
|
|
||||||
* e.g. Create Font
|
|
||||||
* OpenCV::CvFont.new(:simplex, :hscale => 2, :vslace => 2, :italic => true)
|
* OpenCV::CvFont.new(:simplex, :hscale => 2, :vslace => 2, :italic => true)
|
||||||
* # create 2x bigger than normal, italic type font.
|
* # create 2x bigger than normal, italic type font.
|
||||||
|
*
|
||||||
|
* @opencv_func cvInitFont
|
||||||
*/
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_initialize(int argc, VALUE *argv, VALUE self)
|
rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
|
@ -161,48 +105,124 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns font face
|
||||||
|
* @overload face
|
||||||
|
* @return [Fixnum] Font face
|
||||||
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_face(VALUE self)
|
rb_face(VALUE self)
|
||||||
{
|
{
|
||||||
return INT2FIX(CVFONT(self)->font_face);
|
return INT2FIX(CVFONT(self)->font_face);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns hscale
|
||||||
|
* @overload hscale
|
||||||
|
* @return [Number] hscale
|
||||||
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_hscale(VALUE self)
|
rb_hscale(VALUE self)
|
||||||
{
|
{
|
||||||
return rb_float_new(CVFONT(self)->hscale);
|
return rb_float_new(CVFONT(self)->hscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns vscale
|
||||||
|
* @overload vscale
|
||||||
|
* @return [Number] vscale
|
||||||
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_vscale(VALUE self)
|
rb_vscale(VALUE self)
|
||||||
{
|
{
|
||||||
return rb_float_new(CVFONT(self)->vscale);
|
return rb_float_new(CVFONT(self)->vscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns shear
|
||||||
|
* @overload shear
|
||||||
|
* @return [Number] shear
|
||||||
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_shear(VALUE self)
|
rb_shear(VALUE self)
|
||||||
{
|
{
|
||||||
return rb_float_new(CVFONT(self)->shear);
|
return rb_float_new(CVFONT(self)->shear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns thickness
|
||||||
|
* @overload thickness
|
||||||
|
* @return [Fixnum] thickness
|
||||||
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_thickness(VALUE self)
|
rb_thickness(VALUE self)
|
||||||
{
|
{
|
||||||
return INT2FIX(CVFONT(self)->thickness);
|
return INT2FIX(CVFONT(self)->thickness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns line type
|
||||||
|
* @overload line_type
|
||||||
|
* @return [Fixnum] line_type
|
||||||
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_line_type(VALUE self)
|
rb_line_type(VALUE self)
|
||||||
{
|
{
|
||||||
return INT2FIX(CVFONT(self)->line_type);
|
return INT2FIX(CVFONT(self)->line_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns italic or not
|
||||||
|
* @overload italic
|
||||||
|
* @return [Boolean] self is italic or not
|
||||||
|
*/
|
||||||
VALUE
|
VALUE
|
||||||
rb_italic(VALUE self)
|
rb_italic(VALUE self)
|
||||||
{
|
{
|
||||||
return ((CVFONT(self)->font_face & CV_FONT_ITALIC) > 0) ? Qtrue : Qfalse;
|
return ((CVFONT(self)->font_face & CV_FONT_ITALIC) > 0) ? Qtrue : Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init_ruby_class()
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
// For documentation using YARD
|
||||||
|
VALUE opencv = rb_define_module("OpenCV");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (rb_klass)
|
||||||
|
return;
|
||||||
|
|
||||||
|
VALUE opencv = rb_module_opencv();
|
||||||
|
rb_klass = rb_define_class_under(opencv, "CvFont", rb_cObject);
|
||||||
|
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||||
|
VALUE face = rb_hash_new();
|
||||||
|
rb_define_const(rb_klass, "FACE", face);
|
||||||
|
rb_hash_aset(face, ID2SYM(rb_intern("simplex")), INT2FIX(CV_FONT_HERSHEY_SIMPLEX));
|
||||||
|
rb_hash_aset(face, ID2SYM(rb_intern("plain")), INT2FIX(CV_FONT_HERSHEY_PLAIN));
|
||||||
|
rb_hash_aset(face, ID2SYM(rb_intern("duplex")), INT2FIX(CV_FONT_HERSHEY_DUPLEX));
|
||||||
|
rb_hash_aset(face, ID2SYM(rb_intern("triplex")), INT2FIX(CV_FONT_HERSHEY_TRIPLEX));
|
||||||
|
rb_hash_aset(face, ID2SYM(rb_intern("complex_small")), INT2FIX(CV_FONT_HERSHEY_COMPLEX_SMALL));
|
||||||
|
rb_hash_aset(face, ID2SYM(rb_intern("script_simplex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_SIMPLEX));
|
||||||
|
rb_hash_aset(face, ID2SYM(rb_intern("script_complex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_COMPLEX));
|
||||||
|
|
||||||
|
VALUE default_option = rb_hash_new();
|
||||||
|
rb_define_const(rb_klass, "FONT_OPTION", default_option);
|
||||||
|
rb_hash_aset(default_option, ID2SYM(rb_intern("hscale")), rb_float_new(1.0));
|
||||||
|
rb_hash_aset(default_option, ID2SYM(rb_intern("vscale")), rb_float_new(1.0));
|
||||||
|
rb_hash_aset(default_option, ID2SYM(rb_intern("shear")), INT2FIX(0));
|
||||||
|
rb_hash_aset(default_option, ID2SYM(rb_intern("thickness")), INT2FIX(1));
|
||||||
|
rb_hash_aset(default_option, ID2SYM(rb_intern("line_type")), INT2FIX(8));
|
||||||
|
|
||||||
|
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||||
|
rb_define_method(rb_klass, "face", RUBY_METHOD_FUNC(rb_face), 0);
|
||||||
|
rb_define_method(rb_klass, "hscale", RUBY_METHOD_FUNC(rb_hscale), 0);
|
||||||
|
rb_define_method(rb_klass, "vscale", RUBY_METHOD_FUNC(rb_vscale), 0);
|
||||||
|
rb_define_method(rb_klass, "shear", RUBY_METHOD_FUNC(rb_shear), 0);
|
||||||
|
rb_define_method(rb_klass, "thickness", RUBY_METHOD_FUNC(rb_thickness), 0);
|
||||||
|
rb_define_method(rb_klass, "line_type", RUBY_METHOD_FUNC(rb_line_type), 0);
|
||||||
|
rb_define_method(rb_klass, "italic", RUBY_METHOD_FUNC(rb_italic), 0);
|
||||||
|
}
|
||||||
|
|
||||||
__NAMESPACE_END_CVFONT
|
__NAMESPACE_END_CVFONT
|
||||||
__NAMESPACE_END_OPENCV
|
__NAMESPACE_END_OPENCV
|
||||||
|
|
|
@ -28,7 +28,7 @@ __NAMESPACE_BEGIN_CVFONT
|
||||||
|
|
||||||
VALUE rb_class();
|
VALUE rb_class();
|
||||||
|
|
||||||
void define_ruby_class();
|
void init_ruby_class();
|
||||||
|
|
||||||
VALUE rb_allocate(VALUE klass);
|
VALUE rb_allocate(VALUE klass);
|
||||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||||
|
|
|
@ -676,7 +676,7 @@ extern "C" {
|
||||||
mOpenCV::cCvSlice::define_ruby_class();
|
mOpenCV::cCvSlice::define_ruby_class();
|
||||||
mOpenCV::cCvTermCriteria::define_ruby_class();
|
mOpenCV::cCvTermCriteria::define_ruby_class();
|
||||||
mOpenCV::cCvBox2D::init_ruby_class();
|
mOpenCV::cCvBox2D::init_ruby_class();
|
||||||
mOpenCV::cCvFont::define_ruby_class();
|
mOpenCV::cCvFont::init_ruby_class();
|
||||||
mOpenCV::cIplConvKernel::define_ruby_class();
|
mOpenCV::cIplConvKernel::define_ruby_class();
|
||||||
mOpenCV::cCvMoments::define_ruby_class();
|
mOpenCV::cCvMoments::define_ruby_class();
|
||||||
mOpenCV::cCvHuMoments::define_ruby_class();
|
mOpenCV::cCvHuMoments::define_ruby_class();
|
||||||
|
|
Loading…
Reference in a new issue