flash_tool 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of flash_tool might be problematic. Click here for more details.

data/.gitignore CHANGED
@@ -6,3 +6,4 @@ coverage
6
6
  pkg
7
7
  .loadpath
8
8
  .project
9
+ rdoc
@@ -1,10 +1,15 @@
1
1
  = Flash Tool
2
2
 
3
- A ruby wrapper for swftool command line tool. http://www.swftools.org/
3
+ A ruby wrapper for swftool command line tool. http://www.swftools.org
4
4
 
5
5
  Flash tool is small and mini tool for creating swf files from pdfs, pictures and
6
6
  fonts and parsing data from flash files.
7
7
 
8
+
9
+ == Install
10
+
11
+ gem install flash_tool
12
+
8
13
  == Use
9
14
 
10
15
  With this wrapper you commands from swftools program.
@@ -14,13 +19,15 @@ With Flash tool you can easely creates and manipulates flash files.
14
19
 
15
20
  == Creating flash files
16
21
 
22
+ === Creataing flash files from documents
23
+
17
24
  With Flash tool you can create swf file from pdf, jpeg (jpeg and jpg extension),
18
25
  png, gif, fonts (ttf, afm, pfa, pfb formats) and wav(this funcionality is untested
19
26
  and you can often have problems with SWFTools installation with command wav2swf)
20
27
 
21
28
  Simple creating flash object from pdf file
22
29
 
23
- swfile = FlashObject.new('path_to_file.pdf')
30
+ swfile = FlashTool::FlashObject.new('path_to_file.pdf')
24
31
  swfile.pages('1-10')
25
32
  swfile.jpegquality('80')
26
33
  swfile.save('outputfile_path.swf') # no need to declare ouptutfile_path in save if you used swfile.output() method before
@@ -29,7 +36,7 @@ Creating file from other format is very similar
29
36
 
30
37
  Example for jpg
31
38
 
32
- swfile = FlashObject.new('path_to_file.jpg')
39
+ swfile = FlashTool::FlashObject.new('path_to_file.jpg')
33
40
  swfile.output('outputfile_path.swf')
34
41
  swfile.save()
35
42
 
@@ -37,55 +44,96 @@ Flash tool automaticly recognize extension of file and call propriete SWFTool pr
37
44
  If you use files without extension you just simply add string of extension when
38
45
  initialize FlashObject
39
46
 
40
- swfile = FlashObject.new('path_to_file','jpg')
47
+ swfile = FlashTool::FlashObject.new('path_to_file','jpg')
41
48
 
42
49
  You can use tempfile
43
50
 
44
- swfile = FlashOject.from_blob('path_to_file','jpg')
51
+ swfile = FlashTool::FlashOject.from_blob('path_to_file','jpg')
45
52
 
46
53
  Creating flash with viewer
47
54
 
48
- swfile = FlashObject.new('path_to_file.pdf')
55
+ swfile = FlashTool::FlashObject.new('path_to_file.pdf')
49
56
  swfile.pages('1-10')
50
57
  swfile.viewer('path_to_viewer_file')
51
58
  swfile.save('outputfile_path.swf')
52
59
 
60
+ You can use with the block
61
+
62
+ swfile = FlashTool::FlashObject.new('path_to_file.pdf') do |f|
63
+ f.pages('1-10')
64
+ f.viewer('path_to_viewer_file')
65
+ f.save('outputfile_path.swf')
66
+ end
67
+
53
68
  SWFTool command will be called when you save object.
54
69
 
70
+ === Creating flash from scritps
71
+
72
+ With SWFTool you can use scripts for creating flash files. More on http://wiki.swftools.org/index.php/Swfc
73
+
74
+ flash_object = FlashTool::FlashScript.new("path_to_script")
75
+ flash_object.save(output_file)
76
+
77
+ Other way
78
+ FlashTool::FlashScript.create("path_to_script","output_path")
79
+
80
+ It is possible to push flash data in variable
81
+ flash = FlashScript.flash_data("path_to_script")
82
+
83
+ or
84
+
85
+ flash_object = FlashTool::FlashScript.new("path_to_script")
86
+ flash = flash_object.cgi
87
+
88
+
55
89
  ==Parsing text from file
56
90
 
57
91
  It is very simple
58
92
 
59
- FlashTool.parse_text('path_to_file.swf')
93
+ FlashTool::FlashTool.parse_text('path_to_file.swf')
60
94
 
61
95
  ==Geting data from flash files
62
96
 
63
97
  You can get data from flash files with swfdump tool
64
98
 
65
- FlashTool.swfdump('path_to_file.swf', 'command') #use swfdump options http://www.swftools.org/swfdump.html
99
+ FlashTool::FlashTool.swfdump('path_to_file.swf', 'command') #use swfdump options http://www.swftools.org/swfdump.html
66
100
 
67
- Don't use option text it is buggy, instead use method FlashTool.parse_text
101
+ Don't use option text it is buggy, instead that use method FlashTool.parse_text
68
102
  With method swfdump output is string
69
103
 
70
104
  Better way
71
105
 
72
- FlashTool.(command) List of command can get from http://www.swftools.org/swfdump.html
106
+ FlashTool::FlashTool.(command) List of command can get from http://www.swftools.org/swfdump.html
73
107
 
74
108
  Examples
75
- FlashTool.rate(file) #return Float
76
- FlashTool.width(file) #return Integer
77
- FlashTool.height(file) #return Integer
78
- FlashTool.frames(file) #return Integer
109
+ FlashTool::FlashTool.rate(file) #return Float
110
+ FlashTool::FlashTool.width(file) #return Integer
111
+ FlashTool::FlashTool.height(file) #return Integer
112
+ FlashTool::FlashTool.frames(file) #return Integer
79
113
 
80
114
  Other methods returns String
81
115
 
82
116
  All this methods call commands swfdump, every time you call method. If you want
83
117
  to do it in one pass use
84
118
 
85
- FlashTool.flash_info(file)
119
+ FlashTool::FlashTool.flash_info(file)
86
120
 
87
121
  Returns hash with keys 'width', 'rate', 'height', 'frames', and all values are strings
88
122
 
123
+ == Flash combine
124
+
125
+ This is advance technique for combining flash files. It is possible to combine two or more flash files
126
+ More about this on http://www.swftools.org/swfcombine.html
127
+ For simple adding viewer use FlashObject and creating vith view method
128
+
129
+ flash = FlashCombine.new() do |f|
130
+ f.master(inputs)
131
+ f.slave("viewport",TEST_SWF)
132
+ f.rate(25)
133
+ f.output(output_file)
134
+ f.save()
135
+ end
136
+
89
137
 
90
138
 
91
139
 
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ fonts and parsing data from flash files."
12
12
  gem.email = "milboj@gmail.com"
13
13
  gem.homepage = "http://github.com/milboj/flash_tool"
14
14
  gem.authors = ["Bojan Milosavljevic"]
15
- gem.rubyforge_project = 'flashtool'
15
+ gem.rubyforge_project = 'flash_tool'
16
16
 
17
17
 
18
18
  # gem.add_development_dependency "", ">= 0"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{flash_tool}
8
- s.version = "0.5.0"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bojan Milosavljevic"]
12
- s.date = %q{2010-03-20}
12
+ s.date = %q{2010-03-23}
13
13
  s.description = %q{A ruby wrapper for swftool command line tool. http://www.swftools.org/
14
14
  Flash tool is small and mini tool for creating swf files from pdfs, pictures and
15
15
  fonts and parsing data from flash files.}
@@ -27,29 +27,39 @@ fonts and parsing data from flash files.}
27
27
  "VERSION",
28
28
  "flash_tool.gemspec",
29
29
  "lib/flash_tool.rb",
30
- "test/25-1.gif",
31
- "test/bad_ext.txt",
32
- "test/bad_swf.swf",
33
- "test/jpeg.swf",
34
- "test/liberationserif_bold.ttf",
35
- "test/rfxview.swf",
36
- "test/test.jpg",
37
- "test/test.pdf",
38
- "test/test.png",
39
- "test/test_flash_data.rb",
40
- "test/test_flash_tool.rb",
41
- "test/test_with_password.pdf",
42
- "test/tester.swf"
30
+ "lib/flash_tool/flash.rb",
31
+ "lib/flash_tool/flash_combine.rb",
32
+ "lib/flash_tool/flash_object.rb",
33
+ "lib/flash_tool/flash_script.rb",
34
+ "test/test_files/25-1.gif",
35
+ "test/test_files/bad.sc",
36
+ "test/test_files/bad_ext.txt",
37
+ "test/test_files/bad_swf.swf",
38
+ "test/test_files/jpeg.swf",
39
+ "test/test_files/liberationserif_bold.ttf",
40
+ "test/test_files/rfxview.swf",
41
+ "test/test_files/script.sc",
42
+ "test/test_files/test.jpg",
43
+ "test/test_files/test.pdf",
44
+ "test/test_files/test.png",
45
+ "test/test_files/test_with_password.pdf",
46
+ "test/test_files/tester.swf",
47
+ "test/test_flash_combine.rb",
48
+ "test/test_flash_object.rb",
49
+ "test/test_flash_script.rb",
50
+ "test/test_flash_tool.rb"
43
51
  ]
44
52
  s.homepage = %q{http://github.com/milboj/flash_tool}
45
53
  s.rdoc_options = ["--charset=UTF-8"]
46
54
  s.require_paths = ["lib"]
47
- s.rubyforge_project = %q{flashtool}
55
+ s.rubyforge_project = %q{flash_tool}
48
56
  s.rubygems_version = %q{1.3.6}
49
57
  s.summary = %q{Simple and mini tool for creating swf (flash) files from pdf, jpg, png and gif with swftools}
50
58
  s.test_files = [
51
- "test/test_flash_tool.rb",
52
- "test/test_flash_data.rb"
59
+ "test/test_flash_script.rb",
60
+ "test/test_flash_combine.rb",
61
+ "test/test_flash_tool.rb",
62
+ "test/test_flash_object.rb"
53
63
  ]
54
64
 
55
65
  if s.respond_to? :specification_version then
@@ -1,195 +1,101 @@
1
1
  require 'tempfile'
2
+ require File.dirname(__FILE__) + '/flash_tool/flash_script.rb'
3
+ require File.dirname(__FILE__) + '/flash_tool/flash_object.rb'
4
+ require File.dirname(__FILE__) + '/flash_tool/flash.rb'
5
+ require File.dirname(__FILE__) + '/flash_tool/flash_combine.rb'
2
6
 
3
7
  module FlashTool
4
8
  class FlashToolError < RuntimeError
5
9
  end
6
10
 
7
- # Creating flash swf files from pdf, jpg, png, gif and fonts file
8
- class FlashObject
9
- attr :input
10
- attr :type
11
- attr :args
12
-
13
- # Input is path file with good extesnion
14
- # Approved formats are :
15
- # *pdf,
16
- # *jpeg (jpeg and jpg extension),
17
- # *png,
18
- # *gif,
19
- # *fonts (ttf, afm, pfa, pfb formats) and
20
- # *wav (wav funcionality is untested and you can often have problems with SWFTools installation with command wav2swf)
21
- #
22
- # type - is extension name string if your input file have other extension
23
- #
24
- # == Example
25
- # flash = FlashOjbect.new('path_to_file', 'png')
26
- #
27
- # Raise exceptions
28
- def initialize(input,type = nil, tempfile = nil)
29
- @args = []
30
- @tempfile = tempfile
31
- @input = input
32
- @type = type || input.split('.').last
33
- @command = type_parser(@type)
34
-
35
- raise FlashToolError, "File not found" unless File.exist?(input)
36
- end
37
-
38
-
39
- def self.from_blob(blob, ext)
40
- begin
41
- tempfile = Tempfile.new(['swf_tool', ext.to_s])
42
- tempfile.binmode
43
- tempfile.write(blob)
44
- ensure
45
- tempfile.close if tempfile
46
- end
47
-
48
- return self.new(tempfile.path, ext ,tempfile)
49
- end
50
-
51
- #
52
- def save(output_path=nil)
53
- if output_path
54
- @args << "--output"
55
- @args << output_path
11
+ # This class provides usefull utilities for getting informations from flash files
12
+ # ===<b>Important</b>
13
+ # Method FlashTool.text and options FlashTool.method_missing("text", "file") and
14
+ # swfdump("file","text") on same system don't work appropriate instead use method <b>parse_text</b>
15
+ #
16
+ class FlashTool
17
+ class <<self
18
+ # This method parse text from swf file.
19
+ # File must have extension swf
20
+ def parse_text(file)
21
+ # something is bad with this program don't send errors, and we must check for errors
22
+ # we must check file first
23
+ # by documetation swfdump --text need to do this but
24
+ raise FlashToolError, "File missing path: #{file}" unless File.exist?(file)
25
+ raise FlashToolError, "Wrong file type SWF path: #{file} " unless file =~ /(.swf)$/i
26
+ command = "swfstrings #{file}"
27
+ output = `#{command} 2>&1`
28
+ # if file have appropiate name but is something is wrong with him
29
+ raise FlashToolError, output if output =~/(errors.)$/
30
+ return output
56
31
  end
57
- run_command(@command,*@args << @input)
58
- end
59
-
60
-
61
-
62
-
63
- def method_missing(symbol, *args)
64
- @args << ("--#{symbol}")
65
- @args +=(args)
66
- end
67
32
 
68
- private
69
33
 
70
- def type_parser input
71
- case input.downcase
72
- when "pdf"
73
- command = "pdf2swf"
74
- when "jpg", "jpeg"
75
- command = "jpeg2swf"
76
- when "png"
77
- command = "png2swf"
78
- when "gif"
79
- command = "gif2swf"
80
- when "ttf", "afm", "pfa", "pfb"
81
- command = "font2swf"
82
- when "wav"
83
- command = "wav2swf"
84
- else
85
- raise FlashToolError, "Invalid type"
86
- end
87
- return command
88
- end
89
34
 
90
- def +(value)
91
- @args << "+#{value}"
92
- end
93
-
94
-
95
- def run_command(command ,*args)
96
- args.collect! do |arg|
97
- # args can contain characters like '>' so we must escape them, but don't quote switches
98
- if arg !~ /^[\+\-]/
99
- "\"#{arg}\""
35
+ # Call swfdump commands in shorter way
36
+ # Can be used any option from swfdump command
37
+ # in casess: width, heihght and frames returns Integer
38
+ # in case rate returns Float
39
+ # in all other casess retruns String
40
+ #
41
+ def method_missing(option, file)
42
+ text = self.swfdump(file, option)
43
+ option = option.to_s
44
+ if option == "width" || option == 'height' || option == 'frames'
45
+ return text.split(' ').last.to_i
46
+ elsif option == 'rate'
47
+ return text.split(' ').last.to_f
100
48
  else
101
- arg.to_s
49
+ return text
102
50
  end
103
51
  end
104
- command = "#{command} #{args.join(" ")}"
105
- output = `#{command} 2>&1`
106
-
107
- if $?.exitstatus != 0
108
- raise FlashToolError, "SWF command (#{command.inspect}) failed: #{{:status_code => $?, :output => output}.inspect}"
109
- else
110
- output
111
- end
112
- end
113
-
114
-
115
- end
116
-
117
-
118
-
119
-
120
- # This method parse text from swf file.
121
- # File must have extension swf
122
- def FlashTool.parse_text(file)
123
- # something is bad with this program don't send errors, and ther is no need to check for errors
124
- # we must check file first
125
- # by documetation swfdump --text need to do this but
126
- raise FlashToolError, "File missing path: #{file}" unless File.exist?(file)
127
- raise FlashToolError, "Wrong file type SWF path: #{file} " unless file =~ /(.swf)$/i
128
- command = "swfstrings #{file}"
129
- output = `#{command} 2>&1`
130
- # if file have appropiate name but is something is wrong with him
131
- raise FlashToolError, output if output =~/(errors.)$/
132
- return output
133
- end
134
-
135
- def FlashTool.method_missing(option, file)
136
- text = self.swfdump(file, option)
137
- option = option.to_s
138
- if option == "width" || option == 'height' || option == 'frames'
139
- return text.split(' ').last.to_i
140
- elsif option == 'rate'
141
- return text.split(' ').last.to_f
142
- else
143
- return text
144
- end
145
- end
146
52
 
147
- ###
148
- # Returns hash value with basic flash parameters
149
- # Keys are [width, rate, height, frames] and
150
- # values are kind of string
151
- def FlashTool.flash_info(file)
152
- args = ['width', 'rate', 'height', 'frames']
153
- data = swfdump(file, args)
154
- data.gsub!(/(-X)/, "width ")
155
- data.gsub!(/(-Y)/, "height ")
156
- data.gsub!(/(-r)/, "rate ")
157
- data.gsub!(/(-f)/, "frames ")
53
+ ###
54
+ # Returns hash value with basic flash parameters
55
+ # Keys are [width, rate, height, frames] and
56
+ # values are kind of string
57
+ def flash_info(file)
58
+ args = ['width', 'rate', 'height', 'frames']
59
+ data = swfdump(file, args)
60
+ data.gsub!(/(-X)/, "width ")
61
+ data.gsub!(/(-Y)/, "height ")
62
+ data.gsub!(/(-r)/, "rate ")
63
+ data.gsub!(/(-f)/, "frames ")
158
64
 
159
- return Hash[*data.split(' ')]
65
+ return Hash[*data.split(' ')]
160
66
 
161
- end
67
+ end
162
68
 
163
69
 
164
- ###
165
- # This method is very similar to swfdump command http://www.swftools.org/swfdump.html
166
- # Use longer options for this commands without --
167
- # DON'T use option text that option don't work
168
- # ==Examples
169
- # FlashTool.swfdump('test.swf', 'rate')
170
- #
171
- # FlashTool.swfdump('test.swf', ['rate','width','height']
172
- def FlashTool.swfdump(file, option=nil)
173
- command = 'swfdump'
174
- if option
175
- if option.kind_of? Array
176
- option.collect! { |a| "--#{a}" }
177
- option = option.join(' ')
178
- else
179
- option = "--#{option}"
70
+ ###
71
+ # This method is very similar to swfdump command http://www.swftools.org/swfdump.html
72
+ # Use longer options for this commands without --
73
+ # DON'T use option text that option don't work
74
+ # ===Examples
75
+ # FlashTool.swfdump('test.swf', 'rate')
76
+ #
77
+ # FlashTool.swfdump('test.swf', ['rate','width','height'])
78
+ def swfdump(file, option=nil)
79
+ command = 'swfdump'
80
+ if option
81
+ if option.kind_of? Array
82
+ option.collect! { |a| "--#{a}" }
83
+ option = option.join(' ')
84
+ else
85
+ option = "--#{option}"
86
+ end
87
+ end
88
+ command = "#{command} #{option} #{file}"
89
+ output = `#{command} 2>&1`
90
+ if $?.exitstatus != 0
91
+ raise FlashToolError, "SWF command : #{command.inspect} failed : #{{:status_code => $?, :output => output}.inspect}"
92
+ else
93
+ return output
94
+ end
180
95
  end
181
96
  end
182
97
 
183
- command = "#{command} #{option} #{file}"
184
-
185
- output = `#{command} 2>&1`
186
- if $?.exitstatus != 0
187
- raise FlashToolError, "SWF command : #{command.inspect} failed : #{{:status_code => $?, :output => output}.inspect}"
188
- else
189
- return output
190
- end
191
98
  end
192
99
  end
193
100
 
194
101
 
195
-