rays 0.3.16 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +29 -9
  3. data/.doc/ext/rays/bounds.cpp +2 -5
  4. data/.doc/ext/rays/camera.cpp +15 -7
  5. data/.doc/ext/rays/color.cpp +2 -4
  6. data/.doc/ext/rays/color_space.cpp +13 -9
  7. data/.doc/ext/rays/font.cpp +117 -22
  8. data/.doc/ext/rays/image.cpp +31 -7
  9. data/.doc/ext/rays/matrix.cpp +2 -5
  10. data/.doc/ext/rays/painter.cpp +13 -5
  11. data/.doc/ext/rays/point.cpp +2 -5
  12. data/.doc/ext/rays/polygon.cpp +15 -7
  13. data/.doc/ext/rays/polyline.cpp +15 -10
  14. data/.doc/ext/rays/rays.cpp +10 -6
  15. data/.doc/ext/rays/shader.cpp +15 -7
  16. data/.github/workflows/release-gem.yml +2 -40
  17. data/.github/workflows/tag.yml +5 -28
  18. data/.github/workflows/test.yml +1 -28
  19. data/ChangeLog.md +31 -0
  20. data/Gemfile.lock +13 -8
  21. data/Rakefile +2 -2
  22. data/VERSION +1 -1
  23. data/ext/rays/bitmap.cpp +29 -9
  24. data/ext/rays/bounds.cpp +2 -5
  25. data/ext/rays/camera.cpp +16 -7
  26. data/ext/rays/color.cpp +2 -4
  27. data/ext/rays/color_space.cpp +13 -9
  28. data/ext/rays/defs.h +3 -3
  29. data/ext/rays/extconf.rb +6 -5
  30. data/ext/rays/font.cpp +121 -22
  31. data/ext/rays/image.cpp +31 -7
  32. data/ext/rays/matrix.cpp +2 -5
  33. data/ext/rays/painter.cpp +14 -5
  34. data/ext/rays/point.cpp +2 -5
  35. data/ext/rays/polygon.cpp +16 -7
  36. data/ext/rays/polyline.cpp +16 -10
  37. data/ext/rays/rays.cpp +10 -6
  38. data/ext/rays/shader.cpp +16 -7
  39. data/include/rays/bitmap.h +3 -1
  40. data/include/rays/color_space.h +6 -2
  41. data/include/rays/defs.h +14 -4
  42. data/include/rays/font.h +46 -4
  43. data/include/rays/image.h +11 -7
  44. data/include/rays/painter.h +3 -1
  45. data/include/rays/ruby/color_space.h +2 -0
  46. data/include/rays/shader.h +3 -0
  47. data/lib/rays/camera.rb +1 -1
  48. data/lib/rays/extension.rb +1 -1
  49. data/lib/rays/font.rb +4 -1
  50. data/lib/rays/image.rb +4 -2
  51. data/lib/rays/painter.rb +5 -5
  52. data/lib/rays/polygon.rb +1 -1
  53. data/lib/rays/polyline.rb +1 -1
  54. data/lib/rays/shader.rb +1 -1
  55. data/rays.gemspec +3 -3
  56. data/src/bitmap.cpp +107 -0
  57. data/src/color.cpp +17 -0
  58. data/src/color_space.cpp +5 -5
  59. data/src/font.cpp +121 -25
  60. data/src/font.h +7 -5
  61. data/src/image.cpp +104 -102
  62. data/src/ios/bitmap.mm +3 -3
  63. data/src/ios/font.mm +79 -26
  64. data/src/opengl/bitmap.cpp +1 -1
  65. data/src/opengl/color_space.cpp +15 -3
  66. data/src/opengl/color_space.h +1 -1
  67. data/src/opengl/painter.cpp +86 -18
  68. data/src/opengl/shader.cpp +15 -13
  69. data/src/opengl/texture.cpp +7 -7
  70. data/src/opengl/win32/opengl.cpp +17 -12
  71. data/src/osx/bitmap.mm +14 -3
  72. data/src/osx/font.mm +79 -26
  73. data/src/painter.cpp +12 -12
  74. data/src/painter.h +5 -1
  75. data/src/polygon.cpp +21 -21
  76. data/src/polyline.cpp +4 -4
  77. data/src/sdl/bitmap.cpp +43 -18
  78. data/src/sdl/font.cpp +56 -50
  79. data/src/texture.h +1 -1
  80. data/src/win32/bitmap.cpp +92 -45
  81. data/src/win32/font.cpp +43 -44
  82. data/src/win32/gdi.cpp +43 -46
  83. data/src/win32/gdi.h +6 -1
  84. data/src/win32/rays.cpp +18 -1
  85. data/test/test_bitmap.rb +28 -10
  86. data/test/test_font.rb +58 -0
  87. data/test/test_image.rb +29 -6
  88. data/test/test_painter.rb +39 -0
  89. metadata +8 -8
  90. data/.github/workflows/utils.rb +0 -127
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6103dcc968b6fc21154ea86793205f78fdf698b5eea35ddbc88b504c2b5fdf03
4
- data.tar.gz: 06455c393ef928d7accf7e7639180d7b1bd599489d746af1cef9e989892559b8
3
+ metadata.gz: db829b19cf715370698a98bcf00a47430aeb4896d366eee24a0448db4ac4f58e
4
+ data.tar.gz: 42630c214769a8cf8cea42f39815f6125464b2dcc1b58da4036ef22a4df3e963
5
5
  SHA512:
6
- metadata.gz: 9668987901e8ec97a694b3c760975b523d30588d4ac750c211e122d64036441b07ca44d02cf70ffb6779c1afdfc1743b2922cdd4f5c35244df3f837e60173e1d
7
- data.tar.gz: 87ce33df4fd7f581a673efdbc61847b1c2fb2c150bf69f10234f47c49bb091325750b368e5c54af41330cea357263668bd8a95d5a61bec60c1424b5b42d0f885
6
+ metadata.gz: 40b9c27b937d402a12717ae93a8485fc1c1b1052cafcdeb739c6b679a1e07d23f253b9e5566f94fb2d844f043cb54b6500bf73a4a97f9a7639bf79f1d7f87e45
7
+ data.tar.gz: 3514007e11230a8d5b323026ad0fd2a1102fb066c65072ed05eb6ce91964975df06cf8fa6a315880ce5f6212b2659aa6cede56f7e6240b73854d9d685142e1ce
@@ -11,7 +11,7 @@ RUCY_DEFINE_VALUE_FROM_TO(RAYS_EXPORT, Rays::Bitmap)
11
11
 
12
12
  #define THIS to<Rays::Bitmap*>(self)
13
13
 
14
- #define CHECK RUCY_CHECK_OBJECT(Rays::Bitmap, self)
14
+ #define CHECK RUCY_CHECK_OBJ(Rays::Bitmap, self)
15
15
 
16
16
 
17
17
  static
@@ -23,12 +23,12 @@ VALUE alloc(VALUE klass)
23
23
  static
24
24
  VALUE initialize(VALUE self)
25
25
  {
26
- RUCY_CHECK_OBJ(Rays::Bitmap, self);
26
+ RUCY_CHECK_PTR(Rays::Bitmap, self);
27
27
  check_arg_count(__FILE__, __LINE__, "Bitmap#initialize", argc, 2, 3);
28
28
 
29
29
  *THIS = Rays::Bitmap(
30
30
  to<int>(argv[0]), to<int>(argv[1]),
31
- argc >= 3 ? to<Rays::ColorSpace>(argv[2]) : Rays::RGBA);
31
+ argc >= 3 ? to<Rays::ColorSpace>(argv[2]) : Rays::DEFAULT_COLORSPACE);
32
32
 
33
33
  return self;
34
34
  }
@@ -36,7 +36,7 @@ VALUE initialize(VALUE self)
36
36
  static
37
37
  VALUE initialize_copy(VALUE self, VALUE obj)
38
38
  {
39
- RUCY_CHECK_OBJ(Rays::Bitmap, self);
39
+ RUCY_CHECK_PTR(Rays::Bitmap, self);
40
40
 
41
41
  *THIS = to<Rays::Bitmap&>(obj).dup();
42
42
  return self;
@@ -67,7 +67,7 @@ VALUE color_space(VALUE self)
67
67
  }
68
68
 
69
69
  static void
70
- set_pixels (Rays::Bitmap* bmp, Value pixels)
70
+ set_raw_pixels (Rays::Bitmap* bmp, Value pixels)
71
71
  {
72
72
  int w = bmp->width(), h = bmp->height();
73
73
  const auto& cs = bmp->color_space();
@@ -317,6 +317,23 @@ set_pixels (Rays::Bitmap* bmp, Value pixels)
317
317
  }
318
318
  }
319
319
 
320
+ static void
321
+ set_pixels (Rays::Bitmap* bmp, Value pixels)
322
+ {
323
+ const auto& cs = bmp->color_space();
324
+ if (!cs.has_alpha() || !cs.is_premult())
325
+ return set_raw_pixels(bmp, pixels);
326
+
327
+ int w = bmp->width(), h = bmp->height();
328
+ Rays::Bitmap straight(w, h, Rays::ColorSpace(cs.type(), false));
329
+ set_raw_pixels(&straight, pixels);
330
+
331
+ Rays::Bitmap premult = straight.dup(true);
332
+ size_t size = w * cs.Bpp();
333
+ for (int y = 0; y < h; ++y)
334
+ memcpy(bmp->at<uint8_t>(0, y), premult.at<uint8_t>(0, y), size);
335
+ }
336
+
320
337
  static inline uint32_t
321
338
  to_rgb (uint8_t r, uint8_t g, uint8_t b)
322
339
  {
@@ -602,7 +619,7 @@ get_32bit_pixels_string (const Rays::Bitmap& bmp)
602
619
  }
603
620
 
604
621
  return value(
605
- (const char*) &pixels[0], pixels.size() * sizeof(uint32_t),
622
+ (const char*) pixels.data(), pixels.size() * sizeof(uint32_t),
606
623
  rb_ascii8bit_encoding());
607
624
  }
608
625
 
@@ -620,14 +637,17 @@ VALUE get_pixels(VALUE self)
620
637
  {
621
638
  CHECK;
622
639
 
640
+ const auto& cs = THIS->color_space();
641
+ Rays::Bitmap bmp = cs.has_alpha() && cs.is_premult() ? THIS->dup(false) : *THIS;
642
+
623
643
  #ifdef RAYS_32BIT_PIXELS_STRING
624
- Value str = get_32bit_pixels_string(*THIS);
644
+ Value str = get_32bit_pixels_string(bmp);
625
645
  if (str) return str;
626
646
  #endif
627
647
 
628
648
  std::vector<VALUE> pixels;
629
- get_pixels(&pixels, *THIS);
630
- return array((const Value*) &pixels[0], pixels.size());
649
+ get_pixels(&pixels, bmp);
650
+ return array((const Value*) pixels.data(), pixels.size());
631
651
  }
632
652
 
633
653
  static
@@ -1,7 +1,6 @@
1
1
  #include "rays/ruby/bounds.h"
2
2
 
3
3
 
4
- #include <assert.h>
5
4
  #include "rays/ruby/point.h"
6
5
  #include "defs.h"
7
6
 
@@ -10,7 +9,7 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Bounds)
10
9
 
11
10
  #define THIS to<Rays::Bounds*>(self)
12
11
 
13
- #define CHECK RUCY_CHECK_OBJ(Rays::Bounds, self)
12
+ #define CHECK RUCY_CHECK_PTR(Rays::Bounds, self)
14
13
 
15
14
 
16
15
  static
@@ -589,14 +588,12 @@ namespace Rucy
589
588
  template <> RAYS_EXPORT Rays::Bounds
590
589
  value_to<Rays::Bounds> (int argc, const Value* argv, bool convert)
591
590
  {
592
- if (argc == 1 && argv->is_array())
591
+ if (argc == 1 && argv && argv->is_array())
593
592
  {
594
593
  argc = argv->size();
595
594
  argv = argv->as_array();
596
595
  }
597
596
 
598
- assert(argc == 0 || (argc > 0 && argv));
599
-
600
597
  if (convert)
601
598
  {
602
599
  if (argc == 0)
@@ -1,6 +1,7 @@
1
1
  #include "rays/ruby/camera.h"
2
2
 
3
3
 
4
+ #include "rays/exception.h"
4
5
  #include "rays/ruby/image.h"
5
6
  #include "defs.h"
6
7
 
@@ -9,7 +10,7 @@ RUCY_DEFINE_VALUE_FROM_TO(RAYS_EXPORT, Rays::Camera)
9
10
 
10
11
  #define THIS to<Rays::Camera*>(self)
11
12
 
12
- #define CHECK RUCY_CHECK_OBJECT(Rays::Camera, self)
13
+ #define CHECK RUCY_CHECK_OBJ(Rays::Camera, self)
13
14
 
14
15
 
15
16
  static
@@ -19,9 +20,9 @@ VALUE alloc(VALUE klass)
19
20
  }
20
21
 
21
22
  static
22
- VALUE setup(VALUE self, VALUE device_name, VALUE min_width, VALUE min_height, VALUE resize, VALUE crop)
23
+ VALUE initialize(VALUE self, VALUE device_name, VALUE min_width, VALUE min_height, VALUE resize, VALUE crop)
23
24
  {
24
- RUCY_CHECK_OBJ(Rays::Camera, self);
25
+ RUCY_CHECK_PTR(Rays::Camera, self);
25
26
 
26
27
  *THIS = Rays::Camera(
27
28
  device_name ? device_name.c_str() : NULL,
@@ -30,6 +31,12 @@ VALUE setup(VALUE self, VALUE device_name, VALUE min_width, VALUE min_height, VA
30
31
  return self;
31
32
  }
32
33
 
34
+ static
35
+ VALUE initialize_copy(VALUE self, VALUE obj)
36
+ {
37
+ Rays::rays_error(__FILE__, __LINE__, "can not duplicate Camera");
38
+ }
39
+
33
40
  static
34
41
  VALUE start(VALUE self)
35
42
  {
@@ -124,10 +131,10 @@ VALUE device_names(VALUE self)
124
131
  {
125
132
  auto names = Rays::get_camera_device_names();
126
133
 
127
- std::vector<Value> v;
134
+ Value v = array(NULL, names.size());
128
135
  for (const auto& name : names)
129
- v.emplace_back(name.c_str());
130
- return array(&v[0], v.size());
136
+ v.push(name.c_str());
137
+ return v;
131
138
  }
132
139
 
133
140
 
@@ -140,7 +147,8 @@ Init_rays_camera ()
140
147
 
141
148
  cCamera = rb_define_class_under(mRays, "Camera", rb_cObject);
142
149
  rb_define_alloc_func(cCamera, alloc);
143
- rb_define_private_method(cCamera, "setup", RUBY_METHOD_FUNC(setup), 5);
150
+ cCamera.define_private_method("initialize!", initialize);
151
+ rb_define_private_method(cCamera, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
144
152
  rb_define_method(cCamera, "start", RUBY_METHOD_FUNC(start), 0);
145
153
  rb_define_method(cCamera, "stop", RUBY_METHOD_FUNC(stop), 0);
146
154
  cCamera.define_method("active?", is_active);
@@ -10,7 +10,7 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Color)
10
10
 
11
11
  #define THIS to<Rays::Color*>(self)
12
12
 
13
- #define CHECK RUCY_CHECK_OBJ(Rays::Color, self)
13
+ #define CHECK RUCY_CHECK_PTR(Rays::Color, self)
14
14
 
15
15
 
16
16
  static const char* NIL_COLOR_NO = "no";
@@ -352,14 +352,12 @@ namespace Rucy
352
352
  template <> RAYS_EXPORT Rays::Color
353
353
  value_to<Rays::Color> (int argc, const Value*argv, bool convert)
354
354
  {
355
- if (argc == 1 && argv->is_array())
355
+ if (argc == 1 && argv && argv->is_array())
356
356
  {
357
357
  argc = argv->size();
358
358
  argv = argv->as_array();
359
359
  }
360
360
 
361
- assert(argc == 0 || (argc > 0 && argv));
362
-
363
361
  if (convert)
364
362
  {
365
363
  if (argc == 0)
@@ -1,15 +1,16 @@
1
1
  #include "rays/ruby/color_space.h"
2
2
 
3
3
 
4
- #include <assert.h>
5
4
  #include "defs.h"
6
5
 
7
6
 
8
7
  RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::ColorSpace)
9
8
 
9
+ RUCY_DEFINE_CONVERT_TO(RAYS_EXPORT, Rays::ColorSpaceType)
10
+
10
11
  #define THIS to<Rays::ColorSpace*>(self)
11
12
 
12
- #define CHECK RUCY_CHECK_OBJECT(Rays::ColorSpace, self)
13
+ #define CHECK RUCY_CHECK_OBJ(Rays::ColorSpace, self)
13
14
 
14
15
 
15
16
  static struct ColorSpaceEnum
@@ -72,7 +73,7 @@ VALUE alloc(VALUE klass)
72
73
  static
73
74
  VALUE initialize(VALUE self)
74
75
  {
75
- RUCY_CHECK_OBJ(Rays::ColorSpace, self);
76
+ RUCY_CHECK_PTR(Rays::ColorSpace, self);
76
77
  check_arg_count(__FILE__, __LINE__, "ColorSpace#initialize", argc, 1, 2);
77
78
 
78
79
  *THIS = to<Rays::ColorSpace>(argc, argv);
@@ -209,13 +210,14 @@ namespace Rucy
209
210
  template <> RAYS_EXPORT Rays::ColorSpace
210
211
  value_to<Rays::ColorSpace> (int argc, const Value* argv, bool convert)
211
212
  {
212
- if (argc == 1 && argv->is_array())
213
+ if (argc == 1 && argv && argv->is_array())
213
214
  {
214
215
  argc = argv->size();
215
216
  argv = argv->as_array();
216
217
  }
217
218
 
218
- assert(argc > 0 && argv);
219
+ if (argc <= 0 || !argv)
220
+ argument_error(__FILE__, __LINE__);
219
221
 
220
222
  if (convert)
221
223
  {
@@ -235,13 +237,15 @@ namespace Rucy
235
237
 
236
238
 
237
239
  template <> RAYS_EXPORT Rays::ColorSpaceType
238
- value_to<Rays::ColorSpaceType> (Value value, bool convert)
240
+ value_to<Rays::ColorSpaceType> (int argc, const Value* argv, bool convert)
239
241
  {
242
+ assert(argc > 0 && argv);
243
+
240
244
  if (convert)
241
245
  {
242
- if (value.is_s() || value.is_sym())
246
+ if (argv->is_s() || argv->is_sym())
243
247
  {
244
- const char* str = value.c_str();
248
+ const char* str = argv->c_str();
245
249
  for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
246
250
  {
247
251
  if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
@@ -250,7 +254,7 @@ namespace Rucy
250
254
  }
251
255
  }
252
256
 
253
- uint type = value_to<uint>(value, convert);
257
+ uint type = value_to<uint>(*argv, convert);
254
258
  if (type >= Rays::COLORSPACE_MAX)
255
259
  argument_error(__FILE__, __LINE__, "invalid color space type -- %d", type);
256
260
 
@@ -1,7 +1,7 @@
1
1
  #include "rays/ruby/font.h"
2
2
 
3
3
 
4
- #include <assert.h>
4
+ #include <strings.h>
5
5
  #include "defs.h"
6
6
 
7
7
 
@@ -9,7 +9,7 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Font)
9
9
 
10
10
  #define THIS to<Rays::Font*>(self)
11
11
 
12
- #define CHECK RUCY_CHECK_OBJECT(Rays::Font, self)
12
+ #define CHECK RUCY_CHECK_OBJ(Rays::Font, self)
13
13
 
14
14
 
15
15
  static
@@ -21,7 +21,7 @@ VALUE alloc(VALUE klass)
21
21
  static
22
22
  VALUE initialize(VALUE self)
23
23
  {
24
- RUCY_CHECK_OBJ(Rays::Font, self);
24
+ RUCY_CHECK_PTR(Rays::Font, self);
25
25
  check_arg_count(__FILE__, __LINE__, "Font#initialize", argc, 0, 1, 2, 3);
26
26
 
27
27
  *THIS = to<Rays::Font>(argc, argv);
@@ -31,7 +31,7 @@ VALUE initialize(VALUE self)
31
31
  static
32
32
  VALUE initialize_copy(VALUE self, VALUE obj)
33
33
  {
34
- RUCY_CHECK_OBJ(Rays::Font, self);
34
+ RUCY_CHECK_PTR(Rays::Font, self);
35
35
 
36
36
  *THIS = to<Rays::Font&>(obj).dup();
37
37
  return self;
@@ -41,7 +41,10 @@ static
41
41
  VALUE name(VALUE self)
42
42
  {
43
43
  CHECK;
44
- return value(THIS->name().c_str());
44
+ check_arg_count(__FILE__, __LINE__, "Font#name", argc, 0, 1);
45
+
46
+ bool resolved = argc >= 1 ? to<bool>(argv[0]) : false;
47
+ return value(THIS->name(resolved).c_str());
45
48
  }
46
49
 
47
50
  static
@@ -59,6 +62,70 @@ VALUE size(VALUE self)
59
62
  return value(THIS->size());
60
63
  }
61
64
 
65
+ static int
66
+ to_font_weight (Value weight)
67
+ {
68
+ if (weight.is_s() || weight.is_sym())
69
+ {
70
+ static const struct {const char* name; int weight;} WEIGHTS[] =
71
+ {
72
+ // most used first
73
+ {"normal", Rays::Font::WEIGHT_NORMAL},
74
+ {"regular", Rays::Font::WEIGHT_NORMAL},
75
+ {"bold", Rays::Font::WEIGHT_BOLD},
76
+
77
+ {"thin", Rays::Font::WEIGHT_THIN},
78
+ {"extralight", Rays::Font::WEIGHT_EXTRALIGHT},
79
+ {"light", Rays::Font::WEIGHT_LIGHT},
80
+ {"medium", Rays::Font::WEIGHT_MEDIUM},
81
+ {"semibold", Rays::Font::WEIGHT_SEMIBOLD},
82
+ {"extrabold", Rays::Font::WEIGHT_EXTRABOLD},
83
+ {"black", Rays::Font::WEIGHT_BLACK},
84
+ };
85
+
86
+ const char* name = weight.c_str();
87
+ for (const auto& w : WEIGHTS)
88
+ {
89
+ if (strcasecmp(name, w.name) == 0)
90
+ return w.weight;
91
+ }
92
+
93
+ argument_error(
94
+ __FILE__, __LINE__, "unknown font weight: %s", weight.inspect().c_str());
95
+ }
96
+ return to<int>(weight);
97
+ }
98
+
99
+ static
100
+ VALUE set_weight(VALUE self, VALUE weight)
101
+ {
102
+ CHECK;
103
+ THIS->set_weight(to_font_weight(weight));
104
+ return weight;
105
+ }
106
+
107
+ static
108
+ VALUE weight(VALUE self)
109
+ {
110
+ CHECK;
111
+ return value(THIS->weight());
112
+ }
113
+
114
+ static
115
+ VALUE set_italic(VALUE self, VALUE italic)
116
+ {
117
+ CHECK;
118
+ THIS->set_italic(to<bool>(italic));
119
+ return italic;
120
+ }
121
+
122
+ static
123
+ VALUE get_italic(VALUE self)
124
+ {
125
+ CHECK;
126
+ return value(THIS->italic());
127
+ }
128
+
62
129
  static
63
130
  VALUE set_smooth(VALUE self, VALUE smooth)
64
131
  {
@@ -68,7 +135,7 @@ VALUE set_smooth(VALUE self, VALUE smooth)
68
135
  }
69
136
 
70
137
  static
71
- VALUE smooth(VALUE self)
138
+ VALUE get_smooth(VALUE self)
72
139
  {
73
140
  CHECK;
74
141
  return value(THIS->smooth());
@@ -121,10 +188,10 @@ VALUE families(VALUE self)
121
188
  Hash hash;
122
189
  for (const auto& family : Rays::get_font_families())
123
190
  {
124
- std::vector<Value> members;
191
+ Value members = array(NULL, family.second.size());
125
192
  for (const auto& member : family.second)
126
- members.emplace_back(member.c_str());
127
- hash.set(family.first.c_str(), array(&members[0], members.size()));
193
+ members.push(member.c_str());
194
+ hash.set(family.first.c_str(), members);
128
195
  }
129
196
  return hash;
130
197
  }
@@ -154,11 +221,15 @@ Init_rays_font ()
154
221
  rb_define_alloc_func(cFont, alloc);
155
222
  rb_define_private_method(cFont, "initialize", RUBY_METHOD_FUNC(initialize), -1);
156
223
  rb_define_private_method(cFont, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
157
- rb_define_method(cFont, "name", RUBY_METHOD_FUNC(name), 0);
224
+ rb_define_method(cFont, "name", RUBY_METHOD_FUNC(name), -1);
158
225
  rb_define_method(cFont, "size=", RUBY_METHOD_FUNC(set_size), 1);
159
226
  rb_define_method(cFont, "size", RUBY_METHOD_FUNC(size), 0);
227
+ rb_define_method(cFont, "weight=", RUBY_METHOD_FUNC(set_weight), 1);
228
+ rb_define_method(cFont, "weight", RUBY_METHOD_FUNC(weight), 0);
229
+ rb_define_method(cFont, "italic=", RUBY_METHOD_FUNC(set_italic), 1);
230
+ rb_define_method(cFont, "italic", RUBY_METHOD_FUNC(get_italic), 0);
160
231
  rb_define_method(cFont, "smooth=", RUBY_METHOD_FUNC(set_smooth), 1);
161
- rb_define_method(cFont, "smooth", RUBY_METHOD_FUNC(smooth), 0);
232
+ rb_define_method(cFont, "smooth", RUBY_METHOD_FUNC(get_smooth), 0);
162
233
  rb_define_method(cFont, "width", RUBY_METHOD_FUNC(width), 1);
163
234
  rb_define_method(cFont, "height", RUBY_METHOD_FUNC(height), 0);
164
235
  rb_define_method(cFont, "ascent", RUBY_METHOD_FUNC(ascent), 0);
@@ -166,6 +237,18 @@ Init_rays_font ()
166
237
  rb_define_method(cFont, "leading", RUBY_METHOD_FUNC(leading), 0);
167
238
  rb_define_module_function(cFont, "families", RUBY_METHOD_FUNC(families), 0);
168
239
  rb_define_module_function(cFont, "load", RUBY_METHOD_FUNC(load), -1);
240
+
241
+ cFont.define_const("WEIGHT_MIN", Rays::Font::WEIGHT_MIN);
242
+ cFont.define_const("WEIGHT_THIN", Rays::Font::WEIGHT_THIN);
243
+ cFont.define_const("WEIGHT_EXTRALIGHT", Rays::Font::WEIGHT_EXTRALIGHT);
244
+ cFont.define_const("WEIGHT_LIGHT", Rays::Font::WEIGHT_LIGHT);
245
+ cFont.define_const("WEIGHT_NORMAL", Rays::Font::WEIGHT_NORMAL);
246
+ cFont.define_const("WEIGHT_MEDIUM", Rays::Font::WEIGHT_MEDIUM);
247
+ cFont.define_const("WEIGHT_SEMIBOLD", Rays::Font::WEIGHT_SEMIBOLD);
248
+ cFont.define_const("WEIGHT_BOLD", Rays::Font::WEIGHT_BOLD);
249
+ cFont.define_const("WEIGHT_EXTRABOLD", Rays::Font::WEIGHT_EXTRABOLD);
250
+ cFont.define_const("WEIGHT_BLACK", Rays::Font::WEIGHT_BLACK);
251
+ cFont.define_const("WEIGHT_MAX", Rays::Font::WEIGHT_MAX);
169
252
  }
170
253
 
171
254
 
@@ -176,26 +259,38 @@ namespace Rucy
176
259
  template <> RAYS_EXPORT Rays::Font
177
260
  value_to<Rays::Font> (int argc, const Value* argv, bool convert)
178
261
  {
179
- if (argc == 1 && argv->is_array())
262
+ if (argc == 1 && argv && argv->is_array())
180
263
  {
181
264
  argc = argv->size();
182
265
  argv = argv->as_array();
183
266
  }
184
267
 
185
- assert(argc == 0 || (argc > 0 && argv));
186
-
187
268
  if (convert)
188
269
  {
189
- if (argc == 0)
270
+ Value options = argc >= 1 && argv[argc - 1].is_hash() ? argv[--argc] : nil();
271
+ if (argc == 0 && !options)
190
272
  return Rays::get_default_font();
191
273
 
192
- coord size = argc >= 2 ? to<coord>(argv[1]) : (coord) Rays::Font::DEFAULT_SIZE;
193
- bool smooth = argc >= 3 ? to<bool>(argv[2]) : true;
194
-
195
- if (argv->is_nil())
196
- return Rays::Font(NULL, size, smooth);
197
- else if (argv->is_s() || argv->is_sym())
198
- return Rays::Font(argv[0].c_str(), size, smooth);
274
+ int weight = Rays::Font::DEFAULT_WEIGHT;
275
+ bool italic = false;
276
+ bool smooth = true;
277
+ if (options)
278
+ {
279
+ RUCY_SYMBOL(weight_sym, "weight");
280
+ RUCY_SYMBOL(italic_sym, "italic");
281
+ RUCY_SYMBOL(smooth_sym, "smooth");
282
+ Value v;
283
+ if (!(v = options.get(weight_sym.value())).is_nil()) weight = to_font_weight(v);
284
+ if (!(v = options.get(italic_sym.value())).is_nil()) italic = to<bool>(v);
285
+ if (!(v = options.get(smooth_sym.value())).is_nil()) smooth = to<bool>(v);
286
+ }
287
+
288
+ if (argc == 0 || argv->is_nil() || argv->is_s() || argv->is_sym())
289
+ {
290
+ const char* name = argc >= 1 && !argv[0].is_nil() ? argv[0].c_str() : NULL;
291
+ coord size = argc >= 2 ? to<coord>(argv[1]) : (coord) Rays::Font::DEFAULT_SIZE;
292
+ return Rays::Font(name, size, weight, italic, smooth);
293
+ }
199
294
  }
200
295
 
201
296
  if (argc != 1)
@@ -7,11 +7,31 @@
7
7
  #include "defs.h"
8
8
 
9
9
 
10
- RUCY_DEFINE_VALUE_FROM_TO(RAYS_EXPORT, Rays::Image)
10
+ RUCY_DEFINE_VALUE_TO(RAYS_EXPORT, Rays::Image)
11
+
12
+ namespace Rucy
13
+ {
14
+
15
+ // An image with a loader is read-only, so its ruby object is frozen
16
+ RAYS_EXPORT Value
17
+ value (const Rays::Image& obj)
18
+ {
19
+ Value v = new_type(get_ruby_class<Rays::Image>(), new Rays::Image(obj));
20
+ if (obj.loader()) v.freeze();
21
+ return v;
22
+ }
23
+
24
+ RAYS_EXPORT Value
25
+ value (const Rays::Image* obj)
26
+ {
27
+ return obj ? value(*obj) : nil();
28
+ }
29
+
30
+ }// Rucy
11
31
 
12
32
  #define THIS to<Rays::Image*>(self)
13
33
 
14
- #define CHECK RUCY_CHECK_OBJECT(Rays::Image, self)
34
+ #define CHECK RUCY_CHECK_OBJ(Rays::Image, self)
15
35
 
16
36
 
17
37
  static
@@ -23,7 +43,7 @@ VALUE alloc(VALUE klass)
23
43
  static
24
44
  VALUE initialize(VALUE self, VALUE args, VALUE pixel_density, VALUE smooth)
25
45
  {
26
- RUCY_CHECK_OBJ(Rays::Image, self);
46
+ RUCY_CHECK_PTR(Rays::Image, self);
27
47
 
28
48
  size_t argc = args.size();
29
49
  check_arg_count(__FILE__, __LINE__, "Image#initialize!", argc, 1, 2, 3);
@@ -41,7 +61,7 @@ VALUE initialize(VALUE self, VALUE args, VALUE pixel_density, VALUE smooth)
41
61
  {
42
62
  int width = to<int>(args[0]);
43
63
  int height = to<int>(args[1]);
44
- auto cs = (argc >= 3) ? to<Rays::ColorSpace>(args[2]) : Rays::RGBA;
64
+ auto cs = (argc >= 3) ? to<Rays::ColorSpace>(args[2]) : Rays::DEFAULT_COLORSPACE;
45
65
  *THIS = Rays::Image(width, height, cs, pd, smooth);
46
66
  }
47
67
 
@@ -51,7 +71,7 @@ VALUE initialize(VALUE self, VALUE args, VALUE pixel_density, VALUE smooth)
51
71
  static
52
72
  VALUE initialize_copy(VALUE self, VALUE obj)
53
73
  {
54
- RUCY_CHECK_OBJ(Rays::Image, self);
74
+ RUCY_CHECK_PTR(Rays::Image, self);
55
75
 
56
76
  *THIS = to<Rays::Image&>(obj).dup();
57
77
  return self;
@@ -97,6 +117,7 @@ static
97
117
  VALUE painter(VALUE self)
98
118
  {
99
119
  CHECK;
120
+ self.check_frozen();
100
121
  return value(THIS->painter());
101
122
  }
102
123
 
@@ -104,6 +125,7 @@ static
104
125
  VALUE get_bitmap(VALUE self, VALUE modify)
105
126
  {
106
127
  CHECK;
128
+ if (modify) self.check_frozen();
107
129
  return value(THIS->bitmap(modify));
108
130
  }
109
131
 
@@ -111,6 +133,7 @@ static
111
133
  VALUE set_smooth(VALUE self, VALUE smooth)
112
134
  {
113
135
  CHECK;
136
+ self.check_frozen();
114
137
  THIS->set_smooth(smooth);
115
138
  return smooth;
116
139
  }
@@ -132,9 +155,10 @@ VALUE compare(VALUE self, VALUE other)
132
155
  }
133
156
 
134
157
  static
135
- VALUE load(VALUE self, VALUE path)
158
+ VALUE load(VALUE self, VALUE path, VALUE pixel_density, VALUE smooth)
136
159
  {
137
- return value(Rays::load_image(path.c_str()));
160
+ return value(Rays::load_image(
161
+ path.c_str(), to<float>(pixel_density), to<bool>(smooth)));
138
162
  }
139
163
 
140
164
 
@@ -1,7 +1,6 @@
1
1
  #include "rays/ruby/matrix.h"
2
2
 
3
3
 
4
- #include <assert.h>
5
4
  #include "rays/ruby/point.h"
6
5
  #include "defs.h"
7
6
 
@@ -10,7 +9,7 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Matrix)
10
9
 
11
10
  #define THIS to<Rays::Matrix*>(self)
12
11
 
13
- #define CHECK RUCY_CHECK_OBJ(Rays::Matrix, self)
12
+ #define CHECK RUCY_CHECK_PTR(Rays::Matrix, self)
14
13
 
15
14
 
16
15
  static
@@ -284,14 +283,12 @@ namespace Rucy
284
283
  template <> RAYS_EXPORT Rays::Matrix
285
284
  value_to<Rays::Matrix> (int argc, const Value* argv, bool convert)
286
285
  {
287
- if (argc == 1 && argv->is_array())
286
+ if (argc == 1 && argv && argv->is_array())
288
287
  {
289
288
  argc = argv->size();
290
289
  argv = argv->as_array();
291
290
  }
292
291
 
293
- assert(argc == 0 || (argc > 0 && argv));
294
-
295
292
  if (convert)
296
293
  {
297
294
  if (argc == 0)