Class: Cairo::Context

Inherits:
Object
  • Object
show all
Includes:
Color, Blur, Circle, Path, Rectangle, Triangle
Defined in:
lib/cairo/context.rb,
lib/cairo/context/blur.rb,
lib/cairo/context/path.rb,
lib/cairo/context/color.rb,
lib/cairo/context/circle.rb,
lib/cairo/context/triangle.rb,
lib/cairo/context/rectangle.rb,
ext/cairo/rb_cairo_context.c

Defined Under Namespace

Modules: Blur, Circle, Color, Path, Rectangle, Triangle

Constant Summary

Constants included from Color

Cairo::Color::ALICE_BLUE, Cairo::Color::ALIZARIN_CRIMSON, Cairo::Color::AMARANTH, Cairo::Color::AMBER, Cairo::Color::AMETHYST, Cairo::Color::APRICOT, Cairo::Color::AQUA, Cairo::Color::AQUAMARINE, Cairo::Color::ASPARAGUS, Cairo::Color::AZURE, Cairo::Color::BEIGE, Cairo::Color::BISTRE, Cairo::Color::BLACK, Cairo::Color::BLAZE_ORANGE, Cairo::Color::BLUE, Cairo::Color::BONDI_BLUE, Cairo::Color::BRIGHT_GREEN, Cairo::Color::BRIGHT_TURQUOISE, Cairo::Color::BROWN, Cairo::Color::BUFF, Cairo::Color::BURGUNDY, Cairo::Color::BURNT_ORANGE, Cairo::Color::BURNT_SIENNA, Cairo::Color::BURNT_UMBER, Cairo::Color::CAMOUFLAGE_GREEN, Cairo::Color::CARDINAL, Cairo::Color::CARMINE, Cairo::Color::CARNATION, Cairo::Color::CARROT_ORANGE, Cairo::Color::CELADON, Cairo::Color::CERISE, Cairo::Color::CERULEAN, Cairo::Color::CERULEAN_BLUE, Cairo::Color::CHARTREUSE, Cairo::Color::CHARTREUSE_YELLOW, Cairo::Color::CHESTNUT, Cairo::Color::CHOCOLATE, Cairo::Color::CINNAMON, Cairo::Color::COBALT, Cairo::Color::COPPER, Cairo::Color::COPPER_ROSE, Cairo::Color::CORAL, Cairo::Color::CORAL_RED, Cairo::Color::CORN, Cairo::Color::CORNFLOWER_BLUE, Cairo::Color::CREAM, Cairo::Color::CRIMSON, Cairo::Color::CYAN, Cairo::Color::DARK_BLUE, Cairo::Color::DARK_POWDER_BLUE, Cairo::Color::DENIM, Cairo::Color::DODGER_BLUE, Cairo::Color::EGGPLANT, Cairo::Color::EMERALD, Cairo::Color::FALU_RED, Cairo::Color::FERN_GREEN, Cairo::Color::FLAX, Cairo::Color::FOREST_GREEN, Cairo::Color::FRENCH_ROSE, Cairo::Color::FUCHSIA, Cairo::Color::GAMBOGE, Cairo::Color::GOLD, Cairo::Color::GOLDENROD, Cairo::Color::GRAY, Cairo::Color::GRAY_ASPARAGUS, Cairo::Color::GREEN, Cairo::Color::GREEN_YELLOW, Cairo::Color::HARLEQUIN, Cairo::Color::HELIOTROPE, Cairo::Color::HEX_RE, Cairo::Color::HOLLYWOOD_CERISE, Cairo::Color::HOT_MAGENTA, Cairo::Color::HOT_PINK, Cairo::Color::INDIGO, Cairo::Color::INTERNATIONAL_KLEIN_BLUE, Cairo::Color::INTERNATIONAL_ORANGE, Cairo::Color::IVORY, Cairo::Color::JADE, Cairo::Color::KHAKI, Cairo::Color::KHAKI_X11, Cairo::Color::LAVENDER, Cairo::Color::LAVENDER_BLUE, Cairo::Color::LAVENDER_BLUSH, Cairo::Color::LAVENDER_GRAY, Cairo::Color::LAVENDER_PINK, Cairo::Color::LAVENDER_ROSE, Cairo::Color::LEMON, Cairo::Color::LEMON_CHIFFON, Cairo::Color::LILAC, Cairo::Color::LIME, Cairo::Color::LINEN, Cairo::Color::MAGENTA, Cairo::Color::MALACHITE, Cairo::Color::MAROON, Cairo::Color::MAUVE, Cairo::Color::MEDIUM_CARMINE, Cairo::Color::MEDIUM_LAVENDER, Cairo::Color::MEDIUM_PURPLE, Cairo::Color::MIDNIGHT_BLUE, Cairo::Color::MINT_GREEN, Cairo::Color::MOSS_GREEN, Cairo::Color::MOUNTBATTEN_PINK, Cairo::Color::MUSTARD, Cairo::Color::NAVAJO_WHITE, Cairo::Color::NAVY_BLUE, Cairo::Color::OCHRE, Cairo::Color::OLD_GOLD, Cairo::Color::OLD_LACE, Cairo::Color::OLD_LAVENDER, Cairo::Color::OLD_ROSE, Cairo::Color::OLIVE, Cairo::Color::OLIVE_DRAB, Cairo::Color::ORANGE, Cairo::Color::ORANGE_COLOR_WHEEL, Cairo::Color::ORANGE_PEEL, Cairo::Color::ORANGE_WEB, Cairo::Color::ORCHID, Cairo::Color::PAPAYA_WHIP, Cairo::Color::PASTEL_GREEN, Cairo::Color::PASTEL_PINK, Cairo::Color::PEACH, Cairo::Color::PEACH_ORANGE, Cairo::Color::PEACH_YELLOW, Cairo::Color::PEAR, Cairo::Color::PERIWINKLE, Cairo::Color::PERSIAN_BLUE, Cairo::Color::PERSIAN_GREEN, Cairo::Color::PERSIAN_INDIGO, Cairo::Color::PERSIAN_PINK, Cairo::Color::PERSIAN_RED, Cairo::Color::PERSIAN_ROSE, Cairo::Color::PINE_GREEN, Cairo::Color::PINK, Cairo::Color::PINK_ORANGE, Cairo::Color::POMEGRANATE, Cairo::Color::POWDER_BLUE_WEB, Cairo::Color::PRUSSIAN_BLUE, Cairo::Color::PUCE, Cairo::Color::PUMPKIN, Cairo::Color::PURPLE, Cairo::Color::RAW_UMBER, Cairo::Color::RED, Cairo::Color::RED_VIOLET, Cairo::Color::ROBIN_EGG_BLUE, Cairo::Color::ROSE, Cairo::Color::ROYAL_BLUE, Cairo::Color::RUSSET, Cairo::Color::RUST, Cairo::Color::SAFETY_ORANGE, Cairo::Color::SAFFRON, Cairo::Color::SALMON, Cairo::Color::SANDY_BROWN, Cairo::Color::SANGRIA, Cairo::Color::SAPPHIRE, Cairo::Color::SCARLET, Cairo::Color::SCHOOL_BUS_YELLOW, Cairo::Color::SEASHELL, Cairo::Color::SEA_GREEN, Cairo::Color::SELECTIVE_YELLOW, Cairo::Color::SEPIA, Cairo::Color::SHOCKING_PINK, Cairo::Color::SILVER, Cairo::Color::SLATE_GRAY, Cairo::Color::SMALT, Cairo::Color::SPRING_GREEN, Cairo::Color::STEEL_BLUE, Cairo::Color::SWAMP_GREEN, Cairo::Color::TAN, Cairo::Color::TANGERINE, Cairo::Color::TAUPE, Cairo::Color::TAWNY, Cairo::Color::TEAL, Cairo::Color::TEA_GREEN, Cairo::Color::TENNE, Cairo::Color::TERRA_COTTA, Cairo::Color::THISTLE, Cairo::Color::TURQUOISE, Cairo::Color::ULTRAMARINE, Cairo::Color::VERMILION, Cairo::Color::VIOLET, Cairo::Color::VIOLET_EGGPLANT, Cairo::Color::VIRIDIAN, Cairo::Color::WHEAT, Cairo::Color::WHITE, Cairo::Color::WISTERIA, Cairo::Color::YELLOW, Cairo::Color::ZINNWALDITE

Constants included from Cairo::Color::X11

Cairo::Color::X11::ALICE_BLUE, Cairo::Color::X11::ANTIQUE_WHITE, Cairo::Color::X11::AQUA, Cairo::Color::X11::AQUAMARINE, Cairo::Color::X11::AZURE, Cairo::Color::X11::BEIGE, Cairo::Color::X11::BISQUE, Cairo::Color::X11::BLACK, Cairo::Color::X11::BLANCHED_ALMOND, Cairo::Color::X11::BLUE, Cairo::Color::X11::BLUE_VIOLET, Cairo::Color::X11::BROWN, Cairo::Color::X11::BURLY_WOOD, Cairo::Color::X11::CADET_BLUE, Cairo::Color::X11::CHARTREUSE, Cairo::Color::X11::CHOCOLATE, Cairo::Color::X11::CORAL, Cairo::Color::X11::CORNFLOWER_BLUE, Cairo::Color::X11::CORNSILK, Cairo::Color::X11::CRIMSON, Cairo::Color::X11::CYAN, Cairo::Color::X11::DARK_BLUE, Cairo::Color::X11::DARK_CYAN, Cairo::Color::X11::DARK_GOLDENROD, Cairo::Color::X11::DARK_GRAY, Cairo::Color::X11::DARK_GREEN, Cairo::Color::X11::DARK_KHAKI, Cairo::Color::X11::DARK_MAGENTA, Cairo::Color::X11::DARK_OLIVE_GREEN, Cairo::Color::X11::DARK_ORANGE, Cairo::Color::X11::DARK_ORCHID, Cairo::Color::X11::DARK_RED, Cairo::Color::X11::DARK_SALMON, Cairo::Color::X11::DARK_SEA_GREEN, Cairo::Color::X11::DARK_SLATE_BLUE, Cairo::Color::X11::DARK_SLATE_GRAY, Cairo::Color::X11::DARK_TURQUOISE, Cairo::Color::X11::DARK_VIOLET, Cairo::Color::X11::DEEP_PINK, Cairo::Color::X11::DEEP_SKY_BLUE, Cairo::Color::X11::DIM_GRAY, Cairo::Color::X11::DODGER_BLUE, Cairo::Color::X11::FIRE_BRICK, Cairo::Color::X11::FLORAL_WHITE, Cairo::Color::X11::FOREST_GREEN, Cairo::Color::X11::FUCHSIA, Cairo::Color::X11::GAINSBORO, Cairo::Color::X11::GHOST_WHITE, Cairo::Color::X11::GOLD, Cairo::Color::X11::GOLDENROD, Cairo::Color::X11::GRAY, Cairo::Color::X11::GREEN, Cairo::Color::X11::GREEN_YELLOW, Cairo::Color::X11::HONEYDEW, Cairo::Color::X11::HOT_PINK, Cairo::Color::X11::INDIAN_RED, Cairo::Color::X11::INDIGO, Cairo::Color::X11::IVORY, Cairo::Color::X11::KHAKI, Cairo::Color::X11::LAVENDER, Cairo::Color::X11::LAVENDER_BLUSH, Cairo::Color::X11::LAWN_GREEN, Cairo::Color::X11::LEMON_CHIFFON, Cairo::Color::X11::LIGHT_BLUE, Cairo::Color::X11::LIGHT_CORAL, Cairo::Color::X11::LIGHT_CYAN, Cairo::Color::X11::LIGHT_GOLDENROD_YELLOW, Cairo::Color::X11::LIGHT_GREEN, Cairo::Color::X11::LIGHT_GREY, Cairo::Color::X11::LIGHT_PINK, Cairo::Color::X11::LIGHT_SALMON, Cairo::Color::X11::LIGHT_SEA_GREEN, Cairo::Color::X11::LIGHT_SKY_BLUE, Cairo::Color::X11::LIGHT_SLATE_GRAY, Cairo::Color::X11::LIGHT_STEEL_BLUE, Cairo::Color::X11::LIGHT_YELLOW, Cairo::Color::X11::LIME, Cairo::Color::X11::LIME_GREEN, Cairo::Color::X11::LINEN, Cairo::Color::X11::MAGENTA, Cairo::Color::X11::MAROON, Cairo::Color::X11::MEDIUM_AQUAMARINE, Cairo::Color::X11::MEDIUM_BLUE, Cairo::Color::X11::MEDIUM_ORCHID, Cairo::Color::X11::MEDIUM_PURPLE, Cairo::Color::X11::MEDIUM_SEA_GREEN, Cairo::Color::X11::MEDIUM_SLATE_BLUE, Cairo::Color::X11::MEDIUM_SPRING_GREEN, Cairo::Color::X11::MEDIUM_TURQUOISE, Cairo::Color::X11::MEDIUM_VIOLET_RED, Cairo::Color::X11::MIDNIGHT_BLUE, Cairo::Color::X11::MINT_CREAM, Cairo::Color::X11::MISTY_ROSE, Cairo::Color::X11::MOCCASIN, Cairo::Color::X11::NAVAJO_WHITE, Cairo::Color::X11::OLD_LACE, Cairo::Color::X11::OLIVE, Cairo::Color::X11::OLIVE_DRAB, Cairo::Color::X11::ORANGE, Cairo::Color::X11::ORANGE_RED, Cairo::Color::X11::ORCHID, Cairo::Color::X11::PALE_GOLDENROD, Cairo::Color::X11::PALE_GREEN, Cairo::Color::X11::PALE_TURQUOISE, Cairo::Color::X11::PALE_VIOLET_RED, Cairo::Color::X11::PAPAYA_WHIP, Cairo::Color::X11::PEACH_PUFF, Cairo::Color::X11::PERU, Cairo::Color::X11::PINK, Cairo::Color::X11::PLUM, Cairo::Color::X11::POWDER_BLUE, Cairo::Color::X11::PURPLE, Cairo::Color::X11::RED, Cairo::Color::X11::ROSY_BROWN, Cairo::Color::X11::ROYAL_BLUE, Cairo::Color::X11::SADDLE_BROWN, Cairo::Color::X11::SALMON, Cairo::Color::X11::SANDY_BROWN, Cairo::Color::X11::SEASHELL, Cairo::Color::X11::SEA_GREEN, Cairo::Color::X11::SIENNA, Cairo::Color::X11::SILVER, Cairo::Color::X11::SKY_BLUE, Cairo::Color::X11::SLATE_BLUE, Cairo::Color::X11::SLATE_GRAY, Cairo::Color::X11::SNOW, Cairo::Color::X11::SPRING_GREEN, Cairo::Color::X11::STEEL_BLUE, Cairo::Color::X11::TAN, Cairo::Color::X11::TEAL, Cairo::Color::X11::THISTLE, Cairo::Color::X11::TOMATO, Cairo::Color::X11::TURQUOISE, Cairo::Color::X11::VIOLET, Cairo::Color::X11::WHEAT, Cairo::Color::X11::WHITE, Cairo::Color::X11::WHITE_SMOKE, Cairo::Color::X11::YELLOW, Cairo::Color::X11::YELLOW_GREEN

Instance Method Summary collapse

Methods included from Color

parse, parse_hex_color

Methods included from Blur

#pseudo_blur

Methods included from Path

#map_path_onto, #transform_path

Methods included from Circle

#circle

Methods included from Triangle

#triangle

Methods included from Rectangle

#rounded_rectangle

Constructor Details

#initializeObject

Functions for manipulating state objects



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'ext/cairo/rb_cairo_context.c', line 148

static VALUE
cr_initialize (VALUE self, VALUE target)
{
  cairo_t *cr;
  VALUE result = Qnil;

  cr = cairo_create (RVAL2CRSURFACE (target));
  cr_check_status (cr);
  rb_ivar_set (self, cr_id_surface, target);
  cr_set_user_data (cr,
                    &cr_object_holder_key,
                    cr_object_holder_new(self),
                    cr_object_holder_free);
  DATA_PTR (self) = cr;
  if (rb_block_given_p ())
    result = rb_ensure (rb_yield, self, cr_destroy_with_destroy_check, self);
  return result;
}

Instance Method Details

#antialiasObject



1365
1366
1367
1368
1369
# File 'ext/cairo/rb_cairo_context.c', line 1365

static VALUE
cr_get_antialias(VALUE self)
{
  return INT2NUM (cairo_get_antialias (_SELF));
}

#append_pathObject



1502
1503
1504
1505
1506
1507
1508
# File 'ext/cairo/rb_cairo_context.c', line 1502

static VALUE
cr_copy_append_path (VALUE self, VALUE path)
{
  cairo_append_path (_SELF, RVAL2CRPATH (path));
  cr_check_status (_SELF);
  return self;
}

#arcObject



707
708
709
710
711
712
713
714
715
# File 'ext/cairo/rb_cairo_context.c', line 707

static VALUE
cr_arc (VALUE self, VALUE xc, VALUE yc, VALUE radius,
        VALUE angle1, VALUE angle2)
{
  cairo_arc (_SELF, NUM2DBL (xc), NUM2DBL (yc), NUM2DBL (radius),
             NUM2DBL (angle1), NUM2DBL (angle2));
  cr_check_status (_SELF);
  return self;
}

#arc_negativeObject



717
718
719
720
721
722
723
724
725
# File 'ext/cairo/rb_cairo_context.c', line 717

static VALUE
cr_arc_negative (VALUE self, VALUE xc, VALUE yc, VALUE radius,
                 VALUE angle1, VALUE angle2)
{
  cairo_arc_negative (_SELF, NUM2DBL (xc), NUM2DBL (yc), NUM2DBL (radius),
                      NUM2DBL (angle1), NUM2DBL (angle2));
  cr_check_status (_SELF);
  return self;
}

#clipObject



1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
# File 'ext/cairo/rb_cairo_context.c', line 1036

static VALUE
cr_clip (int argc, VALUE *argv, VALUE self)
{
  VALUE preserve;

  rb_scan_args(argc, argv, "01", &preserve);

  if (rb_block_given_p ())
    {
      cr_new_path (self);
      rb_yield (self);
    }

  if (RVAL2CBOOL (preserve))
    cairo_clip_preserve(_SELF);
  else
    cairo_clip (_SELF);

  cr_check_status (_SELF);
  return self;
}

#clip_extentsObject



1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
# File 'ext/cairo/rb_cairo_context.c', line 1059

static VALUE
cr_clip_extents (VALUE self)
{
  double x1, y1, x2, y2;
  cairo_clip_extents (_SELF, &x1, &y1, &x2, &y2);
  cr_check_status (_SELF);
  return rb_ary_new3 (4,
                      rb_float_new (x1), rb_float_new (y1),
                      rb_float_new (x2), rb_float_new (y2));
}

#clip_preserve(&block) ⇒ Object



25
26
27
# File 'lib/cairo/context.rb', line 25

def clip_preserve(&block)
  clip(true, &block)
end

#clip_rectangle_listObject



1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
# File 'ext/cairo/rb_cairo_context.c', line 1070

static VALUE
cr_clip_rectangle_list (VALUE self)
{
  VALUE rb_rectangles;
  cairo_rectangle_list_t *rectangles;
  int i;

  rectangles = cairo_copy_clip_rectangle_list (_SELF);
  rb_cairo_check_status (rectangles->status);

  rb_rectangles = rb_ary_new2 (rectangles->num_rectangles);
  for (i = 0; i < rectangles->num_rectangles; i++) {
    VALUE argv[4];
    cairo_rectangle_t rectangle = rectangles->rectangles[i];

    argv[0] = rb_float_new (rectangle.x);
    argv[1] = rb_float_new (rectangle.y);
    argv[2] = rb_float_new (rectangle.width);
    argv[3] = rb_float_new (rectangle.height);
    rb_ary_push (rb_rectangles,
                 rb_class_new_instance (4, argv, rb_cCairo_Rectangle));
  }
  cairo_rectangle_list_destroy (rectangles);

  return rb_rectangles;
}

#close_pathObject



802
803
804
805
806
807
808
# File 'ext/cairo/rb_cairo_context.c', line 802

static VALUE
cr_close_path (VALUE self)
{
  cairo_close_path (_SELF);
  cr_check_status (_SELF);
  return self;
}

#copy_pageObject



948
949
950
951
952
953
954
# File 'ext/cairo/rb_cairo_context.c', line 948

static VALUE
cr_copy_page (VALUE self)
{
  cairo_copy_page (_SELF);
  cr_check_status (_SELF);
  return self;
}

#copy_pathObject

Paths



1482
1483
1484
1485
1486
1487
1488
1489
1490
# File 'ext/cairo/rb_cairo_context.c', line 1482

static VALUE
cr_copy_path (VALUE self)
{
  cairo_path_t *path;

  path = cairo_copy_path (_SELF);
  rb_cairo_check_status (path->status);
  return CRPATH2RVAL (path);
}

#copy_path_flatObject



1492
1493
1494
1495
1496
1497
1498
1499
1500
# File 'ext/cairo/rb_cairo_context.c', line 1492

static VALUE
cr_copy_path_flat (VALUE self)
{
  cairo_path_t *path;

  path =  cairo_copy_path_flat (_SELF);
  rb_cairo_check_status (path->status);
  return CRPATH2RVAL (path);
}

#current_pointObject



1379
1380
1381
1382
1383
1384
1385
# File 'ext/cairo/rb_cairo_context.c', line 1379

static VALUE
cr_get_current_point (VALUE self)
{
  double point[2];
  cairo_get_current_point (_SELF, point, point + 1);
  return rb_cairo__float_array (point, 2);
}

#curve_toObject



684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
# File 'ext/cairo/rb_cairo_context.c', line 684

static VALUE
cr_curve_to_generic (int argc, VALUE *argv, VALUE self)
{
  VALUE x1, y1, x2, y2, x3, y3;

  rb_scan_args (argc, argv, "42", &x1, &y1, &x2, &y2, &x3, &y3);

  if (!(argc == 4 || argc == 6))
    {
      VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
      rb_raise (rb_eArgError,
                "invalid argument: %s (expect "
                "(x1, y1, x2, y2) (quadratic) or "
                "(x1, y1, x2, y2, x3, y3) (cubic))",
                StringValuePtr (inspected_arg));
    }

  if (argc == 4)
    return cr_quadratic_curve_to (self, x1, y1, x2, y2);
  else
    return cr_curve_to (self, x1, y1, x2, y2, x3, y3);
}

#dashObject



1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
# File 'ext/cairo/rb_cairo_context.c', line 1424

static VALUE
cr_get_dash (VALUE self)
{
  int count;
  double *dashes, offset;

  count = cairo_get_dash_count (_SELF);
  dashes = ALLOCA_N (double, count);
  cairo_get_dash (_SELF, dashes, &offset);

  return rb_ary_new3 (2,
                      rb_cairo__float_array (dashes, count),
                      rb_float_new (offset));
}

#dash_countObject



1418
1419
1420
1421
1422
# File 'ext/cairo/rb_cairo_context.c', line 1418

static VALUE
cr_get_dash_count (VALUE self)
{
  return INT2NUM (cairo_get_dash_count (_SELF));
}

#destroyObject



127
128
129
130
131
132
133
134
135
136
137
138
# File 'ext/cairo/rb_cairo_context.c', line 127

static VALUE
cr_destroy (VALUE self)
{
  cairo_t *cr;

  cr = _SELF;
  cr_set_user_data (cr, &cr_object_holder_key, NULL, NULL);
  cairo_destroy (cr);

  DATA_PTR (self) = NULL;
  return Qnil;
}

#device_to_userObject



588
589
590
591
592
593
594
595
596
597
# File 'ext/cairo/rb_cairo_context.c', line 588

static VALUE
cr_device_to_user (VALUE self, VALUE x, VALUE y)
{
  double pair[2];
  pair[0] = NUM2DBL (x);
  pair[1] = NUM2DBL (y);
  cairo_device_to_user (_SELF, pair, pair + 1);
  cr_check_status (_SELF);
  return rb_cairo__float_array (pair, 2);
}

#device_to_user_distanceObject



599
600
601
602
603
604
605
606
607
608
# File 'ext/cairo/rb_cairo_context.c', line 599

static VALUE
cr_device_to_user_distance (VALUE self, VALUE dx, VALUE dy)
{
  double pair[2];
  pair[0] = NUM2DBL (dx);
  pair[1] = NUM2DBL (dy);
  cairo_device_to_user_distance (_SELF, pair, pair + 1);
  cr_check_status (_SELF);
  return rb_cairo__float_array (pair, 2);
}

#fillObject



925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
# File 'ext/cairo/rb_cairo_context.c', line 925

static VALUE
cr_fill (int argc, VALUE *argv, VALUE self)
{
  VALUE preserve;

  rb_scan_args (argc, argv, "01", &preserve);

  if (rb_block_given_p ())
    {
      cr_new_path (self);
      rb_yield (self);
    }

  if (RVAL2CBOOL (preserve))
    cairo_fill_preserve (_SELF);
  else
    cairo_fill (_SELF);

  cr_check_status (_SELF);
  return self;
}

#fill_extentsObject



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
# File 'ext/cairo/rb_cairo_context.c', line 1014

static VALUE
cr_fill_extents (VALUE self)
{
  double extents[4];
  if (rb_block_given_p ())
    {
      cr_new_path (self);
      rb_yield (self);
    }
  cairo_fill_extents (_SELF, extents, extents + 1, extents + 2, extents + 3);
  return rb_cairo__float_array (extents, 4);
}

#fill_preserve(&block) ⇒ Object



21
22
23
# File 'lib/cairo/context.rb', line 21

def fill_preserve(&block)
  fill(true, &block)
end

#fill_ruleObject



1387
1388
1389
1390
1391
# File 'ext/cairo/rb_cairo_context.c', line 1387

static VALUE
cr_get_fill_rule (VALUE self)
{
  return INT2FIX (cairo_get_fill_rule (_SELF));
}

#font_extentsObject



1266
1267
1268
1269
1270
1271
1272
1273
# File 'ext/cairo/rb_cairo_context.c', line 1266

static VALUE
cr_font_extents (VALUE self)
{
  cairo_font_extents_t extents;
  cairo_font_extents (_SELF, &extents);
  cr_check_status (_SELF);
  return CRFONTEXTENTS2RVAL (&extents);
}

#font_faceObject



1256
1257
1258
1259
1260
1261
1262
1263
1264
# File 'ext/cairo/rb_cairo_context.c', line 1256

static VALUE
cr_get_font_face (VALUE self)
{
  cairo_font_face_t *face;

  face = cairo_get_font_face (_SELF);
  rb_cairo_check_status (cairo_font_face_status (face));
  return CRFONTFACE2RVAL (face);
}

#font_matrixObject



1159
1160
1161
1162
1163
1164
1165
1166
# File 'ext/cairo/rb_cairo_context.c', line 1159

static VALUE
cr_get_font_matrix (VALUE self)
{
  cairo_matrix_t matrix;
  cairo_get_font_matrix (_SELF, &matrix);
  cr_check_status (_SELF);
  return CRMATRIX2RVAL (&matrix);
}

#font_optionsObject



1176
1177
1178
1179
1180
1181
1182
1183
1184
# File 'ext/cairo/rb_cairo_context.c', line 1176

static VALUE
cr_get_font_options (VALUE self)
{
  cairo_font_options_t *options = cairo_font_options_create ();
  rb_cairo_check_status (cairo_font_options_status (options));
  cairo_get_font_options (_SELF, options);
  rb_cairo_check_status (cairo_font_options_status (options));
  return CRFONTOPTIONS2RVAL (options);
}

#glyph_extentsObject



1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
# File 'ext/cairo/rb_cairo_context.c', line 1292

static VALUE
cr_glyph_extents (VALUE self, VALUE rb_glyphs)
{
  cairo_text_extents_t extents;
  cairo_glyph_t *glyphs;
  int length;

  RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, length);
  cairo_glyph_extents (_SELF, glyphs, length, &extents);
  cr_check_status (_SELF);
  return CRTEXTEXTENTS2RVAL (&extents);
}

#glyph_pathObject



1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
# File 'ext/cairo/rb_cairo_context.c', line 1313

static VALUE
cr_glyph_path (VALUE self, VALUE rb_glyphs)
{
  int count;
  cairo_glyph_t *glyphs;

  RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, count);
  cairo_glyph_path (_SELF, glyphs, count);
  cr_check_status (_SELF);

  return self;
}

#group_targetObject



1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
# File 'ext/cairo/rb_cairo_context.c', line 1469

static VALUE
cr_get_group_target (VALUE self)
{
  cairo_surface_t *surface;

  surface = cairo_get_group_target (_SELF);
  if (!surface)
    return Qnil;
  rb_cairo_check_status (cairo_surface_status (surface));
  return CRSURFACE2RVAL (surface);
}

#have_current_point?Boolean Also known as: has_current_point?

Returns:

  • (Boolean)


1372
1373
1374
1375
1376
# File 'ext/cairo/rb_cairo_context.c', line 1372

static VALUE
cr_has_current_point(VALUE self)
{
  return RTEST (cairo_has_current_point (_SELF));
}

#identity_matrixObject



558
559
560
561
562
563
564
# File 'ext/cairo/rb_cairo_context.c', line 558

static VALUE
cr_identity_matrix (VALUE self)
{
  cairo_identity_matrix (_SELF);
  cr_check_status (_SELF);
  return self;
}

#in_clip?Boolean

Returns:

  • (Boolean)


988
989
990
991
992
993
994
995
996
997
# File 'ext/cairo/rb_cairo_context.c', line 988

static VALUE
cr_in_clip (VALUE self, VALUE x, VALUE y)
{
  if (rb_block_given_p ())
    {
      cr_new_path (self);
      rb_yield (self);
    }
  return CBOOL2RVAL (cairo_in_clip (_SELF, NUM2DBL (x), NUM2DBL (y)));
}

#in_fill?Boolean

Returns:

  • (Boolean)


976
977
978
979
980
981
982
983
984
985
# File 'ext/cairo/rb_cairo_context.c', line 976

static VALUE
cr_in_fill (VALUE self, VALUE x, VALUE y)
{
  if (rb_block_given_p ())
    {
      cr_new_path (self);
      rb_yield (self);
    }
  return CBOOL2RVAL (cairo_in_fill (_SELF, NUM2DBL (x), NUM2DBL (y)));
}

#in_stroke?Boolean

Insideness testing

Returns:

  • (Boolean)


965
966
967
968
969
970
971
972
973
974
# File 'ext/cairo/rb_cairo_context.c', line 965

static VALUE
cr_in_stroke (VALUE self, VALUE x, VALUE y)
{
  if (rb_block_given_p ())
    {
      cr_new_path (self);
      rb_yield (self);
    }
  return CBOOL2RVAL (cairo_in_stroke (_SELF, NUM2DBL (x), NUM2DBL (y)));
}

#line_capObject



1399
1400
1401
1402
1403
# File 'ext/cairo/rb_cairo_context.c', line 1399

static VALUE
cr_get_line_cap (VALUE self)
{
  return INT2FIX (cairo_get_line_cap (_SELF));
}

#line_joinObject



1405
1406
1407
1408
1409
# File 'ext/cairo/rb_cairo_context.c', line 1405

static VALUE
cr_get_line_join (VALUE self)
{
  return INT2FIX (cairo_get_line_join (_SELF));
}

#line_toObject



636
637
638
639
640
641
642
# File 'ext/cairo/rb_cairo_context.c', line 636

static VALUE
cr_line_to (VALUE self, VALUE x, VALUE y)
{
  cairo_line_to (_SELF, NUM2DBL (x), NUM2DBL (y));
  cr_check_status (_SELF);
  return self;
}

#line_widthObject



1393
1394
1395
1396
1397
# File 'ext/cairo/rb_cairo_context.c', line 1393

static VALUE
cr_get_line_width (VALUE self)
{
  return rb_float_new (cairo_get_line_width (_SELF));
}

#maskObject



880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
# File 'ext/cairo/rb_cairo_context.c', line 880

static VALUE
cr_mask_generic (int argc, VALUE *argv, VALUE self)
{
  VALUE arg1, arg2, arg3;
  int n;

  n = rb_scan_args (argc, argv, "12", &arg1, &arg2, &arg3);

  if (n == 1)
    {
      return cr_mask (self, arg1);
    }
  else if (n == 3)
    {
      return cr_mask_surface (self, arg1, arg2, arg3);
    }
  else
    {
      rb_raise (rb_eArgError,
                "invalid argument (expect (pattern) or (surface, x, y))");
    }
}

#matrixObject



1440
1441
1442
1443
1444
1445
1446
1447
# File 'ext/cairo/rb_cairo_context.c', line 1440

static VALUE
cr_get_matrix (VALUE self)
{
  cairo_matrix_t matrix;
  cairo_get_matrix (_SELF, &matrix);
  cr_check_status (_SELF);
  return CRMATRIX2RVAL (&matrix);
}

#miter_limitObject



1411
1412
1413
1414
1415
# File 'ext/cairo/rb_cairo_context.c', line 1411

static VALUE
cr_get_miter_limit (VALUE self)
{
  return rb_float_new (cairo_get_miter_limit (_SELF));
}

#move_toObject



620
621
622
623
624
625
626
# File 'ext/cairo/rb_cairo_context.c', line 620

static VALUE
cr_move_to (VALUE self, VALUE x, VALUE y)
{
  cairo_move_to (_SELF, NUM2DBL (x), NUM2DBL (y));
  cr_check_status (_SELF);
  return self;
}

#new_pathObject

Path creation functions



612
613
614
615
616
617
618
# File 'ext/cairo/rb_cairo_context.c', line 612

static VALUE
cr_new_path (VALUE self)
{
  cairo_new_path (_SELF);
  cr_check_status (_SELF);
  return self;
}

#new_sub_pathObject



628
629
630
631
632
633
634
# File 'ext/cairo/rb_cairo_context.c', line 628

static VALUE
cr_new_sub_path (VALUE self)
{
  cairo_new_sub_path (_SELF);
  cr_check_status (_SELF);
  return self;
}

#operatorObject

Query functions



1327
1328
1329
1330
1331
# File 'ext/cairo/rb_cairo_context.c', line 1327

static VALUE
cr_get_operator (VALUE self)
{
  return INT2FIX (cairo_get_operator (_SELF));
}

#paint(*args) ⇒ Object

Painting functions



840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
# File 'ext/cairo/rb_cairo_context.c', line 840

static VALUE
cr_paint_generic(int argc, VALUE *argv, VALUE self)
{
  VALUE alpha;
  int n;

  n = rb_scan_args (argc, argv, "01", &alpha);

  if (n == 0 || (n == 1 && NIL_P (alpha)))
    {
      return cr_paint (self);
    }
  if (n == 1)
    {
      return cr_paint_with_alpha (self, alpha);
    }
  else
    {
      rb_raise (rb_eArgError,
                "invalid argument (expect () or (alpha))");
    }
}

#path_extentsObject



811
812
813
814
815
816
817
818
819
820
# File 'ext/cairo/rb_cairo_context.c', line 811

static VALUE
cr_path_extents (VALUE self)
{
  double x1, y1, x2, y2;
  cairo_path_extents (_SELF, &x1, &y1, &x2, &y2);
  cr_check_status (_SELF);
  return rb_ary_new3 (4,
                      rb_float_new(x1), rb_float_new(y1),
                      rb_float_new(x2), rb_float_new(y2));
}

#pop_groupObject



209
210
211
212
213
214
215
216
217
218
# File 'ext/cairo/rb_cairo_context.c', line 209

static VALUE
cr_pop_group_generic (int argc, VALUE *argv, VALUE self)
{
  VALUE to_source;
  rb_scan_args (argc, argv, "01", &to_source);
  if (RVAL2CBOOL (to_source))
    return cr_pop_group_to_source (self);
  else
    return cr_pop_group (self);
}

#pop_group_to_sourceObject



201
202
203
204
205
206
207
# File 'ext/cairo/rb_cairo_context.c', line 201

static VALUE
cr_pop_group_to_source (VALUE self)
{
  cairo_pop_group_to_source (_SELF);
  cr_check_status (_SELF);
  return Qnil;
}

#push_groupObject



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'ext/cairo/rb_cairo_context.c', line 220

static VALUE
cr_push_group (int argc, VALUE *argv, VALUE self)
{
  VALUE result = Qnil;
  VALUE content, pop_to_source;
  rb_scan_args (argc, argv, "02", &content, &pop_to_source);

  if (NIL_P(content))
    cairo_push_group (_SELF);
  else
    cairo_push_group_with_content (_SELF, RVAL2CRCONTENT(content));
  cr_check_status (_SELF);

  if (rb_block_given_p ())
    {
      int state = 0;

      if (NIL_P (pop_to_source))
        pop_to_source = Qtrue;

      result = rb_protect (rb_yield, self, &state);
      if (cairo_status(_SELF) == CAIRO_STATUS_SUCCESS)
        {
          if (RVAL2CBOOL (pop_to_source))
            cr_pop_group_to_source (self);
          else
            result = cr_pop_group (self);
        }

      if (state)
        rb_jump_tag (state);
    }

  return result;
}

#rectangleObject



793
794
795
796
797
798
799
800
# File 'ext/cairo/rb_cairo_context.c', line 793

static VALUE
cr_rectangle (VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
{
  cairo_rectangle (_SELF, NUM2DBL (x), NUM2DBL (y),
                   NUM2DBL (width), NUM2DBL (height));
  cr_check_status (_SELF);
  return self;
}

#rel_curve_toObject



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_context.c', line 770

static VALUE
cr_rel_curve_to_generic (int argc, VALUE *argv, VALUE self)
{
  VALUE dx1, dy1, dx2, dy2, dx3, dy3;

  rb_scan_args (argc, argv, "42", &dx1, &dy1, &dx2, &dy2, &dx3, &dy3);

  if (!(argc == 4 || argc == 6))
    {
      VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
      rb_raise (rb_eArgError,
                "invalid argument: %s (expect "
                "(dx1, dy1, dx2, dy2) (quadratic) or "
                "(dx1, dy1, dx2, dy2, dx3, dy3) (cubic))",
                StringValuePtr (inspected_arg));
    }

  if (argc == 4)
    return cr_rel_quadratic_curve_to (self, dx1, dy1, dx2, dy2);
  else
    return cr_rel_curve_to (self, dx1, dy1, dx2, dy2, dx3, dy3);
}

#rel_line_toObject



735
736
737
738
739
740
741
# File 'ext/cairo/rb_cairo_context.c', line 735

static VALUE
cr_rel_line_to (VALUE self, VALUE x, VALUE y)
{
  cairo_rel_line_to (_SELF, NUM2DBL (x), NUM2DBL (y));
  cr_check_status (_SELF);
  return self;
}

#rel_move_toObject



727
728
729
730
731
732
733
# File 'ext/cairo/rb_cairo_context.c', line 727

static VALUE
cr_rel_move_to (VALUE self, VALUE x, VALUE y)
{
  cairo_rel_move_to (_SELF, NUM2DBL (x), NUM2DBL (y));
  cr_check_status (_SELF);
  return self;
}

#reset_clipObject

Clipping



1028
1029
1030
1031
1032
1033
1034
# File 'ext/cairo/rb_cairo_context.c', line 1028

static VALUE
cr_reset_clip (VALUE self)
{
  cairo_reset_clip (_SELF);
  cr_check_status (_SELF);
  return self;
}

#restoreObject



167
168
169
170
171
172
173
# File 'ext/cairo/rb_cairo_context.c', line 167

static VALUE
cr_restore (VALUE self)
{
  cairo_restore (_SELF);
  cr_check_status (_SELF);
  return Qnil;
}

#rotateObject



534
535
536
537
538
539
540
# File 'ext/cairo/rb_cairo_context.c', line 534

static VALUE
cr_rotate (VALUE self, VALUE radians)
{
  cairo_rotate (_SELF, NUM2DBL (radians));
  cr_check_status (_SELF);
  return self;
}

#saveObject



175
176
177
178
179
180
181
182
183
184
185
186
# File 'ext/cairo/rb_cairo_context.c', line 175

static VALUE
cr_save (VALUE self)
{
  VALUE result = Qnil;
  cairo_save (_SELF);
  cr_check_status (_SELF);
  if (rb_block_given_p ())
    {
      result = rb_ensure (rb_yield, self, cr_restore, self);
    }
  return result;
}

#scaleObject



526
527
528
529
530
531
532
# File 'ext/cairo/rb_cairo_context.c', line 526

static VALUE
cr_scale (VALUE self, VALUE sx, VALUE sy)
{
  cairo_scale (_SELF, NUM2DBL (sx), NUM2DBL (sy));
  cr_check_status (_SELF);
  return self;
}

#scaled_fontObject



1195
1196
1197
1198
1199
# File 'ext/cairo/rb_cairo_context.c', line 1195

static VALUE
cr_get_scaled_font (VALUE self)
{
  return CRSCALEDFONT2RVAL (cairo_get_scaled_font (_SELF));
}

#select_font_faceObject

Font/Text functions



1099
1100
1101
1102
1103
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
# File 'ext/cairo/rb_cairo_context.c', line 1099

static   VALUE
cr_select_font_face (int argc, VALUE *argv, VALUE self)
{
  VALUE rb_family, rb_slant, rb_weight;
  const char *family;
  cairo_font_slant_t slant;
  cairo_font_weight_t weight;

  rb_scan_args(argc, argv, "03", &rb_family, &rb_slant, &rb_weight);

  if (NIL_P (rb_family))
    {
      family = "";
    }
  else if (rb_cairo__is_kind_of (rb_family, rb_cString))
    {
      family = RSTRING_PTR (rb_family);
    }
  else if (rb_cairo__is_kind_of (rb_family, rb_cSymbol))
    {
      family = rb_id2name (SYM2ID (rb_family));
    }
  else
    {
      rb_raise (rb_eArgError,
                "family name should be nil, String or Symbol: %s",
                rb_cairo__inspect (rb_family));
    }

  if (NIL_P (rb_slant))
    slant = CAIRO_FONT_SLANT_NORMAL;
  else
    slant = RVAL2CRFONTSLANT (rb_slant);

  if (NIL_P (rb_weight))
    weight = CAIRO_FONT_WEIGHT_NORMAL;
  else
    weight = RVAL2CRFONTWEIGHT (rb_weight);

  cairo_select_font_face (_SELF, family, slant, weight);
  cr_check_status (_SELF);
  return self;
}

#set_antialias(antialias) ⇒ Object



420
421
422
423
424
425
426
# File 'ext/cairo/rb_cairo_context.c', line 420

static VALUE
cr_set_antialias(VALUE self, VALUE antialias)
{
  cairo_set_antialias(_SELF, RVAL2CRANTIALIAS (antialias));
  cr_check_status(_SELF);
  return self;
}

#set_dashObject



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'ext/cairo/rb_cairo_context.c', line 459

static VALUE
cr_set_dash (int argc, VALUE *argv, VALUE self)
{
  VALUE dash_array, rb_offset;
  double offset;
  cairo_bool_t is_num;

  rb_scan_args(argc, argv, "11", &dash_array, &rb_offset);

  is_num = rb_cairo__is_kind_of (dash_array, rb_cNumeric);
  if (!(NIL_P (dash_array) || is_num))
    {
      Check_Type (dash_array, T_ARRAY);
    }

  if (NIL_P (rb_offset))
    offset = 0.0;
  else
    offset = NUM2DBL (rb_offset);

  if (is_num)
    {
      double values[1];
      values[0] = NUM2DBL (dash_array);
      cairo_set_dash (_SELF, values, 1, offset);
    }
  else if (NIL_P (dash_array) || RARRAY_LEN (dash_array) == 0)
    {
      cairo_set_dash (_SELF, NULL, 0, offset);
    }
  else
    {
      int i, length;
      double *values;
      length = RARRAY_LEN (dash_array);
      values = ALLOCA_N (double, length);
      if (!values)
        {
          rb_cairo_check_status (CAIRO_STATUS_NO_MEMORY);
        }
      for (i = 0; i < length; i++)
        {
          values[i] = NUM2DBL (RARRAY_PTR (dash_array)[i]);
        }
      cairo_set_dash (_SELF, values, length, offset);
    }

  cr_check_status (_SELF);
  return self;
}

#set_fill_ruleObject



428
429
430
431
432
433
434
# File 'ext/cairo/rb_cairo_context.c', line 428

static VALUE
cr_set_fill_rule (VALUE self, VALUE rule)
{
  cairo_set_fill_rule (_SELF, RVAL2CRFILLRULE (rule));
  cr_check_status (_SELF);
  return self;
}

#set_font_faceObject



1275
1276
1277
1278
1279
1280
1281
# File 'ext/cairo/rb_cairo_context.c', line 1275

static VALUE
cr_set_font_face (VALUE self, VALUE face)
{
  cairo_set_font_face (_SELF, NIL_P (face) ? NULL : RVAL2CRFONTFACE (face));
  cr_check_status (_SELF);
  return self;
}

#set_font_matrixObject



1151
1152
1153
1154
1155
1156
1157
# File 'ext/cairo/rb_cairo_context.c', line 1151

static VALUE
cr_set_font_matrix (VALUE self, VALUE matrix)
{
  cairo_set_font_matrix (_SELF, RVAL2CRMATRIX (matrix));
  cr_check_status (_SELF);
  return self;
}

#set_font_optionsObject



1168
1169
1170
1171
1172
1173
1174
# File 'ext/cairo/rb_cairo_context.c', line 1168

static VALUE
cr_set_font_options (VALUE self, VALUE options)
{
  cairo_set_font_options (_SELF, RVAL2CRFONTOPTIONS (options));
  cr_check_status (_SELF);
  return self;
}

#set_font_sizeObject



1143
1144
1145
1146
1147
1148
1149
# File 'ext/cairo/rb_cairo_context.c', line 1143

static VALUE
cr_set_font_size (VALUE self, VALUE scale)
{
  cairo_set_font_size (_SELF, NUM2DBL (scale));
  cr_check_status (_SELF);
  return self;
}

#set_line_capObject



443
444
445
446
447
448
449
# File 'ext/cairo/rb_cairo_context.c', line 443

static VALUE
cr_set_line_cap (VALUE self, VALUE cap)
{
  cairo_set_line_cap (_SELF, RVAL2CRLINECAP (cap));
  cr_check_status (_SELF);
  return self;
}

#set_line_joinObject



451
452
453
454
455
456
457
# File 'ext/cairo/rb_cairo_context.c', line 451

static VALUE
cr_set_line_join (VALUE self, VALUE join)
{
  cairo_set_line_join (_SELF, RVAL2CRLINEJOIN (join));
  cr_check_status (_SELF);
  return self;
}

#set_line_widthObject



436
437
438
439
440
441
# File 'ext/cairo/rb_cairo_context.c', line 436

static VALUE
cr_set_line_width (VALUE self, VALUE width)
{
  cairo_set_line_width (_SELF, NUM2DBL (width));
  return self;
}

#set_matrixObject



550
551
552
553
554
555
556
# File 'ext/cairo/rb_cairo_context.c', line 550

static VALUE
cr_set_matrix (VALUE self, VALUE matrix)
{
  cairo_set_matrix (_SELF, RVAL2CRMATRIX (matrix));
  cr_check_status (_SELF);
  return self;
}

#set_miter_limitObject



510
511
512
513
514
515
516
# File 'ext/cairo/rb_cairo_context.c', line 510

static VALUE
cr_set_miter_limit (VALUE self, VALUE limit)
{
  cairo_set_miter_limit (_SELF, NUM2DBL (limit));
  cr_check_status (_SELF);
  return self;
}

#set_operatorObject

Modify state



258
259
260
261
262
263
264
# File 'ext/cairo/rb_cairo_context.c', line 258

static VALUE
cr_set_operator (VALUE self, VALUE operator)
{
  cairo_set_operator (_SELF, RVAL2CROPERATOR (operator));
  cr_check_status (_SELF);
  return self;
}

#set_scaled_fontObject



1186
1187
1188
1189
1190
1191
1192
# File 'ext/cairo/rb_cairo_context.c', line 1186

static VALUE
cr_set_scaled_font (VALUE self, VALUE scaled_font)
{
  cairo_set_scaled_font (_SELF, RVAL2CRSCALEDFONT (scaled_font));
  cr_check_status (_SELF);
  return self;
}

#set_sourceObject



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'ext/cairo/rb_cairo_context.c', line 372

static VALUE
cr_set_source_generic (int argc, VALUE *argv, VALUE self)
{
  VALUE arg1, arg2, arg3, arg4;
  int n;

  n = rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4);

  if (n == 1 && rb_cairo__is_kind_of (arg1, rb_cArray))
    {
      return cr_set_source_rgba (argc, argv, self);
    }
  else if (n == 1 && rb_cairo__is_kind_of (arg1, rb_cCairo_Surface))
    {
      return cr_set_source_surface (self, arg1,
                                    rb_float_new (0),
                                    rb_float_new (0));
    }
  else if (n == 1)
    {
      return cr_set_source (self, arg1);
    }
  else if (n == 3 && rb_cairo__is_kind_of (arg1, rb_cCairo_Surface))
    {
      return cr_set_source_surface (self, arg1, arg2, arg3);
    }
  else if (n == 3 || n == 4)
    {
      return cr_set_source_rgba (argc, argv, self);
    }
  else
    {
      rb_raise (rb_eArgError,
                "invalid argument (expect "
                "(red, green, blue), (red, green, blue, alpha), "
                "([red, green, blue]), ([red, green, blue, alpha]), "
                "(surface), (pattern) or (surface, x, y))");
    }
}

#set_source_rgbObject



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'ext/cairo/rb_cairo_context.c', line 266

static VALUE
cr_set_source_rgb (int argc, VALUE *argv, VALUE self)
{
  VALUE red, green, blue;
  int n;

  n = rb_scan_args (argc, argv, "12", &red, &green, &blue);

  if (n == 1 && rb_cairo__is_kind_of (red, rb_cArray))
    {
      VALUE ary = red;
      n = RARRAY_LEN (ary);
      red = rb_ary_entry (ary, 0);
      green = rb_ary_entry (ary, 1);
      blue = rb_ary_entry (ary, 2);
    }

  if (n == 3)
    {
      cairo_set_source_rgb (_SELF,
                            NUM2DBL (red),
                            NUM2DBL (green),
                            NUM2DBL (blue));
    }
  else
    {
      VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
      rb_raise (rb_eArgError,
                "invalid RGB: %s (expect "
                "(red, green, blue) or ([red, green, blue]))",
                StringValuePtr (inspected_arg));
    }
  cr_check_status (_SELF);
  rb_ivar_set (self, cr_id_source, Qnil);
  return self;
}

#set_source_rgbaObject



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'ext/cairo/rb_cairo_context.c', line 303

static VALUE
cr_set_source_rgba (int argc, VALUE *argv, VALUE self)
{
  VALUE red, green, blue, alpha;
  int n;

  n = rb_scan_args (argc, argv, "13", &red, &green, &blue, &alpha);

  if (n == 1 && rb_cairo__is_kind_of (red, rb_cArray))
    {
      VALUE ary = red;
      n = RARRAY_LEN (ary);
      red = rb_ary_entry (ary, 0);
      green = rb_ary_entry (ary, 1);
      blue = rb_ary_entry (ary, 2);
      alpha = rb_ary_entry (ary, 3);
    }

  if (n == 3)
    {
      cairo_set_source_rgb (_SELF,
                            NUM2DBL (red),
                            NUM2DBL (green),
                            NUM2DBL (blue));
    }
  else if (n == 4)
    {
      cairo_set_source_rgba (_SELF,
                             NUM2DBL (red),
                             NUM2DBL (green),
                             NUM2DBL (blue),
                             NUM2DBL (alpha));
    }
  else
    {
      VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
      rb_raise (rb_eArgError,
                "invalid RGB%s: %s (expect "
                "(red, green, blue), (red, green, blue, alpha), "
                "([red, green, blue]) or ([red, green, blue, alpha]))",
                n == 4 ? "A" : "",
                StringValuePtr (inspected_arg));
    }
  cr_check_status (_SELF);
  rb_ivar_set (self, cr_id_source, Qnil);
  return self;
}

#set_toleranceObject



412
413
414
415
416
417
418
# File 'ext/cairo/rb_cairo_context.c', line 412

static VALUE
cr_set_tolerance (VALUE self, VALUE tolerance)
{
  cairo_set_tolerance (_SELF, NUM2DBL (tolerance));
  cr_check_status (_SELF);
  return self;
}

#show_glyphsObject



1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
# File 'ext/cairo/rb_cairo_context.c', line 1210

static VALUE
cr_show_glyphs (VALUE self, VALUE rb_glyphs)
{
  int count;
  cairo_glyph_t *glyphs;

  RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, count);
  cairo_show_glyphs (_SELF, glyphs, count);
  cr_check_status (_SELF);
  return self;
}

#show_pageObject



956
957
958
959
960
961
962
# File 'ext/cairo/rb_cairo_context.c', line 956

static VALUE
cr_show_page (VALUE self)
{
  cairo_show_page (_SELF);
  cr_check_status (_SELF);
  return self;
}

#show_textObject



1202
1203
1204
1205
1206
1207
1208
# File 'ext/cairo/rb_cairo_context.c', line 1202

static VALUE
cr_show_text (VALUE self, VALUE utf8)
{
  cairo_show_text (_SELF, RVAL2CSTR (utf8));
  cr_check_status (_SELF);
  return self;
}

#show_text_glyphsObject



1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
# File 'ext/cairo/rb_cairo_context.c', line 1223

static VALUE
cr_show_text_glyphs (VALUE self, VALUE rb_utf8, VALUE rb_glyphs,
                     VALUE rb_clusters, VALUE rb_cluster_flags)
{
  cairo_t *cr;
  const char *utf8;
  int utf8_len;
  cairo_glyph_t *glyphs = NULL;
  int num_glyphs = 0;
  cairo_text_cluster_t *clusters = NULL;
  int num_clusters = 0;
  cairo_text_cluster_flags_t cluster_flags;

  cr = _SELF;
  utf8 = RSTRING_PTR (rb_utf8);
  utf8_len = RSTRING_LEN (rb_utf8);
  rb_cairo__glyphs_from_ruby_object (rb_glyphs, &glyphs, &num_glyphs);
  rb_cairo__text_clusters_from_ruby_object (rb_clusters,
                                            &clusters, &num_clusters);
  cluster_flags = RVAL2CRTEXTCLUSTERFLAGS (rb_cluster_flags);
  cairo_show_text_glyphs (cr, utf8, utf8_len,
                          glyphs, num_glyphs,
                          clusters, num_clusters,
                          cluster_flags);
  if (glyphs)
    cairo_glyph_free (glyphs);
  if (clusters)
    cairo_text_cluster_free (clusters);

  return self;
}

#sourceObject



1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
# File 'ext/cairo/rb_cairo_context.c', line 1333

static VALUE
cr_get_source (VALUE self)
{
  VALUE rb_source = Qnil;
  cairo_pattern_t *source;
  source = cairo_get_source (_SELF);

  if (source)
    {
      rb_cairo_check_status (cairo_pattern_status (source));
      rb_source = rb_ivar_get (self, cr_id_source);
      if (NIL_P (rb_source) || RVAL2CRPATTERN (rb_source) != source)
        {
          rb_source = CRPATTERN2RVAL (source);
          rb_ivar_set (self, cr_id_source, rb_source);
        }
    }
  else
    {
      rb_source = Qnil;
      rb_ivar_set (self, cr_id_source, rb_source);
    }

  return rb_source;
}

#strokeObject



903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
# File 'ext/cairo/rb_cairo_context.c', line 903

static VALUE
cr_stroke (int argc, VALUE *argv, VALUE self)
{
  VALUE preserve;

  rb_scan_args (argc, argv, "01", &preserve);

  if (rb_block_given_p ())
    {
      cr_new_path (self);
      rb_yield (self);
    }

  if (RVAL2CBOOL (preserve))
    cairo_stroke_preserve (_SELF);
  else
    cairo_stroke (_SELF);

  cr_check_status (_SELF);
  return self;
}

#stroke_extentsObject

Rectangular extents



1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
# File 'ext/cairo/rb_cairo_context.c', line 1001

static VALUE
cr_stroke_extents (VALUE self)
{
  double extents[4];
  if (rb_block_given_p ())
    {
      cr_new_path (self);
      rb_yield (self);
    }
  cairo_stroke_extents (_SELF, extents, extents + 1, extents + 2, extents + 3);
  return rb_cairo__float_array (extents, 4);
}

#stroke_preserve(&block) ⇒ Object



17
18
19
# File 'lib/cairo/context.rb', line 17

def stroke_preserve(&block)
  stroke(true, &block)
end

#targetObject



1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
# File 'ext/cairo/rb_cairo_context.c', line 1449

static VALUE
cr_get_target (VALUE self)
{
  cairo_surface_t *surface;
  VALUE rb_surface = Qnil;

  surface = cairo_get_target (_SELF);
  rb_cairo_check_status (cairo_surface_status (surface));

  if (RTEST (rb_ivar_defined (self, cr_id_surface)))
      rb_surface = rb_ivar_get (self, cr_id_surface);
  if (NIL_P (rb_surface) || RVAL2CRSURFACE (rb_surface) != surface)
    {
      rb_surface = CRSURFACE2RVAL (surface);
      rb_ivar_set (self, cr_id_surface, rb_surface);
    }

  return rb_surface;
}

#text_extentsObject



1283
1284
1285
1286
1287
1288
1289
1290
# File 'ext/cairo/rb_cairo_context.c', line 1283

static VALUE
cr_text_extents (VALUE self, VALUE utf8)
{
  cairo_text_extents_t extents;
  cairo_text_extents (_SELF, StringValuePtr (utf8), &extents);
  cr_check_status (_SELF);
  return CRTEXTEXTENTS2RVAL (&extents);
}

#text_pathObject



1305
1306
1307
1308
1309
1310
1311
# File 'ext/cairo/rb_cairo_context.c', line 1305

static VALUE
cr_text_path (VALUE self, VALUE utf8)
{
  cairo_text_path (_SELF, StringValuePtr (utf8));
  cr_check_status (_SELF);
  return self;
}

#toleranceObject



1359
1360
1361
1362
1363
# File 'ext/cairo/rb_cairo_context.c', line 1359

static VALUE
cr_get_tolerance (VALUE self)
{
  return rb_float_new (cairo_get_tolerance (_SELF));
}

#transformObject



542
543
544
545
546
547
548
# File 'ext/cairo/rb_cairo_context.c', line 542

static VALUE
cr_transform (VALUE self, VALUE matrix)
{
  cairo_transform (_SELF, RVAL2CRMATRIX (matrix));
  cr_check_status (_SELF);
  return self;
}

#translateObject



518
519
520
521
522
523
524
# File 'ext/cairo/rb_cairo_context.c', line 518

static VALUE
cr_translate (VALUE self, VALUE tx, VALUE ty)
{
  cairo_translate (_SELF, NUM2DBL (tx), NUM2DBL (ty));
  cr_check_status (_SELF);
  return self;
}

#user_to_deviceObject



566
567
568
569
570
571
572
573
574
575
# File 'ext/cairo/rb_cairo_context.c', line 566

static VALUE
cr_user_to_device (VALUE self, VALUE x, VALUE y)
{
  double pair[2];
  pair[0] = NUM2DBL (x);
  pair[1] = NUM2DBL (y);
  cairo_user_to_device (_SELF, pair, pair + 1);
  cr_check_status (_SELF);
  return rb_cairo__float_array (pair, 2);
}

#user_to_device_distanceObject



577
578
579
580
581
582
583
584
585
586
# File 'ext/cairo/rb_cairo_context.c', line 577

static VALUE
cr_user_to_device_distance (VALUE self, VALUE dx, VALUE dy)
{
  double pair[2];
  pair[0] = NUM2DBL (dx);
  pair[1] = NUM2DBL (dy);
  cairo_user_to_device_distance (_SELF, pair, pair + 1);
  cr_check_status (_SELF);
  return rb_cairo__float_array (pair, 2);
}