dyi 0.0.0
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.
- data/COPYING +674 -0
- data/README +28 -0
- data/examples/class_diagram.rb +151 -0
- data/examples/data/03311056.xlsx +0 -0
- data/examples/data/currency.xlsx +0 -0
- data/examples/data/money.csv +12 -0
- data/examples/line_and_bar.rb +26 -0
- data/examples/line_chart.rb +30 -0
- data/examples/logo.rb +68 -0
- data/examples/pie_chart.rb +19 -0
- data/examples/simple_shapes.rb +15 -0
- data/lib/dyi.rb +49 -0
- data/lib/dyi/chart.rb +34 -0
- data/lib/dyi/chart/array_reader.rb +136 -0
- data/lib/dyi/chart/base.rb +580 -0
- data/lib/dyi/chart/csv_reader.rb +93 -0
- data/lib/dyi/chart/excel_reader.rb +100 -0
- data/lib/dyi/chart/line_chart.rb +468 -0
- data/lib/dyi/chart/pie_chart.rb +141 -0
- data/lib/dyi/chart/table.rb +201 -0
- data/lib/dyi/color.rb +218 -0
- data/lib/dyi/coordinate.rb +224 -0
- data/lib/dyi/drawing.rb +32 -0
- data/lib/dyi/drawing/canvas.rb +100 -0
- data/lib/dyi/drawing/clipping.rb +61 -0
- data/lib/dyi/drawing/color_effect.rb +118 -0
- data/lib/dyi/drawing/filter.rb +74 -0
- data/lib/dyi/drawing/pen.rb +231 -0
- data/lib/dyi/drawing/pen_3d.rb +270 -0
- data/lib/dyi/font.rb +132 -0
- data/lib/dyi/formatter.rb +36 -0
- data/lib/dyi/formatter/base.rb +245 -0
- data/lib/dyi/formatter/emf_formatter.rb +253 -0
- data/lib/dyi/formatter/eps_formatter.rb +397 -0
- data/lib/dyi/formatter/svg_formatter.rb +260 -0
- data/lib/dyi/formatter/svg_reader.rb +113 -0
- data/lib/dyi/formatter/xaml_formatter.rb +317 -0
- data/lib/dyi/length.rb +399 -0
- data/lib/dyi/matrix.rb +122 -0
- data/lib/dyi/painting.rb +177 -0
- data/lib/dyi/shape.rb +1332 -0
- data/lib/dyi/svg_element.rb +149 -0
- data/lib/dyi/type.rb +104 -0
- data/lib/ironruby.rb +326 -0
- data/lib/util.rb +231 -0
- data/test/path_command_test.rb +217 -0
- data/test/test_length.rb +91 -0
- metadata +114 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
|
4
|
+
#
|
5
|
+
# Author:: Mamoru Yuo
|
6
|
+
#
|
7
|
+
# This file is part of DYI.
|
8
|
+
#
|
9
|
+
# DYI is free software: you can redistribute it and/or modify it
|
10
|
+
# under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# DYI is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with DYI. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
|
22
|
+
module DYI #:nodoc:
|
23
|
+
|
24
|
+
module SvgElement
|
25
|
+
|
26
|
+
def draw_on(canvas)
|
27
|
+
canvas.child_elements.push(self)
|
28
|
+
self.root_node = canvas.root_node
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def save_as_svg(file_name)
|
33
|
+
open(file_name, "w+b") {|io|
|
34
|
+
puts_as_svg(io)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def puts_as_svg(io=$>)
|
39
|
+
io.puts(to_svg)
|
40
|
+
end
|
41
|
+
|
42
|
+
def puts_as_png(io=$>)
|
43
|
+
io.puts(to_png)
|
44
|
+
end
|
45
|
+
|
46
|
+
def save(file_name, format=nil)
|
47
|
+
if format
|
48
|
+
format = format.to_s.downcase
|
49
|
+
else
|
50
|
+
file_name.scan(/.\.([^\.]+)$/) {|s| format = s[0].downcase}
|
51
|
+
end
|
52
|
+
|
53
|
+
format ||= 'svg'
|
54
|
+
|
55
|
+
if format == 'svg'
|
56
|
+
save_as_svg(file_name)
|
57
|
+
elsif format == 'png'
|
58
|
+
begin
|
59
|
+
save_as_png(file_name)
|
60
|
+
rescue
|
61
|
+
tmp_file_name = file_name + '.temp'
|
62
|
+
save_as_svg(tmp_file_name)
|
63
|
+
system "\"#{INKSCAPE_PATH}\" -z -T -f #{File.expand_path(tmp_file_name)} -e #{File.expand_path(file_name)}"
|
64
|
+
File.delete(tmp_file_name)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
tmp_file_name = file_name + '.temp'
|
68
|
+
save_as_svg(tmp_file_name)
|
69
|
+
opt =
|
70
|
+
case format
|
71
|
+
when 'ps' then opt = '-P'
|
72
|
+
when 'eps' then opt = '-E'
|
73
|
+
when 'pdf' then opt = '-A'
|
74
|
+
else raise ArgumentError, "Unimplement Format: #{format}"
|
75
|
+
end
|
76
|
+
system "\"#{INKSCAPE_PATH}\" -z -T -f #{File.expand_path(tmp_file_name)} #{opt} #{File.expand_path(file_name)}"
|
77
|
+
File.delete(tmp_file_name)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_svg(xml=nil)
|
82
|
+
unless xml
|
83
|
+
xml = Builder::XmlMarkup.new :indent=>2
|
84
|
+
xml.instruct!
|
85
|
+
xml.declare! :DOCTYPE, :svg, :PUBLIC, "-//W3C//DTD SVG 1.0//EN", "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd"
|
86
|
+
xml.svg(root_attributes.merge(:xmlns=>"http://www.w3.org/2000/svg")) {
|
87
|
+
to_svg(xml)
|
88
|
+
}
|
89
|
+
else
|
90
|
+
if respond_to?(:svg_tag, true)
|
91
|
+
if draw_children?
|
92
|
+
xml.tag!(svg_tag, svg_attributes) {
|
93
|
+
child_elements_to_svg(xml)
|
94
|
+
}
|
95
|
+
else
|
96
|
+
xml.tag!(svg_tag, svg_attributes)
|
97
|
+
end
|
98
|
+
else
|
99
|
+
child_elements_to_svg(xml)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_png
|
105
|
+
IO.popen('rsvg-convert', 'w+') {|pipe|
|
106
|
+
puts_as_svg(pipe)
|
107
|
+
pipe.close_write
|
108
|
+
pipe.read
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def draw_children? #:nodoc:
|
115
|
+
not child_elements.empty?
|
116
|
+
end
|
117
|
+
|
118
|
+
def svg_attributes #:nodoc:
|
119
|
+
attrs =
|
120
|
+
attributes.inject({}) do |hash, (key, value)|
|
121
|
+
hash[name_to_attribute(key).to_sym] = value if value
|
122
|
+
hash
|
123
|
+
end
|
124
|
+
if respond_to?(:style) && style && !style.empty?
|
125
|
+
sty =
|
126
|
+
style.inject([]) do |array, (key, value)|
|
127
|
+
array << "#{name_to_attribute(key)}:#{value}" if value
|
128
|
+
array
|
129
|
+
end
|
130
|
+
attrs[:style] = sty.join(';')
|
131
|
+
end
|
132
|
+
attrs
|
133
|
+
end
|
134
|
+
|
135
|
+
def name_to_attribute(name) #:nodoc:
|
136
|
+
name.to_s.gsub(/_/,'-')
|
137
|
+
end
|
138
|
+
|
139
|
+
def root_attributes #:nodoc:
|
140
|
+
{}
|
141
|
+
end
|
142
|
+
|
143
|
+
def child_elements_to_svg(xml) #:nodoc:
|
144
|
+
child_elements.each {|child|
|
145
|
+
child.to_svg(xml)
|
146
|
+
}
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
data/lib/dyi/type.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
|
4
|
+
#
|
5
|
+
# Author:: Mamoru Yuo
|
6
|
+
#
|
7
|
+
# This file is part of DYI.
|
8
|
+
#
|
9
|
+
# DYI is free software: you can redistribute it and/or modify it
|
10
|
+
# under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# DYI is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with DYI. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
|
22
|
+
module DYI #:nodoc:
|
23
|
+
|
24
|
+
module AttributeCreator
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def attr_font(*names)
|
29
|
+
names.each do |name|
|
30
|
+
define_method(name.to_sym) {| |
|
31
|
+
instance_variable_get("@#{name}") || Font.new
|
32
|
+
}
|
33
|
+
define_method("#{name}=".to_sym) {|font|
|
34
|
+
instance_variable_set("@#{name}", Font.new_or_nil(font))
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def attr_painting(*names)
|
40
|
+
names.each do |name|
|
41
|
+
define_method(name.to_sym) {| |
|
42
|
+
instance_variable_get("@#{name}") || Painting.new
|
43
|
+
}
|
44
|
+
define_method("#{name}=".to_sym) {|painting|
|
45
|
+
instance_variable_set("@#{name}", Painting.new_or_nil(painting))
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def attr_length(*names)
|
51
|
+
names.each do |name|
|
52
|
+
define_method(name.to_sym) {| |
|
53
|
+
instance_variable_get("@#{name}")
|
54
|
+
}
|
55
|
+
define_method("#{name}=".to_sym) {|length|
|
56
|
+
instance_variable_set("@#{name}", Length.new(length))
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def attr_coordinate(*names)
|
62
|
+
names.each do |name|
|
63
|
+
define_method(name.to_sym) {| |
|
64
|
+
instance_variable_get("@#{name}")
|
65
|
+
}
|
66
|
+
define_method("#{name}=".to_sym) {|coordinate|
|
67
|
+
instance_variable_set("@#{name}", Coordinate.new(coordinate))
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module StringFormat
|
74
|
+
|
75
|
+
class << self
|
76
|
+
|
77
|
+
# :call-seq:
|
78
|
+
# set_default_formats (formats)
|
79
|
+
# set_default_formats (formats) { ... }
|
80
|
+
#
|
81
|
+
def set_default_formats(formats)
|
82
|
+
org_formats = {}
|
83
|
+
if formats.key?(:color)
|
84
|
+
org_formats[:color] = Color.default_format
|
85
|
+
Color.set_default_format(*formats[:color])
|
86
|
+
end
|
87
|
+
if formats.key?(:length)
|
88
|
+
org_formats[:length] = Length.default_format
|
89
|
+
Length.set_default_format(*formats[:length])
|
90
|
+
end
|
91
|
+
if formats.key?(:coordinate)
|
92
|
+
org_formats[:coordinate] = Coordinate.default_format
|
93
|
+
Coordinate.set_default_format(*formats[:coordinate])
|
94
|
+
end
|
95
|
+
if block_given?
|
96
|
+
yield
|
97
|
+
Color.set_default_format(*org_formats[:color]) if org_formats.key?(:color)
|
98
|
+
Length.set_default_format(*org_formats[:length]) if org_formats.key?(:length)
|
99
|
+
Coordinate.set_default_format(*org_formats[:coordinate]) if org_formats.key?(:coordinate)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/ironruby.rb
ADDED
@@ -0,0 +1,326 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) 2009-2011 Sound-F Co., Ltd. All rights reserved.
|
4
|
+
#
|
5
|
+
# Author:: Mamoru Yuo
|
6
|
+
#
|
7
|
+
# This file is part of DYI.
|
8
|
+
#
|
9
|
+
# DYI is free software: you can redistribute it and/or modify it
|
10
|
+
# under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# DYI is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with DYI. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
|
22
|
+
require 'bigdecimal'
|
23
|
+
require 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
|
24
|
+
require 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
|
25
|
+
require 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
|
26
|
+
require 'Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
|
27
|
+
require File.join(File.dirname(__FILE__), 'dyi/formatter/emf_formatter')
|
28
|
+
|
29
|
+
class BigDecimal < Numeric #:nodoc:
|
30
|
+
alias __org_div__ div
|
31
|
+
def div(other)
|
32
|
+
case other
|
33
|
+
when BigDecimal then __org_div__(other)
|
34
|
+
when Integer then __org_div__(BigDecimal.new(other.to_s))
|
35
|
+
else to_f.div(other.to_f)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module DYI #:nodoc:
|
41
|
+
|
42
|
+
class Coordinate #:nodoc:
|
43
|
+
def to_cls_point
|
44
|
+
System::Drawing::PointF.new(x.to_f, y.to_f)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Color #:nodoc:
|
49
|
+
def to_cls_color(opacity=nil)
|
50
|
+
if opacity
|
51
|
+
System::Drawing::Color.from_argb((opacity.to_f * 255).to_i, @r, @g, @b)
|
52
|
+
else
|
53
|
+
System::Drawing::Color.from_argb(@r, @g, @b)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_cls_pen(opacity=nil)
|
58
|
+
System::Drawing::Pen.new(to_cls_color(opacity))
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_cls_brush(opacity=nil, shape=nil)
|
62
|
+
System::Drawing::SolidBrush.new(to_cls_color(opacity))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class Painting #:nodoc:
|
67
|
+
def cls_line_join
|
68
|
+
case stroke_linejoin
|
69
|
+
when 'miter' then System::Drawing::Drawing2D::LineJoin.miter
|
70
|
+
when 'round' then System::Drawing::Drawing2D::LineJoin.round
|
71
|
+
when 'bevel' then System::Drawing::Drawing2D::LineJoin.bevel
|
72
|
+
else System::Drawing::Drawing2D::LineJoin.miter
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def cls_line_cap
|
77
|
+
case stroke_linecap
|
78
|
+
when 'butt' then System::Drawing::Drawing2D::LineCap.flat
|
79
|
+
when 'round' then System::Drawing::Drawing2D::LineCap.round
|
80
|
+
when 'square' then System::Drawing::Drawing2D::LineCap.square
|
81
|
+
else System::Drawing::Drawing2D::LineCap.flat
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def cls_fill_mode
|
86
|
+
case fill_rule
|
87
|
+
when 'nonzero' then System::Drawing::Drawing2D::FillMode.winding
|
88
|
+
when 'evenodd' then System::Drawing::Drawing2D::FillMode.alternate
|
89
|
+
else System::Drawing::Drawing2D::FillMode.winding
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def cls_dash_pattern
|
94
|
+
return nil if !stroke_dasharray || stroke_dasharray.size == 0
|
95
|
+
pattern = System::Array[System::Single].new(stroke_dasharray.size)
|
96
|
+
stroke_dasharray.each_with_index do |dash, i|
|
97
|
+
pattern[i] = dash.to_f
|
98
|
+
end
|
99
|
+
pattern
|
100
|
+
end
|
101
|
+
|
102
|
+
def cls_pen
|
103
|
+
return nil unless stroke && (stroke_width != DYI::Length::ZERO)
|
104
|
+
pen = stroke.create_cls_pen(stroke_opacity)
|
105
|
+
pen.width = stroke_width ? stroke_width.to_f : 1.0
|
106
|
+
pen.start_cap = pen.end_cap = cls_line_cap
|
107
|
+
pen.line_join = cls_line_join
|
108
|
+
pen.dash_pattern = cls_dash_pattern if cls_dash_pattern
|
109
|
+
pen
|
110
|
+
end
|
111
|
+
|
112
|
+
def cls_brush(shape)
|
113
|
+
fill ? fill.create_cls_brush(fill_opacity, shape) : System::Drawing::SolidBrush.new(System::Drawing::Color.black)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class Font #:nodoc:
|
118
|
+
def to_cls_font
|
119
|
+
System::Drawing::Font.new(font_family || '', size ? size.to_f : DEFAULT_SIZE.to_f('pt'))
|
120
|
+
end
|
121
|
+
|
122
|
+
class << self
|
123
|
+
def to_cls_font(font)
|
124
|
+
font ? font.to_cls_font : System::Drawing::Font.new('', DEFAULT_SIZE.to_f('pt'))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class Matrix #:nodoc:
|
130
|
+
def to_cls_matrix
|
131
|
+
System::Drawing::Drawing2D::Matrix.new(xx, yx, xy, yy, x0, y0)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
module Shape #:nodoc:
|
136
|
+
class Text < Base #:nodoc:
|
137
|
+
def string_format
|
138
|
+
format = System::Drawing::StringFormat.new
|
139
|
+
format.alignment =
|
140
|
+
case attributes[:text_anchor]
|
141
|
+
when 'start' then System::Drawing::StringAlignment.near
|
142
|
+
when 'middle' then System::Drawing::StringAlignment.center
|
143
|
+
when 'end' then System::Drawing::StringAlignment.far
|
144
|
+
else System::Drawing::StringAlignment.near
|
145
|
+
end
|
146
|
+
format.line_alignment =
|
147
|
+
case attributes[:alignment_baseline]
|
148
|
+
when 'baseline' then System::Drawing::StringAlignment.far
|
149
|
+
when 'top' then System::Drawing::StringAlignment.near
|
150
|
+
when 'middle' then System::Drawing::StringAlignment.center
|
151
|
+
when 'bottom' then System::Drawing::StringAlignment.far
|
152
|
+
else System::Drawing::StringAlignment.far
|
153
|
+
end
|
154
|
+
format
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
module Drawing #:nodoc:
|
160
|
+
class Canvas #:nodoc:
|
161
|
+
private
|
162
|
+
def get_formatter(format=nil)
|
163
|
+
case format
|
164
|
+
when :svg, nil then Formatter::SvgFormatter.new(self, 2)
|
165
|
+
when :xaml then Formatter::XamlFormatter.new(self, 2)
|
166
|
+
when :eps then Formatter::EpsFormatter.new(self)
|
167
|
+
when :emf then Formatter::EmfFormatter.new(self) # added 'Windows Meta File'
|
168
|
+
else raise ArgumentError, "`#{format}' is unknown format"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
module ColorEffect #:nodoc:
|
174
|
+
class LinearGradient
|
175
|
+
def create_cls_brush(opacity=nil, shape=nil)
|
176
|
+
brush = System::Drawing::Drawing2D::LinearGradientBrush.new(
|
177
|
+
System::Drawing::PointF.new(
|
178
|
+
shape.left.to_f * (1.0 - start_point[0]) + shape.right.to_f * start_point[0],
|
179
|
+
shape.top.to_f * (1.0 - start_point[1]) + shape.bottom.to_f * start_point[1]),
|
180
|
+
System::Drawing::PointF.new(
|
181
|
+
shape.left.to_f * (1.0 - stop_point[0]) + shape.right.to_f * stop_point[0],
|
182
|
+
shape.top.to_f * (1.0 - stop_point[1]) + shape.bottom.to_f * stop_point[1]),
|
183
|
+
System::Drawing::Color.empty,
|
184
|
+
System::Drawing::Color.empty)
|
185
|
+
start_pad = end_pad = false
|
186
|
+
if !spread_method || spread_method == 'pad'
|
187
|
+
start_pad = (0.001 < @child_elements.first.offset && @child_elements.first.offset < 0.999)
|
188
|
+
end_pad = (0.001 < @child_elements.last.offset && @child_elements.last.offset < 0.999)
|
189
|
+
end
|
190
|
+
color_count = @child_elements.size
|
191
|
+
color_count += 1 if start_pad
|
192
|
+
color_count += 1 if end_pad
|
193
|
+
color_blend = System::Drawing::Drawing2D::ColorBlend.new(color_count)
|
194
|
+
cls_colors = System::Array[System::Drawing::Color].new(color_count)
|
195
|
+
positions = System::Array[System::Single].new(color_count)
|
196
|
+
if start_pad
|
197
|
+
gradient_stop = @child_elements.first
|
198
|
+
cls_colors[0] = gradient_stop.color.to_cls_color(gradient_stop.opacity)
|
199
|
+
positions[0] = 0.0
|
200
|
+
end
|
201
|
+
@child_elements.each_with_index do |gradient_stop, i|
|
202
|
+
idx = start_pad ? i + 1 : i
|
203
|
+
cls_colors[idx] = gradient_stop.color.to_cls_color(gradient_stop.opacity)
|
204
|
+
positions[idx] = gradient_stop.offset.to_f
|
205
|
+
end
|
206
|
+
if end_pad
|
207
|
+
gradient_stop = @child_elements.last
|
208
|
+
cls_colors[color_count - 1] = gradient_stop.color.to_cls_color(gradient_stop.opacity)
|
209
|
+
positions[color_count - 1] = 1.0
|
210
|
+
end
|
211
|
+
color_blend.colors = cls_colors
|
212
|
+
color_blend.positions = positions
|
213
|
+
brush.interpolation_colors = color_blend
|
214
|
+
brush.wrap_mode = cls_wrap_mode
|
215
|
+
brush
|
216
|
+
end
|
217
|
+
|
218
|
+
def cls_wrap_mode
|
219
|
+
case spread_method
|
220
|
+
when 'pad' then System::Drawing::Drawing2D::WrapMode.tile_flip_xy
|
221
|
+
when 'reflect' then System::Drawing::Drawing2D::WrapMode.tile_flip_xy
|
222
|
+
when 'repeat' then System::Drawing::Drawing2D::WrapMode.tile
|
223
|
+
else System::Drawing::Drawing2D::WrapMode.tile_flip_xy
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
module Chart #:nodoc:
|
231
|
+
class CsvReader < ArrayReader #:nodoc:
|
232
|
+
def read(path, options={})
|
233
|
+
options = options.dup
|
234
|
+
@date_format = options.delete(:date_format)
|
235
|
+
@datetime_format = options.delete(:datetime_format)
|
236
|
+
|
237
|
+
encode =
|
238
|
+
case (options[:encode] || :utf8).to_sym
|
239
|
+
when :utf8 then 'UTF-8'
|
240
|
+
when :sjis then 'Shift_JIS'
|
241
|
+
when :euc then 'EUC-JP'
|
242
|
+
when :jis then 'iso-2022-jp'
|
243
|
+
when :utf16 then 'UTF-16'
|
244
|
+
end
|
245
|
+
parser = Microsoft::VisualBasic::FileIO::TextFieldParser.new(
|
246
|
+
path,
|
247
|
+
System::Text::Encoding.get_encoding(encode))
|
248
|
+
parser.set_delimiters(options[:col_sep] || ',')
|
249
|
+
|
250
|
+
parsed_array = []
|
251
|
+
while !parser.end_of_data
|
252
|
+
parsed_array << parser.read_fields.map {|v| v.to_s}
|
253
|
+
end
|
254
|
+
super(parsed_array, options)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
class ExcelReader < ArrayReader #:nodoc:
|
259
|
+
def read(path, options={})
|
260
|
+
if defined? WIN32OLE
|
261
|
+
# for Windows
|
262
|
+
path = WIN32OLE.new('Scripting.FileSystemObject').getAbsolutePathName(path)
|
263
|
+
excel = WIN32OLE.new('Excel.Application')
|
264
|
+
book = excel.workbooks.open(path)
|
265
|
+
sheet = book.worksheets.item(options[:sheet] || 1)
|
266
|
+
range = sheet.usedRange
|
267
|
+
sheet_values = sheet.range(sheet.cells(1,1), sheet.cells(range.end(4).row, range.end(2).column)).value
|
268
|
+
|
269
|
+
jagged_array = []
|
270
|
+
sheet_values.get_length(0).times do |i|
|
271
|
+
jagged_array << []
|
272
|
+
sheet_values.get_length(1).times do |j|
|
273
|
+
jagged_array[i] << sheet_values.get_value(i+1, j+1)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
sheet_values = jagged_array
|
277
|
+
end
|
278
|
+
|
279
|
+
begin
|
280
|
+
super(sheet_values, options)
|
281
|
+
ensure
|
282
|
+
if defined? WIN32OLE
|
283
|
+
book.close(false)
|
284
|
+
excel.quit
|
285
|
+
excel = sheet = nil
|
286
|
+
end
|
287
|
+
book = sheet_values = nil
|
288
|
+
GC.start
|
289
|
+
end
|
290
|
+
self
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
module Formatter #:nodoc:
|
296
|
+
class EpsFormatter < Base #:nodoc:
|
297
|
+
def write_text(shape, io)
|
298
|
+
command_block(io) {
|
299
|
+
puts_line(io, '/GothicBBB-Medium-RKSJ-H findfont', shape.font.draw_size, 'scalefont setfont')
|
300
|
+
text = String.new(
|
301
|
+
System::Text::Encoding.convert(
|
302
|
+
System::Text::Encoding.get_encoding('UTF-8'),
|
303
|
+
System::Text::Encoding.get_encoding('Shift_JIS'),
|
304
|
+
shape.formated_text
|
305
|
+
)
|
306
|
+
).unpack('H*').first
|
307
|
+
# text = NKF.nkf('-s -W', shape.formated_text).unpack('H*').first
|
308
|
+
case shape.attributes[:text_anchor]
|
309
|
+
when 'middle' then dx = "<#{text}> stringwidth pop -0.5 mul"
|
310
|
+
when 'end' then dx = "<#{text}> stringwidth pop -1 mul"
|
311
|
+
else dx = "0"
|
312
|
+
end
|
313
|
+
case shape.attributes[:alignment_baseline]
|
314
|
+
when 'top' then y = shape.point.y - shape.font_height * 0.85
|
315
|
+
when 'middle' then y = shape.point.y - shape.font_height * 0.35
|
316
|
+
when 'bottom' then y = shape.point.y + shape.font_height * 0.15
|
317
|
+
else y = shape.point.y
|
318
|
+
end
|
319
|
+
puts_line(io, "[ 1 0 0 -1 #{dx}", shape.point.y * 2, '] concat')
|
320
|
+
puts_line(io, shape.point.x, y, 'moveto')
|
321
|
+
puts_line(io, "<#{text}>", 'show')
|
322
|
+
}
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|