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.
- checksums.yaml +4 -4
- data/.doc/ext/rays/bitmap.cpp +287 -46
- data/.doc/ext/rays/camera.cpp +2 -2
- data/.doc/ext/rays/color.cpp +11 -0
- data/.doc/ext/rays/defs.cpp +32 -8
- data/.doc/ext/rays/font.cpp +50 -2
- data/.doc/ext/rays/image.cpp +3 -3
- data/.doc/ext/rays/matrix.cpp +65 -7
- data/.doc/ext/rays/native.cpp +2 -4
- data/.doc/ext/rays/painter.cpp +117 -9
- data/.doc/ext/rays/point.cpp +1 -11
- data/.doc/ext/rays/polygon.cpp +133 -97
- data/.doc/ext/rays/polyline.cpp +89 -10
- data/.doc/ext/rays/rays.cpp +80 -0
- data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/ChangeLog.md +46 -0
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +288 -46
- data/ext/rays/camera.cpp +2 -2
- data/ext/rays/color.cpp +13 -1
- data/ext/rays/defs.cpp +32 -8
- data/ext/rays/defs.h +56 -3
- data/ext/rays/font.cpp +56 -4
- data/ext/rays/image.cpp +3 -3
- data/ext/rays/matrix.cpp +69 -7
- data/ext/rays/native.cpp +2 -4
- data/ext/rays/painter.cpp +132 -13
- data/ext/rays/point.cpp +1 -12
- data/ext/rays/polygon.cpp +136 -99
- data/ext/rays/polyline.cpp +95 -9
- data/ext/rays/rays.cpp +80 -0
- data/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/include/rays/color.h +3 -1
- data/include/rays/defs.h +24 -26
- data/include/rays/font.h +17 -3
- data/include/rays/image.h +1 -1
- data/include/rays/matrix.h +24 -0
- data/include/rays/painter.h +24 -0
- data/include/rays/polygon.h +68 -43
- data/include/rays/polyline.h +17 -2
- data/include/rays/ruby/polygon.h +0 -11
- data/include/rays/ruby/rays.h +4 -0
- data/include/rays/{noise.h → util.h} +2 -2
- data/lib/rays/color.rb +7 -1
- data/lib/rays/font.rb +1 -1
- data/lib/rays/image.rb +11 -1
- data/lib/rays/matrix.rb +16 -0
- data/lib/rays/painter.rb +18 -7
- data/lib/rays/point.rb +5 -1
- data/lib/rays/polygon.rb +44 -35
- data/lib/rays/polyline.rb +54 -8
- data/lib/rays.rb +0 -1
- data/rays.gemspec +2 -2
- data/src/color.cpp +11 -2
- data/src/font.cpp +37 -18
- data/src/font.h +6 -5
- data/src/image.cpp +58 -14
- data/src/ios/font.mm +89 -32
- data/src/ios/helper.h +2 -2
- data/src/ios/helper.mm +2 -2
- data/src/matrix.cpp +45 -0
- data/src/osx/font.mm +93 -33
- data/src/osx/helper.h +2 -2
- data/src/osx/helper.mm +2 -2
- data/src/painter.cpp +246 -114
- data/src/painter.h +11 -3
- data/src/polygon.cpp +431 -332
- data/src/polyline.cpp +138 -27
- data/src/polyline.h +3 -5
- data/src/shader.cpp +36 -4
- data/src/shader.h +1 -1
- data/src/texture.cpp +23 -4
- data/src/texture.h +2 -0
- data/src/{noise.cpp → util.cpp} +1 -1
- data/src/win32/font.cpp +1 -1
- data/test/test_bitmap.rb +12 -5
- data/test/test_color.rb +25 -4
- data/test/test_font.rb +23 -2
- data/test/test_image.rb +44 -18
- data/test/test_matrix.rb +22 -0
- data/test/test_painter.rb +27 -0
- data/test/test_point.rb +1 -1
- data/test/test_polygon.rb +52 -45
- data/test/test_polyline.rb +191 -72
- metadata +12 -18
- data/.doc/ext/rays/polygon_line.cpp +0 -97
- data/ext/rays/polygon_line.cpp +0 -100
- data/lib/rays/polygon_line.rb +0 -33
- 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>
|
18
|
+
typedef std::shared_ptr<const __CFString> CFStringPtr;
|
19
19
|
|
20
|
-
|
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
|
-
|
16
|
+
CFStringPtr
|
17
17
|
cfstring (const char* str)
|
18
18
|
{
|
19
19
|
CFStringRef ref = CFStringCreateWithCString(
|
20
20
|
kCFAllocatorDefault, str, kCFStringEncodingUTF8);
|
21
|
-
return
|
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 <
|
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
|
-
|
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
|
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
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
61
|
-
|
96
|
+
RawFont
|
97
|
+
RawFont_load (const char* path, coord size)
|
98
|
+
{
|
99
|
+
if (!path)
|
100
|
+
argument_error(__FILE__, __LINE__);
|
62
101
|
|
63
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
215
|
+
CTLinePtr line = make_line(self->font, str);
|
153
216
|
if (!line)
|
154
217
|
rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
|
155
218
|
|
156
|
-
|
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>
|
18
|
+
typedef std::shared_ptr<const __CFString> CFStringPtr;
|
19
19
|
|
20
|
-
|
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
|
-
|
16
|
+
CFStringPtr
|
17
17
|
cfstring (const char* str)
|
18
18
|
{
|
19
19
|
CFStringRef ref = CFStringCreateWithCString(
|
20
20
|
kCFAllocatorDefault, str, kCFStringEncodingUTF8);
|
21
|
-
return
|
21
|
+
return CFStringPtr(ref, safe_cfrelease);
|
22
22
|
}
|
23
23
|
|
24
24
|
|