flash_tool 0.5.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 +8 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +91 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/flash_tool.gemspec +65 -0
- data/lib/flash_tool.rb +195 -0
- data/test/25-1.gif +0 -0
- data/test/bad_ext.txt +1 -0
- data/test/bad_swf.swf +0 -0
- data/test/jpeg.swf +0 -0
- data/test/liberationserif_bold.ttf +0 -0
- data/test/rfxview.swf +0 -0
- data/test/test.jpg +0 -0
- data/test/test.pdf +0 -0
- data/test/test.png +0 -0
- data/test/test_flash_data.rb +69 -0
- data/test/test_flash_tool.rb +162 -0
- data/test/test_with_password.pdf +0 -0
- data/test/tester.swf +0 -0
- metadata +87 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Bojan Milosavljević milboj@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
= Flash Tool
|
2
|
+
|
3
|
+
A ruby wrapper for swftool command line tool. http://www.swftools.org/
|
4
|
+
|
5
|
+
Flash tool is small and mini tool for creating swf files from pdfs, pictures and
|
6
|
+
fonts and parsing data from flash files.
|
7
|
+
|
8
|
+
== Use
|
9
|
+
|
10
|
+
With this wrapper you commands from swftools program.
|
11
|
+
|
12
|
+
SWFTools is a collection of utilities for working with Adobe Flash files.
|
13
|
+
With Flash tool you can easely creates and manipulates flash files.
|
14
|
+
|
15
|
+
== Creating flash files
|
16
|
+
|
17
|
+
With Flash tool you can create swf file from pdf, jpeg (jpeg and jpg extension),
|
18
|
+
png, gif, fonts (ttf, afm, pfa, pfb formats) and wav(this funcionality is untested
|
19
|
+
and you can often have problems with SWFTools installation with command wav2swf)
|
20
|
+
|
21
|
+
Simple creating flash object from pdf file
|
22
|
+
|
23
|
+
swfile = FlashObject.new('path_to_file.pdf')
|
24
|
+
swfile.pages('1-10')
|
25
|
+
swfile.jpegquality('80')
|
26
|
+
swfile.save('outputfile_path.swf') # no need to declare ouptutfile_path in save if you used swfile.output() method before
|
27
|
+
|
28
|
+
Creating file from other format is very similar
|
29
|
+
|
30
|
+
Example for jpg
|
31
|
+
|
32
|
+
swfile = FlashObject.new('path_to_file.jpg')
|
33
|
+
swfile.output('outputfile_path.swf')
|
34
|
+
swfile.save()
|
35
|
+
|
36
|
+
Flash tool automaticly recognize extension of file and call propriete SWFTool program
|
37
|
+
If you use files without extension you just simply add string of extension when
|
38
|
+
initialize FlashObject
|
39
|
+
|
40
|
+
swfile = FlashObject.new('path_to_file','jpg')
|
41
|
+
|
42
|
+
You can use tempfile
|
43
|
+
|
44
|
+
swfile = FlashOject.from_blob('path_to_file','jpg')
|
45
|
+
|
46
|
+
Creating flash with viewer
|
47
|
+
|
48
|
+
swfile = FlashObject.new('path_to_file.pdf')
|
49
|
+
swfile.pages('1-10')
|
50
|
+
swfile.viewer('path_to_viewer_file')
|
51
|
+
swfile.save('outputfile_path.swf')
|
52
|
+
|
53
|
+
SWFTool command will be called when you save object.
|
54
|
+
|
55
|
+
==Parsing text from file
|
56
|
+
|
57
|
+
It is very simple
|
58
|
+
|
59
|
+
FlashTool.parse_text('path_to_file.swf')
|
60
|
+
|
61
|
+
==Geting data from flash files
|
62
|
+
|
63
|
+
You can get data from flash files with swfdump tool
|
64
|
+
|
65
|
+
FlashTool.swfdump('path_to_file.swf', 'command') #use swfdump options http://www.swftools.org/swfdump.html
|
66
|
+
|
67
|
+
Don't use option text it is buggy, instead use method FlashTool.parse_text
|
68
|
+
With method swfdump output is string
|
69
|
+
|
70
|
+
Better way
|
71
|
+
|
72
|
+
FlashTool.(command) List of command can get from http://www.swftools.org/swfdump.html
|
73
|
+
|
74
|
+
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
|
79
|
+
|
80
|
+
Other methods returns String
|
81
|
+
|
82
|
+
All this methods call commands swfdump, every time you call method. If you want
|
83
|
+
to do it in one pass use
|
84
|
+
|
85
|
+
FlashTool.flash_info(file)
|
86
|
+
|
87
|
+
Returns hash with keys 'width', 'rate', 'height', 'frames', and all values are strings
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "flash_tool"
|
8
|
+
gem.summary = "Simple and mini tool for creating swf (flash) files from pdf, jpg, png and gif with swftools"
|
9
|
+
gem.description = "A ruby wrapper for swftool command line tool. http://www.swftools.org/
|
10
|
+
Flash tool is small and mini tool for creating swf files from pdfs, pictures and
|
11
|
+
fonts and parsing data from flash files."
|
12
|
+
gem.email = "milboj@gmail.com"
|
13
|
+
gem.homepage = "http://github.com/milboj/flash_tool"
|
14
|
+
gem.authors = ["Bojan Milosavljevic"]
|
15
|
+
gem.rubyforge_project = 'flashtool'
|
16
|
+
|
17
|
+
|
18
|
+
# gem.add_development_dependency "", ">= 0"
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
23
|
+
rubyforge.doc_task = "rdoc"
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'rcov/rcovtask'
|
38
|
+
Rcov::RcovTask.new do |test|
|
39
|
+
test.libs << 'test'
|
40
|
+
test.pattern = 'test/test_*.rb'
|
41
|
+
test.verbose = true
|
42
|
+
end
|
43
|
+
rescue LoadError
|
44
|
+
task :rcov do
|
45
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
task :test => :check_dependencies
|
51
|
+
|
52
|
+
task :default => :test
|
53
|
+
|
54
|
+
require 'rake/rdoctask'
|
55
|
+
Rake::RDocTask.new do |rdoc|
|
56
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
57
|
+
|
58
|
+
rdoc.rdoc_dir = 'rdoc'
|
59
|
+
rdoc.title = "flash_tool #{version}"
|
60
|
+
rdoc.rdoc_files.include('README*')
|
61
|
+
rdoc.rdoc_files.include('lib/*.rb')
|
62
|
+
end
|
63
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0
|
data/flash_tool.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{flash_tool}
|
8
|
+
s.version = "0.5.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Bojan Milosavljevic"]
|
12
|
+
s.date = %q{2010-03-20}
|
13
|
+
s.description = %q{A ruby wrapper for swftool command line tool. http://www.swftools.org/
|
14
|
+
Flash tool is small and mini tool for creating swf files from pdfs, pictures and
|
15
|
+
fonts and parsing data from flash files.}
|
16
|
+
s.email = %q{milboj@gmail.com}
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".gitignore",
|
22
|
+
".loadpath",
|
23
|
+
".project",
|
24
|
+
"MIT-LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"flash_tool.gemspec",
|
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"
|
43
|
+
]
|
44
|
+
s.homepage = %q{http://github.com/milboj/flash_tool}
|
45
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubyforge_project = %q{flashtool}
|
48
|
+
s.rubygems_version = %q{1.3.6}
|
49
|
+
s.summary = %q{Simple and mini tool for creating swf (flash) files from pdf, jpg, png and gif with swftools}
|
50
|
+
s.test_files = [
|
51
|
+
"test/test_flash_tool.rb",
|
52
|
+
"test/test_flash_data.rb"
|
53
|
+
]
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
|
+
s.specification_version = 3
|
58
|
+
|
59
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
60
|
+
else
|
61
|
+
end
|
62
|
+
else
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/lib/flash_tool.rb
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module FlashTool
|
4
|
+
class FlashToolError < RuntimeError
|
5
|
+
end
|
6
|
+
|
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
|
56
|
+
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
|
+
|
68
|
+
private
|
69
|
+
|
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
|
+
|
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}\""
|
100
|
+
else
|
101
|
+
arg.to_s
|
102
|
+
end
|
103
|
+
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
|
+
|
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 ")
|
158
|
+
|
159
|
+
return Hash[*data.split(' ')]
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
|
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}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
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
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
|
data/test/25-1.gif
ADDED
Binary file
|
data/test/bad_ext.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Just for test
|
data/test/bad_swf.swf
ADDED
Binary file
|
data/test/jpeg.swf
ADDED
Binary file
|
Binary file
|
data/test/rfxview.swf
ADDED
Binary file
|
data/test/test.jpg
ADDED
Binary file
|
data/test/test.pdf
ADDED
Binary file
|
data/test/test.png
ADDED
Binary file
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), '../lib/flash_tool.rb')
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
class Test_Flash_Data < Test::Unit::TestCase
|
9
|
+
include FlashTool
|
10
|
+
CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/"
|
11
|
+
TEST_SWF = CURRENT_DIR + "tester.swf"
|
12
|
+
BAD_FILE = CURRENT_DIR + "bad_ext.txt"
|
13
|
+
JPG_SWF = CURRENT_DIR + "jpeg.swf"
|
14
|
+
NO_FILE = CURRENT_DIR + "jpegswf.swf"
|
15
|
+
BAD_SWF = CURRENT_DIR + "bad_swf.swf"
|
16
|
+
|
17
|
+
def test_get_info
|
18
|
+
info = FlashTool.flash_info(TEST_SWF)
|
19
|
+
assert_kind_of Hash, info
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_missing_methods
|
23
|
+
assert_kind_of(Integer, FlashTool.width(TEST_SWF))
|
24
|
+
assert_kind_of(Integer, FlashTool.height(TEST_SWF))
|
25
|
+
assert_kind_of(Integer, FlashTool.frames(TEST_SWF))
|
26
|
+
assert_kind_of(Float, FlashTool.rate(TEST_SWF))
|
27
|
+
assert_kind_of(String, FlashTool.html(TEST_SWF))
|
28
|
+
assert_kind_of(String, FlashTool.xhtml(TEST_SWF))
|
29
|
+
assert_kind_of(String, FlashTool.full(TEST_SWF))
|
30
|
+
assert_kind_of(String, FlashTool.hex(TEST_SWF))
|
31
|
+
assert_kind_of(String, FlashTool.buttons(TEST_SWF))
|
32
|
+
assert_kind_of(String, FlashTool.placements(TEST_SWF))
|
33
|
+
assert_kind_of(String, FlashTool.fonts(TEST_SWF))
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_bad_file
|
38
|
+
|
39
|
+
assert_raise(FlashToolError) { FlashTool.flash_info(BAD_FILE) }
|
40
|
+
assert_raise(FlashToolError) { FlashTool.full(BAD_FILE) }
|
41
|
+
assert_raise(FlashToolError) { FlashTool.width(BAD_FILE) }
|
42
|
+
assert_raise(FlashToolError) { FlashTool.parse_text(BAD_FILE) }
|
43
|
+
assert_raise(FlashToolError) { FlashTool.swfdump(BAD_FILE, 'width') }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_no_file
|
47
|
+
|
48
|
+
assert_raise(FlashToolError) { FlashTool.flash_info(NO_FILE) }
|
49
|
+
assert_raise(FlashToolError) { FlashTool.full(NO_FILE) }
|
50
|
+
assert_raise(FlashToolError) { FlashTool.width(NO_FILE) }
|
51
|
+
assert_raise(FlashToolError) { FlashTool.parse_text(NO_FILE) }
|
52
|
+
assert_raise(FlashToolError) { FlashTool.swfdump(NO_FILE, 'width') }
|
53
|
+
end
|
54
|
+
|
55
|
+
# Testing bad swf
|
56
|
+
def test_bad_swf_file
|
57
|
+
|
58
|
+
assert_raise(FlashToolError) { FlashTool.flash_info(BAD_SWF) }
|
59
|
+
assert_raise(FlashToolError) { FlashTool.full(BAD_SWF) }
|
60
|
+
assert_raise(FlashToolError) { FlashTool.width(BAD_SWF) }
|
61
|
+
assert_raise(FlashToolError) { FlashTool.parse_text(BAD_SWF) }
|
62
|
+
assert_raise(FlashToolError) { FlashTool.swfdump(BAD_SWF, 'width') }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_parse_text
|
66
|
+
assert_equal "",FlashTool.parse_text(JPG_SWF) #image flash
|
67
|
+
assert_true(FlashTool.parse_text(TEST_SWF).length > 100 ) #test number of charachters
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require File.join(File.dirname(__FILE__), '../lib/flash_tool.rb')
|
6
|
+
|
7
|
+
class FlashToolsTest < Test::Unit::TestCase
|
8
|
+
include FlashTool
|
9
|
+
|
10
|
+
CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/"
|
11
|
+
|
12
|
+
PDF_FILE = CURRENT_DIR + "test.pdf"
|
13
|
+
PDF_PASSW_PROTECTED = CURRENT_DIR + "test_with_password.pdf"
|
14
|
+
GIF_FILE = CURRENT_DIR + "25-1.gif"
|
15
|
+
FONT_FILE = CURRENT_DIR + "liberationserif_bold.ttf"
|
16
|
+
JPG_FILE = CURRENT_DIR + "test.jpg"
|
17
|
+
PNG_FILE = CURRENT_DIR + "test.png"
|
18
|
+
VIEW_SWF = CURRENT_DIR + "rfxview.swf"
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
def test_flash_object_from_blob
|
23
|
+
File.open(JPG_FILE, "rb") do |f|
|
24
|
+
flash_object = FlashObject.from_blob(f.read, 'jpg')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def test_flash_object_new
|
30
|
+
flash_object = FlashObject.new(JPG_FILE)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Testing file type detection and creation by file type
|
35
|
+
#
|
36
|
+
#
|
37
|
+
|
38
|
+
def test_pdf_create
|
39
|
+
begin
|
40
|
+
output_file = "#{CURRENT_DIR}/test.swf"
|
41
|
+
flash_object = FlashObject.new(PDF_FILE)
|
42
|
+
flash_object.jpegquality(80)
|
43
|
+
flash_object.save(output_file)
|
44
|
+
|
45
|
+
assert(File.exist?(output_file))
|
46
|
+
ensure
|
47
|
+
File.delete(output_file)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
def test_pdf_create_with_password
|
51
|
+
output_file = "#{CURRENT_DIR}/test_password.swf"
|
52
|
+
begin
|
53
|
+
flash_object = FlashObject.new(PDF_PASSW_PROTECTED)
|
54
|
+
flash_object.jpegquality(80)
|
55
|
+
flash_object.password("test")
|
56
|
+
flash_object.save(output_file)
|
57
|
+
assert(File.exist?(output_file))
|
58
|
+
ensure
|
59
|
+
File.delete(output_file)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_pdf_create_with_password_without_save_declaration
|
64
|
+
output_file = "#{CURRENT_DIR}/test_password.swf"
|
65
|
+
begin
|
66
|
+
flash_object = FlashObject.new(PDF_PASSW_PROTECTED)
|
67
|
+
flash_object.jpegquality(80)
|
68
|
+
flash_object.password("test")
|
69
|
+
flash_object.output(output_file)
|
70
|
+
flash_object.save()
|
71
|
+
assert(File.exist?(output_file))
|
72
|
+
ensure
|
73
|
+
File.delete(output_file)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_font_create
|
78
|
+
output_file = "#{CURRENT_DIR}/arial.swf"
|
79
|
+
begin
|
80
|
+
flash_object = FlashObject.new(FONT_FILE)
|
81
|
+
flash_object.save(output_file)
|
82
|
+
assert(File.exist?(output_file))
|
83
|
+
ensure
|
84
|
+
File.delete(output_file)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_gif_create
|
89
|
+
output_file = "#{CURRENT_DIR}/gif.swf"
|
90
|
+
begin
|
91
|
+
flash_object = FlashObject.new(GIF_FILE)
|
92
|
+
flash_object.save(output_file)
|
93
|
+
assert(File.exist?(output_file))
|
94
|
+
ensure
|
95
|
+
File.delete(output_file)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_png_create
|
100
|
+
output_file = "#{CURRENT_DIR}/png.swf"
|
101
|
+
begin
|
102
|
+
flash_object = FlashObject.new(PNG_FILE)
|
103
|
+
flash_object.save(output_file)
|
104
|
+
assert(File.exist?(output_file))
|
105
|
+
ensure
|
106
|
+
File.delete(output_file)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_jpg_create
|
111
|
+
output_file = "#{CURRENT_DIR}/jpg.swf"
|
112
|
+
begin
|
113
|
+
flash_object = FlashObject.new(JPG_FILE)
|
114
|
+
flash_object.save(output_file)
|
115
|
+
assert(File.exist?(output_file))
|
116
|
+
ensure
|
117
|
+
File.delete(output_file)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_create_from_blob
|
122
|
+
output_file = "#{CURRENT_DIR}/jpg.swf"
|
123
|
+
begin
|
124
|
+
tt = File.open(JPG_FILE, "rb")
|
125
|
+
flash_object = FlashObject.from_blob(tt.read, 'jpg')
|
126
|
+
flash_object.quality(80)
|
127
|
+
flash_object.save(output_file)
|
128
|
+
ensure
|
129
|
+
File.delete(output_file)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_creating_viewer
|
134
|
+
output_file = "#{CURRENT_DIR}/jpg.swf"
|
135
|
+
output_file = "#{CURRENT_DIR}/test_viewer.swf"
|
136
|
+
begin
|
137
|
+
flash_object = FlashObject.new(PDF_FILE)
|
138
|
+
flash_object.jpegquality(80)
|
139
|
+
flash_object.viewer(VIEW_SWF)
|
140
|
+
flash_object.save(output_file)
|
141
|
+
assert(File.exist?(output_file))
|
142
|
+
ensure
|
143
|
+
File.delete(output_file)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
#
|
149
|
+
# Testing errors and bad types
|
150
|
+
#
|
151
|
+
|
152
|
+
def test_file_not_exist
|
153
|
+
assert_raise(FlashToolError) { flash_object = FlashObject.new("nofile.jpg") }
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_wrong_file_type
|
157
|
+
assert_raise(FlashToolError) {flash_object = FlashObject.new("bad_ext.txt")}
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
end
|
162
|
+
|
Binary file
|
data/test/tester.swf
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flash_tool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Bojan Milosavljevic
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-20 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: |-
|
22
|
+
A ruby wrapper for swftool command line tool. http://www.swftools.org/
|
23
|
+
Flash tool is small and mini tool for creating swf files from pdfs, pictures and
|
24
|
+
fonts and parsing data from flash files.
|
25
|
+
email: milboj@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.rdoc
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- .loadpath
|
35
|
+
- .project
|
36
|
+
- MIT-LICENSE
|
37
|
+
- README.rdoc
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- flash_tool.gemspec
|
41
|
+
- lib/flash_tool.rb
|
42
|
+
- test/25-1.gif
|
43
|
+
- test/bad_ext.txt
|
44
|
+
- test/bad_swf.swf
|
45
|
+
- test/jpeg.swf
|
46
|
+
- test/liberationserif_bold.ttf
|
47
|
+
- test/rfxview.swf
|
48
|
+
- test/test.jpg
|
49
|
+
- test/test.pdf
|
50
|
+
- test/test.png
|
51
|
+
- test/test_flash_data.rb
|
52
|
+
- test/test_flash_tool.rb
|
53
|
+
- test/test_with_password.pdf
|
54
|
+
- test/tester.swf
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/milboj/flash_tool
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: flashtool
|
81
|
+
rubygems_version: 1.3.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Simple and mini tool for creating swf (flash) files from pdf, jpg, png and gif with swftools
|
85
|
+
test_files:
|
86
|
+
- test/test_flash_tool.rb
|
87
|
+
- test/test_flash_data.rb
|