rays 0.1.47 → 0.1.49

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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +287 -46
  3. data/.doc/ext/rays/camera.cpp +2 -2
  4. data/.doc/ext/rays/color.cpp +11 -0
  5. data/.doc/ext/rays/defs.cpp +32 -8
  6. data/.doc/ext/rays/font.cpp +50 -2
  7. data/.doc/ext/rays/image.cpp +3 -3
  8. data/.doc/ext/rays/matrix.cpp +65 -7
  9. data/.doc/ext/rays/native.cpp +2 -4
  10. data/.doc/ext/rays/painter.cpp +117 -9
  11. data/.doc/ext/rays/point.cpp +1 -11
  12. data/.doc/ext/rays/polygon.cpp +133 -97
  13. data/.doc/ext/rays/polyline.cpp +89 -10
  14. data/.doc/ext/rays/rays.cpp +80 -0
  15. data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
  16. data/ChangeLog.md +46 -0
  17. data/VERSION +1 -1
  18. data/ext/rays/bitmap.cpp +288 -46
  19. data/ext/rays/camera.cpp +2 -2
  20. data/ext/rays/color.cpp +13 -1
  21. data/ext/rays/defs.cpp +32 -8
  22. data/ext/rays/defs.h +56 -3
  23. data/ext/rays/font.cpp +56 -4
  24. data/ext/rays/image.cpp +3 -3
  25. data/ext/rays/matrix.cpp +69 -7
  26. data/ext/rays/native.cpp +2 -4
  27. data/ext/rays/painter.cpp +132 -13
  28. data/ext/rays/point.cpp +1 -12
  29. data/ext/rays/polygon.cpp +136 -99
  30. data/ext/rays/polyline.cpp +95 -9
  31. data/ext/rays/rays.cpp +80 -0
  32. data/ext/rays/{noise.cpp → util.cpp} +2 -2
  33. data/include/rays/color.h +3 -1
  34. data/include/rays/defs.h +24 -26
  35. data/include/rays/font.h +17 -3
  36. data/include/rays/image.h +1 -1
  37. data/include/rays/matrix.h +24 -0
  38. data/include/rays/painter.h +24 -0
  39. data/include/rays/polygon.h +68 -43
  40. data/include/rays/polyline.h +17 -2
  41. data/include/rays/ruby/polygon.h +0 -11
  42. data/include/rays/ruby/rays.h +4 -0
  43. data/include/rays/{noise.h → util.h} +2 -2
  44. data/lib/rays/color.rb +7 -1
  45. data/lib/rays/font.rb +1 -1
  46. data/lib/rays/image.rb +11 -1
  47. data/lib/rays/matrix.rb +16 -0
  48. data/lib/rays/painter.rb +18 -7
  49. data/lib/rays/point.rb +5 -1
  50. data/lib/rays/polygon.rb +44 -35
  51. data/lib/rays/polyline.rb +54 -8
  52. data/lib/rays.rb +0 -1
  53. data/rays.gemspec +2 -2
  54. data/src/color.cpp +11 -2
  55. data/src/font.cpp +37 -18
  56. data/src/font.h +6 -5
  57. data/src/image.cpp +58 -14
  58. data/src/ios/font.mm +89 -32
  59. data/src/ios/helper.h +2 -2
  60. data/src/ios/helper.mm +2 -2
  61. data/src/matrix.cpp +45 -0
  62. data/src/osx/font.mm +93 -33
  63. data/src/osx/helper.h +2 -2
  64. data/src/osx/helper.mm +2 -2
  65. data/src/painter.cpp +246 -114
  66. data/src/painter.h +11 -3
  67. data/src/polygon.cpp +431 -332
  68. data/src/polyline.cpp +138 -27
  69. data/src/polyline.h +3 -5
  70. data/src/shader.cpp +36 -4
  71. data/src/shader.h +1 -1
  72. data/src/texture.cpp +23 -4
  73. data/src/texture.h +2 -0
  74. data/src/{noise.cpp → util.cpp} +1 -1
  75. data/src/win32/font.cpp +1 -1
  76. data/test/test_bitmap.rb +12 -5
  77. data/test/test_color.rb +25 -4
  78. data/test/test_font.rb +23 -2
  79. data/test/test_image.rb +44 -18
  80. data/test/test_matrix.rb +22 -0
  81. data/test/test_painter.rb +27 -0
  82. data/test/test_point.rb +1 -1
  83. data/test/test_polygon.rb +52 -45
  84. data/test/test_polyline.rb +191 -72
  85. metadata +12 -18
  86. data/.doc/ext/rays/polygon_line.cpp +0 -97
  87. data/ext/rays/polygon_line.cpp +0 -100
  88. data/lib/rays/polygon_line.rb +0 -33
  89. data/test/test_polygon_line.rb +0 -164
data/src/ios/helper.h CHANGED
@@ -15,9 +15,9 @@ namespace Rays
15
15
  void safe_cfrelease (CFTypeRef ref);
16
16
 
17
17
 
18
- typedef std::shared_ptr<const __CFString> CFString;
18
+ typedef std::shared_ptr<const __CFString> CFStringPtr;
19
19
 
20
- CFString cfstring (const char* str);
20
+ CFStringPtr cfstring (const char* str);
21
21
 
22
22
 
23
23
  }// Rays
data/src/ios/helper.mm CHANGED
@@ -13,12 +13,12 @@ namespace Rays
13
13
  }
14
14
 
15
15
 
16
- CFString
16
+ CFStringPtr
17
17
  cfstring (const char* str)
18
18
  {
19
19
  CFStringRef ref = CFStringCreateWithCString(
20
20
  kCFAllocatorDefault, str, kCFStringEncodingUTF8);
21
- return CFString(ref, safe_cfrelease);
21
+ return CFStringPtr(ref, safe_cfrelease);
22
22
  }
23
23
 
24
24
 
data/src/matrix.cpp CHANGED
@@ -13,6 +13,44 @@ namespace Rays
13
13
  {
14
14
 
15
15
 
16
+ Matrix
17
+ ortho (coord left, coord right, coord top, coord bottom)
18
+ {
19
+ return to_rays(glm::ortho(left, right, bottom, top));
20
+ }
21
+
22
+ Matrix
23
+ ortho (coord left, coord right, coord top, coord bottom, coord near, coord far)
24
+ {
25
+ return to_rays(glm::ortho(left, right, bottom, top, near, far));
26
+ }
27
+
28
+ Matrix
29
+ perspective (float fov_y, float aspect_ratio, coord near, coord far)
30
+ {
31
+ return to_rays(glm::perspective(
32
+ (float) Xot::deg2rad(fov_y), aspect_ratio, near, far));
33
+ }
34
+
35
+ Matrix
36
+ look_at (
37
+ coord eye_x, coord eye_y, coord eye_z,
38
+ coord target_x, coord target_y, coord target_z,
39
+ coord up_x, coord up_y, coord up_z)
40
+ {
41
+ return to_rays(glm::lookAt(
42
+ Vec3( eye_x, eye_y, eye_z),
43
+ Vec3(target_x, target_y, target_z),
44
+ Vec3( up_x, up_y, up_z)));
45
+ }
46
+
47
+ Matrix
48
+ look_at (const Point& eye, const Point& target, const Point& up)
49
+ {
50
+ return to_rays(glm::lookAt(to_glm(eye), to_glm(target), to_glm(up)));
51
+ }
52
+
53
+
16
54
  Matrix::Matrix (coord value)
17
55
  {
18
56
  reset(value);
@@ -84,6 +122,13 @@ namespace Rays
84
122
  return *this;
85
123
  }
86
124
 
125
+ Matrix&
126
+ Matrix::transpose ()
127
+ {
128
+ to_glm(*this) = glm::transpose(to_glm(*this));
129
+ return *this;
130
+ }
131
+
87
132
  Matrix&
88
133
  Matrix::translate (coord x, coord y, coord z)
89
134
  {
data/src/osx/font.mm CHANGED
@@ -2,7 +2,9 @@
2
2
  #include "../font.h"
3
3
 
4
4
 
5
- #include <ApplicationServices/ApplicationServices.h>
5
+ #include <memory>
6
+ #import <ApplicationServices/ApplicationServices.h>
7
+ #import <AppKit/AppKit.h>
6
8
  #include "rays/exception.h"
7
9
  #include "helper.h"
8
10
 
@@ -11,15 +13,23 @@ namespace Rays
11
13
  {
12
14
 
13
15
 
16
+ typedef std::shared_ptr<const __CFDictionary> CFDictionaryPtr;
17
+
18
+ typedef std::shared_ptr<const __CFAttributedString> CFAttributedStringPtr;
19
+
20
+ typedef std::shared_ptr<CGDataProvider> CGDataProviderPtr;
21
+
22
+ typedef std::shared_ptr<CGFont> CGFontPtr;
23
+
24
+ typedef std::shared_ptr<const __CTLine> CTLinePtr;
25
+
26
+
14
27
  struct RawFont::Data
15
28
  {
16
29
 
17
- CTFontRef font;
30
+ CTFontRef font = NULL;
18
31
 
19
- Data ()
20
- : font(NULL)
21
- {
22
- }
32
+ String path;
23
33
 
24
34
  ~Data ()
25
35
  {
@@ -33,7 +43,7 @@ namespace Rays
33
43
  };// RawFont::Data
34
44
 
35
45
 
36
- static CTLineRef
46
+ static CTLinePtr
37
47
  make_line (CTFontRef font, const char* str)
38
48
  {
39
49
  if (!font || !str || *str == '\0')
@@ -49,18 +59,67 @@ namespace Rays
49
59
  };
50
60
  size_t nkeys = sizeof(keys) / sizeof(keys[0]);
51
61
 
52
- CFDictionaryRef attr = CFDictionaryCreate(
53
- NULL, (const void**) &keys, (const void**) &values, nkeys,
54
- &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
62
+ CFDictionaryPtr attr(
63
+ CFDictionaryCreate(
64
+ NULL, (const void**) &keys, (const void**) &values, nkeys,
65
+ &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks),
66
+ CFRelease);
67
+
68
+ CFAttributedStringPtr attrstr(
69
+ CFAttributedStringCreate(NULL, cfstring(str).get(), attr.get()),
70
+ CFRelease);
71
+
72
+ return CTLinePtr(
73
+ CTLineCreateWithAttributedString(attrstr.get()),
74
+ CFRelease);
75
+ }
76
+
77
+ const FontFamilyMap&
78
+ get_font_families ()
79
+ {
80
+ static const FontFamilyMap MAP = []() {
81
+ NSFontManager* fm = NSFontManager.sharedFontManager;
55
82
 
56
- CFAttributedStringRef attrstr = CFAttributedStringCreate(
57
- NULL, cfstring(str).get(), attr);
58
- CFRelease(attr);
83
+ FontFamilyMap map;
84
+ for (NSString* family in fm.availableFontFamilies)
85
+ {
86
+ FontFamilyMap::mapped_type array;
87
+ for (NSArray<NSString*>* members in [fm availableMembersOfFontFamily: family])
88
+ array.emplace_back(members[0].UTF8String);
89
+ map[family.UTF8String] = array;
90
+ }
91
+ return map;
92
+ }();
93
+ return MAP;
94
+ }
59
95
 
60
- CTLineRef line = CTLineCreateWithAttributedString(attrstr);
61
- CFRelease(attrstr);
96
+ RawFont
97
+ RawFont_load (const char* path, coord size)
98
+ {
99
+ if (!path)
100
+ argument_error(__FILE__, __LINE__);
62
101
 
63
- return line;
102
+ CGDataProviderPtr data_provider(
103
+ CGDataProviderCreateWithFilename(path),
104
+ CGDataProviderRelease);
105
+ if (!data_provider)
106
+ rays_error(__FILE__, __LINE__, "failed to create CGDataProvider");
107
+
108
+ CGFontPtr cgfont(
109
+ CGFontCreateWithDataProvider(data_provider.get()),
110
+ CGFontRelease);
111
+ if (!cgfont)
112
+ rays_error(__FILE__, __LINE__, "failed to create CGFont");
113
+
114
+ CTFontRef ctfont = CTFontCreateWithGraphicsFont(
115
+ cgfont.get(), size, NULL, NULL);
116
+ if (!ctfont)
117
+ rays_error(__FILE__, __LINE__, "failed to create CTFont");
118
+
119
+ RawFont rawfont;
120
+ rawfont.self->font = ctfont;
121
+ rawfont.self->path = path;
122
+ return rawfont;
64
123
  }
65
124
 
66
125
 
@@ -75,6 +134,15 @@ namespace Rays
75
134
  : CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, size, NULL);
76
135
  }
77
136
 
137
+ RawFont::RawFont (const This& obj, coord size)
138
+ {
139
+ const char* path = obj.self->path.empty() ? NULL : obj.self->path.c_str();
140
+ if (path)
141
+ *this = RawFont_load(path, size);
142
+ else
143
+ self->font = CTFontCreateWithName(cfstring(obj.name()).get(), size, NULL);
144
+ }
145
+
78
146
  RawFont::~RawFont ()
79
147
  {
80
148
  }
@@ -91,15 +159,13 @@ namespace Rays
91
159
 
92
160
  if (*str == '\0') return;
93
161
 
94
- CTLineRef line = make_line(self->font, str);
162
+ CTLinePtr line = make_line(self->font, str);
95
163
  if (!line)
96
164
  rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
97
165
 
98
- coord width = 0, height = 0, ascent = 0;
99
- width = get_width(str);
100
- height = get_height(&ascent);
101
-
102
- height = ceil(height);
166
+ coord width, height, ascent = 0;
167
+ width = ceil(get_width(str));
168
+ height = ceil(get_height(&ascent));
103
169
  ascent = floor(ascent);
104
170
 
105
171
  CGRect rect = CGRectMake(x, context_height - height - y, width, height);
@@ -109,10 +175,8 @@ namespace Rays
109
175
  CGContextSaveGState(context);
110
176
  CGContextSetTextMatrix(context, CGAffineTransformIdentity);
111
177
  CGContextSetTextPosition(context, x, context_height - ascent - y);
112
- CTLineDraw(line, context);
178
+ CTLineDraw(line.get(), context);
113
179
  CGContextRestoreGState(context);
114
-
115
- CFRelease(line);
116
180
  }
117
181
 
118
182
  String
@@ -120,14 +184,13 @@ namespace Rays
120
184
  {
121
185
  if (!*this) return "";
122
186
 
123
- CFStringRef str = CTFontCopyFullName(self->font);
187
+ CFStringPtr str(CTFontCopyFullName(self->font), CFRelease);
124
188
 
125
189
  enum {BUFSIZE = 2048};
126
190
  char buf[BUFSIZE + 1];
127
- if (!CFStringGetCString(str, buf, BUFSIZE, kCFStringEncodingUTF8))
191
+ if (!CFStringGetCString(str.get(), buf, BUFSIZE, kCFStringEncodingUTF8))
128
192
  buf[0] = '\0';
129
193
 
130
- CFRelease(str);
131
194
  return buf;
132
195
  }
133
196
 
@@ -149,14 +212,11 @@ namespace Rays
149
212
 
150
213
  if (*str == '\0') return 0;
151
214
 
152
- CTLineRef line = make_line(self->font, str);
215
+ CTLinePtr line = make_line(self->font, str);
153
216
  if (!line)
154
217
  rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
155
218
 
156
- coord w = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
157
- CFRelease(line);
158
-
159
- return w;
219
+ return CTLineGetTypographicBounds(line.get(), NULL, NULL, NULL);
160
220
  }
161
221
 
162
222
  coord
data/src/osx/helper.h CHANGED
@@ -15,9 +15,9 @@ namespace Rays
15
15
  void safe_cfrelease (CFTypeRef ref);
16
16
 
17
17
 
18
- typedef std::shared_ptr<const __CFString> CFString;
18
+ typedef std::shared_ptr<const __CFString> CFStringPtr;
19
19
 
20
- CFString cfstring (const char* str);
20
+ CFStringPtr cfstring (const char* str);
21
21
 
22
22
 
23
23
  }// Rays
data/src/osx/helper.mm CHANGED
@@ -13,12 +13,12 @@ namespace Rays
13
13
  }
14
14
 
15
15
 
16
- CFString
16
+ CFStringPtr
17
17
  cfstring (const char* str)
18
18
  {
19
19
  CFStringRef ref = CFStringCreateWithCString(
20
20
  kCFAllocatorDefault, str, kCFStringEncodingUTF8);
21
- return CFString(ref, safe_cfrelease);
21
+ return CFStringPtr(ref, safe_cfrelease);
22
22
  }
23
23
 
24
24