rays 0.1.12 → 0.1.17

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 (168) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/camera.cpp +171 -0
  5. data/.doc/ext/rays/color.cpp +223 -45
  6. data/.doc/ext/rays/color_space.cpp +146 -46
  7. data/.doc/ext/rays/defs.cpp +183 -0
  8. data/.doc/ext/rays/font.cpp +69 -21
  9. data/.doc/ext/rays/image.cpp +26 -37
  10. data/.doc/ext/rays/matrix.cpp +186 -29
  11. data/.doc/ext/rays/native.cpp +14 -8
  12. data/.doc/ext/rays/noise.cpp +53 -0
  13. data/.doc/ext/rays/painter.cpp +187 -292
  14. data/.doc/ext/rays/point.cpp +96 -77
  15. data/.doc/ext/rays/polygon.cpp +313 -0
  16. data/.doc/ext/rays/polygon_line.cpp +96 -0
  17. data/.doc/ext/rays/polyline.cpp +167 -0
  18. data/.doc/ext/rays/rays.cpp +103 -12
  19. data/.doc/ext/rays/shader.cpp +83 -9
  20. data/LICENSE +21 -0
  21. data/README.md +1 -1
  22. data/Rakefile +24 -9
  23. data/VERSION +1 -1
  24. data/ext/rays/bitmap.cpp +23 -81
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +186 -0
  27. data/ext/rays/color.cpp +231 -51
  28. data/ext/rays/color_space.cpp +149 -47
  29. data/ext/rays/defs.cpp +183 -0
  30. data/ext/rays/defs.h +26 -2
  31. data/ext/rays/extconf.rb +2 -3
  32. data/ext/rays/font.cpp +74 -24
  33. data/ext/rays/image.cpp +28 -40
  34. data/ext/rays/matrix.cpp +198 -30
  35. data/ext/rays/native.cpp +14 -8
  36. data/ext/rays/noise.cpp +55 -0
  37. data/ext/rays/painter.cpp +203 -298
  38. data/ext/rays/point.cpp +105 -81
  39. data/ext/rays/polygon.cpp +329 -0
  40. data/ext/rays/polygon_line.cpp +99 -0
  41. data/ext/rays/polyline.cpp +176 -0
  42. data/ext/rays/rays.cpp +103 -13
  43. data/ext/rays/shader.cpp +84 -9
  44. data/include/rays.h +10 -2
  45. data/include/rays/bitmap.h +14 -26
  46. data/include/rays/bounds.h +21 -4
  47. data/include/rays/camera.h +74 -0
  48. data/include/rays/color.h +25 -14
  49. data/include/rays/color_space.h +15 -10
  50. data/include/rays/coord.h +114 -0
  51. data/include/rays/debug.h +22 -0
  52. data/include/rays/defs.h +36 -0
  53. data/include/rays/exception.h +6 -2
  54. data/include/rays/font.h +4 -4
  55. data/include/rays/image.h +12 -18
  56. data/include/rays/matrix.h +50 -24
  57. data/include/rays/noise.h +42 -0
  58. data/include/rays/opengl.h +2 -50
  59. data/include/rays/painter.h +89 -93
  60. data/include/rays/point.h +44 -51
  61. data/include/rays/polygon.h +198 -0
  62. data/include/rays/polyline.h +71 -0
  63. data/include/rays/rays.h +3 -0
  64. data/include/rays/ruby.h +7 -1
  65. data/include/rays/ruby/bounds.h +1 -1
  66. data/include/rays/ruby/camera.h +41 -0
  67. data/include/rays/ruby/color.h +1 -1
  68. data/include/rays/ruby/color_space.h +1 -1
  69. data/include/rays/ruby/font.h +1 -1
  70. data/include/rays/ruby/matrix.h +1 -1
  71. data/include/rays/ruby/point.h +1 -1
  72. data/include/rays/ruby/polygon.h +52 -0
  73. data/include/rays/ruby/polyline.h +41 -0
  74. data/include/rays/ruby/rays.h +8 -0
  75. data/include/rays/ruby/shader.h +1 -1
  76. data/include/rays/shader.h +36 -8
  77. data/lib/rays.rb +7 -2
  78. data/lib/rays/bitmap.rb +0 -15
  79. data/lib/rays/bounds.rb +17 -23
  80. data/lib/rays/camera.rb +24 -0
  81. data/lib/rays/color.rb +20 -47
  82. data/lib/rays/color_space.rb +13 -13
  83. data/lib/rays/image.rb +3 -7
  84. data/lib/rays/matrix.rb +28 -0
  85. data/lib/rays/module.rb +4 -19
  86. data/lib/rays/painter.rb +78 -93
  87. data/lib/rays/point.rb +13 -21
  88. data/lib/rays/polygon.rb +58 -0
  89. data/lib/rays/polygon_line.rb +36 -0
  90. data/lib/rays/polyline.rb +32 -0
  91. data/lib/rays/shader.rb +20 -1
  92. data/rays.gemspec +5 -7
  93. data/src/bitmap.h +36 -0
  94. data/src/bounds.cpp +74 -11
  95. data/src/color.cpp +58 -23
  96. data/src/color_space.cpp +52 -34
  97. data/src/color_space.h +22 -0
  98. data/src/coord.cpp +170 -0
  99. data/src/coord.h +35 -0
  100. data/src/font.cpp +118 -0
  101. data/src/font.h +64 -0
  102. data/src/frame_buffer.cpp +37 -71
  103. data/src/frame_buffer.h +4 -4
  104. data/src/image.cpp +172 -98
  105. data/src/image.h +25 -0
  106. data/src/ios/bitmap.h +23 -0
  107. data/src/ios/bitmap.mm +133 -110
  108. data/src/ios/camera.mm +510 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +4 -4
  111. data/src/ios/opengl.mm +19 -4
  112. data/src/ios/rays.mm +3 -0
  113. data/src/matrix.cpp +111 -26
  114. data/src/matrix.h +30 -0
  115. data/src/noise.cpp +74 -0
  116. data/src/opengl.cpp +9 -27
  117. data/src/opengl.h +37 -0
  118. data/src/osx/bitmap.h +23 -0
  119. data/src/osx/bitmap.mm +133 -110
  120. data/src/osx/camera.mm +451 -0
  121. data/src/osx/font.mm +49 -62
  122. data/src/osx/helper.h +2 -2
  123. data/src/osx/opengl.mm +19 -83
  124. data/src/osx/rays.mm +3 -0
  125. data/src/painter.cpp +845 -671
  126. data/src/painter.h +24 -0
  127. data/src/point.cpp +140 -119
  128. data/src/polygon.cpp +1266 -0
  129. data/src/polygon.h +32 -0
  130. data/src/polyline.cpp +160 -0
  131. data/src/polyline.h +69 -0
  132. data/src/render_buffer.cpp +11 -4
  133. data/src/render_buffer.h +2 -2
  134. data/src/shader.cpp +163 -106
  135. data/src/shader.h +38 -0
  136. data/src/shader_program.cpp +533 -0
  137. data/src/{program.h → shader_program.h} +28 -16
  138. data/src/shader_source.cpp +140 -0
  139. data/src/shader_source.h +52 -0
  140. data/src/texture.cpp +136 -160
  141. data/src/texture.h +65 -0
  142. data/src/win32/bitmap.cpp +62 -52
  143. data/src/win32/font.cpp +11 -13
  144. data/src/win32/font.h +24 -0
  145. data/src/win32/gdi.h +6 -6
  146. data/test/helper.rb +0 -3
  147. data/test/test_bitmap.rb +31 -7
  148. data/test/test_bounds.rb +36 -0
  149. data/test/test_color.rb +59 -19
  150. data/test/test_color_space.rb +95 -0
  151. data/test/test_font.rb +5 -0
  152. data/test/test_image.rb +24 -20
  153. data/test/test_matrix.rb +106 -0
  154. data/test/test_painter.rb +157 -51
  155. data/test/test_painter_shape.rb +102 -0
  156. data/test/test_point.rb +29 -0
  157. data/test/test_polygon.rb +234 -0
  158. data/test/test_polygon_line.rb +167 -0
  159. data/test/test_polyline.rb +171 -0
  160. data/test/test_shader.rb +9 -9
  161. metadata +102 -70
  162. data/.doc/ext/rays/texture.cpp +0 -138
  163. data/ext/rays/texture.cpp +0 -149
  164. data/include/rays/ruby/texture.h +0 -41
  165. data/include/rays/texture.h +0 -71
  166. data/lib/rays/texture.rb +0 -24
  167. data/src/program.cpp +0 -648
  168. data/test/test_texture.rb +0 -27
@@ -0,0 +1,451 @@
1
+ // -*- mode: objc -*-
2
+ #import "rays/camera.h"
3
+
4
+
5
+ #import <AVFoundation/AVFoundation.h>
6
+ #include "rays/exception.h"
7
+ #include "bitmap.h"
8
+
9
+
10
+ static int video_input_queue_index = 0;
11
+
12
+
13
+ @interface VideoInput : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>
14
+ @end
15
+
16
+
17
+ @implementation VideoInput
18
+
19
+ {
20
+ AVCaptureSession* session;
21
+ dispatch_queue_t queue;
22
+ CGImageRef image;
23
+ }
24
+
25
+ - (id) init
26
+ {
27
+ self = [super init];
28
+ if (self)
29
+ {
30
+ session = nil;
31
+ queue = nil;
32
+ image = nil;
33
+ }
34
+ return self;
35
+ }
36
+
37
+ - (void) dealloc
38
+ {
39
+ [self stop];
40
+ [self clearImage];
41
+
42
+ if (queue)
43
+ {
44
+ dispatch_release(queue);
45
+ queue = nil;
46
+ }
47
+
48
+ [super dealloc];
49
+ }
50
+
51
+ - (dispatch_queue_t) getQueue
52
+ {
53
+ if (!queue)
54
+ {
55
+ auto name = Xot::stringf(
56
+ "org.xord.RaysVideoInputQueue_%d",
57
+ video_input_queue_index++);
58
+ queue = dispatch_queue_create(name, DISPATCH_QUEUE_SERIAL);
59
+ }
60
+ return queue;
61
+ }
62
+
63
+ - (BOOL) start: (AVCaptureDevice*) device
64
+ preset: (AVCaptureSessionPreset) preset
65
+ {
66
+ if (!device) return NO;
67
+
68
+ [self stop];
69
+
70
+ AVCaptureSession* sess = [[[AVCaptureSession alloc] init] autorelease];
71
+ if (preset != nil)
72
+ sess.sessionPreset = preset;
73
+
74
+ //device.activeVideoMinFrameDuration = CMTimeMake(1, 30);
75
+
76
+ NSError* error = nil;
77
+ AVCaptureDeviceInput* input = [[[AVCaptureDeviceInput alloc]
78
+ initWithDevice: device error: &error]
79
+ autorelease];
80
+ if (!input || error || ![sess canAddInput: input])
81
+ return NO;
82
+
83
+ AVCaptureVideoDataOutput* output =
84
+ [[[AVCaptureVideoDataOutput alloc] init] autorelease];
85
+ output.videoSettings = @{
86
+ (NSString*) kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)
87
+ };
88
+ output.alwaysDiscardsLateVideoFrames = YES;
89
+ [output setSampleBufferDelegate: self queue: [self getQueue]];
90
+ if (![sess canAddOutput: output])
91
+ return NO;
92
+
93
+ [sess addInput: input];
94
+ [sess addOutput: output];
95
+ [sess startRunning];
96
+
97
+ session = [sess retain];
98
+ return YES;
99
+ }
100
+
101
+ - (void) captureOutput: (AVCaptureOutput*) output
102
+ didOutputSampleBuffer: (CMSampleBufferRef) sampleBuffer
103
+ fromConnection: (AVCaptureConnection*) connection
104
+ {
105
+ CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
106
+ if (!pixelBuffer) return;
107
+
108
+ CIImage* ciImage = [CIImage imageWithCVPixelBuffer: pixelBuffer];
109
+ if (!ciImage) return;
110
+
111
+ CIContext* context = [CIContext contextWithOptions: nil];
112
+ size_t width = CVPixelBufferGetWidth(pixelBuffer);
113
+ size_t height = CVPixelBufferGetHeight(pixelBuffer);
114
+ CGRect rect = CGRectMake(0, 0, width, height);
115
+ CGImageRef cgImage = [context createCGImage: ciImage fromRect: rect];
116
+
117
+ dispatch_async(dispatch_get_main_queue(), ^{
118
+ [self clearImage];
119
+ image = cgImage;
120
+ });
121
+ }
122
+
123
+ - (void) stop
124
+ {
125
+ if (!session) return;
126
+
127
+ [session stopRunning];
128
+ [session release];
129
+ session = nil;
130
+ }
131
+
132
+ - (BOOL) isActive
133
+ {
134
+ return session != nil;
135
+ }
136
+
137
+ - (void) clearImage
138
+ {
139
+ if (!image) return;
140
+
141
+ CGImageRelease(image);
142
+ image = nil;
143
+ }
144
+
145
+ - (CGImageRef) getImage
146
+ {
147
+ return image;
148
+ }
149
+
150
+ @end// VideoInput
151
+
152
+
153
+ namespace Rays
154
+ {
155
+
156
+
157
+ struct Camera::Data
158
+ {
159
+
160
+ String device_name;
161
+
162
+ int min_width = -1, min_height = -1;
163
+
164
+ bool resize = false, crop = false;
165
+
166
+ mutable Image image;
167
+
168
+ VideoInput* video_input = nil;
169
+
170
+ AVCaptureSessionPreset get_preset (AVCaptureDevice* device)
171
+ {
172
+ int w = min_width, h = min_height;
173
+ if (w > 0 && h > 0)
174
+ {
175
+ #define SUPPORT(x) \
176
+ [device supportsAVCaptureSessionPreset: AVCaptureSessionPreset##x]
177
+
178
+ if (w <= 320 && h <= 240 && SUPPORT(320x240))
179
+ return AVCaptureSessionPreset320x240;
180
+
181
+ if (w <= 352 && h <= 288 && SUPPORT(352x288))
182
+ return AVCaptureSessionPreset352x288;
183
+
184
+ if (w <= 640 && h <= 480 && SUPPORT(640x480))
185
+ return AVCaptureSessionPreset640x480;
186
+
187
+ if (w <= 960 && h <= 540 && SUPPORT(960x540))
188
+ return AVCaptureSessionPreset960x540;
189
+
190
+ if (/*w <= 1280 && h <= 720 &&*/ SUPPORT(1280x720))
191
+ return AVCaptureSessionPreset1280x720;
192
+
193
+ //if (w <= 1920 && h <= 1080 && SUPPORT(1920x1080))
194
+ // return AVCaptureSessionPreset1920x1080;
195
+
196
+ //if (SUPPORT(3840x2160))
197
+ // return AVCaptureSessionPreset3840x2160;
198
+
199
+ #undef SUPPORT
200
+ }
201
+
202
+ return nil;
203
+ }
204
+
205
+ void update_image_from_video_input () const
206
+ {
207
+ if (!video_input) return;
208
+
209
+ CGImageRef cgImage = [video_input getImage];
210
+ if (!cgImage) return;
211
+
212
+ coord draw_x, draw_y, draw_width, draw_height;
213
+ int bitmap_width, bitmap_height;
214
+ get_draw_bounds(
215
+ &draw_x, &draw_y, &draw_width, &draw_height,
216
+ &bitmap_width, &bitmap_height,
217
+ cgImage);
218
+
219
+ if (
220
+ !image ||
221
+ image.bitmap().width() != bitmap_width ||
222
+ image.bitmap().height() != bitmap_height)
223
+ {
224
+ image = Image(Bitmap(bitmap_width, bitmap_height));
225
+ }
226
+
227
+ Bitmap_draw_image(
228
+ &image.bitmap(), cgImage,
229
+ draw_x, draw_y, draw_width, draw_height);
230
+
231
+ [video_input clearImage];
232
+ }
233
+
234
+ void get_draw_bounds (
235
+ coord* draw_x, coord* draw_y, coord* draw_width, coord* draw_height,
236
+ int* bitmap_width, int* bitmap_height,
237
+ CGImageRef image) const
238
+ {
239
+ int image_width = (int) CGImageGetWidth(image);
240
+ int image_height = (int) CGImageGetHeight(image);
241
+ float image_ratio = (float) image_width / (float) image_height;
242
+
243
+ if (resize && min_width > 0 && min_height > 0)
244
+ {
245
+ float min_size_ratio = (float) min_width / (float) min_height;
246
+ if (image_ratio > min_size_ratio)
247
+ {
248
+ *draw_width = min_height * image_ratio;
249
+ *draw_height = min_height;
250
+ }
251
+ else
252
+ {
253
+ *draw_width = min_width;
254
+ *draw_height = min_width / image_ratio;
255
+ }
256
+ }
257
+ else if (resize && min_width > 0)
258
+ {
259
+ *draw_width = min_width;
260
+ *draw_height = min_width / image_ratio;
261
+ }
262
+ else if (resize && min_height > 0)
263
+ {
264
+ *draw_width = min_height * image_ratio;
265
+ *draw_height = min_height;
266
+ }
267
+ else
268
+ {
269
+ *draw_width = image_width;
270
+ *draw_height = image_height;
271
+ }
272
+
273
+ *draw_x = 0;
274
+ *draw_y = 0;
275
+ *bitmap_width = *draw_width;
276
+ *bitmap_height = *draw_height;
277
+
278
+ if (crop && min_width > 0)
279
+ {
280
+ *draw_x = min_width / 2 - *draw_width / 2;
281
+ *bitmap_width = min_width;
282
+ }
283
+ else if (crop && min_height > 0)
284
+ {
285
+ *draw_y = min_height / 2 - *draw_height / 2;
286
+ *bitmap_height = min_height;
287
+ }
288
+ }
289
+
290
+ };// Camera::Data
291
+
292
+
293
+ static NSArray<AVCaptureDevice*>*
294
+ get_video_devices ()
295
+ {
296
+ NSMutableArray<AVCaptureDevice*>* devices = [NSMutableArray array];
297
+ for (AVCaptureDevice* d in AVCaptureDevice.devices)
298
+ {
299
+ if ([d hasMediaType: AVMediaTypeVideo])
300
+ [devices addObject: d];
301
+ }
302
+ return devices;
303
+ }
304
+
305
+ static AVCaptureDevice*
306
+ get_default_video_device ()
307
+ {
308
+ AVCaptureDevice* device =
309
+ [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
310
+ if (!device)
311
+ rays_error(__FILE__, __LINE__, "Default camera device is not found.");
312
+
313
+ return device;
314
+ }
315
+
316
+ static AVCaptureDevice*
317
+ get_video_device (const char* name)
318
+ {
319
+ if (!name || *name == 0)
320
+ return get_default_video_device();
321
+
322
+ for (AVCaptureDevice* d in get_video_devices())
323
+ {
324
+ if (strcmp(name, d.localizedName.UTF8String) == 0)
325
+ return d;
326
+ }
327
+
328
+ rays_error(__FILE__, __LINE__, "Camera device '%s' is not found.", name);
329
+ return nil;
330
+ }
331
+
332
+ std::vector<String>
333
+ get_camera_device_names ()
334
+ {
335
+ std::vector<String> names;
336
+ for (AVCaptureDevice* d in get_video_devices())
337
+ names.emplace_back(d.localizedName.UTF8String);
338
+ return names;
339
+ }
340
+
341
+
342
+ Camera::Camera (
343
+ const char* device_name,
344
+ int min_width, int min_height, bool resize, bool crop)
345
+ {
346
+ if (device_name)
347
+ self->device_name = device_name;
348
+
349
+ self->min_width = min_width;
350
+ self->min_height = min_height;
351
+ self->resize = resize;
352
+ self->crop = crop;
353
+ }
354
+
355
+ Camera::~Camera ()
356
+ {
357
+ stop();
358
+ if (self->video_input) [self->video_input release];
359
+ }
360
+
361
+ bool
362
+ Camera::start ()
363
+ {
364
+ if (!self->video_input) self->video_input = [[VideoInput alloc] init];
365
+
366
+ AVCaptureDevice* device = get_video_device(self->device_name.c_str());
367
+ return [self->video_input start: device preset: self->get_preset(device)];
368
+ }
369
+
370
+ void
371
+ Camera::stop ()
372
+ {
373
+ if (!self->video_input) return;
374
+
375
+ [self->video_input stop];
376
+ }
377
+
378
+ bool
379
+ Camera::is_active () const
380
+ {
381
+ return self->video_input && [self->video_input isActive];
382
+ }
383
+
384
+ void
385
+ Camera::set_min_width (int width)
386
+ {
387
+ self->min_width = width;
388
+ }
389
+
390
+ int
391
+ Camera::min_width () const
392
+ {
393
+ return self->min_width;
394
+ }
395
+
396
+ void
397
+ Camera::set_min_height (int height)
398
+ {
399
+ self->min_height = height;
400
+ }
401
+
402
+ int
403
+ Camera::min_height () const
404
+ {
405
+ return self->min_height;
406
+ }
407
+
408
+ void
409
+ Camera::set_resize (bool resize)
410
+ {
411
+ self->resize = resize;
412
+ }
413
+
414
+ bool
415
+ Camera::is_resize () const
416
+ {
417
+ return self->resize;
418
+ }
419
+
420
+ void
421
+ Camera::set_crop (bool crop)
422
+ {
423
+ self->crop = crop;
424
+ }
425
+
426
+ bool
427
+ Camera::is_crop () const
428
+ {
429
+ return self->crop;
430
+ }
431
+
432
+ const Image*
433
+ Camera::image () const
434
+ {
435
+ self->update_image_from_video_input();
436
+ return self->image ? &self->image : NULL;
437
+ }
438
+
439
+ Camera::operator bool () const
440
+ {
441
+ return true;
442
+ }
443
+
444
+ bool
445
+ Camera::operator ! () const
446
+ {
447
+ return !operator bool();
448
+ }
449
+
450
+
451
+ }// Rays
@@ -1,5 +1,5 @@
1
1
  // -*- objc -*-
2
- #include "rays/font.h"
2
+ #include "../font.h"
3
3
 
4
4
 
5
5
  #include <ApplicationServices/ApplicationServices.h>
@@ -11,7 +11,7 @@ namespace Rays
11
11
  {
12
12
 
13
13
 
14
- struct Font::Data
14
+ struct RawFont::Data
15
15
  {
16
16
 
17
17
  CTFontRef font;
@@ -30,7 +30,7 @@ namespace Rays
30
30
  }
31
31
  }
32
32
 
33
- };// Font::Data
33
+ };// RawFont::Data
34
34
 
35
35
 
36
36
  static CTLineRef
@@ -64,29 +64,61 @@ namespace Rays
64
64
  }
65
65
 
66
66
 
67
- Font::Font ()
67
+ RawFont::RawFont ()
68
68
  {
69
69
  }
70
70
 
71
- Font::Font (const char* name, coord size)
71
+ RawFont::RawFont (const char* name, coord size)
72
72
  {
73
73
  self->font = name
74
- ? CTFontCreateWithName(cfstring(name).get(), size, NULL)
75
- : CTFontCreateUIFontForLanguage(kCTFontSystemFontType, size, NULL);
74
+ ? CTFontCreateWithName(cfstring(name).get(), size, NULL)
75
+ : CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, size, NULL);
76
76
  }
77
77
 
78
- Font::~Font ()
78
+ RawFont::~RawFont ()
79
79
  {
80
80
  }
81
81
 
82
- Font
83
- Font::copy () const
82
+ void
83
+ RawFont::draw_string (
84
+ void* context_, coord context_height,
85
+ const char* str, coord x, coord y) const
84
86
  {
85
- return Font(name(), size());
87
+ CGContextRef context = (CGContextRef) context_;
88
+
89
+ if (!*this || !context || !str)
90
+ argument_error(__FILE__, __LINE__);
91
+
92
+ if (*str == '\0') return;
93
+
94
+ CTLineRef line = make_line(self->font, str);
95
+ if (!line)
96
+ rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
97
+
98
+ coord width = 0, height = 0, ascent = 0;
99
+ width = get_width(str);
100
+ height = get_height(&ascent);
101
+
102
+ height = ceil(height);
103
+ ascent = floor(ascent);
104
+
105
+ CGRect rect = CGRectMake(x, context_height - height - y, width, height);
106
+ CGContextClearRect(context, rect);
107
+ //CGContextSetRGBFillColor(context, 0, 0, 0, 1);
108
+ //CGContextFillRect(context, rect);
109
+ CGContextSetRGBFillColor(context, 1, 1, 1, 1);
110
+
111
+ CGContextSaveGState(context);
112
+ CGContextSetTextMatrix(context, CGAffineTransformIdentity);
113
+ CGContextSetTextPosition(context, x, context_height - ascent - y);
114
+ CTLineDraw(line, context);
115
+ CGContextRestoreGState(context);
116
+
117
+ CFRelease(line);
86
118
  }
87
119
 
88
120
  String
89
- Font::name () const
121
+ RawFont::name () const
90
122
  {
91
123
  if (!*this) return "";
92
124
 
@@ -102,14 +134,14 @@ namespace Rays
102
134
  }
103
135
 
104
136
  coord
105
- Font::size () const
137
+ RawFont::size () const
106
138
  {
107
139
  if (!*this) return 0;
108
140
  return CTFontGetSize(self->font);
109
141
  }
110
142
 
111
143
  coord
112
- Font::get_width (const char* str) const
144
+ RawFont::get_width (const char* str) const
113
145
  {
114
146
  if (!str)
115
147
  argument_error(__FILE__, __LINE__);
@@ -130,7 +162,7 @@ namespace Rays
130
162
  }
131
163
 
132
164
  coord
133
- Font::get_height (coord* ascent, coord* descent, coord* leading) const
165
+ RawFont::get_height (coord* ascent, coord* descent, coord* leading) const
134
166
  {
135
167
  if (!*this)
136
168
  invalid_state_error(__FILE__, __LINE__);
@@ -146,61 +178,16 @@ namespace Rays
146
178
  return asc + desc + lead;
147
179
  }
148
180
 
149
- Font::operator bool () const
181
+ RawFont::operator bool () const
150
182
  {
151
183
  return !!self->font;
152
184
  }
153
185
 
154
186
  bool
155
- Font::operator ! () const
187
+ RawFont::operator ! () const
156
188
  {
157
189
  return !operator bool();
158
190
  }
159
191
 
160
192
 
161
- const Font&
162
- default_font ()
163
- {
164
- static const Font FONT(NULL);
165
- return FONT;
166
- }
167
-
168
-
169
- void
170
- draw_string (
171
- CGContextRef context, coord context_height,
172
- const char* str, coord x, coord y, const Font& font)
173
- {
174
- if (!context || !str || !font)
175
- argument_error(__FILE__, __LINE__);
176
-
177
- if (*str == '\0') return;
178
-
179
- CTLineRef line = make_line(font.self->font, str);
180
- if (!line)
181
- rays_error(__FILE__, __LINE__, "creating CTLineRef failed.");
182
-
183
- coord width = 0, height = 0, ascent = 0;
184
- width = font.get_width(str);
185
- height = font.get_height(&ascent);
186
-
187
- height = ceil(height);
188
- ascent = floor(ascent);
189
-
190
- CGRect rect = CGRectMake(x, context_height - height - y, width, height);
191
- CGContextClearRect(context, rect);
192
- //CGContextSetRGBFillColor(context, 0, 0, 0, 1);
193
- //CGContextFillRect(context, rect);
194
- CGContextSetRGBFillColor(context, 1, 1, 1, 1);
195
-
196
- CGContextSaveGState(context);
197
- CGContextSetTextMatrix(context, CGAffineTransformIdentity);
198
- CGContextSetTextPosition(context, x, context_height - ascent - y);
199
- CTLineDraw(line, context);
200
- CGContextRestoreGState(context);
201
-
202
- CFRelease(line);
203
- }
204
-
205
-
206
193
  }// Rays