Class: P1788::Figure
- Inherits:
-
Object
- Object
- P1788::Figure
- Defined in:
- ext/p1788/figure_wrapper.cc,
ext/p1788/figure_wrapper.cc
Instance Attribute Summary collapse
-
#background_color ⇒ Integer
Background color of the figure.
-
#decoration_color ⇒ Integer
Color of the decoration (frame, graduations, title and axis labels).
-
#decoration_font ⇒ String?
The font used to display the title, labels and graduations.
-
#decoration_font_size ⇒ Float
Size of the font used to display the title, labels and graduations.
-
#decoration_line_width ⇒ Float
Line width for drawing the frame around the figure.
-
#height ⇒ Integer?
The height of the output image, in pixels.
-
#label_font_size ⇒ Float?
Size of the font used to display the labels.
-
#title ⇒ String?
The title to be drawn on top of the figure.
-
#title_font_size ⇒ Float?
Size of the font used to display the title.
-
#title_in_bold ⇒ Boolean
Draw the title in a bold font?.
-
#width ⇒ Integer?
The width of the output image, in pixels.
-
#with_decorations ⇒ Boolean
Draw decorations around the figure?.
-
#xlabel ⇒ String?
The label to be drawn below the horizontal axis.
-
#xrange ⇒ Interval?
The horizontal range that will be displayed.
-
#ylabel ⇒ String?
The label to be drawn on the left of the vertical axis.
-
#yrange ⇒ Interval?
The vertical range that will be displayed.
Instance Method Summary collapse
-
#content_range ⇒ IntervalVector
Returns the union of all the boxes that have ben sent to the figure for drwawing.
-
#draw_box(box, format = nil) ⇒ self
Draw a single box.
-
#draw_boxes(array_of_boxes, format = nil) ⇒ self
Draw multiple boxes at once.
-
#fill? ⇒ Boolean
Returns true if new objects (boxes) will be filled.
-
#fill_color ⇒ Integer
Returns the current color used to fill objects (boxes).
-
#fill_color=(c) ⇒ self
Set the fill color of the new objects (boxes) that will be drawned.
-
#fill_off ⇒ self
Tell the figure not to fill new objects (boxes).
-
#fill_on ⇒ self
Tell the figure to fill new objects (boxes) with the fill color.
-
#new(width: nil, height: nil, xrange: nil, yrange: nil, with_decorations: true, title: nil, xlabel: nil, ylabel: nil, background_color: 't', decoration_color: 'k', decoration_font: 'Sans', decoration_font_size: 11, decoration_line_width: 1, label_font_size: nil, title_font_size: nil, title_in_bold: false) ⇒ Figure
constructor
Returns a new Figure.
-
#nice_range ⇒ IntervalVector
Returns a range that would be nice to display, according to the content of the figure.
-
#reset! ⇒ self
Reset the figure to its default, clearing all boxes, labels, etc.
-
#set_range(box) ⇒ self
Set the horizontal and vertical range that will be displayed.
-
#stroke? ⇒ Boolean
Returns true if new objects (boxes) will be drawned with a border.
-
#stroke_color ⇒ Integer
Returns the current color used to draw the border of objects (boxes).
-
#stroke_color=(c) ⇒ self
Set the border color of the new objects (boxes) that will be drawned.
-
#stroke_off ⇒ self
Tell the figure to draw new objects (boxes) without border.
-
#stroke_on ⇒ self
Tell the figure to draw new objects (boxes) with a border.
-
#stroke_width ⇒ Float
Returns the current line width used to draw the border of objects (boxes).
-
#stroke_width=(w) ⇒ self
Set the line width of the new objects (boxes) that will be drawned.
-
#to_pdf ⇒ String
Generate the figure and return its content as a string in the PDF format.
-
#to_png ⇒ String
Generate the figure and return its content as a string in the PNG format.
-
#to_svg ⇒ String
Generate the figure and return its content as a string in the SVG format.
-
#write(file_name) ⇒ self
Generate the figure and write the output image to file file_name.
-
#write_pdf(file_name) ⇒ self
Generate the figure and write the output image in PDF format to file file_name.
-
#write_png(file_name) ⇒ self
Generate the figure and write the output image in PNG format to file file_name.
-
#write_svg(file_name) ⇒ self
Generate the figure and write the output image in SVG format to file file_name.
Constructor Details
#new(width: nil, height: nil, xrange: nil, yrange: nil, with_decorations: true, title: nil, xlabel: nil, ylabel: nil, background_color: 't', decoration_color: 'k', decoration_font: 'Sans', decoration_font_size: 11, decoration_line_width: 1, label_font_size: nil, title_font_size: nil, title_in_bold: false) ⇒ Figure
Returns a new P1788::Figure
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 |
# File 'ext/p1788/figure_wrapper.cc', line 1104 static VALUE p1788_figure_initialize(int argc, VALUE *argv, VALUE self) { const ID kwkeys[] = { id_width, id_height, id_xrange, id_yrange, id_with_decorations, id_title, id_xlabel, id_ylabel, id_background_color, id_decoration_color, id_decoration_font, id_decoration_font_size, id_decoration_line_width, id_label_font_size, id_title_font_size, id_title_in_bold }; VALUE kwvalues[] = {Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef}; VALUE kw; rb_scan_args(argc, argv, ":", &kw); if (NIL_P(kw)) return self; rb_get_kwargs(kw, kwkeys, 0, 16, kwvalues); if (kwvalues[0] != Qundef) p1788_figure_set_width(self, kwvalues[0]); if (kwvalues[1] != Qundef) p1788_figure_set_height(self, kwvalues[1]); if (kwvalues[2] != Qundef) p1788_figure_set_xrange(self, kwvalues[2]); if (kwvalues[3] != Qundef) p1788_figure_set_yrange(self, kwvalues[3]); if (kwvalues[4] != Qundef) p1788_figure_set_with_decorations(self, kwvalues[4]); if (kwvalues[5] != Qundef) p1788_figure_set_title(self, kwvalues[5]); if (kwvalues[6] != Qundef) p1788_figure_set_xlabel(self, kwvalues[6]); if (kwvalues[7] != Qundef) p1788_figure_set_ylabel(self, kwvalues[7]); if (kwvalues[8] != Qundef) p1788_figure_set_background_color(self, kwvalues[8]); if (kwvalues[9] != Qundef) p1788_figure_set_decoration_color(self, kwvalues[9]); if (kwvalues[10] != Qundef) p1788_figure_set_decoration_font(self, kwvalues[10]); if (kwvalues[11] != Qundef) p1788_figure_set_decoration_font_size(self, kwvalues[11]); if (kwvalues[12] != Qundef) p1788_figure_set_decoration_line_width(self, kwvalues[12]); if (kwvalues[13] != Qundef) p1788_figure_set_label_font_size(self, kwvalues[13]); if (kwvalues[14] != Qundef) p1788_figure_set_title_font_size(self, kwvalues[14]); if (kwvalues[15] != Qundef) p1788_figure_set_title_in_bold(self, kwvalues[15]); return self; } |
Instance Attribute Details
#background_color ⇒ Integer
Background color of the figure.
The color is encoded into a 32-bit integer that can be split in hexadecimal as: 0xRRGGBBAA, for the red, green, blue and alpha channels.
This attribute can also be set to a string, like "#cc000080"
, "#cc0000.5"
,"r.5"
or "W"
.
426 427 428 429 |
# File 'ext/p1788/figure_wrapper.cc', line 426 static VALUE p1788_figure_get_background_color(VALUE self) { return UINT2NUM(p1788_figure_rb2ref(self).background_color()); } |
#decoration_color ⇒ Integer
Color of the decoration (frame, graduations, title and axis labels).
The color is encoded into a 32-bit integer that can be split in hexadecimal as: 0xRRGGBBAA, for the red, green, blue and alpha channels.
This attribute can also be set to a string, like "#cc000080"
, "#cc0000.5"
,"r.5"
or "W"
.
404 405 406 407 |
# File 'ext/p1788/figure_wrapper.cc', line 404 static VALUE p1788_figure_get_decoration_color(VALUE self) { return UINT2NUM(p1788_figure_rb2ref(self).graduation_color()); } |
#decoration_font ⇒ String?
The font used to display the title, labels and graduations. Set the font to nil to reset it to its default ("Sans").
281 282 283 284 285 286 287 288 |
# File 'ext/p1788/figure_wrapper.cc', line 281 static VALUE p1788_figure_get_decoration_font(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); const std::string& t = f.graduation_font(); if (t.empty()) return Qnil; return p1788_cppstring_to_rbstring_utf8(t); } |
#decoration_font_size ⇒ Float
Size of the font used to display the title, labels and graduations.
306 307 308 309 310 |
# File 'ext/p1788/figure_wrapper.cc', line 306 static VALUE p1788_figure_get_decoration_font_size(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); return DBL2NUM(f.graduation_font_size()); } |
#decoration_line_width ⇒ Float
Line width for drawing the frame around the figure.
380 381 382 383 384 |
# File 'ext/p1788/figure_wrapper.cc', line 380 static VALUE p1788_figure_get_decoration_line_width(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); return DBL2NUM(f.graduation_stroke_width()); } |
#height ⇒ Integer?
The height of the output image, in pixels. Set the height to nil or 0 to get automatic sizing.
474 475 476 477 478 479 480 481 |
# File 'ext/p1788/figure_wrapper.cc', line 474 static VALUE p1788_figure_get_height(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); int i = f.height(); if (i < 1) return Qnil; return INT2NUM(i); } |
#label_font_size ⇒ Float?
Size of the font used to display the labels.
If set to nil, the labels will automatically be drawn at 1.1 times the decoration font size.
356 357 358 359 360 361 362 |
# File 'ext/p1788/figure_wrapper.cc', line 356 static VALUE p1788_figure_get_label_font_size(VALUE self) { double s = p1788_figure_rb2ref(self).label_font_size_as_set(); if (s <= 0.0) return Qnil; return DBL2NUM(s); } |
#title ⇒ String?
The title to be drawn on top of the figure. Set the title to nil to remove the title.
203 204 205 206 207 208 209 210 |
# File 'ext/p1788/figure_wrapper.cc', line 203 static VALUE p1788_figure_get_title(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); const std::string& t = f.title(); if (t.empty()) return Qnil; return p1788_cppstring_to_rbstring_utf8(t); } |
#title_font_size ⇒ Float?
Size of the font used to display the title.
If set to nil, the title will automatically be drawn at 1.23 times the decoration font size.
330 331 332 333 334 335 336 |
# File 'ext/p1788/figure_wrapper.cc', line 330 static VALUE p1788_figure_get_title_font_size(VALUE self) { double s = p1788_figure_rb2ref(self).title_font_size_as_set(); if (s <= 0.0) return Qnil; return DBL2NUM(s); } |
#title_in_bold ⇒ Boolean
Draw the title in a bold font?
If #with_decorations is set to true and #title is not nil nor empty, the title will be drawn in bold or normal weight according to this attribute.
615 616 617 618 619 |
# File 'ext/p1788/figure_wrapper.cc', line 615 static VALUE p1788_figure_get_title_in_bold(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); return f.title_bold() ? Qtrue : Qfalse; } |
#width ⇒ Integer?
The width of the output image, in pixels. Set the width to nil or 0 to get automatic sizing.
444 445 446 447 448 449 450 451 |
# File 'ext/p1788/figure_wrapper.cc', line 444 static VALUE p1788_figure_get_width(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); int i = f.width(); if (i < 1) return Qnil; return INT2NUM(i); } |
#with_decorations ⇒ Boolean
Draw decorations around the figure?.
If set to false, no frame, ticks, title nor labels will be drawn around the figure, even if they are set. The output image size will be width x height.
If set to true, a frame and graduations will be drawn around the figure. If they are set, title and labels will also be drawn. The output image size will be larger than width x height.
591 592 593 594 595 |
# File 'ext/p1788/figure_wrapper.cc', line 591 static VALUE p1788_figure_get_with_decorations(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); return f.print_graduations() ? Qtrue : Qfalse; } |
#xlabel ⇒ String?
The label to be drawn below the horizontal axis. Set the label to nil to remove it.
229 230 231 232 233 234 235 236 |
# File 'ext/p1788/figure_wrapper.cc', line 229 static VALUE p1788_figure_get_xlabel(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); const std::string& t = f.xlabel(); if (t.empty()) return Qnil; return p1788_cppstring_to_rbstring_utf8(t); } |
#xrange ⇒ Interval?
The horizontal range that will be displayed. Set xrange to nil or an empty interval to get automatic range adjustment.
504 505 506 507 508 509 510 511 512 513 |
# File 'ext/p1788/figure_wrapper.cc', line 504 static VALUE p1788_figure_get_xrange(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); const Interval& r = f.xlim(); if (!Interval::is_common_interval(r)) return Qnil; VALUE res; P1788_NEW_RB_INTERVAL(res, r); return res; } |
#ylabel ⇒ String?
The label to be drawn on the left of the vertical axis. Set the label to nil to remove it.
255 256 257 258 259 260 261 262 |
# File 'ext/p1788/figure_wrapper.cc', line 255 static VALUE p1788_figure_get_ylabel(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); const std::string& t = f.ylabel(); if (t.empty()) return Qnil; return p1788_cppstring_to_rbstring_utf8(t); } |
#yrange ⇒ Interval?
The vertical range that will be displayed. Set yrange to nil or an empty interval to get automatic range adjustment.
531 532 533 534 535 536 537 538 539 540 |
# File 'ext/p1788/figure_wrapper.cc', line 531 static VALUE p1788_figure_get_yrange(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); const Interval& r = f.ylim(); if (!Interval::is_common_interval(r)) return Qnil; VALUE res; P1788_NEW_RB_INTERVAL(res, r); return res; } |
Instance Method Details
#content_range ⇒ IntervalVector
Returns the union of all the boxes that have ben sent to the figure for drwawing.
633 634 635 636 637 638 639 640 641 642 643 |
# File 'ext/p1788/figure_wrapper.cc', line 633 static VALUE p1788_figure_content_range(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); P1788Figure::Box b; f.find_unbounded_limits(b); IntervalVector *v = new IntervalVector(2); (*v)[0] = b.x; (*v)[1] = b.y; return p1788_vector_alloc_from_pointer(v); } |
#draw_box(box, format = nil) ⇒ self
Draw a single box.
978 979 980 981 982 983 984 985 986 987 |
# File 'ext/p1788/figure_wrapper.cc', line 978 static VALUE p1788_figure_draw_box(int argc, VALUE *argv, VALUE self) { VALUE rbox, rformat; rb_scan_args(argc, argv, "11", &rbox, &rformat); P1788Figure::Figure& f = p1788_figure_rb2ref(self); if (rformat != Qnil) p1788_figure_parse_format(f, rformat); f.cmd_draw_box(p1788_vector_rb2ref(rbox)); return self; } |
#draw_boxes(array_of_boxes, format = nil) ⇒ self
Draw multiple boxes at once.
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 |
# File 'ext/p1788/figure_wrapper.cc', line 996 static VALUE p1788_figure_draw_boxes(int argc, VALUE *argv, VALUE self) { VALUE rboxes, rformat; rb_scan_args(argc, argv, "11", &rboxes, &rformat); P1788Figure::Figure& f = p1788_figure_rb2ref(self); if (!RB_TYPE_P(rboxes, T_ARRAY)) rb_raise(rb_eTypeError, "expecting an array of %" PRIsVALUE ", not a %" PRIsVALUE, rb_class_name(c_IntervalVector), rb_class_name(rb_class_of(rboxes))); if (rformat != Qnil) p1788_figure_parse_format(f, rformat); const size_t l = rb_array_len(rboxes); if (l < 1) return self; std::vector<P1788Figure::Box> bv; bv.reserve(l); for (size_t i = 0; i < l; i++) { VALUE e = rb_ary_entry(rboxes, i); if (!is_an_interval_vector(e)) rb_raise(rb_eTypeError, "expecting interval vectors in the array, not %" PRIsVALUE, rb_class_name(rb_class_of(e))); const IntervalVector& iv = p1788_vector_rb2ref(e); if (!(iv.size() < 2 || Interval::is_empty(iv[0]) || Interval::is_empty(iv[1]))) bv.emplace_back(iv[0], iv[1]); } if (bv.size() > 0) f.cmd_draw_boxes(std::move(bv)); return self; } |
#fill? ⇒ Boolean
Returns true if new objects (boxes) will be filled.
843 844 845 846 |
# File 'ext/p1788/figure_wrapper.cc', line 843 static VALUE p1788_figure_get_fill_onoff(VALUE self) { return p1788_figure_rb2ref(self).do_fill() ? Qtrue : Qfalse; } |
#fill_color ⇒ Integer
Returns the current color used to fill objects (boxes). The color is encoded into a 32-bit integer that can be split in hexadecimal as: 0xRRGGBBAA, for the red, green, blue and alpha channels.
926 927 928 929 |
# File 'ext/p1788/figure_wrapper.cc', line 926 static VALUE p1788_figure_get_fill_color(VALUE self) { return UINT2NUM(p1788_figure_rb2ref(self).fill_color()); } |
#fill_color=(c) ⇒ self
Set the fill color of the new objects (boxes) that will be drawned.
The color is encoded into a 32-bit integer that can be split in hexadecimal as: 0xRRGGBBAA, for the red, green, blue and alpha channels.
The color can also be set to a string, like "#cc000080"
, "#cc0000.5"
,"r.5"
or "W"
.
912 913 914 915 916 917 |
# File 'ext/p1788/figure_wrapper.cc', line 912 static VALUE p1788_figure_set_fill_color(VALUE self, VALUE c) { unsigned int n = p1788_figure_parse_color(c); p1788_figure_rb2ref(self).cmd_fill_color(n); return self; } |
#fill_off ⇒ self
Tell the figure not to fill new objects (boxes).
831 832 833 834 835 |
# File 'ext/p1788/figure_wrapper.cc', line 831 static VALUE p1788_figure_fill_off(VALUE self) { p1788_figure_rb2ref(self).cmd_fill(false); return self; } |
#fill_on ⇒ self
Tell the figure to fill new objects (boxes) with the fill color.
819 820 821 822 823 |
# File 'ext/p1788/figure_wrapper.cc', line 819 static VALUE p1788_figure_fill_on(VALUE self) { p1788_figure_rb2ref(self).cmd_fill(true); return self; } |
#nice_range ⇒ IntervalVector
Returns a range that would be nice to display, according to the content of the figure.
649 650 651 652 653 654 655 656 657 658 659 |
# File 'ext/p1788/figure_wrapper.cc', line 649 static VALUE p1788_figure_nice_range(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); P1788Figure::Box b, c; f.find_limits(c, b); IntervalVector *v = new IntervalVector(2); (*v)[0] = b.x; (*v)[1] = b.y; return p1788_vector_alloc_from_pointer(v); } |
#reset! ⇒ self
Reset the figure to its default, clearing all boxes, labels, etc.
After a reset, the figure state is the same than after Figure.new()
.
1029 1030 1031 1032 1033 |
# File 'ext/p1788/figure_wrapper.cc', line 1029 static VALUE p1788_figure_reset(VALUE self) { p1788_figure_rb2ref(self).reset(); return self; } |
#set_range(box) ⇒ self
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'ext/p1788/figure_wrapper.cc', line 560 static VALUE p1788_figure_set_range(VALUE self, VALUE box) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); if (NIL_P(box)) { f.set_xlimit(Interval()); f.set_ylimit(Interval()); return self; } if (!is_an_interval_vector(box)) rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %" PRIsVALUE, rb_class_name(c_IntervalVector), rb_class_name(rb_class_of(box))); const IntervalVector& r = p1788_vector_rb2ref(box); if (r.size() < 2) rb_raise(rb_eRuntimeError, "the interval vector must have at least two elements (for the x an y axis)"); f.set_xlimit(r[0]); f.set_ylimit(r[1]); return self; } |
#stroke? ⇒ Boolean
Returns true if new objects (boxes) will be drawned with a border.
807 808 809 810 |
# File 'ext/p1788/figure_wrapper.cc', line 807 static VALUE p1788_figure_get_stroke_onoff(VALUE self) { return p1788_figure_rb2ref(self).do_stroke() ? Qtrue : Qfalse; } |
#stroke_color ⇒ Integer
Returns the current color used to draw the border of objects (boxes). The color is encoded into a 32-bit integer that can be split in hexadecimal as: 0xRRGGBBAA, for the red, green, blue and alpha channels.
896 897 898 899 |
# File 'ext/p1788/figure_wrapper.cc', line 896 static VALUE p1788_figure_get_stroke_color(VALUE self) { return UINT2NUM(p1788_figure_rb2ref(self).stroke_color()); } |
#stroke_color=(c) ⇒ self
Set the border color of the new objects (boxes) that will be drawned.
The color is encoded into a 32-bit integer that can be split in hexadecimal as: 0xRRGGBBAA, for the red, green, blue and alpha channels.
The color can also be set to a string, like "#cc000080"
, "#cc0000.5"
,"r.5"
or "W"
.
882 883 884 885 886 887 |
# File 'ext/p1788/figure_wrapper.cc', line 882 static VALUE p1788_figure_set_stroke_color(VALUE self, VALUE c) { unsigned int n = p1788_figure_parse_color(c); p1788_figure_rb2ref(self).cmd_stroke_color(n); return self; } |
#stroke_off ⇒ self
Tell the figure to draw new objects (boxes) without border.
795 796 797 798 799 |
# File 'ext/p1788/figure_wrapper.cc', line 795 static VALUE p1788_figure_stroke_off(VALUE self) { p1788_figure_rb2ref(self).cmd_stroke(false); return self; } |
#stroke_on ⇒ self
Tell the figure to draw new objects (boxes) with a border.
783 784 785 786 787 |
# File 'ext/p1788/figure_wrapper.cc', line 783 static VALUE p1788_figure_stroke_on(VALUE self) { p1788_figure_rb2ref(self).cmd_stroke(true); return self; } |
#stroke_width ⇒ Float
Returns the current line width used to draw the border of objects (boxes).
865 866 867 868 |
# File 'ext/p1788/figure_wrapper.cc', line 865 static VALUE p1788_figure_get_stroke_width(VALUE self) { return DBL2NUM(p1788_figure_rb2ref(self).stroke_width()); } |
#stroke_width=(w) ⇒ self
Set the line width of the new objects (boxes) that will be drawned.
854 855 856 857 858 |
# File 'ext/p1788/figure_wrapper.cc', line 854 static VALUE p1788_figure_set_stroke_width(VALUE self, VALUE w) { p1788_figure_rb2ref(self).cmd_stroke_width(NUM2DBL(w)); return self; } |
#to_pdf ⇒ String
Generate the figure and return its content as a string in the PDF format.
762 763 764 765 766 767 768 769 770 771 772 |
# File 'ext/p1788/figure_wrapper.cc', line 762 static VALUE p1788_figure_to_pdf(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); std::string s; try { s = std::move(f.to_pdf()); } catch (const std::exception &e) { rb_raise(rb_eRuntimeError, "%s", e.what()); } return rb_usascii_str_new(s.c_str(), s.size()); } |
#to_png ⇒ String
Generate the figure and return its content as a string in the PNG format.
686 687 688 689 690 691 692 693 694 695 696 |
# File 'ext/p1788/figure_wrapper.cc', line 686 static VALUE p1788_figure_to_png(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); std::string s; try { s = std::move(f.to_png()); } catch (const std::exception &e) { rb_raise(rb_eRuntimeError, "%s", e.what()); } return rb_usascii_str_new(s.c_str(), s.size()); } |
#to_svg ⇒ String
Generate the figure and return its content as a string in the SVG format.
724 725 726 727 728 729 730 731 732 733 734 |
# File 'ext/p1788/figure_wrapper.cc', line 724 static VALUE p1788_figure_to_svg(VALUE self) { P1788Figure::Figure& f = p1788_figure_rb2ref(self); std::string s; try { s = std::move(f.to_svg()); } catch (const std::exception &e) { rb_raise(rb_eRuntimeError, "%s", e.what()); } return rb_usascii_str_new(s.c_str(), s.size()); } |
#write(file_name) ⇒ self
Generate the figure and write the output image to file file_name. The output format (either png, svg or pdf) is deduced from the extension of the file.
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 |
# File 'ext/p1788/figure_wrapper.cc', line 1045 static VALUE p1788_figure_write(VALUE self, VALUE file_name) { file_name = rb_funcallv(file_name, id_to_s, 0, NULL); if (RSTRING_LEN(file_name) < 1) rb_raise(rb_eRuntimeError, "file name is empty"); VALUE cr = rb_str_new_static(extension_regexp, 34); VALUE regexp = rb_class_new_instance(1, &cr, rb_cRegexp); VALUE match = rb_funcallv(file_name, id_match, 1, ®exp); if (NIL_P(match)) rb_raise(rb_eRuntimeError, "cannot deduce format from file name \"%" PRIsVALUE "\"", file_name); VALUE m; m = rb_funcall(match, id_brackets, 1, INT2NUM(2)); if (m != Qnil) { #ifdef CAIRO_HAS_PNG_FUNCTIONS return p1788_figure_write_png(self, file_name); #else rb_raise(rb_eRuntimeError, "no support for PNG, sorry"); #endif } m = rb_funcall(match, id_brackets, 1, INT2NUM(3)); if (m != Qnil) { #ifdef CAIRO_HAS_SVG_SURFACE return p1788_figure_write_svg(self, file_name); #else rb_raise(rb_eRuntimeError, "no support for SVG, sorry"); #endif } m = rb_funcall(match, id_brackets, 1, INT2NUM(4)); if (m != Qnil) { #ifdef CAIRO_HAS_PDF_SURFACE return p1788_figure_write_pdf(self, file_name); #else rb_raise(rb_eRuntimeError, "no support for PDF, sorry"); #endif } return self; } |
#write_pdf(file_name) ⇒ self
Generate the figure and write the output image in PDF format to file file_name.
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
# File 'ext/p1788/figure_wrapper.cc', line 743 static VALUE p1788_figure_write_pdf(VALUE self, VALUE file_name) { file_name = rb_funcallv(file_name, id_to_s, 0, NULL); if (RSTRING_LEN(file_name) < 1) rb_raise(rb_eRuntimeError, "file name is empty"); file_name = rb_funcallv(rb_cFile, rb_intern("absolute_path"), 1, &file_name); P1788Figure::Figure& f = p1788_figure_rb2ref(self); std::string cppfname = p1788_rbstring_to_cppstring(file_name); try { f.write_pdf(cppfname); } catch (const std::exception &e) { rb_raise(rb_eRuntimeError, "%s", e.what()); } return self; } |
#write_png(file_name) ⇒ self
Generate the figure and write the output image in PNG format to file file_name.
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
# File 'ext/p1788/figure_wrapper.cc', line 667 static VALUE p1788_figure_write_png(VALUE self, VALUE file_name) { file_name = rb_funcallv(file_name, id_to_s, 0, NULL); if (RSTRING_LEN(file_name) < 1) rb_raise(rb_eRuntimeError, "file name is empty"); file_name = rb_funcallv(rb_cFile, rb_intern("absolute_path"), 1, &file_name); P1788Figure::Figure& f = p1788_figure_rb2ref(self); std::string cppfname = p1788_rbstring_to_cppstring(file_name); try { f.write_png(cppfname); } catch (const std::exception &e) { rb_raise(rb_eRuntimeError, "%s", e.what()); } return self; } |
#write_svg(file_name) ⇒ self
Generate the figure and write the output image in SVG format to file file_name.
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
# File 'ext/p1788/figure_wrapper.cc', line 705 static VALUE p1788_figure_write_svg(VALUE self, VALUE file_name) { file_name = rb_funcallv(file_name, id_to_s, 0, NULL); if (RSTRING_LEN(file_name) < 1) rb_raise(rb_eRuntimeError, "file name is empty"); file_name = rb_funcallv(rb_cFile, rb_intern("absolute_path"), 1, &file_name); P1788Figure::Figure& f = p1788_figure_rb2ref(self); std::string cppfname = p1788_rbstring_to_cppstring(file_name); try { f.write_svg(cppfname); } catch (const std::exception &e) { rb_raise(rb_eRuntimeError, "%s", e.what()); } return self; } |