rays 0.1.46 → 0.1.48

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +499 -0
  3. data/.doc/ext/rays/camera.cpp +2 -2
  4. data/.doc/ext/rays/defs.cpp +35 -11
  5. data/.doc/ext/rays/font.cpp +50 -2
  6. data/.doc/ext/rays/native.cpp +2 -4
  7. data/.doc/ext/rays/painter.cpp +111 -6
  8. data/.doc/ext/rays/polygon.cpp +152 -41
  9. data/.doc/ext/rays/polyline.cpp +89 -10
  10. data/.doc/ext/rays/rays.cpp +91 -11
  11. data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
  12. data/.github/workflows/test.yml +0 -1
  13. data/ChangeLog.md +38 -0
  14. data/Rakefile +4 -4
  15. data/VERSION +1 -1
  16. data/ext/rays/bitmap.cpp +501 -0
  17. data/ext/rays/camera.cpp +2 -2
  18. data/ext/rays/defs.cpp +35 -11
  19. data/ext/rays/defs.h +56 -3
  20. data/ext/rays/font.cpp +56 -4
  21. data/ext/rays/native.cpp +2 -4
  22. data/ext/rays/painter.cpp +125 -11
  23. data/ext/rays/polygon.cpp +161 -41
  24. data/ext/rays/polyline.cpp +95 -9
  25. data/ext/rays/rays.cpp +91 -11
  26. data/ext/rays/{noise.cpp → util.cpp} +2 -2
  27. data/include/rays/defs.h +24 -0
  28. data/include/rays/font.h +17 -3
  29. data/include/rays/matrix.h +2 -0
  30. data/include/rays/painter.h +29 -1
  31. data/include/rays/polygon.h +57 -33
  32. data/include/rays/polyline.h +20 -1
  33. data/include/rays/ruby/polygon.h +0 -11
  34. data/include/rays/ruby/rays.h +4 -0
  35. data/include/rays/{noise.h → util.h} +2 -2
  36. data/lib/rays/color.rb +1 -1
  37. data/lib/rays/font.rb +1 -1
  38. data/lib/rays/image.rb +1 -1
  39. data/lib/rays/painter.rb +13 -2
  40. data/lib/rays/point.rb +1 -1
  41. data/lib/rays/polygon.rb +54 -16
  42. data/lib/rays/polyline.rb +54 -8
  43. data/lib/rays.rb +0 -1
  44. data/rays.gemspec +2 -2
  45. data/src/color_space.cpp +2 -2
  46. data/src/font.cpp +24 -2
  47. data/src/font.h +8 -1
  48. data/src/ios/font.mm +88 -27
  49. data/src/matrix.cpp +8 -0
  50. data/src/osx/font.mm +90 -28
  51. data/src/osx/helper.h +2 -2
  52. data/src/osx/helper.mm +2 -2
  53. data/src/painter.cpp +227 -90
  54. data/src/painter.h +11 -3
  55. data/src/polygon.cpp +588 -205
  56. data/src/polyline.cpp +154 -28
  57. data/src/polyline.h +3 -5
  58. data/src/shader.cpp +36 -4
  59. data/src/shader.h +1 -1
  60. data/src/texture.cpp +2 -2
  61. data/src/{noise.cpp → util.cpp} +1 -1
  62. data/src/win32/font.cpp +1 -1
  63. data/test/test_bitmap.rb +16 -2
  64. data/test/test_color.rb +4 -0
  65. data/test/test_font.rb +20 -2
  66. data/test/test_image.rb +18 -18
  67. data/test/test_point.rb +1 -1
  68. data/test/test_polygon.rb +52 -45
  69. data/test/test_polyline.rb +191 -72
  70. metadata +11 -17
  71. data/.doc/ext/rays/polygon_line.cpp +0 -97
  72. data/ext/rays/polygon_line.cpp +0 -100
  73. data/lib/rays/polygon_line.rb +0 -33
  74. 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 <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);
55
71
 
56
- CFAttributedStringRef attrstr = CFAttributedStringCreate(
57
- NULL, cfstring(str).get(), attr);
58
- CFRelease(attr);
72
+ return CTLinePtr(
73
+ CTLineCreateWithAttributedString(attrstr.get()),
74
+ CFRelease);
75
+ }
59
76
 
60
- CTLineRef line = CTLineCreateWithAttributedString(attrstr);
61
- CFRelease(attrstr);
77
+ const FontFamilyMap&
78
+ get_font_families ()
79
+ {
80
+ static const FontFamilyMap MAP = []() {
81
+ NSFontManager* fm = NSFontManager.sharedFontManager;
62
82
 
63
- return line;
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
- 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
 
@@ -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
- CFStringRef str = CTFontCopyFullName(self->font);
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
- CTLineRef line = make_line(self->font, str);
217
+ CTLinePtr line = make_line(self->font, str);
153
218
  if (!line)
154
219
  rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
155
220
 
156
- coord w = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
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> 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