mn2pdf 1.96 → 1.97
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/mn2pdf.jar +0 -0
- data/lib/mn2pdf/jvm.rb +60 -0
- data/lib/mn2pdf/version.rb +1 -1
- data/lib/mn2pdf.rb +17 -35
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03474d63db276351bed0aab5f76b80ce7f18dda8abf198e4c785f7a0242cf1ed
|
4
|
+
data.tar.gz: '02333967ae637ce3748ea696701207a2d03fc4e8786920dcb5ea7326da857835'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/mn2pdf/version.rb
CHANGED
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, =
|
13
|
+
_, help_message, = Jvm.run
|
27
14
|
help_message
|
28
15
|
end
|
29
16
|
|
30
17
|
def self.version
|
31
|
-
|
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
|
-
|
23
|
+
args = build_args(url_path, output_path, xsl_stylesheet)
|
38
24
|
|
39
|
-
return unless
|
25
|
+
return unless args
|
40
26
|
|
41
27
|
case options
|
42
28
|
when String
|
43
|
-
mn2pdf(
|
29
|
+
mn2pdf(args + [options])
|
44
30
|
when Hash
|
45
|
-
mn2pdf_hash(
|
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.
|
37
|
+
def self.build_args(url, output, xslt)
|
52
38
|
return if url.nil? || output.nil? || xslt.nil?
|
53
39
|
|
54
|
-
["
|
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(
|
45
|
+
def self.mn2pdf_hash(args, options)
|
62
46
|
manifest = options.delete(FONTS_MANIFEST)
|
63
|
-
options_to_cmd(options,
|
47
|
+
options_to_cmd(options, args)
|
64
48
|
if manifest
|
65
49
|
dump_fontist_manifest_locations(manifest) do |manifest_path|
|
66
|
-
|
67
|
-
mn2pdf(
|
50
|
+
args << "--font-manifest" << quote(manifest_path)
|
51
|
+
mn2pdf(args)
|
68
52
|
end
|
69
53
|
else
|
70
|
-
mn2pdf(
|
54
|
+
mn2pdf(args)
|
71
55
|
end
|
72
56
|
end
|
73
57
|
|
74
|
-
def self.mn2pdf(
|
75
|
-
|
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.
|
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-
|
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
|