rays 0.1.46 → 0.1.48
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 +499 -0
- data/.doc/ext/rays/camera.cpp +2 -2
- data/.doc/ext/rays/defs.cpp +35 -11
- data/.doc/ext/rays/font.cpp +50 -2
- data/.doc/ext/rays/native.cpp +2 -4
- data/.doc/ext/rays/painter.cpp +111 -6
- data/.doc/ext/rays/polygon.cpp +152 -41
- data/.doc/ext/rays/polyline.cpp +89 -10
- data/.doc/ext/rays/rays.cpp +91 -11
- data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/.github/workflows/test.yml +0 -1
- data/ChangeLog.md +38 -0
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +501 -0
- data/ext/rays/camera.cpp +2 -2
- data/ext/rays/defs.cpp +35 -11
- 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 +125 -11
- data/ext/rays/polygon.cpp +161 -41
- data/ext/rays/polyline.cpp +95 -9
- data/ext/rays/rays.cpp +91 -11
- data/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/include/rays/defs.h +24 -0
- data/include/rays/font.h +17 -3
- data/include/rays/matrix.h +2 -0
- data/include/rays/painter.h +29 -1
- data/include/rays/polygon.h +57 -33
- data/include/rays/polyline.h +20 -1
- 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 +13 -2
- data/lib/rays/point.rb +1 -1
- data/lib/rays/polygon.rb +54 -16
- data/lib/rays/polyline.rb +54 -8
- data/lib/rays.rb +0 -1
- data/rays.gemspec +2 -2
- data/src/color_space.cpp +2 -2
- data/src/font.cpp +24 -2
- data/src/font.h +8 -1
- data/src/ios/font.mm +88 -27
- data/src/matrix.cpp +8 -0
- 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 +227 -90
- data/src/painter.h +11 -3
- data/src/polygon.cpp +588 -205
- data/src/polyline.cpp +154 -28
- 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 +16 -2
- 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 +11 -17
- 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/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
|
|