libis-format 1.2.9 → 1.3.2

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/bin/{pdf_copy → pdf_tool} +3 -2
  4. data/data/types.yml +1 -1
  5. data/lib/libis/format/command_line.rb +2 -3
  6. data/lib/libis/format/config.rb +17 -20
  7. data/lib/libis/format/converter/base.rb +9 -16
  8. data/lib/libis/format/converter/chain.rb +36 -28
  9. data/lib/libis/format/converter/email_converter.rb +5 -8
  10. data/lib/libis/format/converter/fop_pdf_converter.rb +4 -6
  11. data/lib/libis/format/converter/image_converter.rb +51 -58
  12. data/lib/libis/format/converter/jp2_converter.rb +33 -35
  13. data/lib/libis/format/converter/office_converter.rb +19 -23
  14. data/lib/libis/format/converter/pdf_converter.rb +133 -52
  15. data/lib/libis/format/converter/repository.rb +7 -13
  16. data/lib/libis/format/converter/spreadsheet_converter.rb +7 -11
  17. data/lib/libis/format/converter/video_converter.rb +41 -55
  18. data/lib/libis/format/converter/xslt_converter.rb +14 -13
  19. data/lib/libis/format/converter.rb +1 -1
  20. data/lib/libis/format/identifier.rb +41 -43
  21. data/lib/libis/format/tool/droid.rb +29 -30
  22. data/lib/libis/format/tool/ff_mpeg.rb +11 -13
  23. data/lib/libis/format/tool/fido.rb +1 -1
  24. data/lib/libis/format/tool/pdf_optimizer.rb +21 -27
  25. data/lib/libis/format/tool/pdf_to_pdfa.rb +2 -6
  26. data/lib/libis/format/tool/pdf_tool.rb +52 -0
  27. data/lib/libis/format/tool/pdfa_validator.rb +2 -3
  28. data/lib/libis/format/tool/spreadsheet_to_ods.rb +23 -20
  29. data/lib/libis/format/tool.rb +2 -2
  30. data/lib/libis/format/type_database.rb +51 -28
  31. data/lib/libis/format/type_database_impl.rb +57 -24
  32. data/lib/libis/format/version.rb +1 -1
  33. data/lib/libis/format.rb +3 -2
  34. data/lib/libis-format.rb +2 -0
  35. data/tools/PdfTool.jar +0 -0
  36. data/tools/pdfbox/pdfbox-app-3.0.3.jar +0 -0
  37. data/tools/pdfbox/{preflight-app-2.0.13.jar → preflight-app-3.0.3.jar} +0 -0
  38. metadata +8 -10
  39. data/lib/libis/format/tool/pdf_copy.rb +0 -57
  40. data/lib/libis/format/tool/pdf_merge.rb +0 -58
  41. data/lib/libis/format/tool/pdf_split.rb +0 -56
  42. data/tools/pdfbox/pdfbox-app-2.0.13.jar +0 -0
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
4
  require 'libis/format/identifier'
@@ -13,26 +13,26 @@ MiniMagick.configure do |config|
13
13
  config.validate_on_create = false
14
14
  config.validate_on_write = false
15
15
  config.whiny = false
16
+ config.tmpdir = Libis::Format::Config[:tempdir] || Dir.tmpdir
16
17
  end
17
18
 
18
19
  module Libis
19
20
  module Format
20
21
  module Converter
21
-
22
22
  # noinspection RubyTooManyInstanceVariablesInspection
23
23
  class ImageConverter < Libis::Format::Converter::Base
24
-
25
24
  def self.input_types
26
- [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2]
25
+ %i[TIFF JPG PNG BMP GIF PDF JP2]
27
26
  end
28
27
 
29
28
  def self.output_types(format = nil)
30
29
  return [] unless input_types.include?(format)
31
- [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2]
30
+
31
+ %i[TIFF JPG PNG BMP GIF PDF JP2]
32
32
  end
33
33
 
34
34
  def self.multipage?(format)
35
- [:PDF, :TIFF, :GIF, :PBM, :PGM, :PPM].include?(format)
35
+ %i[PDF TIFF GIF PBM PGM PPM].include?(format)
36
36
  end
37
37
 
38
38
  def initialize
@@ -41,15 +41,15 @@ module Libis
41
41
  end
42
42
 
43
43
  def image_convert(_)
44
- #force usage of this converter
44
+ # force usage of this converter
45
45
  end
46
46
 
47
- def quiet(v)
48
- @quiet = !!v
47
+ def quiet(value)
48
+ @quiet = !!value
49
49
  end
50
50
 
51
- def page(nr)
52
- @page = nr
51
+ def page(number)
52
+ @page = number
53
53
  end
54
54
 
55
55
  def scale(percent)
@@ -122,33 +122,33 @@ module Libis
122
122
  @wm_gap = ((options[:gap] || 0.2).to_f * 100).to_i
123
123
  rotation = 360 - (options[:rotation] || 30).to_i
124
124
  @wm_image = MiniMagick::Image.new(options[:file]) if options[:file]
125
- unless @wm_image && @wm_image.valid?
126
- image = options[:file] || (Dir::Tmpname.create(%w(wm_image .png)) {|_|})
127
- # noinspection RubyResolve
128
- MiniMagick::Tool::Convert.new do |convert|
129
- # noinspection RubyLiteralArrayInspection
130
- convert.quiet
131
- convert.background 'transparent'
132
- convert.size('2000x2000')
133
- convert.gravity 'Center'
134
- convert.font('Helvetica').fill('black').pointsize(72) #.stroke('black').strokewidth(1)
135
- convert << "label:#{text}"
136
- convert.rotate rotation
137
- convert.trim.repage.+
138
- convert << image
139
- end
140
- if options[:file]
141
- @wm_image = MiniMagick::Image.new(image)
142
- else
143
- @wm_image = MiniMagick::Image.open(image)
144
- File.delete(image)
145
- end
146
- # noinspection RubyResolve
147
- unless @wm_image.valid?
148
- error "Problem creating watermark image '#{image}'."
149
- @wm_image = nil
150
- end
125
+ return if @wm_image&.valid?
126
+
127
+ image = options[:file] || (Dir::Tmpname.create(%w[wm_image .png]) { |_| })
128
+ # noinspection RubyResolve
129
+ MiniMagick::Tool::Convert.new do |convert|
130
+ # noinspection RubyLiteralArrayInspection
131
+ convert.quiet
132
+ convert.background 'transparent'
133
+ convert.size('2000x2000')
134
+ convert.gravity 'Center'
135
+ convert.font('Helvetica').fill('black').pointsize(72) # .stroke('black').strokewidth(1)
136
+ convert << "label:#{text}"
137
+ convert.rotate rotation
138
+ convert.trim.repage.+ # rubocop:disable Lint/Void
139
+ convert << image
140
+ end
141
+ if options[:file]
142
+ @wm_image = MiniMagick::Image.new(image)
143
+ else
144
+ @wm_image = MiniMagick::Image.open(image)
145
+ File.delete(image)
151
146
  end
147
+ # noinspection RubyResolve
148
+ return if @wm_image.valid?
149
+
150
+ error "Problem creating watermark image '#{image}'."
151
+ @wm_image = nil
152
152
  end
153
153
 
154
154
  def convert(source, target, format, opts = {})
@@ -161,34 +161,33 @@ module Libis
161
161
  assemble_and_convert(source, target, format)
162
162
 
163
163
  elsif File.directory?(source)
164
- source_list = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
164
+ source_list = Dir[File.join(source, '**', '*')].reject { |p| File.directory? p }
165
165
 
166
166
  assemble_and_convert(source_list, target, format)
167
167
 
168
168
  else
169
169
 
170
- image = MiniMagick::Image.open(source) { |b| b.quiet }
170
+ image = MiniMagick::Image.open(source) { |b| b.quiet } # rubocop:disable Style/SymbolProc
171
171
 
172
172
  if image.pages.size > 1
173
173
  if @page
174
174
  convert_image(image.pages[@page].path, target, format)
175
175
  else
176
176
  # noinspection RubyBlockToMethodReference
177
- assemble_and_convert(image.pages.map {|page| page.path}, target, format)
177
+ assemble_and_convert(image.pages.map(&:path), target, format)
178
178
  end
179
179
  else
180
180
  convert_image(source, target, format)
181
181
  end
182
182
  end
183
-
184
- {
183
+
184
+ {
185
185
  files: [target],
186
186
  converter: self.class.name
187
187
  }
188
188
  end
189
189
 
190
190
  def assemble_and_convert(sources, target, format)
191
-
192
191
  warn 'Received multiple images as input and single page format as target.' unless self.class.multipage?(format)
193
192
  converted_pages = sources.inject([]) do |list, path|
194
193
  # noinspection RubyArgCount
@@ -198,7 +197,7 @@ module Libis
198
197
  end
199
198
  MiniMagick::Tool::Convert.new do |b|
200
199
  b.append unless self.class.multipage?(format)
201
- converted_pages.each {|page| b << page.path}
200
+ converted_pages.each { |page| b << page.path }
202
201
  b << target
203
202
  end
204
203
  converted_pages.each do |temp_file|
@@ -210,17 +209,16 @@ module Libis
210
209
  protected
211
210
 
212
211
  def convert_image(source, target, format)
213
-
214
212
  image_info = nil
215
- image_info = MiniMagick::Image::Info.new(source) {|b| b.quiet} if @wm_image
213
+ image_info = MiniMagick::Image::Info.new(source) { |b| b.quiet } if @wm_image # rubocop:disable Style/SymbolProc
216
214
 
217
215
  MiniMagick::Tool::Convert.new do |convert|
218
216
  convert.quiet if @quiet
219
217
  if @wm_image
220
218
  convert << @wm_image.path
221
- convert.bordercolor('transparent').border("#{@wm_gap}%") if @wm_gap > 0
219
+ convert.bordercolor('transparent').border("#{@wm_gap}%") if @wm_gap.positive?
222
220
  convert.filter('Lagrange')
223
- convert.resize("#{image_info['width'] / @wm_tiles}x#{image_info['height'] / @wm_tiles}") if @wm_tiles > 0
221
+ convert.resize("#{image_info['width'] / @wm_tiles}x#{image_info['height'] / @wm_tiles}") if @wm_tiles.positive?
224
222
  convert.resize("#{@wm_resize}%") if @wm_resize
225
223
  convert.write('mpr:watermark').delete.+
226
224
  end
@@ -229,7 +227,7 @@ module Libis
229
227
  convert << source
230
228
  convert.flatten if @options[:flatten].nil? && format == :JPG
231
229
  if @wm_image
232
- if @wm_tiles >= 0 and @wm_tiles <= 1
230
+ if (@wm_tiles >= 0) && (@wm_tiles <= 1)
233
231
  convert << 'mpr:watermark'
234
232
  else
235
233
  convert.stack do |stack|
@@ -242,15 +240,13 @@ module Libis
242
240
  convert.compose(@wm_composition).gravity(@wm_gravity).define("compose:args=#{@wm_opacity}%").composite
243
241
  end
244
242
 
245
- @flags.each {|f, v| v.is_a?(TrueClass) ? convert.send(f).+ : convert.send(f)}
246
- if @delete_date
247
- convert << '+set' << 'modify-date' << '+set' << 'create-date'
248
- end
243
+ @flags.each { |f, v| v.is_a?(TrueClass) ? convert.send(f).+ : convert.send(f) }
244
+ convert << '+set' << 'modify-date' << '+set' << 'create-date' if @delete_date
249
245
 
250
246
  colorspace = @options.delete(:colorspace) || 'sRGB'
251
247
  unless @options.empty?
252
248
  convert.colorspace('RGB')
253
- @options.each {|o, v| convert.send(o, v)}
249
+ @options.each { |o, v| convert.send(o, v) }
254
250
  end
255
251
  convert.colorspace(colorspace)
256
252
  convert.profile @profile if @profile
@@ -262,11 +258,8 @@ module Libis
262
258
  end
263
259
 
264
260
  target
265
-
266
261
  end
267
-
268
262
  end
269
-
270
263
  end
271
264
  end
272
- end
265
+ end
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'libis-tools'
3
4
  require 'fileutils'
4
5
  require 'libis/format/config'
@@ -7,32 +8,31 @@ require_relative 'base'
7
8
  module Libis
8
9
  module Format
9
10
  module Converter
10
-
11
11
  class Jp2Converter < Libis::Format::Converter::Base
12
-
13
12
  def self.input_types
14
- [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF]
13
+ %i[TIFF JPG PNG BMP GIF PDF]
15
14
  end
16
15
 
17
16
  def self.output_types(format = nil)
18
17
  return [] unless input_types.include?(format)
18
+
19
19
  [:JP2]
20
20
  end
21
21
 
22
22
  def initialize
23
23
  super
24
24
  @options = {
25
- color_xform: false,
26
- error_resilience: :ALL,
27
- lossless: true,
28
- progression_order: 'RLCP',
29
- tile_size: [1024, 1024],
30
- codeblock_size: [6, 6],
25
+ color_xform: false,
26
+ error_resilience: :ALL,
27
+ lossless: true,
28
+ progression_order: 'RLCP',
29
+ tile_size: [1024, 1024],
30
+ codeblock_size: [6, 6]
31
31
  }
32
32
  end
33
33
 
34
34
  def j2kdriver(_)
35
- #force usage of this converter
35
+ # force usage of this converter
36
36
  end
37
37
 
38
38
  def color_xform(flag = true)
@@ -68,38 +68,36 @@ module Libis
68
68
 
69
69
  @options.each do |key, value|
70
70
  case key
71
- when :color_xform
72
- options << '--set-output-j2k-color-xform' << (value ? 'YES' : 'NO')
73
- when :error_resilience
74
- options << '--set-output-j2k-error-resilience' << value.to_s
75
- when :lossless
76
- if value
77
- options << '--set-output-j2k-xform' << 'R53' << '5' << '--set-output-j2k-ratio' << '0'
78
- else
79
- options << '--set-output-j2k-xform' << 'I97' << '--set-output-j2k-psnr' << '46'
80
- end
81
- when :progression_order
82
- options << '--set-output-j2k-progression-order' << value.to_s
83
- when :tile_size
84
- options << '--set-output-j2k-tile-size' << value[0].to_s << value[1].to_s
85
- when :codeblock_size
86
- options << '--set-output-j2k-codeblock-size' << value[0].to_s << value[1].to_s
71
+ when :color_xform
72
+ options << '--set-output-j2k-color-xform' << (value ? 'YES' : 'NO')
73
+ when :error_resilience
74
+ options << '--set-output-j2k-error-resilience' << value.to_s
75
+ when :lossless
76
+ if value
77
+ options << '--set-output-j2k-xform' << 'R53' << '5' << '--set-output-j2k-ratio' << '0'
87
78
  else
88
- #do nothing
79
+ options << '--set-output-j2k-xform' << 'I97' << '--set-output-j2k-psnr' << '46'
80
+ end
81
+ when :progression_order
82
+ options << '--set-output-j2k-progression-order' << value.to_s
83
+ when :tile_size
84
+ options << '--set-output-j2k-tile-size' << value[0].to_s << value[1].to_s
85
+ when :codeblock_size
86
+ options << '--set-output-j2k-codeblock-size' << value[0].to_s << value[1].to_s
87
+ else # rubocop:disable Style/EmptyElse
88
+ # do nothing
89
89
  end
90
90
  end
91
91
 
92
-
93
92
  result = Libis::Tools::Command.run(
94
- Libis::Format::Config[:j2k_cmd],
95
- '--input-file-name', source,
96
- '--set-output-type', 'JP2',
97
- *options,
98
- '--output-file-name', target,
93
+ Libis::Format::Config[:j2k_cmd],
94
+ '--input-file-name', source,
95
+ '--set-output-type', 'JP2',
96
+ *options,
97
+ '--output-file-name', target
99
98
  )
100
99
 
101
100
  result.merge(files: [target], converter: self.class.name)
102
-
103
101
  end
104
102
  end
105
103
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
4
 
@@ -8,47 +8,43 @@ require 'libis/format/type_database'
8
8
  module Libis
9
9
  module Format
10
10
  module Converter
11
-
12
11
  class OfficeConverter < Libis::Format::Converter::Base
13
-
14
12
  def self.input_types
15
- [
16
- :TXT,
17
- :RTF,
18
- :HTML,
19
- :MSDOC,
20
- :MSDOT,
21
- :MSXLS,
22
- :MSPPT,
23
- :MSDOCX,
24
- :MSDOTX,
25
- :MSXLSX,
26
- :MSPPTX,
27
- :WORDPERFECT,
28
- :OO_WRITER,
29
- :OO_IMPRESS,
30
- :OO_CALC
13
+ %i[
14
+ TXT
15
+ RTF
16
+ HTML
17
+ MSDOC
18
+ MSDOT
19
+ MSXLS
20
+ MSPPT
21
+ MSDOCX
22
+ MSDOTX
23
+ MSXLSX
24
+ MSPPTX
25
+ WORDPERFECT
26
+ OO_WRITER
27
+ OO_IMPRESS
28
+ OO_CALC
31
29
  ]
32
30
  end
33
31
 
34
32
  def self.output_types(format = nil)
35
33
  return [] unless input_types.include?(format)
34
+
36
35
  [:PDF]
37
36
  end
38
37
 
39
38
  def office_convert(_)
40
- #force usage of this converter
39
+ # force usage of this converter
41
40
  end
42
41
 
43
42
  def convert(source, target, format, opts = {})
44
43
  super
45
44
 
46
45
  Format::Tool::OfficeToPdf.run(source, target)
47
-
48
46
  end
49
-
50
47
  end
51
-
52
48
  end
53
49
  end
54
50
  end