libis-format 1.2.7 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,16 @@
1
- require "tempfile"
2
- require "csv"
3
- require "fileutils"
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+ require 'csv'
5
+ require 'fileutils'
4
6
  require 'pdfinfo'
5
7
 
6
- require "libis/tools/extend/string"
7
- require "libis/tools/logger"
8
- require "libis/tools/command"
9
- require "libis/tools/temp_file"
8
+ require 'libis/tools/extend/string'
9
+ require 'libis/tools/logger'
10
+ require 'libis/tools/command'
11
+ require 'libis/tools/temp_file'
10
12
 
11
- require "libis/format"
13
+ require 'libis/format'
12
14
 
13
15
  module Libis
14
16
  module Format
@@ -18,47 +20,47 @@ module Libis
18
20
 
19
21
  def self.installed?
20
22
  result = Libis::Tools::Command.run(Libis::Format::Config[:ghostscript_cmd])
21
- result == 0
23
+ result.zero?
22
24
  end
23
25
 
24
- def self.run(source, target = nil, options = {})
25
- new.run source, target, options
26
+ def self.run(source, target = nil, **options)
27
+ new.run source, target, **options
26
28
  end
27
29
 
28
- def run(source, target = nil, options = nil)
29
- tmp_target = Tools::TempFile.name(File.basename(source, ".*"), ".pdf")
30
+ def run(source, target = nil, **options)
31
+ tmp_target = Tools::TempFile.name(File.basename(source, '.*'), '.pdf')
30
32
  target ||= tmp_target
31
33
 
32
34
  metadata = get_metadata(source)
33
35
 
34
36
  icc_info = icc_options(options[:colorspace])
35
37
 
36
- icc_file = Tools::TempFile.name(icc_info[:icc_name], ".icc")
38
+ icc_file = Tools::TempFile.name(icc_info[:icc_name], '.icc')
37
39
  FileUtils.cp(File.join(Libis::Format::DATA_DIR, "#{icc_info[:icc_name]}.icc"), icc_file)
38
40
 
39
- def_filename = Tools::TempFile.name("PDFA_def", ".ps")
40
- File.open(def_filename, "w") do |f|
41
- f.puts File.read(File.join(Libis::Format::DATA_DIR, "PDFA_def.ps"))
42
- .gsub("[**ICC profile**]", icc_file)
43
- .gsub("[**ICC reference**]", icc_info[:icc_ref])
44
- .gsub("[**METADATA**]", metadata)
41
+ def_filename = Tools::TempFile.name('PDFA_def', '.ps')
42
+ File.open(def_filename, 'w') do |f|
43
+ f.puts File.read(File.join(Libis::Format::DATA_DIR, 'PDFA_def.ps'))
44
+ .gsub('[**ICC profile**]', icc_file)
45
+ .gsub('[**ICC reference**]', icc_info[:icc_ref])
46
+ .gsub('[**METADATA**]', metadata)
45
47
  end
46
48
 
47
49
  timeout = Libis::Format::Config[:timeouts][:pdf_to_pdfa]
48
50
  result = Libis::Tools::Command.run(
49
51
  Libis::Format::Config[:ghostscript_cmd],
50
- "-q",
51
- "-dBATCH", "-dNOPAUSE", "-dNOOUTERSAVE", "-dNOSAFER",
52
+ '-q',
53
+ '-dBATCH', '-dNOPAUSE', '-dNOOUTERSAVE', '-dNOSAFER',
52
54
  # "-dNOPLATFONTS", "-dUseCIEColor=true",
53
55
  # "-sColorConversionStrategy=/UseDeviceIndependentColor",
54
56
  "-sProcessColorModel=#{icc_info[:device]}",
55
57
  "-sOutputICCProfile=#{icc_file}",
56
- "-dCompatibilityLevel=1.4",
57
- "-sDEVICE=pdfwrite", "-dPDFA=1", "-dPDFACompatibilityPolicy=1",
58
- "-o", File.absolute_path(target),
58
+ '-dCompatibilityLevel=1.4',
59
+ '-sDEVICE=pdfwrite', '-dPDFA=1', '-dPDFACompatibilityPolicy=1',
60
+ '-o', File.absolute_path(target),
59
61
  def_filename,
60
62
  source,
61
- timeout: timeout,
63
+ timeout:,
62
64
  kill_after: timeout * 2
63
65
  )
64
66
 
@@ -84,13 +86,13 @@ module Libis
84
86
  metadata += "\n /Creator (#{info.creator})" if info.creator
85
87
  metadata
86
88
  end
87
-
89
+
88
90
  def icc_options(colorspace)
89
91
  case colorspace.to_s.downcase
90
- when "cmyk"
91
- {icc_name: "ISOcoated_v2_eci", icc_ref: "FOGRA39L", device: "DeviceCMYK"}
92
+ when 'cmyk'
93
+ { icc_name: 'ISOcoated_v2_eci', icc_ref: 'FOGRA39L', device: 'DeviceCMYK' }
92
94
  else
93
- {icc_name: "AdobeRGB1998", icc_ref: "sRGB", device: "DeviceRGB"}
95
+ { icc_name: 'AdobeRGB1998', icc_ref: 'sRGB', device: 'DeviceRGB' }
94
96
  end
95
97
  end
96
98
  end
@@ -1,10 +1,12 @@
1
- require "fileutils"
1
+ # frozen_string_literal: true
2
2
 
3
- require "libis/tools/extend/string"
4
- require "libis/tools/logger"
5
- require "libis/tools/command"
3
+ require 'fileutils'
6
4
 
7
- require "libis/format/config"
5
+ require 'libis/tools/extend/string'
6
+ require 'libis/tools/logger'
7
+ require 'libis/tools/command'
8
+
9
+ require 'libis/format/config'
8
10
 
9
11
  module Libis
10
12
  module Format
@@ -20,6 +22,7 @@ module Libis
20
22
  src_file = File.absolute_path(source)
21
23
 
22
24
  timeout = Libis::Format::Config[:timeouts][:pdfa_validator]
25
+ result = nil
23
26
  if (pdfa = Libis::Format::Config[:pdfa_cmd])
24
27
  # Keep it clean: tool generates fontconfig/ cache dir in current working dir
25
28
  previous_wd = Dir.getwd
@@ -27,16 +30,16 @@ module Libis
27
30
 
28
31
  result = Libis::Tools::Command.run(
29
32
  pdfa,
30
- "--noxml",
31
- "--level", "B",
32
- "--verb", "0",
33
+ '--noxml',
34
+ '--level', 'B',
35
+ '--verb', '0',
33
36
  src_file,
34
- timeout: timeout,
37
+ timeout:,
35
38
  kill_after: timeout * 2
36
39
  )
37
40
 
38
41
  raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
39
- raise "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
42
+ raise "#{self.class} errors: #{result[:err].join("\n")}" unless (result[:status]).zero? && result[:err].empty?
40
43
 
41
44
  Dir.chdir(previous_wd)
42
45
 
@@ -44,21 +47,20 @@ module Libis
44
47
  result[:out] = out
45
48
  result[:err] += err
46
49
 
47
- result
48
50
  else
49
51
  jar = Libis::Format::Config[:preflight_jar]
50
52
  result = Libis::Tools::Command.run(
51
53
  Libis::Format::Config[:java_cmd],
52
- "-jar", jar,
54
+ '-jar', jar,
53
55
  src_file,
54
- timeout: timeout,
56
+ timeout:,
55
57
  kill_after: timeout * 2
56
58
  )
57
59
 
58
60
  raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
59
61
 
60
- result
61
62
  end
63
+ result
62
64
  end
63
65
  end
64
66
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Libis
2
4
  module Format
3
- VERSION = '1.2.7'
5
+ VERSION = '1.2.9'
4
6
  end
5
7
  end
data/libis-format.gemspec CHANGED
@@ -1,6 +1,6 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  require 'libis/format/version'
@@ -11,37 +11,38 @@ Gem::Specification.new do |spec|
11
11
  spec.version = Libis::Format::VERSION
12
12
  spec.authors = ['Kris Dekeyser']
13
13
  spec.email = ['kris.dekeyser@libis.be']
14
- spec.summary = %q{LIBIS File format format services.}
15
- spec.description = %q{Collection of tools and classes that help to identify formats of binary files and create derivative copies (e.g. PDF from Word).}
14
+ spec.summary = 'LIBIS File format format services.'
15
+ spec.description = 'Collection of tools and classes that help to identify file formats and create derivative copies.'
16
16
  spec.homepage = ''
17
17
  spec.license = 'MIT'
18
18
 
19
19
  spec.platform = Gem::Platform::JAVA if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
20
+ spec.required_ruby_version = '>= 3.2'
20
21
 
21
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.files = `git ls-files -z`.split("\x0").select do |f|
23
+ f.match(%r{^(bin/|lib/|data/|tools/|Gemfile|libis-format.gemspec|LICENSE\.txt|README\.md)})
24
+ end
22
25
  spec.executables = spec.files.grep(%r{^bin/[^/]+$}) { |f| File.basename(f) }
23
- # spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
26
  spec.require_paths = ['lib']
25
27
 
26
- spec.add_development_dependency 'rake', '~> 10.3'
27
- spec.add_development_dependency 'rspec', '~> 3.1'
28
+ spec.add_runtime_dependency 'chromaprint', '~> 0.0.2'
29
+ spec.add_runtime_dependency 'deep_dive', '~> 0.3'
30
+ spec.add_runtime_dependency 'libis-mapi', '~> 0.3'
31
+ spec.add_runtime_dependency 'libis-tools', '~> 1.1'
32
+ spec.add_runtime_dependency 'mini_magick', '~> 4.12'
33
+ spec.add_runtime_dependency 'naturally', '~> 2.2'
34
+ spec.add_runtime_dependency 'new_rfc_2047', '~> 1.0'
35
+ spec.add_runtime_dependency 'os', '~> 1.1'
36
+ spec.add_runtime_dependency 'pdfinfo', '~> 1.4'
37
+ spec.add_runtime_dependency 'pdfkit', '~> 0.8'
38
+
28
39
  spec.add_development_dependency 'awesome_print'
29
- spec.add_development_dependency 'equivalent-xml', '~> 0.5'
40
+ spec.add_development_dependency 'equivalent-xml'
41
+ spec.add_development_dependency 'rake'
42
+ spec.add_development_dependency 'rspec'
30
43
  if Gem::Platform::JAVA && spec.platform == Gem::Platform::JAVA
31
44
  spec.add_development_dependency 'saxon-xslt'
32
45
  else
33
46
  spec.add_development_dependency 'nokogiri'
34
47
  end
35
-
36
- spec.add_runtime_dependency 'libis-tools', '~> 1.0'
37
- spec.add_runtime_dependency 'os', '= 0.9.6'
38
- spec.add_runtime_dependency 'mini_magick', '~> 4.3'
39
- spec.add_runtime_dependency 'deep_dive', '~> 0.3'
40
- spec.add_runtime_dependency 'chromaprint', '~> 0.0.2'
41
- spec.add_runtime_dependency 'naturally', '~> 2.1'
42
- spec.add_runtime_dependency 'pdfinfo', '~> 1.4'
43
- spec.add_runtime_dependency 'libis-mapi', '~> 0.3'
44
- spec.add_runtime_dependency 'new_rfc_2047'
45
- spec.add_runtime_dependency 'pdfkit'
46
-
47
- end
48
+ end
data/tools/fop/fop.bat CHANGED
@@ -1,75 +1,75 @@
1
- @ECHO OFF
2
- REM Licensed to the Apache Software Foundation (ASF) under one or more
3
- REM contributor license agreements. See the NOTICE file distributed with
4
- REM this work for additional information regarding copyright ownership.
5
- REM The ASF licenses this file to You under the Apache License, Version 2.0
6
- REM (the "License"); you may not use this file except in compliance with
7
- REM the License. You may obtain a copy of the License at
8
- REM
9
- REM http://www.apache.org/licenses/LICENSE-2.0
10
- REM
11
- REM Unless required by applicable law or agreed to in writing, software
12
- REM distributed under the License is distributed on an "AS IS" BASIS,
13
- REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- REM See the License for the specific language governing permissions and
15
- REM limitations under the License.
16
- REM $Id: fop.bat 1736993 2016-03-29 09:19:30Z ssteiner $
17
-
18
- SETLOCAL ENABLEDELAYEDEXPANSION
19
-
20
- rem %~dp0 is the expanded pathname of the current script under NT
21
- set LOCAL_FOP_HOME=
22
- if "%OS%"=="Windows_NT" set LOCAL_FOP_HOME="%~dp0"
23
-
24
- rem Code from Apache Ant project
25
- rem Slurp the command line arguments. This loop allows for an unlimited number
26
- rem of arguments (up to the command line limit, anyway).
27
- rem Could also do a "shift" and "%*" for all params, but apparently doesn't work
28
- rem with Win9x.
29
- set FOP_CMD_LINE_ARGS=%1
30
- if ""%1""=="""" goto doneStart
31
- shift
32
- :setupArgs
33
- if ""%1""=="""" goto doneStart
34
- set FOP_CMD_LINE_ARGS=%FOP_CMD_LINE_ARGS% %1
35
- shift
36
- goto setupArgs
37
- rem This label provides a place for the argument list loop to break out
38
- rem and for NT handling to skip to.
39
- :doneStart
40
-
41
- set LOGCHOICE=
42
- rem The default commons logger for JDK1.4 is JDK1.4Logger.
43
- rem To use a different logger, uncomment the one desired below
44
- rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
45
- rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
46
- rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
47
-
48
- set LOGLEVEL=
49
- rem Logging levels
50
- rem Below option is only if you are using SimpleLog instead of the default JDK1.4 Logger.
51
- rem To set logging levels for JDK 1.4 Logger, edit the %JAVA_HOME%\JRE\LIB\logging.properties
52
- rem file instead.
53
- rem Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal".
54
- rem set LOGLEVEL=-Dorg.apache.commons.logging.simplelog.defaultlog=INFO
55
-
56
- set LIBDIR=%LOCAL_FOP_HOME%lib
57
-
58
- set LOCALCLASSPATH=%FOP_HYPHENATION_PATH%
59
- for %%l in (%LOCAL_FOP_HOME%build\*.jar %LIBDIR%\*.jar %LOCAL_FOP_HOME%target\*.jar) do set LOCALCLASSPATH=!LOCALCLASSPATH!;%%l
60
-
61
- set JAVAOPTS=-Denv.windir=%WINDIR%
62
-
63
- if "%JAVA_HOME%" == "" goto noJavaHome
64
- if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
65
- if "%JAVACMD%" == "" set JAVACMD=%JAVA_HOME%\bin\java
66
- goto runFop
67
-
68
- :noJavaHome
69
- if "%JAVACMD%" == "" set JAVACMD=java
70
-
71
- :runFop
72
- rem echo "%JAVACMD%" %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
73
- "%JAVACMD%" %JAVAOPTS% %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" %FOP_OPTS% org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
74
-
75
- ENDLOCAL
1
+ @ECHO OFF
2
+ REM Licensed to the Apache Software Foundation (ASF) under one or more
3
+ REM contributor license agreements. See the NOTICE file distributed with
4
+ REM this work for additional information regarding copyright ownership.
5
+ REM The ASF licenses this file to You under the Apache License, Version 2.0
6
+ REM (the "License"); you may not use this file except in compliance with
7
+ REM the License. You may obtain a copy of the License at
8
+ REM
9
+ REM http://www.apache.org/licenses/LICENSE-2.0
10
+ REM
11
+ REM Unless required by applicable law or agreed to in writing, software
12
+ REM distributed under the License is distributed on an "AS IS" BASIS,
13
+ REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ REM See the License for the specific language governing permissions and
15
+ REM limitations under the License.
16
+ REM $Id: fop.bat 1736993 2016-03-29 09:19:30Z ssteiner $
17
+
18
+ SETLOCAL ENABLEDELAYEDEXPANSION
19
+
20
+ rem %~dp0 is the expanded pathname of the current script under NT
21
+ set LOCAL_FOP_HOME=
22
+ if "%OS%"=="Windows_NT" set LOCAL_FOP_HOME="%~dp0"
23
+
24
+ rem Code from Apache Ant project
25
+ rem Slurp the command line arguments. This loop allows for an unlimited number
26
+ rem of arguments (up to the command line limit, anyway).
27
+ rem Could also do a "shift" and "%*" for all params, but apparently doesn't work
28
+ rem with Win9x.
29
+ set FOP_CMD_LINE_ARGS=%1
30
+ if ""%1""=="""" goto doneStart
31
+ shift
32
+ :setupArgs
33
+ if ""%1""=="""" goto doneStart
34
+ set FOP_CMD_LINE_ARGS=%FOP_CMD_LINE_ARGS% %1
35
+ shift
36
+ goto setupArgs
37
+ rem This label provides a place for the argument list loop to break out
38
+ rem and for NT handling to skip to.
39
+ :doneStart
40
+
41
+ set LOGCHOICE=
42
+ rem The default commons logger for JDK1.4 is JDK1.4Logger.
43
+ rem To use a different logger, uncomment the one desired below
44
+ rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
45
+ rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
46
+ rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
47
+
48
+ set LOGLEVEL=
49
+ rem Logging levels
50
+ rem Below option is only if you are using SimpleLog instead of the default JDK1.4 Logger.
51
+ rem To set logging levels for JDK 1.4 Logger, edit the %JAVA_HOME%\JRE\LIB\logging.properties
52
+ rem file instead.
53
+ rem Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal".
54
+ rem set LOGLEVEL=-Dorg.apache.commons.logging.simplelog.defaultlog=INFO
55
+
56
+ set LIBDIR=%LOCAL_FOP_HOME%lib
57
+
58
+ set LOCALCLASSPATH=%FOP_HYPHENATION_PATH%
59
+ for %%l in (%LOCAL_FOP_HOME%build\*.jar %LIBDIR%\*.jar %LOCAL_FOP_HOME%target\*.jar) do set LOCALCLASSPATH=!LOCALCLASSPATH!;%%l
60
+
61
+ set JAVAOPTS=-Denv.windir=%WINDIR%
62
+
63
+ if "%JAVA_HOME%" == "" goto noJavaHome
64
+ if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
65
+ if "%JAVACMD%" == "" set JAVACMD=%JAVA_HOME%\bin\java
66
+ goto runFop
67
+
68
+ :noJavaHome
69
+ if "%JAVACMD%" == "" set JAVACMD=java
70
+
71
+ :runFop
72
+ rem echo "%JAVACMD%" %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
73
+ "%JAVACMD%" %JAVAOPTS% %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" %FOP_OPTS% org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
74
+
75
+ ENDLOCAL
data/tools/fop/fop.cmd CHANGED
@@ -1,31 +1,31 @@
1
- @ECHO OFF
2
- REM Licensed to the Apache Software Foundation (ASF) under one or more
3
- REM contributor license agreements. See the NOTICE file distributed with
4
- REM this work for additional information regarding copyright ownership.
5
- REM The ASF licenses this file to You under the Apache License, Version 2.0
6
- REM (the "License"); you may not use this file except in compliance with
7
- REM the License. You may obtain a copy of the License at
8
- REM
9
- REM http://www.apache.org/licenses/LICENSE-2.0
10
- REM
11
- REM Unless required by applicable law or agreed to in writing, software
12
- REM distributed under the License is distributed on an "AS IS" BASIS,
13
- REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- REM See the License for the specific language governing permissions and
15
- REM limitations under the License.
16
- REM $Id: fop.cmd 1734671 2016-03-12 05:39:53Z gadams $
17
-
18
- set LOCAL_FOP_HOME=%~dp0
19
- set FOP_CMD_LINE_ARGS=%1
20
- if ""%1""=="""" goto doneStart
21
- shift
22
- :setupArgs
23
- if ""%1""=="""" goto doneStart
24
- set FOP_CMD_LINE_ARGS=%FOP_CMD_LINE_ARGS% %1
25
- shift
26
- goto setupArgs
27
- rem This label provides a place for the argument list loop to break out
28
- :doneStart
29
-
30
- call "%LOCAL_FOP_HOME%\fop.bat" %FOP_CMD_LINE_ARGS%
31
-
1
+ @ECHO OFF
2
+ REM Licensed to the Apache Software Foundation (ASF) under one or more
3
+ REM contributor license agreements. See the NOTICE file distributed with
4
+ REM this work for additional information regarding copyright ownership.
5
+ REM The ASF licenses this file to You under the Apache License, Version 2.0
6
+ REM (the "License"); you may not use this file except in compliance with
7
+ REM the License. You may obtain a copy of the License at
8
+ REM
9
+ REM http://www.apache.org/licenses/LICENSE-2.0
10
+ REM
11
+ REM Unless required by applicable law or agreed to in writing, software
12
+ REM distributed under the License is distributed on an "AS IS" BASIS,
13
+ REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ REM See the License for the specific language governing permissions and
15
+ REM limitations under the License.
16
+ REM $Id: fop.cmd 1734671 2016-03-12 05:39:53Z gadams $
17
+
18
+ set LOCAL_FOP_HOME=%~dp0
19
+ set FOP_CMD_LINE_ARGS=%1
20
+ if ""%1""=="""" goto doneStart
21
+ shift
22
+ :setupArgs
23
+ if ""%1""=="""" goto doneStart
24
+ set FOP_CMD_LINE_ARGS=%FOP_CMD_LINE_ARGS% %1
25
+ shift
26
+ goto setupArgs
27
+ rem This label provides a place for the argument list loop to break out
28
+ :doneStart
29
+
30
+ call "%LOCAL_FOP_HOME%\fop.bat" %FOP_CMD_LINE_ARGS%
31
+