Class: Cairo::Surface
- Inherits:
-
Object
- Object
- Cairo::Surface
- Defined in:
- lib/cairo.rb,
lib/cairo/surface.rb,
ext/cairo/rb_cairo_surface.c
Direct Known Subclasses
CoglSurface, DRMSurface, GLSurface, ImageSurface, PDFSurface, PSSurface, QtSurface, QuartzImageSurface, QuartzSurface, RecordingSurface, SVGSurface, ScriptSurface, SkiaSurface, SubSurface, TeeSurface, VGSurface, Win32PrintingSurface, Win32Surface, XCBSurface, XLibSurface, XMLSurface
Class Method Summary collapse
- .create ⇒ Object
- .gl_supported? ⇒ Boolean
- .gl_texture_supported? ⇒ Boolean
- .image_supported? ⇒ Boolean
- .pdf_supported? ⇒ Boolean
- .ps_supported? ⇒ Boolean
- .quartz_image_supported? ⇒ Boolean
- .quartz_supported? ⇒ Boolean
- .recording_supported? ⇒ Boolean
- .script_supported? ⇒ Boolean
- .supported?(type) ⇒ Boolean
- .svg_supported? ⇒ Boolean
- .tee_supported? ⇒ Boolean
- .win32_printing_supported? ⇒ Boolean
- .win32_supported? ⇒ Boolean
- .xml_supported? ⇒ Boolean
Instance Method Summary collapse
- #clone ⇒ Object
- #content ⇒ Object
- #copy_page ⇒ Object
- #create_similar ⇒ Object
- #create_similar_image ⇒ Object
- #destroy ⇒ Object
- #device ⇒ Object
- #device_offset ⇒ Object
- #device_scale ⇒ Object
- #dup ⇒ Object
- #fallback_resolution ⇒ Object
- #finish ⇒ Object
- #flush ⇒ Object
- #font_options ⇒ Object
- #get_mime_data ⇒ Object
- #initialize ⇒ Object constructor
- #map_to_image ⇒ Object
- #mark_dirty ⇒ Object
-
#reference_count ⇒ Object
Surface manipulation.
- #set_device_offset ⇒ Object
- #set_device_scale ⇒ Object
- #set_fallback_resolution ⇒ Object
- #set_mime_data ⇒ Object
- #show_page ⇒ Object
- #sub_rectangle_surface ⇒ Object
- #supported_mime_type? ⇒ Boolean
- #unmap_image ⇒ Object
- #write_to_png ⇒ Object
Constructor Details
#initialize ⇒ Object
487 488 489 490 491 492 493 494 495 |
# File 'ext/cairo/rb_cairo_surface.c', line 487
static VALUE
cr_surface_initialize (int argc, VALUE *argv, VALUE self)
{
rb_raise(rb_eNotImpError,
"%s class creation isn't supported on this cairo installation",
rb_obj_classname(self));
return Qnil;
}
|
Class Method Details
.create ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'ext/cairo/rb_cairo_surface.c', line 266
static VALUE
cr_surface_create (int argc, VALUE *argv, VALUE klass)
{
VALUE rb_surface;
rb_surface = rb_funcallv (klass, cr_id_new, argc, argv);
if (rb_block_given_p ())
{
return rb_ensure (rb_cairo__surface_yield_and_finish, rb_surface,
cr_surface_destroy_with_destroy_check, rb_surface);
}
else
{
return rb_surface;
}
}
|
.gl_supported? ⇒ Boolean
378 379 380 381 382 383 384 385 386 |
# File 'ext/cairo/rb_cairo_surface.c', line 378
static VALUE
cr_surface_gl_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_GL_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.gl_texture_supported? ⇒ Boolean
388 389 390 391 392 |
# File 'ext/cairo/rb_cairo_surface.c', line 388
static VALUE
cr_surface_gl_texture_supported_p (VALUE klass)
{
return cr_surface_gl_supported_p(klass);
}
|
.image_supported? ⇒ Boolean
282 283 284 285 286 |
# File 'ext/cairo/rb_cairo_surface.c', line 282
static VALUE
cr_surface_image_supported_p (VALUE klass)
{
return Qtrue;
}
|
.pdf_supported? ⇒ Boolean
288 289 290 291 292 293 294 295 296 |
# File 'ext/cairo/rb_cairo_surface.c', line 288
static VALUE
cr_surface_pdf_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_PDF_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.ps_supported? ⇒ Boolean
298 299 300 301 302 303 304 305 306 |
# File 'ext/cairo/rb_cairo_surface.c', line 298
static VALUE
cr_surface_ps_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_PS_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.quartz_image_supported? ⇒ Boolean
348 349 350 351 352 353 354 355 356 |
# File 'ext/cairo/rb_cairo_surface.c', line 348
static VALUE
cr_surface_quartz_image_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_QUARTZ_IMAGE_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.quartz_supported? ⇒ Boolean
308 309 310 311 312 313 314 315 316 |
# File 'ext/cairo/rb_cairo_surface.c', line 308
static VALUE
cr_surface_quartz_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_QUARTZ_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.recording_supported? ⇒ Boolean
368 369 370 371 372 373 374 375 376 |
# File 'ext/cairo/rb_cairo_surface.c', line 368
static VALUE
cr_surface_recording_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_RECORDING_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.script_supported? ⇒ Boolean
358 359 360 361 362 363 364 365 366 |
# File 'ext/cairo/rb_cairo_surface.c', line 358
static VALUE
cr_surface_script_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_SCRIPT_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.supported?(type) ⇒ Boolean
4 5 6 7 8 9 10 |
# File 'lib/cairo/surface.rb', line 4 def supported?(type) type_components = type.to_s.split(/([A-Z][a-z\d]+)/).reject(&:empty?) snake_case_type_name = type_components.join("_").downcase supported_predicate = "#{snake_case_type_name}_supported?" return false unless respond_to?(supported_predicate) send(supported_predicate) end |
.svg_supported? ⇒ Boolean
328 329 330 331 332 333 334 335 336 |
# File 'ext/cairo/rb_cairo_surface.c', line 328
static VALUE
cr_surface_svg_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_SVG_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.tee_supported? ⇒ Boolean
394 395 396 397 398 399 400 401 402 |
# File 'ext/cairo/rb_cairo_surface.c', line 394
static VALUE
cr_surface_tee_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_TEE_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.win32_printing_supported? ⇒ Boolean
338 339 340 341 342 343 344 345 346 |
# File 'ext/cairo/rb_cairo_surface.c', line 338
static VALUE
cr_surface_win32_printing_supported_p (VALUE klass)
{
#ifdef RB_CAIRO_HAS_WIN32_PRINTING_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.win32_supported? ⇒ Boolean
318 319 320 321 322 323 324 325 326 |
# File 'ext/cairo/rb_cairo_surface.c', line 318
static VALUE
cr_surface_win32_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_WIN32_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
.xml_supported? ⇒ Boolean
404 405 406 407 408 409 410 411 412 |
# File 'ext/cairo/rb_cairo_surface.c', line 404
static VALUE
cr_surface_xml_supported_p (VALUE klass)
{
#ifdef CAIRO_HAS_XML_SURFACE
return Qtrue;
#else
return Qfalse;
#endif
}
|
Instance Method Details
#clone ⇒ Object
80 81 82 |
# File 'lib/cairo.rb', line 80 def clone raise NotImplementedError end |
#content ⇒ Object
698 699 700 701 702 |
# File 'ext/cairo/rb_cairo_surface.c', line 698
static VALUE
cr_surface_get_content (VALUE self)
{
return INT2NUM (cairo_surface_get_content (_SELF));
}
|
#copy_page ⇒ Object
947 948 949 950 951 952 953 |
# File 'ext/cairo/rb_cairo_surface.c', line 947
static VALUE
cr_surface_copy_page (VALUE self)
{
cairo_surface_copy_page (_SELF);
rb_cairo_surface_check_status (_SELF);
return self;
}
|
#create_similar ⇒ Object
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
# File 'ext/cairo/rb_cairo_surface.c', line 551
static VALUE
cr_surface_create_similar (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface, *similar_surface;
cairo_content_t content;
int width, height;
VALUE arg1, arg2, arg3;
rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
surface = _SELF;
if (argc == 2)
{
content = cairo_surface_get_content (surface);
width = NUM2INT (arg1);
height = NUM2INT (arg2);
}
else
{
content = RVAL2CRCONTENT (arg1);
width = NUM2INT (arg2);
height = NUM2INT (arg3);
}
similar_surface = cairo_surface_create_similar (surface, content,
width, height);
rb_cairo_surface_check_status (similar_surface);
return CRSURFACE2RVAL_WITH_DESTROY (similar_surface);
}
|
#create_similar_image ⇒ Object
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'ext/cairo/rb_cairo_surface.c', line 582
static VALUE
cr_surface_create_similar_image (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface, *similar_image;
cairo_format_t format;
int width, height;
VALUE arg1, arg2, arg3;
rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
surface = _SELF;
if (argc == 2)
{
if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE)
{
format = cairo_image_surface_get_format (surface);
}
else
{
format = CAIRO_FORMAT_ARGB32;
}
width = NUM2INT (arg1);
height = NUM2INT (arg2);
}
else
{
format = RVAL2CRFORMAT (arg1);
width = NUM2INT (arg2);
height = NUM2INT (arg3);
}
similar_image = cairo_surface_create_similar_image (surface, format,
width, height);
rb_cairo_surface_check_status (similar_image);
return CRSURFACE2RVAL_WITH_DESTROY (similar_image);
}
|
#destroy ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 |
# File 'ext/cairo/rb_cairo_surface.c', line 246
static VALUE
cr_surface_destroy (VALUE self)
{
cairo_surface_t *surface;
surface = _SELF;
cr_surface_destroy_raw (surface);
DATA_PTR (self) = NULL;
return self;
}
|
#device ⇒ Object
691 692 693 694 695 |
# File 'ext/cairo/rb_cairo_surface.c', line 691
static VALUE
cr_surface_get_device (VALUE self)
{
return CRDEVICE2RVAL (cairo_surface_get_device (_SELF));
}
|
#device_offset ⇒ Object
886 887 888 889 890 891 892 893 894 |
# File 'ext/cairo/rb_cairo_surface.c', line 886
static VALUE
cr_surface_get_device_offset (VALUE self)
{
double x_offset, y_offset;
cairo_surface_get_device_offset (_SELF, &x_offset, &y_offset);
rb_cairo_surface_check_status (_SELF);
return rb_ary_new3 (2, rb_float_new (x_offset), rb_float_new (y_offset));
}
|
#device_scale ⇒ Object
907 908 909 910 911 912 913 914 |
# File 'ext/cairo/rb_cairo_surface.c', line 907
static VALUE
cr_surface_get_device_scale (VALUE self)
{
double x_scale, y_scale;
cairo_surface_get_device_scale (_SELF, &x_scale, &y_scale);
return rb_ary_new3 (2, rb_float_new (x_scale), rb_float_new (y_scale));
}
|
#dup ⇒ Object
77 78 79 |
# File 'lib/cairo.rb', line 77 def dup raise NotImplementedError end |
#fallback_resolution ⇒ Object
930 931 932 933 934 935 936 937 938 939 940 941 942 |
# File 'ext/cairo/rb_cairo_surface.c', line 930
static VALUE
cr_surface_get_fallback_resolution (VALUE self)
{
double x_pixels_per_inch, y_pixels_per_inch;
cairo_surface_get_fallback_resolution (_SELF,
&x_pixels_per_inch,
&y_pixels_per_inch);
rb_cairo_surface_check_status (_SELF);
return rb_ary_new3 (2,
rb_float_new (x_pixels_per_inch),
rb_float_new (y_pixels_per_inch));
}
|
#finish ⇒ Object
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'ext/cairo/rb_cairo_surface.c', line 510
static VALUE
cr_surface_finish (VALUE self)
{
cairo_surface_t *surface;
rb_cairo__io_callback_closure_t *closure;
surface = _SELF;
closure = cairo_surface_get_user_data (surface, &cr_closure_key);
cairo_surface_finish (surface);
cairo_surface_set_user_data (surface, &cr_finished_key, (void *)CR_TRUE, NULL);
cairo_surface_set_user_data (surface, &cr_object_holder_key, NULL, NULL);
if (closure && !NIL_P (closure->error))
rb_exc_raise (closure->error);
rb_cairo_surface_check_status (surface);
return self;
}
|
#flush ⇒ Object
830 831 832 833 834 835 836 |
# File 'ext/cairo/rb_cairo_surface.c', line 830
static VALUE
cr_surface_flush (VALUE self)
{
cairo_surface_flush (_SELF);
rb_cairo_surface_check_status (_SELF);
return self;
}
|
#font_options ⇒ Object
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 |
# File 'ext/cairo/rb_cairo_surface.c', line 809
static VALUE
cr_surface_get_font_options (VALUE self)
{
cairo_font_options_t *options;
VALUE rb_options;
options = cairo_font_options_create ();
rb_cairo_check_status (cairo_font_options_status (options));
/* TODO: Use rb_ensure() */
rb_options = CRFONTOPTIONS2RVAL (options);
cairo_font_options_destroy (options);
options = RVAL2CRFONTOPTIONS (rb_options);
cairo_surface_get_font_options (_SELF, options);
rb_cairo_surface_check_status (_SELF);
rb_cairo_check_status (cairo_font_options_status (options));
return rb_options;
}
|
#get_mime_data ⇒ Object
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 |
# File 'ext/cairo/rb_cairo_surface.c', line 745
static VALUE
cr_surface_get_mime_data (VALUE self, VALUE mime_type)
{
cairo_surface_t *surface;
const unsigned char *data;
unsigned long length;
surface = _SELF;
cairo_surface_get_mime_data (surface, StringValueCStr (mime_type),
&data, &length);
if (data)
return rb_str_new ((const char *)data, length);
else
return Qnil;
}
|
#map_to_image ⇒ Object
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'ext/cairo/rb_cairo_surface.c', line 619
static VALUE
cr_surface_map_to_image (int argc, VALUE *argv, VALUE self)
{
cairo_surface_t *surface, *mapped_image;
cairo_rectangle_int_t extents_value;
cairo_rectangle_int_t *extents = NULL;
VALUE rb_extents;
rb_scan_args (argc, argv, "01", &rb_extents);
surface = _SELF;
if (!NIL_P (rb_extents))
{
extents = &extents_value;
if (rb_cairo__is_kind_of (rb_extents, rb_cCairo_Rectangle))
{
extents->x = NUM2INT (rb_funcall (rb_extents, cr_id_x, 0));
extents->y = NUM2INT (rb_funcall (rb_extents, cr_id_y, 0));
extents->width = NUM2INT (rb_funcall (rb_extents, cr_id_width, 0));
extents->height = NUM2INT (rb_funcall (rb_extents, cr_id_height, 0));
}
else
{
VALUE *values;
rb_extents = rb_convert_type (rb_extents, T_ARRAY, "Array", "to_ary");
values = RARRAY_PTR (rb_extents);
extents->x = NUM2INT (values[0]);
extents->y = NUM2INT (values[1]);
extents->height = NUM2INT (values[2]);
extents->width = NUM2INT (values[3]);
}
}
mapped_image = cairo_surface_map_to_image (surface, extents);
rb_cairo_surface_check_status (mapped_image);
return CRSURFACE2RVAL_WITH_DESTROY (mapped_image);
}
|
#mark_dirty ⇒ Object
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 |
# File 'ext/cairo/rb_cairo_surface.c', line 838
static VALUE
cr_surface_mark_dirty (int argc, VALUE *argv, VALUE self)
{
VALUE x, y, width, height;
int n;
n = rb_scan_args (argc, argv, "04", &x, &y, &width, &height);
if (n == 0)
{
cairo_surface_mark_dirty (_SELF);
}
else if (n == 4)
{
cairo_surface_mark_dirty_rectangle (_SELF,
NUM2INT (x), NUM2INT (y),
NUM2INT (width), NUM2INT (height));
}
else
{
int i;
VALUE args;
args = rb_ary_new2 (n);
for (i = 0; i < n; i++)
{
rb_ary_push (args, argv[i]);
}
rb_raise (rb_eArgError,
"invalid argument (expect () or (x, y, width, height)): %s",
rb_cairo__inspect (args));
}
rb_cairo_surface_check_status (_SELF);
return self;
}
|
#reference_count ⇒ Object
Surface manipulation
498 499 500 501 502 503 504 505 506 507 508 |
# File 'ext/cairo/rb_cairo_surface.c', line 498
static VALUE
cr_surface_get_reference_count (VALUE self)
{
cairo_surface_t *surface;
unsigned int reference_count;
surface = _SELF;
reference_count = cairo_surface_get_reference_count (surface);
return UINT2NUM (reference_count);
}
|
#set_device_offset ⇒ Object
876 877 878 879 880 881 882 883 884 |
# File 'ext/cairo/rb_cairo_surface.c', line 876
static VALUE
cr_surface_set_device_offset (VALUE self, VALUE x_offset, VALUE y_offset)
{
cairo_surface_set_device_offset (_SELF,
NUM2DBL (x_offset),
NUM2DBL (y_offset));
rb_cairo_surface_check_status (_SELF);
return self;
}
|
#set_device_scale ⇒ Object
897 898 899 900 901 902 903 904 905 |
# File 'ext/cairo/rb_cairo_surface.c', line 897
static VALUE
cr_surface_set_device_scale (VALUE self, VALUE x_scale, VALUE y_scale)
{
cairo_surface_set_device_scale (_SELF,
NUM2DBL (x_scale),
NUM2DBL (y_scale));
rb_cairo_surface_check_status (_SELF);
return self;
}
|
#set_fallback_resolution ⇒ Object
917 918 919 920 921 922 923 924 925 926 927 |
# File 'ext/cairo/rb_cairo_surface.c', line 917
static VALUE
cr_surface_set_fallback_resolution (VALUE self,
VALUE x_pixels_per_inch,
VALUE y_pixels_per_inch)
{
cairo_surface_set_fallback_resolution (_SELF,
NUM2DBL (x_pixels_per_inch),
NUM2DBL (y_pixels_per_inch));
rb_cairo_surface_check_status (_SELF);
return self;
}
|
#set_mime_data ⇒ Object
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
# File 'ext/cairo/rb_cairo_surface.c', line 761
static VALUE
cr_surface_set_mime_data (VALUE self, VALUE rb_mime_type, VALUE rb_data)
{
cairo_status_t status;
cairo_surface_t *surface;
const char *mime_type;
surface = _SELF;
mime_type = StringValueCStr (rb_mime_type);
if (NIL_P (rb_data))
{
status = cairo_surface_set_mime_data (surface, mime_type,
NULL, 0, NULL, NULL);
}
else
{
const char *raw_data;
unsigned char *data;
unsigned long length;
raw_data = StringValuePtr (rb_data);
length = RSTRING_LEN (rb_data);
data = xmalloc (length);
memcpy (data, raw_data, length);
status = cairo_surface_set_mime_data (surface, mime_type,
data, length,
xfree, data);
}
rb_cairo_check_status (status);
return Qnil;
}
|
#show_page ⇒ Object
955 956 957 958 959 960 961 |
# File 'ext/cairo/rb_cairo_surface.c', line 955
static VALUE
cr_surface_show_page (VALUE self)
{
cairo_surface_show_page (_SELF);
rb_cairo_surface_check_status (_SELF);
return self;
}
|
#sub_rectangle_surface ⇒ Object
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'ext/cairo/rb_cairo_surface.c', line 670
static VALUE
cr_surface_create_sub_rectangle_surface (VALUE self, VALUE x, VALUE y,
VALUE width, VALUE height)
{
VALUE rb_surface;
cairo_surface_t *surface;
surface = cairo_surface_create_for_rectangle (RVAL2CRSURFACE (self),
NUM2DBL (x),
NUM2DBL (y),
NUM2DBL (width),
NUM2INT (height));
rb_cairo_surface_check_status (surface);
rb_surface = CRSURFACE2RVAL_WITH_DESTROY (surface);
if (rb_block_given_p ())
return rb_ensure (rb_yield, rb_surface,
cr_surface_destroy_with_destroy_check, rb_surface);
else
return rb_surface;
}
|
#supported_mime_type? ⇒ Boolean
795 796 797 798 799 800 801 802 803 804 805 806 |
# File 'ext/cairo/rb_cairo_surface.c', line 795
static VALUE
cr_surface_supported_mime_type_p (VALUE self, VALUE rb_mime_type)
{
cairo_surface_t *surface;
const char *mime_type;
cairo_bool_t supported_p;
surface = _SELF;
mime_type = StringValueCStr (rb_mime_type);
supported_p = cairo_surface_supports_mime_type (surface, mime_type);
return CBOOL2RVAL (supported_p);
}
|
#unmap_image ⇒ Object
657 658 659 660 661 662 663 664 665 666 |
# File 'ext/cairo/rb_cairo_surface.c', line 657
static VALUE
cr_surface_unmap_image (VALUE self, VALUE rb_mapped_image)
{
cairo_surface_t *surface, *mapped_image;
surface = _SELF;
mapped_image = RVAL2CRSURFACE (rb_mapped_image);
cairo_surface_unmap_image (surface, mapped_image);
return Qnil;
}
|
#write_to_png ⇒ Object
734 735 736 737 738 739 740 741 |
# File 'ext/cairo/rb_cairo_surface.c', line 734
static VALUE
cr_surface_write_to_png_generic (VALUE self, VALUE target)
{
if (rb_respond_to (target, rb_cairo__io_id_write))
return cr_surface_write_to_png_stream (self, target);
else
return cr_surface_write_to_png (self, target);
}
|