dyi 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
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
  #
@@ -19,9 +19,11 @@
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 CubicPen < Pen
26
28
  POSITION_TYPE_VALUES = [:baseline, :center, :backline]
27
29
  attr_reader :position_type, :background_color, :background_opacity, :dx, :dy
@@ -93,14 +95,14 @@ module DYI #:nodoc:
93
95
 
94
96
  private
95
97
 
96
- def adjust_z_coordinate(shape) #:nodoc:
98
+ def adjust_z_coordinate(shape)
97
99
  case position_type
98
100
  when :center then shape.translate(-dx / 2, -dy / 2)
99
101
  when :backline then shape.translate(-dx, -dy)
100
102
  end
101
103
  end
102
104
 
103
- def draw_background_shape(canvas, start_point, end_point, options={}) #:nodoc:
105
+ def draw_background_shape(canvas, start_point, end_point, options={})
104
106
  brush.draw_polygon(canvas, start_point, options) {|polygon|
105
107
  polygon.line_to(end_point)
106
108
  polygon.line_to(Coordinate.new(end_point) + Coordinate.new(dx, dy))
@@ -109,6 +111,7 @@ module DYI #:nodoc:
109
111
  end
110
112
  end
111
113
 
114
+ # @since 0.0.0
112
115
  class CylinderBrush < Brush
113
116
 
114
117
  # @since 1.1.0
@@ -160,7 +163,7 @@ module DYI #:nodoc:
160
163
 
161
164
  private
162
165
 
163
- def body_gradient(canvas) #:nodoc:
166
+ def body_gradient(canvas)
164
167
  gradient = ColorEffect::LinearGradient.new([0,0],[1,0])
165
168
  gradient.add_color(0, color.merge(Color.white, 0.4))
166
169
  gradient.add_color(0.3, color.merge(Color.white, 0.65))
@@ -171,13 +174,15 @@ module DYI #:nodoc:
171
174
  gradient
172
175
  end
173
176
 
174
- def top_color #:nodoc:
177
+ def top_color
175
178
  color.merge(Color.white, 0.3)
176
179
  end
177
180
  end
178
181
 
182
+ # @since 0.0.0
179
183
  class ColumnBrush < Brush
180
184
 
185
+ # @since 1.1.0
181
186
  def initialize(options={})
182
187
  self.flank_color = options.delete(:flank_color)
183
188
  self.dy = options.delete(:dy)
@@ -19,6 +19,7 @@
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
+ #
22
23
  module DYI
23
24
 
24
25
  # Abstract class that represents a element contained in the image.
@@ -108,7 +109,7 @@ module DYI
108
109
  # Sets a CSS class attribute.
109
110
  # @param [String] css_class a CSS class attribute
110
111
  # @see {#css_class}
111
- # @raise [ArgumentError] parameter `css_class' is illegal class name
112
+ # @raise [ArgumentError] parameter 'css_class' is illegal class name
112
113
  def css_class=(css_class)
113
114
  return @css_class = nil if css_class.nil?
114
115
  classes = css_class.to_s.split(/\s+/)
@@ -128,9 +129,9 @@ module DYI
128
129
 
129
130
  # Adds a CSS class.
130
131
  # @param [String] css_class a CSS class name
131
- # @return [String, nil] value of parameter `css_class' if successes to add
132
+ # @return [String, nil] value of parameter 'css_class' if successes to add
132
133
  # a class, nil if failures
133
- # @raise [ArgumentError] parameter `css_class' is illegal class name
134
+ # @raise [ArgumentError] parameter 'css_class' is illegal class name
134
135
  def add_css_class(css_class)
135
136
  if css_class.to_s !~ CLASS_REGEXP
136
137
  raise ArgumentError, "`#{css_class}' is a illegal class-name"
@@ -144,7 +145,7 @@ module DYI
144
145
 
145
146
  # Remove a CSS class.
146
147
  # @param [String] css_class a CSS class name that will be removed
147
- # @return [String, nil] value of parameter `css_class' if successes to
148
+ # @return [String, nil] value of parameter 'css_class' if successes to
148
149
  # remove a class, nil if failures
149
150
  def remove_css_class(css_class)
150
151
  classes = css_classes
@@ -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
  #
@@ -26,13 +26,13 @@
26
26
  #
27
27
  # See the documentation to the DYI::Length class for more details and
28
28
  # examples of usage.
29
- #
30
- # @since 1.0.0
31
29
 
30
+ #
32
31
  module DYI
33
32
 
34
33
  # Class representing a event. The event becomes effective only when it is
35
34
  # output by SVG format.
35
+ # @since 1.0.0
36
36
  class Event
37
37
  IMPLEMENT_EVENTS = [:focusin,:focusout,:click,:mousedown,:mouseup,
38
38
  :mouseover,:mousemove,:mouseout,:load]
@@ -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,8 +19,10 @@
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:
22
+ #
23
+ module DYI
23
24
 
25
+ # @since 0.0.0
24
26
  class Font
25
27
  IMPLEMENT_ATTRIBUTES = [:font_family, :style, :variant, :weight, :size, :size_adjust, :stretch]
26
28
  VALID_VALUES = {
@@ -95,7 +97,7 @@ module DYI #:nodoc:
95
97
  @size = Length.new_or_nil(value)
96
98
  end
97
99
 
98
- def size_adjust=(value) #:nodoc:
100
+ def size_adjust=(value)
99
101
  @size_adjust = value ? value.to_f : nil
100
102
  end
101
103
 
@@ -119,7 +121,7 @@ module DYI #:nodoc:
119
121
 
120
122
  class << self
121
123
 
122
- def new(*args) #:nodoc:
124
+ def new(*args)
123
125
  return args.first if args.size == 1 && args.first.instance_of?(self)
124
126
  super
125
127
  end
@@ -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
  #
@@ -21,9 +21,10 @@
21
21
 
22
22
  require 'stringio'
23
23
 
24
- module DYI #:nodoc:
25
- module Formatter #:nodoc:
24
+ module DYI
25
+ module Formatter
26
26
 
27
+ # @since 0.0.0
27
28
  class Base
28
29
 
29
30
  def initialize(canvas)
@@ -88,9 +89,10 @@ module DYI #:nodoc:
88
89
  end
89
90
  end
90
91
 
91
- module XmlChar #:nodoc:
92
+ # @since 0.0.0
93
+ module XmlChar
92
94
  # See http://intertwingly.net/stories/2004/04/14/i18n.html#CleaningWindows
93
- CP1252 = { #:nodoc:
95
+ CP1252 = {
94
96
  128 => 8364, # euro sign
95
97
  130 => 8218, # single low-9 quotation mark
96
98
  131 => 402, # latin small letter f with hook
@@ -121,14 +123,14 @@ module DYI #:nodoc:
121
123
  }
122
124
 
123
125
  # See http://www.w3.org/TR/REC-xml/#dt-chardata for details.
124
- PREDEFINED = { #:nodoc:
126
+ PREDEFINED = {
125
127
  38 => '&amp;', # ampersand
126
128
  60 => '&lt;', # left angle bracket
127
129
  62 => '&gt;' # right angle bracket
128
130
  }
129
131
 
130
132
  # See http://www.w3.org/TR/REC-xml/#dt-chardata for details.
131
- ATTR_PREDEFINED = PREDEFINED.merge( #:nodoc:
133
+ ATTR_PREDEFINED = PREDEFINED.merge(
132
134
  34 => '&quot;', # double quote
133
135
  39 => '&apos;' # single quote
134
136
  )
@@ -143,19 +145,19 @@ module DYI #:nodoc:
143
145
 
144
146
  private
145
147
 
146
- def escape(s) #:nodoc:
148
+ def escape(s)
147
149
  s.to_s.unpack('U*').map {|n| code_to_char(n)}.join # ASCII, UTF-8
148
150
  rescue
149
151
  s.to_s.unpack('C*').map {|n| code_to_char(n)}.join # ISO-8859-1, WIN-1252
150
152
  end
151
153
 
152
- def attr_escape(s) #:nodoc:
154
+ def attr_escape(s)
153
155
  s.to_s.unpack('U*').map {|n| code_to_char(n, true)}.join # ASCII, UTF-8
154
156
  rescue
155
157
  s.to_s.unpack('C*').map {|n| code_to_char(n, true)}.join # ISO-8859-1, WIN-1252
156
158
  end
157
159
 
158
- def code_to_char(code, is_attr=false) #:nodoc:
160
+ def code_to_char(code, is_attr=false)
159
161
  code = CP1252[code] || code
160
162
  case code when *VALID
161
163
  (is_attr ? ATTR_PREDEFINED : PREDEFINED)[code] || (code<128 ? code.chr : "&##{code};")
@@ -165,8 +167,11 @@ module DYI #:nodoc:
165
167
  end
166
168
  end
167
169
 
170
+ # @since 0.0.0
168
171
  class XmlFormatter < Base
169
172
  include XmlChar
173
+
174
+ # @since 1.1.0
170
175
  attr_reader :namespace
171
176
 
172
177
  def initialize(canvas, options={})
@@ -178,18 +183,22 @@ module DYI #:nodoc:
178
183
  @namespace = namespace.empty? ? nil : namespace
179
184
  end
180
185
 
186
+ # @since 1.1.0
181
187
  def inline_mode?
182
188
  @inline_mode ? true : false
183
189
  end
184
190
 
191
+ # @since 1.1.0
185
192
  def inline_mode=(boolean)
186
193
  @inline_mode = boolean ? true : false
187
194
  end
188
195
 
196
+ # @since 1.0.0
189
197
  def xml_instruction
190
198
  %Q{<?xml version="1.0" encoding="UTF-8"?>}
191
199
  end
192
200
 
201
+ # @since 1.0.0
193
202
  def stylesheet_instruction(stylesheet)
194
203
  styles = []
195
204
  styles << '<?xml-stylesheet href="'
@@ -234,13 +243,13 @@ module DYI #:nodoc:
234
243
 
235
244
  private
236
245
 
237
- def puts_line(io, &block) #:nodoc:
246
+ def puts_line(io, &block)
238
247
  io << (' ' * (@indent * @level)) if @indent != 0 && @level != 0
239
248
  yield io
240
249
  io << "\n" if @indent != 0
241
250
  end
242
251
 
243
- def create_node(io, tag_name, attributes={}, &block) #:nodoc:
252
+ def create_node(io, tag_name, attributes={}, &block)
244
253
  _tag_name = @namespace ? "#{namespace}:#{tag_name}" : tag_name
245
254
  puts_line(io) {
246
255
  io << '<' << _tag_name
@@ -253,7 +262,7 @@ module DYI #:nodoc:
253
262
  puts_line(io) {io << '</' << _tag_name << '>'}
254
263
  end
255
264
 
256
- def create_leaf_node(io, tag_name, *attr) #:nodoc:
265
+ def create_leaf_node(io, tag_name, *attr)
257
266
  _tag_name = @namespace ? "#{namespace}:#{tag_name}" : tag_name
258
267
  puts_line(io) {
259
268
  io << '<' << _tag_name
@@ -275,7 +284,7 @@ module DYI #:nodoc:
275
284
  }
276
285
  end
277
286
 
278
- def create_nested_nodes(io, &block) #:nodoc:
287
+ def create_nested_nodes(io, &block)
279
288
  @level += 1
280
289
  yield io
281
290
  ensure
@@ -283,7 +292,7 @@ module DYI #:nodoc:
283
292
  end
284
293
 
285
294
  # @since 1.0.0
286
- def create_cdata_node(io, tag_name, attributes={}, &block) #:nodoc:
295
+ def create_cdata_node(io, tag_name, attributes={}, &block)
287
296
  _tag_name = @namespace ? "#{namespace}:#{tag_name}" : tag_name
288
297
  puts_line(io) {
289
298
  io << '<' << _tag_name
@@ -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
  #
@@ -22,9 +22,10 @@
22
22
  require 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
23
23
  require 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
24
24
 
25
- module DYI #:nodoc:
26
- module Formatter #:nodoc:
25
+ module DYI
26
+ module Formatter
27
27
 
28
+ # @since 0.0.0
28
29
  class EmfFormatter < Base
29
30
 
30
31
  def save(file_name, options={})
@@ -206,7 +207,7 @@ module DYI #:nodoc:
206
207
 
207
208
  private
208
209
  =begin
209
- def pre_render(shape) #:nodoc:
210
+ def pre_render(shape)
210
211
  attributes = {}
211
212
  style = create_style(shape)
212
213
  transform = create_transform(shape)
@@ -217,7 +218,7 @@ module DYI #:nodoc:
217
218
  attributes
218
219
  end
219
220
  =end
220
- def set_transform(shape, graphics, &block) #:nodoc:
221
+ def set_transform(shape, graphics, &block)
221
222
  shape.transform.each do |tr|
222
223
  case tr.first
223
224
  when :translate
@@ -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
  #
@@ -21,9 +21,10 @@
21
21
 
22
22
  require 'nkf'
23
23
 
24
- module DYI #:nodoc:
25
- module Formatter #:nodoc:
24
+ module DYI
25
+ module Formatter
26
26
 
27
+ # @since 0.0.0
27
28
  class EpsFormatter < Base
28
29
 
29
30
  def header_comment
@@ -245,17 +246,17 @@ module DYI #:nodoc:
245
246
 
246
247
  private
247
248
 
248
- def puts_line(io, *args) #:nodoc:
249
+ def puts_line(io, *args)
249
250
  io << args.flatten.join(' ') << "\n"
250
251
  end
251
252
 
252
- def command_block(io) #:nodoc:
253
+ def command_block(io)
253
254
  puts_line(io, 'gsave')
254
255
  yield
255
256
  puts_line(io, 'grestore')
256
257
  end
257
258
 
258
- def stroke_path(io, shape) #:nodoc:
259
+ def stroke_path(io, shape)
259
260
  cmds = []
260
261
  if shape.respond_to?(:painting) && (attrs = shape.painting)
261
262
  cmds.push([attrs.stroke, 'setrgbcolor']) if attrs.stroke
@@ -274,13 +275,13 @@ module DYI #:nodoc:
274
275
  }
275
276
  end
276
277
 
277
- def stroke_current_path(io, shape) #:nodoc:
278
+ def stroke_current_path(io, shape)
278
279
  stroke_path(io, shape) {
279
280
  puts_line(io, 'stroke')
280
281
  } if shape.painting.stroke
281
282
  end
282
283
 
283
- def fill_path(io, shape) #:nodoc:
284
+ def fill_path(io, shape)
284
285
  cmds = []
285
286
  if shape.respond_to?(:painting) && (attrs = shape.painting)
286
287
  if attrs.fill
@@ -300,13 +301,13 @@ module DYI #:nodoc:
300
301
  }
301
302
  end
302
303
 
303
- def fill_current_path(io, shape) #:nodoc:
304
+ def fill_current_path(io, shape)
304
305
  fill_path(io, shape) {
305
306
  puts_line(io, shape.painting.fill_rule == 'evenodd' ? 'eofill' : 'fill')
306
307
  } if shape.painting.fill
307
308
  end
308
309
 
309
- def linecap_to_num(linecap) #:nodoc:
310
+ def linecap_to_num(linecap)
310
311
  case linecap
311
312
  when 'butt' then 0
312
313
  when 'round' then 1
@@ -314,7 +315,7 @@ module DYI #:nodoc:
314
315
  end
315
316
  end
316
317
 
317
- def linejoin_to_num(linejoin) #:nodoc:
318
+ def linejoin_to_num(linejoin)
318
319
  case linejoin
319
320
  when 'miter' then 0
320
321
  when 'round' then 1
@@ -322,7 +323,7 @@ module DYI #:nodoc:
322
323
  end
323
324
  end
324
325
 
325
- def write_lines(io, points) #:nodoc:
326
+ def write_lines(io, points)
326
327
  puts_line(io, points.first.x, points.first.y, 'moveto')
327
328
  points[1..-1].each do |pt|
328
329
  pt = Coordinate.new(pt)
@@ -360,7 +361,7 @@ module DYI #:nodoc:
360
361
  cmds
361
362
  end
362
363
 
363
- def transform_path(io, shape) #:nodoc:
364
+ def transform_path(io, shape)
364
365
  if shape.respond_to?(:transform) && !(tr = shape.transform).empty?
365
366
  tr.each do |t|
366
367
  case t[0]
@@ -381,7 +382,7 @@ module DYI #:nodoc:
381
382
  end
382
383
  end
383
384
 
384
- def clip_path(io, shape) #:nodoc:
385
+ def clip_path(io, shape)
385
386
  if shape.respond_to?(:clipping) && shape.clipping
386
387
  shape.clipping.each_shapes do |shape, rule|
387
388
  s = shape.clone