dyi 1.1.1 → 1.1.2

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 (48) hide show
  1. data/CHANGES +7 -1
  2. data/lib/dyi.rb +3 -1
  3. data/lib/dyi/animation.rb +5 -4
  4. data/lib/dyi/canvas.rb +5 -8
  5. data/lib/dyi/chart.rb +1 -1
  6. data/lib/dyi/chart/array_reader.rb +104 -10
  7. data/lib/dyi/chart/axis_util.rb +31 -17
  8. data/lib/dyi/chart/base.rb +104 -7
  9. data/lib/dyi/chart/csv_reader.rb +56 -8
  10. data/lib/dyi/chart/excel_reader.rb +27 -4
  11. data/lib/dyi/chart/legend.rb +10 -8
  12. data/lib/dyi/chart/line_chart.rb +29 -25
  13. data/lib/dyi/chart/pie_chart.rb +192 -29
  14. data/lib/dyi/chart/table.rb +12 -10
  15. data/lib/dyi/color.rb +9 -7
  16. data/lib/dyi/coordinate.rb +177 -61
  17. data/lib/dyi/drawing.rb +1 -1
  18. data/lib/dyi/drawing/clipping.rb +9 -3
  19. data/lib/dyi/drawing/color_effect.rb +7 -4
  20. data/lib/dyi/drawing/filter.rb +10 -7
  21. data/lib/dyi/drawing/pen.rb +421 -11
  22. data/lib/dyi/drawing/pen_3d.rb +12 -7
  23. data/lib/dyi/element.rb +5 -4
  24. data/lib/dyi/event.rb +3 -3
  25. data/lib/dyi/font.rb +6 -4
  26. data/lib/dyi/formatter.rb +1 -1
  27. data/lib/dyi/formatter/base.rb +24 -15
  28. data/lib/dyi/formatter/emf_formatter.rb +6 -5
  29. data/lib/dyi/formatter/eps_formatter.rb +15 -14
  30. data/lib/dyi/formatter/svg_formatter.rb +16 -14
  31. data/lib/dyi/formatter/svg_reader.rb +4 -3
  32. data/lib/dyi/formatter/xaml_formatter.rb +9 -7
  33. data/lib/dyi/length.rb +213 -114
  34. data/lib/dyi/matrix.rb +4 -2
  35. data/lib/dyi/painting.rb +161 -87
  36. data/lib/dyi/script.rb +1 -1
  37. data/lib/dyi/script/ecmascript.rb +18 -29
  38. data/lib/dyi/script/simple_script.rb +4 -8
  39. data/lib/dyi/shape.rb +1 -1
  40. data/lib/dyi/shape/base.rb +8 -17
  41. data/lib/dyi/shape/path.rb +102 -19
  42. data/lib/dyi/stylesheet.rb +4 -3
  43. data/lib/dyi/svg_element.rb +9 -7
  44. data/lib/dyi/type.rb +5 -2
  45. data/lib/dyi/util.rb +36 -1
  46. data/lib/ironruby.rb +1 -1
  47. data/lib/util.rb +53 -5
  48. metadata +4 -19
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: UTF-8 -*-
2
2
 
3
- # Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
3
+ # Copyright (c) 2009-2012 Sound-F Co., Ltd. All rights reserved.
4
4
  #
5
5
  # Author:: Mamoru Yuo
6
6
  #
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: UTF-8 -*-
2
2
 
3
- # Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
3
+ # Copyright (c) 2009-2012 Sound-F Co., Ltd. All rights reserved.
4
4
  #
5
5
  # Author:: Mamoru Yuo
6
6
  #
@@ -19,12 +19,16 @@
19
19
  # You should have received a copy of the GNU General Public License
20
20
  # along with DYI. If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
- module DYI #:nodoc:
23
- module Drawing #:nodoc:
22
+ #
23
+ module DYI
24
+ module Drawing
24
25
 
26
+ # @since 0.0.0
25
27
  class Clipping < Element
26
28
  RULES = ['nonzero', 'evenodd']
27
29
  attr_reader :rule, :shapes
30
+
31
+ # @since 1.0.0
28
32
  attr_reader :canvas
29
33
 
30
34
  def initialize(*shapes)
@@ -32,10 +36,12 @@ module DYI #:nodoc:
32
36
  @rules = Array.new(shapes.size)
33
37
  end
34
38
 
39
+ # @since 1.0.0
35
40
  def child_elements
36
41
  @shapes
37
42
  end
38
43
 
44
+ # @since 1.0.0
39
45
  def set_canvas(canvas)
40
46
  if @canvas.nil?
41
47
  @canvas = canvas
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: UTF-8 -*-
2
2
 
3
- # Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
3
+ # Copyright (c) 2009-2012 Sound-F Co., Ltd. All rights reserved.
4
4
  #
5
5
  # Author:: Mamoru Yuo
6
6
  #
@@ -19,9 +19,12 @@
19
19
  # You should have received a copy of the GNU General Public License
20
20
  # along with DYI. If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
- module DYI #:nodoc:
23
- module Drawing #:nodoc:
24
- module ColorEffect #:nodoc:
22
+ #
23
+ module DYI
24
+ module Drawing
25
+
26
+ # @since 0.0.0
27
+ module ColorEffect
25
28
 
26
29
  class LinearGradient
27
30
  SPREAD_METHODS = ['pad', 'reflect', 'repeat']
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: UTF-8 -*-
2
2
 
3
- # Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
3
+ # Copyright (c) 2009-2012 Sound-F Co., Ltd. All rights reserved.
4
4
  #
5
5
  # Author:: Mamoru Yuo
6
6
  #
@@ -19,9 +19,12 @@
19
19
  # You should have received a copy of the GNU General Public License
20
20
  # along with DYI. If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
- module DYI #:nodoc:
23
- module Drawing #:nodoc:
24
- module Filter #:nodoc:
22
+ #
23
+ module DYI
24
+ module Drawing
25
+
26
+ # @since 0.0.0
27
+ module Filter
25
28
 
26
29
  class DropShadow
27
30
  include DYI::SvgElement
@@ -45,7 +48,7 @@ module DYI #:nodoc:
45
48
 
46
49
  private
47
50
 
48
- def attributes #:nodoc:
51
+ def attributes
49
52
  {
50
53
  :id => @id,
51
54
  :filterUnits => 'userSpaceOnUse',
@@ -56,11 +59,11 @@ module DYI #:nodoc:
56
59
  }
57
60
  end
58
61
 
59
- def svg_tag #:nodoc:
62
+ def svg_tag
60
63
  'filter'
61
64
  end
62
65
 
63
- def child_elements_to_svg(xml) #:nodoc:
66
+ def child_elements_to_svg(xml)
64
67
  xml.feGaussianBlur(:in => 'SourceAlpha', :stdDeviation => @blur_std, :result => 'blur')
65
68
  xml.feOffset(:in => 'blur', :dx => @dx, :dy => @dy, :result => 'offsetBlur')
66
69
  xml.feMerge {
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: UTF-8 -*-
2
2
 
3
- # Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
3
+ # Copyright (c) 2009-2012 Sound-F Co., Ltd. All rights reserved.
4
4
  #
5
5
  # Author:: Mamoru Yuo
6
6
  #
@@ -19,15 +19,36 @@
19
19
  # You should have received a copy of the GNU General Public License
20
20
  # along with DYI. If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
- module DYI #:nodoc:
23
- module Drawing #:nodoc:
24
-
22
+ #
23
+ module DYI
24
+ module Drawing
25
+
26
+ # A factory base class for createing a shape in the image.
27
+ #
28
+ # +PenBase+ object holds a {Painting} object and a {Font} object. Using
29
+ # these object, +PenBase+ object creates instances of concrete subclass of
30
+ # {Shape::Base}; a created instance has a painting attribute and a font
31
+ # attribute that +PenBase+ object holds.
32
+ #
33
+ # This class has same attributes as {Painting}, these attributs access
34
+ # {Painting} object that +PenBase+ object holds.
35
+ # @abstract
36
+ # @see Painting
37
+ # @see Brush
38
+ # @see Pen
39
+ # @since 0.0.0
25
40
  class PenBase
26
41
  extend AttributeCreator
42
+
43
+ # @private
27
44
  DROP_SHADOW_OPTIONS = [:blur_std, :dx, :dy]
28
45
  attr_font :font
46
+
47
+ # @private
29
48
  attr_reader :drop_shadow
30
49
 
50
+ # @option options [Font, Hash] :font the value of attribute {#font font}
51
+ # @option (see Painting#initialize)
31
52
  def initialize(options={})
32
53
  @attributes = {}
33
54
  @painting = Painting.new
@@ -42,6 +63,74 @@ module DYI #:nodoc:
42
63
  end
43
64
  end
44
65
 
66
+ # @attribute opacity
67
+ # Returns or sets opacity of the paiting operation. Opacity of Both +stroke+
68
+ # and +fill+ is set at the same time by this attribute.
69
+ # @return [Float] the value of attribute opacity
70
+ # @since 1.0.0
71
+ #+++
72
+ # @attribute fill
73
+ # Returns or sets the interior painting of the shape.
74
+ # @return [Color, #write_as] the value of attribute fill
75
+ #+++
76
+ # @attribute fill_opacity
77
+ # Returns or sets the opacity of the paiting operation used to paint the
78
+ # interior of the shape.
79
+ # @return [Float] the value of attribute fill_opacity
80
+ #+++
81
+ # @attribute fill_rule
82
+ # Returns or sets the rule which is to be used to detemine what parts of the
83
+ # canvas are included inside the shape. specifies one of the following
84
+ # values: <tt>"nonzero"</tt>, <tt>"evenodd"</tt>
85
+ # @return [String] the value of attribute fill_rule
86
+ #+++
87
+ # @attribute stroke
88
+ # Returns or sets the painting along the outline of the shape.
89
+ # @return [Color, #write_as] the value of attribute stroke
90
+ #+++
91
+ # @attribute stroke_dasharray
92
+ # Returns or sets the pattern of dashes and gaps used to stroke paths.
93
+ # @return [Array<Length>] the value of attribute stroke_dasharray
94
+ #+++
95
+ # @attribute stroke_dashoffset
96
+ # Returns or sets the distance into the dash pattern to start the dash.
97
+ # @return [Length] the value of attribute stroke_dashoffset
98
+ #+++
99
+ # @attribute stroke_linecap
100
+ # Returns or sets the shape to be used at the end of open subpaths when they
101
+ # are stroked. specifies one of the following values: <tt>"butt"</tt>,
102
+ # <tt>"round"</tt>, <tt>"square"</tt>
103
+ # @return [String] the value of attribute stroke_linecap
104
+ #+++
105
+ # @attribute stroke_linejoin
106
+ # Returns or sets the shape to be used at the corners of paths or basic
107
+ # shapes when they are stroked. specifies one of the following vlaues:
108
+ # <tt>"miter"</tt>, <tt>"round"</tt>, <tt>"bevel"</tt>
109
+ # @return [String] the value of attribute stroke_linejoin
110
+ #+++
111
+ # @attribute stroke_miterlimit
112
+ # Returns or sets the limit value on the ratio of the miter length to the
113
+ # value of +stroke_width+ attribute. When the ratio exceeds this attribute
114
+ # value, the join is converted from a _miter_ to a _bevel_.
115
+ # @return [Float] the value of attribute stroke_mitterlimit
116
+ #+++
117
+ # @attribute stroke_opacity
118
+ # Returns or sets the opacity of the painting operation used to stroke.
119
+ # @return [Float] the value of attribute stroke_opacity
120
+ #+++
121
+ # @attribute stroke_width
122
+ # Returns or sets the width of the stroke.
123
+ # @return [Length] the value of attribute stroke_width
124
+ #+++
125
+ # @attribute display
126
+ # Returns or sets whether the shape is displayed. specifies one of the
127
+ # following vlaues: <tt>"block"</tt>, <tt>"none"</tt>
128
+ # @return [String] the value of attribute display
129
+ #+++
130
+ # @attribute visibility
131
+ # Returns or sets whether the shape is hidden. specifies one of the
132
+ # following vlaues: <tt>"visible"</tt>, <tt>"hidden"</tt>
133
+ # @return [String] the value of attribute visibility
45
134
  Painting::IMPLEMENT_ATTRIBUTES.each do |painting_attr|
46
135
  define_method(painting_attr) {| | @painting.__send__(painting_attr)}
47
136
  define_method("#{painting_attr}=".to_sym) {|value|
@@ -50,22 +139,80 @@ module DYI #:nodoc:
50
139
  }
51
140
  end
52
141
 
142
+ # @private
143
+ # @todo
53
144
  def drop_shadow=(options)
54
145
  DROP_SHADOW_OPTIONS.each do |key|
55
146
  @drop_shadow[key] = options[key.to_sym] if options[key.to_sym]
56
147
  end
57
148
  end
58
149
 
150
+ # Draws a line to specify the start and end points.
151
+ # @param [Element] canvas the element which the line is drawn on
152
+ # @param [Coordinate] start_point the start point of the line
153
+ # @param [Coordinate] end_point the start point of the line
154
+ # @option options [String] :id the ID of the drawn shape
155
+ # @option options [String] :anchor_href the location of a reference of a
156
+ # source anchor for the link of the drawn shape
157
+ # @option options [String] :anchor_target the relevant presentation
158
+ # context when the link is activated
159
+ # @option options [String] :css_class the CSS class attribute of the drawn
160
+ # shape
161
+ # @return [Shape::Line] a drawn line
59
162
  def draw_line(canvas, start_point, end_point, options={})
60
163
  Shape::Line.create_on_start_end(start_point, end_point, merge_option(options)).draw_on(canvas)
61
164
  end
62
165
 
63
166
  alias draw_line_on_start_end draw_line
64
167
 
168
+ # Draws a line to specify the start points and the direction.
169
+ # @param [Element] canvas the element which the line is drawn on
170
+ # @param [Coordinate] start_point the start point of the line
171
+ # @param [Length] direction_x the x-direction of the end point
172
+ # @param [Length] direction_y the y-direction of the end point
173
+ # @option (see #draw_line)
174
+ # @return (see #draw_line)
65
175
  def draw_line_on_direction(canvas, start_point, direction_x, direction_y, options={})
66
176
  Shape::Line.create_on_direction(start_point, direction_x, direction_y, merge_option(options)).draw_on(canvas)
67
177
  end
68
178
 
179
+ # Draws a polyline.
180
+ # @return [Shape::Polyline] a drawn polyline
181
+ # @overload draw_polyline(canvas, point, options = {})
182
+ # Draws a polyline. Second and subsequent making-up points are specified in the
183
+ # block.
184
+ # @param [Element] canvas the element which the polyline is drawn on
185
+ # @param [Coordinate] point the start point of the polyline
186
+ # @option options [String] :id the ID of the drawn shape
187
+ # @option options [String] :anchor_href the location of a reference of a
188
+ # source anchor for the link of the drawn shape
189
+ # @option options [String] :anchor_target the relevant presentation
190
+ # context when the link is activated
191
+ # @option options [String] :css_class the CSS class attribute of the drawn
192
+ # shape
193
+ # @yield [polyline] a block which the polyline is drawn in
194
+ # @yieldparam [Shape::Polyline] polyline the created polyline object
195
+ # @overload draw_polyline(canvas, points, options = {})
196
+ # Draws a polyline to specify in the making-up points.
197
+ # @param [Element] canvas the element which the polyline is drawn on
198
+ # @param [Array<Coordinate>] points the array of the making-up points
199
+ # @option options [String] :id the ID of the drawn shape
200
+ # @option options [String] :anchor_href the location of a reference of a
201
+ # source anchor for the link of the drawn shape
202
+ # @option options [String] :anchor_target the relevant presentation
203
+ # context when the link is activated
204
+ # @option options [String] :css_class the CSS class attribute of the drawn
205
+ # shape
206
+ # @since 1.1.0
207
+ # @example
208
+ # canvas = DYI::Canvas.new(100,100)
209
+ # pen = DYI::Drawing::Pen.black_pen
210
+ # pen.draw_polyline(canvas, [20, 20]) {|polyline|
211
+ # polyline.line_to([20, 80])
212
+ # polyline.line_to([80, 80])
213
+ # }
214
+ # # the following is the same processing
215
+ # # pen.draw_polyline(canvas, [[20, 20], [20, 80], [80, 80]])
69
216
  def draw_polyline(canvas, points, options={})
70
217
  if block_given?
71
218
  polyline = Shape::Polyline.new(points, merge_option(options))
@@ -77,6 +224,43 @@ module DYI #:nodoc:
77
224
  polyline.draw_on(canvas)
78
225
  end
79
226
 
227
+ # Draws a polygon.
228
+ # @return [Shape::Polygon] a drawn polygon
229
+ # @overload draw_polygon(canvas, point, options = {})
230
+ # Draws a polygon. Second and subsequent vertices are specified in the
231
+ # block.
232
+ # @param [Element] canvas the element which the polygon is drawn on
233
+ # @param [Coordinate] point the first vertix of the polygon
234
+ # @option options [String] :id the ID of the drawn shape
235
+ # @option options [String] :anchor_href the location of a reference of a
236
+ # source anchor for the link of the drawn shape
237
+ # @option options [String] :anchor_target the relevant presentation
238
+ # context when the link is activated
239
+ # @option options [String] :css_class the CSS class attribute of the drawn
240
+ # shape
241
+ # @yield [polygon] a block which the polygon is drawn in
242
+ # @yieldparam [Shape::Polygon] polygon the created polygon object
243
+ # @overload draw_polygon(canvas, points, options = {})
244
+ # Draws a polygon to specify in the vertices.
245
+ # @param [Element] canvas the element which the polygon is drawn on
246
+ # @param [Array<Coordinate>] points the array of the vertices
247
+ # @option options [String] :id the ID of the drawn shape
248
+ # @option options [String] :anchor_href the location of a reference of a
249
+ # source anchor for the link of the drawn shape
250
+ # @option options [String] :anchor_target the relevant presentation
251
+ # context when the link is activated
252
+ # @option options [String] :css_class the CSS class attribute of the drawn
253
+ # shape
254
+ # @since 1.1.0
255
+ # @example
256
+ # canvas = DYI::Canvas.new(100,100)
257
+ # brush = DYI::Drawing::Brush.red_brush
258
+ # brush.draw_polygon(canvas, [20, 20]) {|polygon|
259
+ # polygon.line_to([20, 80])
260
+ # polygon.line_to([80, 80])
261
+ # }
262
+ # # the following is the same processing
263
+ # # brush.draw_polygon(canvas, [[20, 20], [20, 80], [80, 80]])
80
264
  def draw_polygon(canvas, points, options={})
81
265
  if block_given?
82
266
  polygon = Shape::Polygon.new(points, merge_option(options))
@@ -88,42 +272,123 @@ module DYI #:nodoc:
88
272
  polygon.draw_on(canvas)
89
273
  end
90
274
 
275
+ # Draws a rectangle to specify the left-top points, the width and the
276
+ # height.
277
+ # @param [Element] canvas the element which the rectangle is drawn on
278
+ # @param [Coordinate] left_top the left-top corner point of the rectangle
279
+ # @param [Length] width the width of the rectangle
280
+ # @param [Length] height the height of the rectangle
281
+ # @option (see #draw_line)
282
+ # @option options [Length] :rx for rounded rectangles, the x-axis radius
283
+ # of the ellipse used to round off the corners of the rectangle
284
+ # @option options [Length] :ry for rounded rectangles, the y-axis radius
285
+ # of the ellipse used to round off the corners of the rectangle
286
+ # @return [Shape::Rectangle] a drawn rectangle
91
287
  def draw_rectangle(canvas, left_top_point, width, height, options={})
92
288
  Shape::Rectangle.create_on_width_height(left_top_point, width, height, merge_option(options)).draw_on(canvas)
93
289
  end
94
290
 
95
291
  alias draw_rectangle_on_width_height draw_rectangle
96
292
 
293
+ # Draws a rectangle to specify the top, right, botton and left cooridinate.
294
+ # @param [Element] canvas the element which the rectangle is drawn on
295
+ # @param [Length] top the y-coordinate of the top of the rectangle
296
+ # @param [Length] right the x-coordinate of the right of the rectangle
297
+ # @param [Length] bottom the y-coordinate of the bottom of the rectangle
298
+ # @param [Length] left the x-coordinate of the left of the rectangle
299
+ # @option (see #draw_rectangle)
300
+ # @return (see #draw_rectangle)
97
301
  def draw_rectangle_on_corner(canvas, top, right, bottom, left, options={})
98
302
  Shape::Rectangle.create_on_corner(top, right, bottom, left, merge_option(options)).draw_on(canvas)
99
303
  end
100
304
 
305
+ # Draws free-form lines or curves. See methods of {Shape::Path} for
306
+ # commands to draw the path.
307
+ # @param [Element] canvas the element which the path is drawn on
308
+ # @param [Coordinate] point the start point of the path
309
+ # @option (see #draw_line)
310
+ # @yield [path] a block which the path is drawn in
311
+ # @yieldparam [Shape::Path] path the created path object
312
+ # @return [Shape::Path] a drawn path
313
+ # @see Shape::Path
101
314
  def draw_path(canvas, point, options={}, &block)
102
315
  Shape::Path.draw(point, merge_option(options), &block).draw_on(canvas)
103
316
  end
104
317
 
318
+ # Draws a free-form line or curve, and closes path finally. See methods of
319
+ # {Shape::Path} for commands to draw the path.
320
+ # @param (see #draw_path)
321
+ # @option (see #draw_path)
322
+ # @yield (see #draw_path)
323
+ # @yieldparam (see #draw_path)
324
+ # @return (see #draw_path)
325
+ # @see (see #draw_path)
105
326
  def draw_closed_path(canvas, point, options={}, &block)
106
327
  Shape::Path.draw_and_close(point, merge_option(options), &block).draw_on(canvas)
107
328
  end
108
329
 
330
+ # Draws a circle to specify the center point and the radius.
331
+ # @param [Element] canvas the element which the circle is drawn on
332
+ # @param [Coordinate] center_point the center point of the circle
333
+ # @param [Length] radius the radius of the circle
334
+ # @option (see #draw_line)
335
+ # @return [Shape::Circle] a drawn circle
109
336
  def draw_circle(canvas, center_point, radius, options={})
110
337
  Shape::Circle.create_on_center_radius(center_point, radius, merge_option(options)).draw_on(canvas)
111
338
  end
112
339
 
340
+ # Draws an ellipse to specify the center point and the radius.
341
+ # @param [Element] canvas the element which the ellipse is drawn on
342
+ # @param [Coordinate] center_point the center point of the ellipse
343
+ # @param [Length] radius_x the x-axis radius of the ellipse
344
+ # @param [Length] radius_y the y-axis radius of the ellipse
345
+ # @option (see #draw_line)
346
+ # @return [Shape::Ellipse] a drawn ellipse
113
347
  def draw_ellipse(canvas, center_point, radius_x, radius_y, options={})
114
348
  Shape::Ellipse.create_on_center_radius(center_point, radius_x, radius_y, merge_option(options)).draw_on(canvas)
115
349
  end
116
350
 
351
+ # Draws an image.
352
+ # @param [Element] canvas the element which the image is drawn on
353
+ # @param [Coordinate] left_top the left-top corner point of the image
354
+ # @param [Length] width the width of the image
355
+ # @param [Length] height the height of the image
356
+ # @param [String] file_path the path of the image file
357
+ # @option (see #draw_line)
358
+ # @option options [String] :content_type the content-type of the image
359
+ # @return [Shape::Image] a drawn image
117
360
  # @since 1.0.0
118
361
  def draw_image(canvas, left_top_point, width, height, file_path, options={})
119
362
  Shape::Image.new(left_top_point, width, height, file_path, merge_option(options)).draw_on(canvas)
120
363
  end
121
364
 
365
+ # Adds a reference to an image.
366
+ # @param [Element] canvas the element which the reference is added on
367
+ # @param [Coordinate] left_top the left-top corner point of the image
368
+ # @param [Length] width the width of the image
369
+ # @param [Length] height the height of the image
370
+ # @param [String] image_uri the reference URI to the image file
371
+ # @option (see #draw_line)
372
+ # @return [Shape::ImageReference] a drawn reference to the image
122
373
  # @since 1.0.0
123
374
  def import_image(canvas, left_top_point, width, height, image_uri, options={})
124
375
  Shape::ImageReference.new(left_top_point, width, height, image_uri, merge_option(options)).draw_on(canvas)
125
376
  end
126
377
 
378
+ # Draws a circular sector.
379
+ # @param [Element] canvas the element which the sector is drawn on
380
+ # @param [Coordinate] center_point the center point of the sector
381
+ # @param [Length] radius_x the x-axis radius of the sector
382
+ # @param [Length] radius_y the y-axis radius of the sector
383
+ # @param [Number] start_angle the starting-radius angle of the sector from
384
+ # x-direction in degrees
385
+ # @param [Number] center_angle the center angle of the sector from the
386
+ # starting-radius in degrees
387
+ # @option (see #draw_line)
388
+ # @option options [#to_f] :inner_radius if you want to make a concentric
389
+ # hole with sector, the ratio of the hole's radius to the sector radius
390
+ # @return [Shape::Path] a drawn sector
391
+ # @raise [ArgumentError] _:inner_radius_ option is out of range
127
392
  def draw_sector(canvas, center_point, radius_x, radius_y, start_angle, center_angle, options={})
128
393
  start_angle = (center_angle > 0 ? start_angle : (start_angle + center_angle)) % 360
129
394
  center_angle = center_angle.abs
@@ -158,10 +423,20 @@ module DYI #:nodoc:
158
423
  end
159
424
  end
160
425
 
426
+ # Draws a toroid.
427
+ # @param [Element] canvas the element which the toroid is drawn on
428
+ # @param [Coordinate] center_point the center point of the toroid
429
+ # @param [Length] radius_x the x-axis radius of the toroid
430
+ # @param [Length] radius_y the y-axis radius of the toroid
431
+ # @param [#to_f] inner_radius the ratio of inner radius to the sector
432
+ # radius
433
+ # @option (see #draw_line)
434
+ # @return [Shape::Path] a drawn toroid
435
+ # @raise [ArgumentError] _inner_radius_ is out of range
161
436
  # @since 1.1.0
162
437
  def draw_toroid(canvas, center_point, radius_x, radius_y, inner_radius, options={})
163
438
  if inner_radius >= 1 || 0 > inner_radius
164
- raise ArgumentError, "inner_radius option is out of range: #{inner_radius}"
439
+ raise ArgumentError, "inner_radius is out of range: #{inner_radius}"
165
440
  end
166
441
  radius_x, radius_y = Length.new(radius_x).abs, Length.new(radius_y).abs
167
442
  center_point = Coordinate.new(center_point)
@@ -184,6 +459,41 @@ module DYI #:nodoc:
184
459
  }
185
460
  end
186
461
 
462
+ # Draws a text.
463
+ # @param [Element] canvas the element which the text is drawn on
464
+ # @param [Coordinate] point the point of the base-line of the
465
+ # text. See _:text_anchor_ option
466
+ # @param [String] text the drawn text string
467
+ # @option (see #draw_line)
468
+ # @option options [String] :text_anchor the way of aligning a string of
469
+ # text relative to _point_ argument. specifies one of the following
470
+ # vlaues: <tt>"start"</tt>, <tt>"middle"</tt>, <tt>"end"</tt>
471
+ # @option options [Length] :text_length the length of the displayed text
472
+ # @option options [String] :text_adjust the way of adjustments to make the
473
+ # rendered length of the text match _text_length_ option. specifies one
474
+ # of the following vlaues: <tt>"spacing"</tt>, <tt>"spacingAndGlyphs"</tt>
475
+ # @option options [String] :text_decoration the decorations that are
476
+ # added to the text. specifies a string in a comma-separated combination
477
+ # of the following vlaues: <tt>"underline"</tt>, <tt>"overline"</tt>,
478
+ # <tt>"line-through"</tt>, <tt>"blink"</tt>
479
+ # @option options [String] :writing_mode the inline-progression-direction
480
+ # for a text. specifies one of the following vlaues: <tt>"lr-tb"</tt>,
481
+ # <tt>"rl-tb"</tt>, <tt>"tb-rl"</tt>, <tt>"lr"</tt>, <tt>"rl"</tt>,
482
+ # <tt>"tb"</tt>
483
+ # @option options [Boolean] :show_border whether the border is shown
484
+ # @option options [Length] :border_rx the x-axis radius of the ellipse
485
+ # used to round off the corners of the rectangle when the rounded border
486
+ # is shown
487
+ # @option options [Length] :border_ry the y-axis radius of the ellipse
488
+ # used to round off the corners of the rectangle when the rounded border
489
+ # is shown
490
+ # @option options [Color, #write_as] :background_color the interior
491
+ # painting of the border-line when the border is shown
492
+ # @option options [Color, #write_as] :border_color the painting along the
493
+ # border-line when the border is shown
494
+ # @option options [Length] :border_width the width of border-line when the
495
+ # border is shown
496
+ # @return [Shape::Text] a drawn text
187
497
  def draw_text(canvas, point, text, options={})
188
498
  Shape::Text.new(point, text, merge_option(options)).draw_on(canvas)
189
499
  end
@@ -216,15 +526,54 @@ module DYI #:nodoc:
216
526
  end
217
527
  end
218
528
 
529
+ # +Pen+ object holds a {Painting} object and a {Font} object. Using these
530
+ # object, +Pen+ object creates instances of concrete subclass of
531
+ # {Shape::Base}; a created instance has a painting attribute and a font
532
+ # attribute that +Pen+ object holds.
533
+ #
534
+ # +Pen+ class has been optimized to draw a line or a outline of the shape.
535
+ # Synonym methods of attributes _stroke_xxx_ has been defined in this class:
536
+ # +color+(synonym of _stroke_), +dashoffset+(synonym of _stroke_dashoffset_),
537
+ # +linecap+(synonym of _stroke_linecap_), +linejoin+(synonym of
538
+ # _stroke_linejoin_), +miterlimit+(synonym of _stroke_miterlimit_) and
539
+ # +width+(synonym of _stroke_width_).
540
+ #
541
+ # This class has shortcut contractors: _color_name_pen_, which a line color
542
+ # is specified in.
543
+ #
544
+ # @example
545
+ # pen = DYI::Drawing::Pen.red_pen(:wdith => 3)
546
+ # # the followings is the same processing
547
+ # # pen = DYI::Drawing::Pen.new(:color => 'red', :wdith => 3)
548
+ # # pen = DYI::Drawing::Pen.new(:stroke => 'red', :stroke_wdith => 3)
549
+ #
550
+ # canvas = DYI::Canvas.new(100, 50)
551
+ # pen.draw_line(canvas, [10, 20], [90, 40])
552
+ #
553
+ # @since 0.0.0
219
554
  class Pen < PenBase
220
- #:stopdoc:
555
+
556
+ # @private
221
557
  ALIAS_ATTRIBUTES =
222
558
  Painting::IMPLEMENT_ATTRIBUTES.inject({}) do |hash, key|
223
559
  hash[$'.empty? ? :color : $'.to_sym] = key if key.to_s =~ /^(stroke_|stroke$)/ && key != :stroke_opacity
224
560
  hash
225
561
  end
226
- #:startdoc:
227
562
 
563
+ # (see PenBase#initialize)
564
+ # @option options [Color, #write_as] :color the value of attribute {#color
565
+ # color}
566
+ # @option options [Array<Length>, String] :dasharray the value of
567
+ # attribute {#dasharray dasharray}
568
+ # @option options [Length] :dashoffset the value of attribute {#dashoffset
569
+ # dashoffset}
570
+ # @option options [String] :linecap the value of attribute {#linecap
571
+ # linecap}
572
+ # @option options [String] :linejoin the value of attribute {#linejoin
573
+ # linejoin}
574
+ # @option options [#to_f] :miterlimit the value of attribute {#miterlimit
575
+ # mitterlimit}
576
+ # @option options [Lengthf] :width the value of attribute {#width width}
228
577
  def initialize(options={})
229
578
  options = options.clone
230
579
  ALIAS_ATTRIBUTES.each do |key, value|
@@ -234,11 +583,39 @@ module DYI #:nodoc:
234
583
  super
235
584
  end
236
585
 
586
+ # @attribute color
587
+ # Synonym of attribute {#stroke stroke}.
588
+ # @return [Color, #write_as] the value of attribute stroke
589
+ #+++
590
+ # @attribute dasharray
591
+ # Synonym of attribute {#stroke_dasharray stroke_dasharray}.
592
+ # @return [Array<Length>] the value of attribute stroke_dasharray
593
+ #+++
594
+ # @attribute dashoffset
595
+ # Synonym of attribute {#stroke_dashoffset stroke_dashoffset}.
596
+ # @return [Length] the value of attribute stroke_dashoffset
597
+ #+++
598
+ # @attribute linecap
599
+ # Synonym of attribute {#stroke_linecap stroke_linecap}.
600
+ # @return [String] the value of attribute stroke_linecap
601
+ #+++
602
+ # @attribute linejoin
603
+ # Synonym of attribute {#stroke_linejoin stroke_linejoin}.
604
+ # @return [String] the value of attribute stroke_linejoin
605
+ #+++
606
+ # @attribute miterlimit
607
+ # Synonym of attribute {#stroke_miterlimit stroke_miterlimit}.
608
+ # @return [Float] the value of attribute stroke_mitterlimit
609
+ #+++
610
+ # @attribute width
611
+ # Synonym of attribute {#stroke_width stroke_width}.
612
+ # @return [Length] the value of attribute stroke_width
237
613
  ALIAS_ATTRIBUTES.each do |key, value|
238
614
  alias_method key, value
239
615
  alias_method "#{key}=", "#{value}="
240
616
  end
241
617
 
618
+ # (see PenBase#draw_text)
242
619
  def draw_text(canvas, point, text, options={})
243
620
  painting = @painting
244
621
  text_painting = Painting.new(painting)
@@ -253,7 +630,7 @@ module DYI #:nodoc:
253
630
  end
254
631
 
255
632
  class << self
256
- def method_missing(method_name, *args, &block) #:nodoc:
633
+ def method_missing(method_name, *args, &block)
257
634
  if method_name.to_s =~ /^([a-z]+)_pen$/
258
635
  if options = args.first
259
636
  self.new(options.merge(:stroke => $1))
@@ -267,15 +644,41 @@ module DYI #:nodoc:
267
644
  end
268
645
  end
269
646
 
647
+ # +Brush+ object holds a {Painting} object and a {Font} object. Using these
648
+ # object, +Brush+ object creates instances of concrete subclass of
649
+ # {Shape::Base}; a created instance has a painting attribute and a font
650
+ # attribute that +Brush+ object holds.
651
+ #
652
+ # +Brush+ class has been optimized to fill a shape with a color and so on.
653
+ # Synonym methods of attributes _fill_xxx_ has been defined in this class:
654
+ # +color+(synonym of _fill_), +rule+(synonym of _fill_rule_).
655
+ #
656
+ # This class has shortcut contractors: _color_name_brush_, which a fill
657
+ # color is specified in.
658
+ #
659
+ # @example
660
+ # brush = DYI::Drawing::Brush.red_brush
661
+ # # the followings is the same processing
662
+ # # brush = DYI::Drawing::Brush.new(:color => 'red')
663
+ # # brush = DYI::Drawing::Brush.new(:fill => 'red')
664
+ #
665
+ # canvas = DYI::Canvas.new(100, 50)
666
+ # brush.draw_ellipse(canvas, [50, 25], 40, 15)
667
+ #
668
+ # @since 0.0.0
270
669
  class Brush < PenBase
271
- #:stopdoc:
670
+
671
+ # @private
272
672
  ALIAS_ATTRIBUTES =
273
673
  Painting::IMPLEMENT_ATTRIBUTES.inject({}) do |hash, key|
274
674
  hash[$'.empty? ? :color : $'.to_sym] = key if key.to_s =~ /^(fill_|fill$)/ && key != :fill_opacity
275
675
  hash
276
676
  end
277
- #:startdoc:
278
677
 
678
+ # (see PenBase#initialize)
679
+ # @option options [Color, #write_as] :color the value of attribute {#color
680
+ # color}
681
+ # @option options [String] :rule the value of attribute {#rule rule}
279
682
  def initialize(options={})
280
683
  options = options.clone
281
684
  ALIAS_ATTRIBUTES.each do |key, value|
@@ -286,13 +689,20 @@ module DYI #:nodoc:
286
689
  super
287
690
  end
288
691
 
692
+ # @attribute color
693
+ # Synonym of attribute {#fill fill}.
694
+ # @return [Color, #write_as] the value of attribute fill
695
+ #+++
696
+ # @attribute rule
697
+ # Synonym of attribute {#fill_rule fill_rule}.
698
+ # @return [String] the value of attribute fill_rule
289
699
  ALIAS_ATTRIBUTES.each do |key, value|
290
700
  alias_method key, value
291
701
  alias_method "#{key}=", "#{value}="
292
702
  end
293
703
 
294
704
  class << self
295
- def method_missing(method_name, *args, &block) #:nodoc:
705
+ def method_missing(method_name, *args, &block)
296
706
  if method_name.to_s =~ /([a-z]+)_brush/
297
707
  if options = args.first
298
708
  self.new(options.merge(:fill => $1))