mn2pdf 1.96 → 1.97

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f995c968b26cd711a41e58589e0c64cd4f26ebe09a7274bea8591478358122ff
4
- data.tar.gz: c574684e8ec29ea41ac279787ad136979036de2c49e86bce1eced9fc152c307b
3
+ metadata.gz: 03474d63db276351bed0aab5f76b80ce7f18dda8abf198e4c785f7a0242cf1ed
4
+ data.tar.gz: '02333967ae637ce3748ea696701207a2d03fc4e8786920dcb5ea7326da857835'
5
5
  SHA512:
6
- metadata.gz: 1e01d97441251afea4f1c5a510023d97df9681c29a7f24a8c107fc88d5afb2be34932161286ce4000f7c32f4bb7c6fe159a5a39fc14d5bde19463ee2a75076ff
7
- data.tar.gz: 86c3d5a0401a374ff7bebed8025184a8cfea5b50f1f1efd77743cdf03acf316092f367a039a0dd2189199ef6a9aea2f2f8aad08cb99e0fa5d2dc093694a4b732
6
+ metadata.gz: 21e6b59a3777b7bbb3898538afd00a1f9408bb5c57e417abf042c1656d901760129f129e04ac1629c147e6e2402b27adf219562d4c9458d9cf5656f71edeedf1
7
+ data.tar.gz: 5b4c925822d7134cf37d4f7723861a34b4bb4401e4e17ef8fdc1e8148825d66cc96311b44fb7ce28b8c2848ff9e5b2d43f707a09ea590c823fd6a2e3531e8bfe
data/bin/mn2pdf.jar CHANGED
Binary file
data/lib/mn2pdf/jvm.rb ADDED
@@ -0,0 +1,60 @@
1
+ require "open3"
2
+ require "pathname"
3
+ require "rbconfig"
4
+
5
+ module Jvm
6
+ MN2PDF_JAR_PATH = Pathname.new(__FILE__)
7
+ .dirname
8
+ .join("../../bin/mn2pdf.jar")
9
+ .realpath
10
+ DEFAULT_JAVA_OPTS = %w[-Xss10m -Xmx3g -Djava.awt.headless=true].freeze
11
+
12
+ def self.to_bytes(value)
13
+ case value[-1].downcase
14
+ when "k"
15
+ value.to_i * 1024
16
+ when "m"
17
+ value.to_i * 1024 * 1024
18
+ when "g"
19
+ value.to_i * 1024 * 1024 * 1024
20
+ else
21
+ value.to_i
22
+ end
23
+ end
24
+
25
+ def self.ensure_java_opts(opts, key, min_value_bytes)
26
+ flag, idx = opts.each_with_index.find { |opt, _| opt.start_with?(key) }
27
+ if flag
28
+ flag_value_bytes = to_bytes(flag[key.length..-1])
29
+
30
+ if flag_value_bytes < min_value_bytes
31
+ min_value_str = "#{key}#{min_value_bytes / (1024 * 1024)}m"
32
+ opts[idx] = min_value_str
33
+ end
34
+ else
35
+ opts << "#{key}#{min_value_bytes / (1024 * 1024)}m"
36
+ end
37
+ end
38
+
39
+ def self.options
40
+ result = ENV["JAVA_OPTS"]&.split || DEFAULT_JAVA_OPTS.dup
41
+
42
+ ensure_java_opts(result, "-Xss", to_bytes("10m"))
43
+ ensure_java_opts(result, "-Xmx", to_bytes("3g"))
44
+
45
+ if RbConfig::CONFIG["host_os"].match?(/darwin|mac os/)
46
+ result << "-Dapple.awt.UIElement=true"
47
+ end
48
+
49
+ result << "-Duser.home=#{Dir.home}"
50
+
51
+ result
52
+ end
53
+
54
+ def self.run(args = [])
55
+ cmd = ["java", *options, "-jar", MN2PDF_JAR_PATH, *args].join(" ")
56
+ puts cmd
57
+ stdout, stderr, status = Open3.capture3(cmd)
58
+ [stdout, stderr, status]
59
+ end
60
+ end
@@ -1,4 +1,4 @@
1
1
  module Mn2pdf
2
- VERSION = "1.96".freeze
2
+ VERSION = "1.97".freeze
3
3
  MN2PDF_JAR_VERSION = VERSION
4
4
  end
data/lib/mn2pdf.rb CHANGED
@@ -3,78 +3,60 @@ require "rbconfig"
3
3
  require "tempfile"
4
4
  require "yaml"
5
5
 
6
+ require "mn2pdf/jvm"
7
+
6
8
  module Mn2pdf
7
- MN2PDF_JAR_PATH = File.join(File.dirname(__FILE__), "../bin/mn2pdf.jar")
8
- DEFAULT_JAVA_OPTS = %w[-Xss10m -Xmx3g -Djava.awt.headless=true].freeze
9
9
  FONTS_MANIFEST = :font_manifest
10
10
 
11
- def self.jvm_options
12
- options = DEFAULT_JAVA_OPTS.dup
13
-
14
- if RbConfig::CONFIG["host_os"].match?(/darwin|mac os/)
15
- options << "-Dapple.awt.UIElement=true"
16
- end
17
-
18
- options << "-Duser.home=#{Dir.home}"
19
-
20
- options
21
- end
22
-
23
11
  def self.help
24
- cmd = ["java", *jvm_options, "-jar", MN2PDF_JAR_PATH].join(" ")
25
12
  # help message goes to STDERR (from mn2pdf v1.36)
26
- _, help_message, = Open3.capture3(cmd)
13
+ _, help_message, = Jvm.run
27
14
  help_message
28
15
  end
29
16
 
30
17
  def self.version
31
- cmd = ["java", *jvm_options, "-jar", MN2PDF_JAR_PATH, "-v"].join(" ")
32
- message, = Open3.capture3(cmd)
18
+ message, = Jvm.run(%w[-v])
33
19
  message.strip
34
20
  end
35
21
 
36
22
  def self.convert(url_path, output_path, xsl_stylesheet, options = {})
37
- cmd = build_cmd(url_path, output_path, xsl_stylesheet)
23
+ args = build_args(url_path, output_path, xsl_stylesheet)
38
24
 
39
- return unless cmd
25
+ return unless args
40
26
 
41
27
  case options
42
28
  when String
43
- mn2pdf(cmd + [options])
29
+ mn2pdf(args + [options])
44
30
  when Hash
45
- mn2pdf_hash(cmd, options)
31
+ mn2pdf_hash(args, options)
46
32
  else
47
33
  warn "Unsupported options type #{options.class}"
48
34
  end
49
35
  end
50
36
 
51
- def self.build_cmd(url, output, xslt)
37
+ def self.build_args(url, output, xslt)
52
38
  return if url.nil? || output.nil? || xslt.nil?
53
39
 
54
- ["java", *jvm_options,
55
- "-jar", MN2PDF_JAR_PATH,
56
- "--xml-file", quote(url),
40
+ ["--xml-file", quote(url),
57
41
  "--xsl-file", quote(xslt),
58
42
  "--pdf-file", quote(output)]
59
43
  end
60
44
 
61
- def self.mn2pdf_hash(cmd, options)
45
+ def self.mn2pdf_hash(args, options)
62
46
  manifest = options.delete(FONTS_MANIFEST)
63
- options_to_cmd(options, cmd)
47
+ options_to_cmd(options, args)
64
48
  if manifest
65
49
  dump_fontist_manifest_locations(manifest) do |manifest_path|
66
- cmd << "--font-manifest" << quote(manifest_path)
67
- mn2pdf(cmd)
50
+ args << "--font-manifest" << quote(manifest_path)
51
+ mn2pdf(args)
68
52
  end
69
53
  else
70
- mn2pdf(cmd)
54
+ mn2pdf(args)
71
55
  end
72
56
  end
73
57
 
74
- def self.mn2pdf(cmd)
75
- cmd = cmd.join(" ")
76
- puts cmd
77
- stdout, stderr, status = Open3.capture3(cmd)
58
+ def self.mn2pdf(args)
59
+ stdout, stderr, status = Jvm.run(args)
78
60
 
79
61
  unless status.success?
80
62
  puts_error_log(stdout, stderr)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mn2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.96'
4
+ version: '1.97'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-26 00:00:00.000000000 Z
11
+ date: 2024-08-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  mn2pdf converts Metanorma XML into PDF.
@@ -36,6 +36,7 @@ files:
36
36
  - bin/mn2pdf.jar
37
37
  - bin/setup
38
38
  - lib/mn2pdf.rb
39
+ - lib/mn2pdf/jvm.rb
39
40
  - lib/mn2pdf/version.rb
40
41
  - mn2pdf.gemspec
41
42
  homepage: https://github.com/metanorma/mn2pdf-ruby