Module: Batik

Defined in:
lib/batik.rb

Overview

simple wrapper for batik (svg rasterizer) ==

by m. <[email protected]>

Constant Summary collapse

JAVA_HOME =
'/opt/java/jre'
BATIK_HOME =
'/opt/batik'

Class Method Summary collapse

Class Method Details

.rasterize(file, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/batik.rb', line 15

def self.rasterize(file, options)

	batik = File.join(@m_java_home || JAVA_HOME, 'bin/java -jar ', @m_batik_home || BATIK_HOME, 'batik-rasterizer.jar')

	command = "#{batik} "

	options.each do |name, value|

		case name

			when :background

				name = 'bg'

			when :width

				name = 'w'

			when :height

				name = 'h'

			when :media

				name = 'cssMedia'

			when :alternatecss

				name = 'cssAlternate'

			when :css

				name = 'cssUser'

			when :destination

				name = 'd'

			when :language

				name = 'lang'

			when :font

				name = 'font-family'

			when :to, :m

				name = 'm'

				case value

					when :png

						value = 'image/png'

					when :jpeg, :jpg

						value = 'image/jpeg'

					when :tiff

						value = 'image/tiff'

					when :pdf

						value = 'application/pdf'

				end

			when :area, :a

				name = 'a'

				value = value.join(',')

			when :quality

				name = 'q'

			when :validate, :onload, :snapshot_time

				value = nil
		end

		command += " -#{name} #{value}"

	end

	command += " #{file}"

	system(command)		
end

.set_batik_home(path) ⇒ Object



13
# File 'lib/batik.rb', line 13

def self.set_batik_home(path); @m_batik_home = path; end

.set_java_home(path) ⇒ Object



11
# File 'lib/batik.rb', line 11

def self.set_java_home(path); @m_java_home = path; end