mn2pdf 1.62 → 1.62.1

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mn2pdf/version.rb +2 -2
  3. data/lib/mn2pdf.rb +41 -24
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc6978a2d6f90c8fe16e3fe7409af92dfadd8cab35d7d94157ea38a19b34a1a7
4
- data.tar.gz: 2ec44dee196ee1aa5157d7d46c706a318d9cfdb3bf40260b095a5300fb5f1115
3
+ metadata.gz: 38d552855d0b21a4841aeae1ffd9369b7661325a82504b13ee477c668f14ed43
4
+ data.tar.gz: 288a4772fe692ed6fea5a53b54e3c940dcc1e33d1d1f818109fca6c4433b6903
5
5
  SHA512:
6
- metadata.gz: 60aba1335f3bc599799a69f40bc49a8a739701e0902daf9e82c98aef8343ce787b7e5317b96ac59d1c8ce336648a2df192dec1315694b8608934252ef41408bd
7
- data.tar.gz: 52ef2b4dc662114f4f679c1b0ecb57e0b1a5cf99a3aaee33bd06c344b670cd09bb24116a2d47c7cf3b06efcb73e1709171f0752484f7cea00edd1cf30636f7d6
6
+ metadata.gz: 3347305976be72acc8474ec9493261ead5f3514267f19bfb3d27b13338dfd00a365f04aba715c8f99dbc2c374eceeb2905fa4b2bf2db1f7f7f5c15337523e89a
7
+ data.tar.gz: d1ac9c63a5cc79736804da71e4acba77b30b20a752ffdc363f75ac88cbe1415e011931d2310824f2b7d8d053bda5fe5fde7cedc155725ea4f2e725d43a65c38a
@@ -1,4 +1,4 @@
1
1
  module Mn2pdf
2
- VERSION = "1.62".freeze
3
- MN2PDF_JAR_VERSION = VERSION
2
+ VERSION = "1.62.1".freeze
3
+ MN2PDF_JAR_VERSION = "1.62".freeze
4
4
  end
data/lib/mn2pdf.rb CHANGED
@@ -5,7 +5,7 @@ require "yaml"
5
5
 
6
6
  module Mn2pdf
7
7
  MN2PDF_JAR_PATH = File.join(File.dirname(__FILE__), "../bin/mn2pdf.jar")
8
- DEFAULT_JAVA_OPTS = ["-Xss5m", "-Xmx2048m"].freeze
8
+ DEFAULT_JAVA_OPTS = %w[-Xss5m -Xmx2048m -Djava.awt.headless=true].freeze
9
9
  FONTS_MANIFEST = :font_manifest
10
10
 
11
11
  def self.jvm_options
@@ -38,24 +38,9 @@ module Mn2pdf
38
38
 
39
39
  case options
40
40
  when String
41
- cmd << options
42
-
43
- mn2pdf(cmd)
41
+ mn2pdf(cmd + [options])
44
42
  when Hash
45
- manifest = options.delete(FONTS_MANIFEST)
46
-
47
- options.each do |k, v|
48
- sep = k.to_s.end_with?("=") ? "" : " "
49
- cmd << "#{k}#{sep}#{quote(v)}"
50
- end
51
- if manifest
52
- dump_fontist_manifest_locations(manifest) do |manifest_path|
53
- cmd << "--font-manifest" << quote(manifest_path)
54
- mn2pdf(cmd)
55
- end
56
- else
57
- mn2pdf(cmd)
58
- end
43
+ mn2pdf_hash(cmd, options)
59
44
  else
60
45
  warn "Unsupported options type #{options.class}"
61
46
  end
@@ -71,18 +56,43 @@ module Mn2pdf
71
56
  "--pdf-file", quote(output)]
72
57
  end
73
58
 
59
+ def self.mn2pdf_hash(cmd, options)
60
+ manifest = options.delete(FONTS_MANIFEST)
61
+ options_to_cmd(options, cmd)
62
+ if manifest
63
+ dump_fontist_manifest_locations(manifest) do |manifest_path|
64
+ cmd << "--font-manifest" << quote(manifest_path)
65
+ mn2pdf(cmd)
66
+ end
67
+ else
68
+ mn2pdf(cmd)
69
+ end
70
+ end
71
+
74
72
  def self.mn2pdf(cmd)
75
73
  cmd = cmd.join(" ")
76
74
  puts cmd
77
- out, err, status = Open3.capture3(cmd)
75
+ stdout, stderr, status = Open3.capture3(cmd)
76
+
77
+ unless status.success?
78
+ puts_error_log(stdout, stderr)
79
+
80
+ raise StandardError.new("mn2pdf failed! #{parse_error_msg(stderr)}")
81
+ end
82
+ end
78
83
 
79
- raise prepare_error_msg(out, err) unless status.success?
84
+ def self.puts_error_log(stdout, stderr)
85
+ puts ["Fatal error!", "STDOUT:", stdout.strip, "STDERR:", stderr.strip]
86
+ .join("\n")
87
+ .split("\n")
88
+ .map { |line| "[mn2pdf] #{line}" }
89
+ .join("\n")
80
90
  end
81
91
 
82
- def self.prepare_error_msg(stdout, stderr)
83
- # Strip default mn2pdf message
84
- stdout = stdout.gsub("Preparing...", "").strip
85
- ["[mn2pdf] Fatal:", stdout, stderr].join(" ").strip
92
+ def self.parse_error_msg(stderr)
93
+ err = stderr.split("\n").detect { |line| line.start_with? "Error: " }
94
+
95
+ err ? err[7..-1] : stderr.strip
86
96
  end
87
97
 
88
98
  def self.quote(str)
@@ -100,4 +110,11 @@ module Mn2pdf
100
110
  yield f.path
101
111
  end
102
112
  end
113
+
114
+ def self.options_to_cmd(options, cmd)
115
+ options.each do |k, v|
116
+ sep = k.to_s.end_with?("=") ? "" : " "
117
+ cmd << "#{k}#{sep}#{quote(v)}"
118
+ end
119
+ end
103
120
  end
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.62'
4
+ version: 1.62.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-24 00:00:00.000000000 Z
11
+ date: 2023-03-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  mn2pdf converts Metanorma XML into PDF.