rays 0.1.47 → 0.1.48
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.doc/ext/rays/bitmap.cpp +287 -46
- data/.doc/ext/rays/camera.cpp +2 -2
- data/.doc/ext/rays/defs.cpp +32 -8
- data/.doc/ext/rays/font.cpp +50 -2
- data/.doc/ext/rays/native.cpp +2 -4
- data/.doc/ext/rays/painter.cpp +73 -3
- data/.doc/ext/rays/polygon.cpp +131 -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 +23 -0
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +288 -46
- data/ext/rays/camera.cpp +2 -2
- data/ext/rays/defs.cpp +32 -8
- data/ext/rays/defs.h +56 -3
- data/ext/rays/font.cpp +56 -4
- data/ext/rays/native.cpp +2 -4
- data/ext/rays/painter.cpp +80 -3
- data/ext/rays/polygon.cpp +134 -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/defs.h +24 -26
- data/include/rays/font.h +17 -3
- data/include/rays/painter.h +14 -0
- data/include/rays/polygon.h +56 -37
- 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 +1 -1
- data/lib/rays/font.rb +1 -1
- data/lib/rays/image.rb +1 -1
- data/lib/rays/painter.rb +12 -1
- data/lib/rays/point.rb +1 -1
- data/lib/rays/polygon.rb +44 -35
- data/lib/rays/polyline.rb +54 -8
- data/lib/rays.rb +0 -1
- data/rays.gemspec +1 -1
- data/src/font.cpp +24 -2
- data/src/font.h +8 -1
- data/src/ios/font.mm +88 -27
- data/src/osx/font.mm +90 -28
- data/src/osx/helper.h +2 -2
- data/src/osx/helper.mm +2 -2
- data/src/painter.cpp +155 -85
- data/src/painter.h +11 -3
- data/src/polygon.cpp +404 -315
- 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 +2 -2
- 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 +4 -0
- data/test/test_font.rb +20 -2
- data/test/test_image.rb +18 -18
- data/test/test_point.rb +1 -1
- data/test/test_polygon.rb +52 -45
- data/test/test_polyline.rb +191 -72
- metadata +9 -15
- 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/font.h
CHANGED
@@ -15,11 +15,15 @@ namespace Rays
|
|
15
15
|
class RawFont
|
16
16
|
{
|
17
17
|
|
18
|
+
typedef RawFont This;
|
19
|
+
|
18
20
|
public:
|
19
21
|
|
20
22
|
RawFont ();
|
21
23
|
|
22
|
-
RawFont (const char* name, coord size
|
24
|
+
RawFont (const char* name, coord size);
|
25
|
+
|
26
|
+
RawFont (const This& obj, coord size);
|
23
27
|
|
24
28
|
~RawFont ();
|
25
29
|
|
@@ -58,6 +62,9 @@ namespace Rays
|
|
58
62
|
coord* ascent = NULL, coord* descent = NULL, coord* leading = NULL);
|
59
63
|
|
60
64
|
|
65
|
+
RawFont RawFont_load (const char* path, coord size);
|
66
|
+
|
67
|
+
|
61
68
|
}// Rays
|
62
69
|
|
63
70
|
|
data/src/ios/font.mm
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#include "../font.h"
|
3
3
|
|
4
4
|
|
5
|
+
#include <memory>
|
5
6
|
#import <CoreGraphics/CGContext.h>
|
6
7
|
#import <CoreText/CoreText.h>
|
7
8
|
#include "rays/exception.h"
|
@@ -12,15 +13,23 @@ namespace Rays
|
|
12
13
|
{
|
13
14
|
|
14
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
|
+
|
15
27
|
struct RawFont::Data
|
16
28
|
{
|
17
29
|
|
18
|
-
CTFontRef font;
|
30
|
+
CTFontRef font = NULL;
|
19
31
|
|
20
|
-
|
21
|
-
: font(NULL)
|
22
|
-
{
|
23
|
-
}
|
32
|
+
String path;
|
24
33
|
|
25
34
|
~Data ()
|
26
35
|
{
|
@@ -34,7 +43,7 @@ namespace Rays
|
|
34
43
|
};// RawFont::Data
|
35
44
|
|
36
45
|
|
37
|
-
static
|
46
|
+
static CTLinePtr
|
38
47
|
make_line (CTFontRef font, const char* str)
|
39
48
|
{
|
40
49
|
if (!font || !str || *str == '\0')
|
@@ -50,18 +59,67 @@ namespace Rays
|
|
50
59
|
};
|
51
60
|
size_t nkeys = sizeof(keys) / sizeof(keys[0]);
|
52
61
|
|
53
|
-
|
54
|
-
|
55
|
-
|
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);
|
56
71
|
|
57
|
-
|
58
|
-
|
59
|
-
|
72
|
+
return CTLinePtr(
|
73
|
+
CTLineCreateWithAttributedString(attrstr.get()),
|
74
|
+
CFRelease);
|
75
|
+
}
|
60
76
|
|
61
|
-
|
62
|
-
|
77
|
+
const FontFamilyMap&
|
78
|
+
get_font_families ()
|
79
|
+
{
|
80
|
+
static const FontFamilyMap MAP = []() {
|
81
|
+
NSFontManager* fm = NSFontManager.sharedFontManager;
|
63
82
|
|
64
|
-
|
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
|
+
}
|
95
|
+
|
96
|
+
RawFont
|
97
|
+
RawFont_load (const char* path, coord size)
|
98
|
+
{
|
99
|
+
if (!path)
|
100
|
+
argument_error(__FILE__, __LINE__);
|
101
|
+
|
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;
|
65
123
|
}
|
66
124
|
|
67
125
|
|
@@ -76,6 +134,15 @@ namespace Rays
|
|
76
134
|
: CTFontCreateUIFontForLanguage(kCTFontSystemFontType, size, NULL);
|
77
135
|
}
|
78
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
|
+
|
79
146
|
RawFont::~RawFont ()
|
80
147
|
{
|
81
148
|
}
|
@@ -92,7 +159,7 @@ namespace Rays
|
|
92
159
|
|
93
160
|
if (*str == '\0') return;
|
94
161
|
|
95
|
-
|
162
|
+
CTLinePtr line = make_line(self->font, str);
|
96
163
|
if (!line)
|
97
164
|
rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
|
98
165
|
|
@@ -112,10 +179,8 @@ namespace Rays
|
|
112
179
|
CGContextSaveGState(context);
|
113
180
|
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
|
114
181
|
CGContextSetTextPosition(context, x, context_height - ascent - y);
|
115
|
-
CTLineDraw(line, context);
|
182
|
+
CTLineDraw(line.get(), context);
|
116
183
|
CGContextRestoreGState(context);
|
117
|
-
|
118
|
-
CFRelease(line);
|
119
184
|
}
|
120
185
|
|
121
186
|
String
|
@@ -123,14 +188,13 @@ namespace Rays
|
|
123
188
|
{
|
124
189
|
if (!*this) return "";
|
125
190
|
|
126
|
-
|
191
|
+
CFStringPtr str(CTFontCopyFullName(self->font), CFRelease);
|
127
192
|
|
128
193
|
enum {BUFSIZE = 2048};
|
129
194
|
char buf[BUFSIZE + 1];
|
130
|
-
if (!CFStringGetCString(str, buf, BUFSIZE, kCFStringEncodingUTF8))
|
195
|
+
if (!CFStringGetCString(str.get(), buf, BUFSIZE, kCFStringEncodingUTF8))
|
131
196
|
buf[0] = '\0';
|
132
197
|
|
133
|
-
CFRelease(str);
|
134
198
|
return buf;
|
135
199
|
}
|
136
200
|
|
@@ -152,14 +216,11 @@ namespace Rays
|
|
152
216
|
|
153
217
|
if (*str == '\0') return 0;
|
154
218
|
|
155
|
-
|
219
|
+
CTLinePtr line = make_line(self->font, str);
|
156
220
|
if (!line)
|
157
221
|
rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
|
158
222
|
|
159
|
-
|
160
|
-
CFRelease(line);
|
161
|
-
|
162
|
-
return w;
|
223
|
+
return CTLineGetTypographicBounds(line.get(), NULL, NULL, NULL);
|
163
224
|
}
|
164
225
|
|
165
226
|
coord
|
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);
|
55
71
|
|
56
|
-
|
57
|
-
|
58
|
-
|
72
|
+
return CTLinePtr(
|
73
|
+
CTLineCreateWithAttributedString(attrstr.get()),
|
74
|
+
CFRelease);
|
75
|
+
}
|
59
76
|
|
60
|
-
|
61
|
-
|
77
|
+
const FontFamilyMap&
|
78
|
+
get_font_families ()
|
79
|
+
{
|
80
|
+
static const FontFamilyMap MAP = []() {
|
81
|
+
NSFontManager* fm = NSFontManager.sharedFontManager;
|
62
82
|
|
63
|
-
|
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
|
+
}
|
95
|
+
|
96
|
+
RawFont
|
97
|
+
RawFont_load (const char* path, coord size)
|
98
|
+
{
|
99
|
+
if (!path)
|
100
|
+
argument_error(__FILE__, __LINE__);
|
101
|
+
|
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,7 +159,7 @@ 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
|
|
@@ -109,10 +177,8 @@ namespace Rays
|
|
109
177
|
CGContextSaveGState(context);
|
110
178
|
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
|
111
179
|
CGContextSetTextPosition(context, x, context_height - ascent - y);
|
112
|
-
CTLineDraw(line, context);
|
180
|
+
CTLineDraw(line.get(), context);
|
113
181
|
CGContextRestoreGState(context);
|
114
|
-
|
115
|
-
CFRelease(line);
|
116
182
|
}
|
117
183
|
|
118
184
|
String
|
@@ -120,14 +186,13 @@ namespace Rays
|
|
120
186
|
{
|
121
187
|
if (!*this) return "";
|
122
188
|
|
123
|
-
|
189
|
+
CFStringPtr str(CTFontCopyFullName(self->font), CFRelease);
|
124
190
|
|
125
191
|
enum {BUFSIZE = 2048};
|
126
192
|
char buf[BUFSIZE + 1];
|
127
|
-
if (!CFStringGetCString(str, buf, BUFSIZE, kCFStringEncodingUTF8))
|
193
|
+
if (!CFStringGetCString(str.get(), buf, BUFSIZE, kCFStringEncodingUTF8))
|
128
194
|
buf[0] = '\0';
|
129
195
|
|
130
|
-
CFRelease(str);
|
131
196
|
return buf;
|
132
197
|
}
|
133
198
|
|
@@ -149,14 +214,11 @@ namespace Rays
|
|
149
214
|
|
150
215
|
if (*str == '\0') return 0;
|
151
216
|
|
152
|
-
|
217
|
+
CTLinePtr line = make_line(self->font, str);
|
153
218
|
if (!line)
|
154
219
|
rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
|
155
220
|
|
156
|
-
|
157
|
-
CFRelease(line);
|
158
|
-
|
159
|
-
return w;
|
221
|
+
return CTLineGetTypographicBounds(line.get(), NULL, NULL, NULL);
|
160
222
|
}
|
161
223
|
|
162
224
|
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
|
|