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
data/ext/rays/bitmap.cpp CHANGED
@@ -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
@@ -24,12 +24,12 @@ RUCY_END
24
24
  static
25
25
  RUCY_DEFN(initialize)
26
26
  {
27
- RUCY_CHECK_OBJ(Rays::Bitmap, self);
27
+ RUCY_CHECK_PTR(Rays::Bitmap, self);
28
28
  check_arg_count(__FILE__, __LINE__, "Bitmap#initialize", argc, 2, 3);
29
29
 
30
30
  *THIS = Rays::Bitmap(
31
31
  to<int>(argv[0]), to<int>(argv[1]),
32
- argc >= 3 ? to<Rays::ColorSpace>(argv[2]) : Rays::RGBA);
32
+ argc >= 3 ? to<Rays::ColorSpace>(argv[2]) : Rays::DEFAULT_COLORSPACE);
33
33
 
34
34
  return self;
35
35
  }
@@ -38,7 +38,7 @@ RUCY_END
38
38
  static
39
39
  RUCY_DEF1(initialize_copy, obj)
40
40
  {
41
- RUCY_CHECK_OBJ(Rays::Bitmap, self);
41
+ RUCY_CHECK_PTR(Rays::Bitmap, self);
42
42
 
43
43
  *THIS = to<Rays::Bitmap&>(obj).dup();
44
44
  return self;
@@ -73,7 +73,7 @@ RUCY_DEF0(color_space)
73
73
  RUCY_END
74
74
 
75
75
  static void
76
- set_pixels (Rays::Bitmap* bmp, Value pixels)
76
+ set_raw_pixels (Rays::Bitmap* bmp, Value pixels)
77
77
  {
78
78
  int w = bmp->width(), h = bmp->height();
79
79
  const auto& cs = bmp->color_space();
@@ -323,6 +323,23 @@ set_pixels (Rays::Bitmap* bmp, Value pixels)
323
323
  }
324
324
  }
325
325
 
326
+ static void
327
+ set_pixels (Rays::Bitmap* bmp, Value pixels)
328
+ {
329
+ const auto& cs = bmp->color_space();
330
+ if (!cs.has_alpha() || !cs.is_premult())
331
+ return set_raw_pixels(bmp, pixels);
332
+
333
+ int w = bmp->width(), h = bmp->height();
334
+ Rays::Bitmap straight(w, h, Rays::ColorSpace(cs.type(), false));
335
+ set_raw_pixels(&straight, pixels);
336
+
337
+ Rays::Bitmap premult = straight.dup(true);
338
+ size_t size = w * cs.Bpp();
339
+ for (int y = 0; y < h; ++y)
340
+ memcpy(bmp->at<uint8_t>(0, y), premult.at<uint8_t>(0, y), size);
341
+ }
342
+
326
343
  static inline uint32_t
327
344
  to_rgb (uint8_t r, uint8_t g, uint8_t b)
328
345
  {
@@ -608,7 +625,7 @@ get_32bit_pixels_string (const Rays::Bitmap& bmp)
608
625
  }
609
626
 
610
627
  return value(
611
- (const char*) &pixels[0], pixels.size() * sizeof(uint32_t),
628
+ (const char*) pixels.data(), pixels.size() * sizeof(uint32_t),
612
629
  rb_ascii8bit_encoding());
613
630
  }
614
631
 
@@ -627,14 +644,17 @@ RUCY_DEF0(get_pixels)
627
644
  {
628
645
  CHECK;
629
646
 
647
+ const auto& cs = THIS->color_space();
648
+ Rays::Bitmap bmp = cs.has_alpha() && cs.is_premult() ? THIS->dup(false) : *THIS;
649
+
630
650
  #ifdef RAYS_32BIT_PIXELS_STRING
631
- Value str = get_32bit_pixels_string(*THIS);
651
+ Value str = get_32bit_pixels_string(bmp);
632
652
  if (str) return str;
633
653
  #endif
634
654
 
635
655
  std::vector<VALUE> pixels;
636
- get_pixels(&pixels, *THIS);
637
- return array((const Value*) &pixels[0], pixels.size());
656
+ get_pixels(&pixels, bmp);
657
+ return array((const Value*) pixels.data(), pixels.size());
638
658
  }
639
659
  RUCY_END
640
660
 
data/ext/rays/bounds.cpp CHANGED
@@ -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
@@ -636,14 +635,12 @@ namespace Rucy
636
635
  template <> RAYS_EXPORT Rays::Bounds
637
636
  value_to<Rays::Bounds> (int argc, const Value* argv, bool convert)
638
637
  {
639
- if (argc == 1 && argv->is_array())
638
+ if (argc == 1 && argv && argv->is_array())
640
639
  {
641
640
  argc = argv->size();
642
641
  argv = argv->as_array();
643
642
  }
644
643
 
645
- assert(argc == 0 || (argc > 0 && argv));
646
-
647
644
  if (convert)
648
645
  {
649
646
  if (argc == 0)
data/ext/rays/camera.cpp CHANGED
@@ -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
@@ -20,9 +21,9 @@ RUCY_DEF_ALLOC(alloc, klass)
20
21
  RUCY_END
21
22
 
22
23
  static
23
- RUCY_DEF5(setup, device_name, min_width, min_height, resize, crop)
24
+ RUCY_DEF5(initialize, device_name, min_width, min_height, resize, crop)
24
25
  {
25
- RUCY_CHECK_OBJ(Rays::Camera, self);
26
+ RUCY_CHECK_PTR(Rays::Camera, self);
26
27
 
27
28
  *THIS = Rays::Camera(
28
29
  device_name ? device_name.c_str() : NULL,
@@ -32,6 +33,13 @@ RUCY_DEF5(setup, device_name, min_width, min_height, resize, crop)
32
33
  }
33
34
  RUCY_END
34
35
 
36
+ static
37
+ RUCY_DEF1(initialize_copy, obj)
38
+ {
39
+ Rays::rays_error(__FILE__, __LINE__, "can not duplicate Camera");
40
+ }
41
+ RUCY_END
42
+
35
43
  static
36
44
  RUCY_DEF0(start)
37
45
  {
@@ -138,10 +146,10 @@ RUCY_DEF0(device_names)
138
146
  {
139
147
  auto names = Rays::get_camera_device_names();
140
148
 
141
- std::vector<Value> v;
149
+ Value v = array(NULL, names.size());
142
150
  for (const auto& name : names)
143
- v.emplace_back(name.c_str());
144
- return array(&v[0], v.size());
151
+ v.push(name.c_str());
152
+ return v;
145
153
  }
146
154
  RUCY_END
147
155
 
@@ -155,7 +163,8 @@ Init_rays_camera ()
155
163
 
156
164
  cCamera = mRays.define_class("Camera");
157
165
  cCamera.define_alloc_func(alloc);
158
- cCamera.define_private_method("setup", setup);
166
+ cCamera.define_private_method("initialize!", initialize);
167
+ cCamera.define_private_method("initialize_copy", initialize_copy);
159
168
  cCamera.define_method("start", start);
160
169
  cCamera.define_method("stop", stop);
161
170
  cCamera.define_method("active?", is_active);
data/ext/rays/color.cpp CHANGED
@@ -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";
@@ -366,14 +366,12 @@ namespace Rucy
366
366
  template <> RAYS_EXPORT Rays::Color
367
367
  value_to<Rays::Color> (int argc, const Value*argv, bool convert)
368
368
  {
369
- if (argc == 1 && argv->is_array())
369
+ if (argc == 1 && argv && argv->is_array())
370
370
  {
371
371
  argc = argv->size();
372
372
  argv = argv->as_array();
373
373
  }
374
374
 
375
- assert(argc == 0 || (argc > 0 && argv));
376
-
377
375
  if (convert)
378
376
  {
379
377
  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
@@ -73,7 +74,7 @@ RUCY_END
73
74
  static
74
75
  RUCY_DEFN(initialize)
75
76
  {
76
- RUCY_CHECK_OBJ(Rays::ColorSpace, self);
77
+ RUCY_CHECK_PTR(Rays::ColorSpace, self);
77
78
  check_arg_count(__FILE__, __LINE__, "ColorSpace#initialize", argc, 1, 2);
78
79
 
79
80
  *THIS = to<Rays::ColorSpace>(argc, argv);
@@ -222,13 +223,14 @@ namespace Rucy
222
223
  template <> RAYS_EXPORT Rays::ColorSpace
223
224
  value_to<Rays::ColorSpace> (int argc, const Value* argv, bool convert)
224
225
  {
225
- if (argc == 1 && argv->is_array())
226
+ if (argc == 1 && argv && argv->is_array())
226
227
  {
227
228
  argc = argv->size();
228
229
  argv = argv->as_array();
229
230
  }
230
231
 
231
- assert(argc > 0 && argv);
232
+ if (argc <= 0 || !argv)
233
+ argument_error(__FILE__, __LINE__);
232
234
 
233
235
  if (convert)
234
236
  {
@@ -248,13 +250,15 @@ namespace Rucy
248
250
 
249
251
 
250
252
  template <> RAYS_EXPORT Rays::ColorSpaceType
251
- value_to<Rays::ColorSpaceType> (Value value, bool convert)
253
+ value_to<Rays::ColorSpaceType> (int argc, const Value* argv, bool convert)
252
254
  {
255
+ assert(argc > 0 && argv);
256
+
253
257
  if (convert)
254
258
  {
255
- if (value.is_s() || value.is_sym())
259
+ if (argv->is_s() || argv->is_sym())
256
260
  {
257
- const char* str = value.c_str();
261
+ const char* str = argv->c_str();
258
262
  for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
259
263
  {
260
264
  if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
@@ -263,7 +267,7 @@ namespace Rucy
263
267
  }
264
268
  }
265
269
 
266
- uint type = value_to<uint>(value, convert);
270
+ uint type = value_to<uint>(*argv, convert);
267
271
  if (type >= Rays::COLORSPACE_MAX)
268
272
  argument_error(__FILE__, __LINE__, "invalid color space type -- %d", type);
269
273
 
data/ext/rays/defs.h CHANGED
@@ -72,17 +72,17 @@ struct CreateParams
72
72
 
73
73
  const Rays::Point* ppoints () const
74
74
  {
75
- return points.empty() ? NULL : &points[0];
75
+ return points.empty() ? NULL : points.data();
76
76
  }
77
77
 
78
78
  const Rays::Color* pcolors () const
79
79
  {
80
- return colors.empty() ? NULL : &colors[0];
80
+ return colors.empty() ? NULL : colors.data();
81
81
  }
82
82
 
83
83
  const Rays::Point* ptexcoords () const
84
84
  {
85
- return texcoords.empty() ? NULL : &texcoords[0];
85
+ return texcoords.empty() ? NULL : texcoords.data();
86
86
  }
87
87
 
88
88
  size_t size () const
data/ext/rays/extconf.rb CHANGED
@@ -12,11 +12,12 @@ require 'rays/extension'
12
12
  Xot::ExtConf.new Xot, Rucy, Rays do
13
13
  setup do
14
14
  headers << 'ruby.h'
15
- libs.unshift 'gdi32', 'opengl32', 'glew32' if win32?
16
- libs.unshift 'SDL2', 'SDL2_ttf', 'GLEW', 'GL' if linux? || wasm?
17
- frameworks << 'AppKit' << 'OpenGL' << 'AVFoundation' if osx?
18
- $CPPFLAGS << ' -DRAYS_32BIT_PIXELS_STRING' if RUBY_PLATFORM == 'x64-mingw-ucrt'
19
- $LDFLAGS << ' -Wl,--out-implib=librays.dll.a' if mingw? || cygwin?
15
+ libs.unshift 'gdi32', 'opengl32', 'glew32' if win32?
16
+ libs.unshift 'SDL2', 'SDL2_ttf', 'GLEW', 'GL' if linux? || wasm?
17
+ frameworks.concat %w[AppKit OpenGL
18
+ AVFoundation CoreMedia CoreImage CoreVideo] if osx?
19
+ $CPPFLAGS << ' -DRAYS_32BIT_PIXELS_STRING' if RUBY_PLATFORM == 'x64-mingw-ucrt'
20
+ $LDFLAGS << ' -Wl,--out-implib=librays.dll.a' if mingw? || cygwin?
20
21
  end
21
22
 
22
23
  create_makefile 'rays_ext'
data/ext/rays/font.cpp CHANGED
@@ -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
@@ -22,7 +22,7 @@ RUCY_END
22
22
  static
23
23
  RUCY_DEFN(initialize)
24
24
  {
25
- RUCY_CHECK_OBJ(Rays::Font, self);
25
+ RUCY_CHECK_PTR(Rays::Font, self);
26
26
  check_arg_count(__FILE__, __LINE__, "Font#initialize", argc, 0, 1, 2, 3);
27
27
 
28
28
  *THIS = to<Rays::Font>(argc, argv);
@@ -33,7 +33,7 @@ RUCY_END
33
33
  static
34
34
  RUCY_DEF1(initialize_copy, obj)
35
35
  {
36
- RUCY_CHECK_OBJ(Rays::Font, self);
36
+ RUCY_CHECK_PTR(Rays::Font, self);
37
37
 
38
38
  *THIS = to<Rays::Font&>(obj).dup();
39
39
  return self;
@@ -41,10 +41,13 @@ RUCY_DEF1(initialize_copy, obj)
41
41
  RUCY_END
42
42
 
43
43
  static
44
- RUCY_DEF0(name)
44
+ RUCY_DEFN(name)
45
45
  {
46
46
  CHECK;
47
- return value(THIS->name().c_str());
47
+ check_arg_count(__FILE__, __LINE__, "Font#name", argc, 0, 1);
48
+
49
+ bool resolved = argc >= 1 ? to<bool>(argv[0]) : false;
50
+ return value(THIS->name(resolved).c_str());
48
51
  }
49
52
  RUCY_END
50
53
 
@@ -65,6 +68,74 @@ RUCY_DEF0(size)
65
68
  }
66
69
  RUCY_END
67
70
 
71
+ static int
72
+ to_font_weight (Value weight)
73
+ {
74
+ if (weight.is_s() || weight.is_sym())
75
+ {
76
+ static const struct {const char* name; int weight;} WEIGHTS[] =
77
+ {
78
+ // most used first
79
+ {"normal", Rays::Font::WEIGHT_NORMAL},
80
+ {"regular", Rays::Font::WEIGHT_NORMAL},
81
+ {"bold", Rays::Font::WEIGHT_BOLD},
82
+
83
+ {"thin", Rays::Font::WEIGHT_THIN},
84
+ {"extralight", Rays::Font::WEIGHT_EXTRALIGHT},
85
+ {"light", Rays::Font::WEIGHT_LIGHT},
86
+ {"medium", Rays::Font::WEIGHT_MEDIUM},
87
+ {"semibold", Rays::Font::WEIGHT_SEMIBOLD},
88
+ {"extrabold", Rays::Font::WEIGHT_EXTRABOLD},
89
+ {"black", Rays::Font::WEIGHT_BLACK},
90
+ };
91
+
92
+ const char* name = weight.c_str();
93
+ for (const auto& w : WEIGHTS)
94
+ {
95
+ if (strcasecmp(name, w.name) == 0)
96
+ return w.weight;
97
+ }
98
+
99
+ argument_error(
100
+ __FILE__, __LINE__, "unknown font weight: %s", weight.inspect().c_str());
101
+ }
102
+ return to<int>(weight);
103
+ }
104
+
105
+ static
106
+ RUCY_DEF1(set_weight, weight)
107
+ {
108
+ CHECK;
109
+ THIS->set_weight(to_font_weight(weight));
110
+ return weight;
111
+ }
112
+ RUCY_END
113
+
114
+ static
115
+ RUCY_DEF0(weight)
116
+ {
117
+ CHECK;
118
+ return value(THIS->weight());
119
+ }
120
+ RUCY_END
121
+
122
+ static
123
+ RUCY_DEF1(set_italic, italic)
124
+ {
125
+ CHECK;
126
+ THIS->set_italic(to<bool>(italic));
127
+ return italic;
128
+ }
129
+ RUCY_END
130
+
131
+ static
132
+ RUCY_DEF0(get_italic)
133
+ {
134
+ CHECK;
135
+ return value(THIS->italic());
136
+ }
137
+ RUCY_END
138
+
68
139
  static
69
140
  RUCY_DEF1(set_smooth, smooth)
70
141
  {
@@ -75,7 +146,7 @@ RUCY_DEF1(set_smooth, smooth)
75
146
  RUCY_END
76
147
 
77
148
  static
78
- RUCY_DEF0(smooth)
149
+ RUCY_DEF0(get_smooth)
79
150
  {
80
151
  CHECK;
81
152
  return value(THIS->smooth());
@@ -134,10 +205,10 @@ RUCY_DEF0(families)
134
205
  Hash hash;
135
206
  for (const auto& family : Rays::get_font_families())
136
207
  {
137
- std::vector<Value> members;
208
+ Value members = array(NULL, family.second.size());
138
209
  for (const auto& member : family.second)
139
- members.emplace_back(member.c_str());
140
- hash.set(family.first.c_str(), array(&members[0], members.size()));
210
+ members.push(member.c_str());
211
+ hash.set(family.first.c_str(), members);
141
212
  }
142
213
  return hash;
143
214
  }
@@ -172,8 +243,12 @@ Init_rays_font ()
172
243
  cFont.define_method("name", name);
173
244
  cFont.define_method("size=", set_size);
174
245
  cFont.define_method("size", size);
246
+ cFont.define_method("weight=", set_weight);
247
+ cFont.define_method("weight", weight);
248
+ cFont.define_method("italic=", set_italic);
249
+ cFont.define_method("italic", get_italic);
175
250
  cFont.define_method("smooth=", set_smooth);
176
- cFont.define_method("smooth", smooth);
251
+ cFont.define_method("smooth", get_smooth);
177
252
  cFont.define_method("width", width);
178
253
  cFont.define_method("height", height);
179
254
  cFont.define_method("ascent", ascent);
@@ -181,6 +256,18 @@ Init_rays_font ()
181
256
  cFont.define_method("leading", leading);
182
257
  cFont.define_module_function("families", families);
183
258
  cFont.define_module_function("load", load);
259
+
260
+ cFont.define_const("WEIGHT_MIN", Rays::Font::WEIGHT_MIN);
261
+ cFont.define_const("WEIGHT_THIN", Rays::Font::WEIGHT_THIN);
262
+ cFont.define_const("WEIGHT_EXTRALIGHT", Rays::Font::WEIGHT_EXTRALIGHT);
263
+ cFont.define_const("WEIGHT_LIGHT", Rays::Font::WEIGHT_LIGHT);
264
+ cFont.define_const("WEIGHT_NORMAL", Rays::Font::WEIGHT_NORMAL);
265
+ cFont.define_const("WEIGHT_MEDIUM", Rays::Font::WEIGHT_MEDIUM);
266
+ cFont.define_const("WEIGHT_SEMIBOLD", Rays::Font::WEIGHT_SEMIBOLD);
267
+ cFont.define_const("WEIGHT_BOLD", Rays::Font::WEIGHT_BOLD);
268
+ cFont.define_const("WEIGHT_EXTRABOLD", Rays::Font::WEIGHT_EXTRABOLD);
269
+ cFont.define_const("WEIGHT_BLACK", Rays::Font::WEIGHT_BLACK);
270
+ cFont.define_const("WEIGHT_MAX", Rays::Font::WEIGHT_MAX);
184
271
  }
185
272
 
186
273
 
@@ -191,26 +278,38 @@ namespace Rucy
191
278
  template <> RAYS_EXPORT Rays::Font
192
279
  value_to<Rays::Font> (int argc, const Value* argv, bool convert)
193
280
  {
194
- if (argc == 1 && argv->is_array())
281
+ if (argc == 1 && argv && argv->is_array())
195
282
  {
196
283
  argc = argv->size();
197
284
  argv = argv->as_array();
198
285
  }
199
286
 
200
- assert(argc == 0 || (argc > 0 && argv));
201
-
202
287
  if (convert)
203
288
  {
204
- if (argc == 0)
289
+ Value options = argc >= 1 && argv[argc - 1].is_hash() ? argv[--argc] : nil();
290
+ if (argc == 0 && !options)
205
291
  return Rays::get_default_font();
206
292
 
207
- coord size = argc >= 2 ? to<coord>(argv[1]) : (coord) Rays::Font::DEFAULT_SIZE;
208
- bool smooth = argc >= 3 ? to<bool>(argv[2]) : true;
209
-
210
- if (argv->is_nil())
211
- return Rays::Font(NULL, size, smooth);
212
- else if (argv->is_s() || argv->is_sym())
213
- return Rays::Font(argv[0].c_str(), size, smooth);
293
+ int weight = Rays::Font::DEFAULT_WEIGHT;
294
+ bool italic = false;
295
+ bool smooth = true;
296
+ if (options)
297
+ {
298
+ RUCY_SYMBOL(weight_sym, "weight");
299
+ RUCY_SYMBOL(italic_sym, "italic");
300
+ RUCY_SYMBOL(smooth_sym, "smooth");
301
+ Value v;
302
+ if (!(v = options.get(weight_sym.value())).is_nil()) weight = to_font_weight(v);
303
+ if (!(v = options.get(italic_sym.value())).is_nil()) italic = to<bool>(v);
304
+ if (!(v = options.get(smooth_sym.value())).is_nil()) smooth = to<bool>(v);
305
+ }
306
+
307
+ if (argc == 0 || argv->is_nil() || argv->is_s() || argv->is_sym())
308
+ {
309
+ const char* name = argc >= 1 && !argv[0].is_nil() ? argv[0].c_str() : NULL;
310
+ coord size = argc >= 2 ? to<coord>(argv[1]) : (coord) Rays::Font::DEFAULT_SIZE;
311
+ return Rays::Font(name, size, weight, italic, smooth);
312
+ }
214
313
  }
215
314
 
216
315
  if (argc != 1)
data/ext/rays/image.cpp CHANGED
@@ -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
@@ -24,7 +44,7 @@ RUCY_END
24
44
  static
25
45
  RUCY_DEF3(initialize, args, pixel_density, smooth)
26
46
  {
27
- RUCY_CHECK_OBJ(Rays::Image, self);
47
+ RUCY_CHECK_PTR(Rays::Image, self);
28
48
 
29
49
  size_t argc = args.size();
30
50
  check_arg_count(__FILE__, __LINE__, "Image#initialize!", argc, 1, 2, 3);
@@ -42,7 +62,7 @@ RUCY_DEF3(initialize, args, pixel_density, smooth)
42
62
  {
43
63
  int width = to<int>(args[0]);
44
64
  int height = to<int>(args[1]);
45
- auto cs = (argc >= 3) ? to<Rays::ColorSpace>(args[2]) : Rays::RGBA;
65
+ auto cs = (argc >= 3) ? to<Rays::ColorSpace>(args[2]) : Rays::DEFAULT_COLORSPACE;
46
66
  *THIS = Rays::Image(width, height, cs, pd, smooth);
47
67
  }
48
68
 
@@ -53,7 +73,7 @@ RUCY_END
53
73
  static
54
74
  RUCY_DEF1(initialize_copy, obj)
55
75
  {
56
- RUCY_CHECK_OBJ(Rays::Image, self);
76
+ RUCY_CHECK_PTR(Rays::Image, self);
57
77
 
58
78
  *THIS = to<Rays::Image&>(obj).dup();
59
79
  return self;
@@ -105,6 +125,7 @@ static
105
125
  RUCY_DEF0(painter)
106
126
  {
107
127
  CHECK;
128
+ self.check_frozen();
108
129
  return value(THIS->painter());
109
130
  }
110
131
  RUCY_END
@@ -113,6 +134,7 @@ static
113
134
  RUCY_DEF1(get_bitmap, modify)
114
135
  {
115
136
  CHECK;
137
+ if (modify) self.check_frozen();
116
138
  return value(THIS->bitmap(modify));
117
139
  }
118
140
  RUCY_END
@@ -121,6 +143,7 @@ static
121
143
  RUCY_DEF1(set_smooth, smooth)
122
144
  {
123
145
  CHECK;
146
+ self.check_frozen();
124
147
  THIS->set_smooth(smooth);
125
148
  return smooth;
126
149
  }
@@ -145,9 +168,10 @@ RUCY_DEF1(compare, other)
145
168
  RUCY_END
146
169
 
147
170
  static
148
- RUCY_DEF1(load, path)
171
+ RUCY_DEF3(load, path, pixel_density, smooth)
149
172
  {
150
- return value(Rays::load_image(path.c_str()));
173
+ return value(Rays::load_image(
174
+ path.c_str(), to<float>(pixel_density), to<bool>(smooth)));
151
175
  }
152
176
  RUCY_END
153
177
 
data/ext/rays/matrix.cpp CHANGED
@@ -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
@@ -304,14 +303,12 @@ namespace Rucy
304
303
  template <> RAYS_EXPORT Rays::Matrix
305
304
  value_to<Rays::Matrix> (int argc, const Value* argv, bool convert)
306
305
  {
307
- if (argc == 1 && argv->is_array())
306
+ if (argc == 1 && argv && argv->is_array())
308
307
  {
309
308
  argc = argv->size();
310
309
  argv = argv->as_array();
311
310
  }
312
311
 
313
- assert(argc == 0 || (argc > 0 && argv));
314
-
315
312
  if (convert)
316
313
  {
317
314
  if (argc == 0)