lib/hexapdf/cli/command.rb in hexapdf-0.9.3 vs lib/hexapdf/cli/command.rb in hexapdf-0.10.0
- old
+ new
@@ -118,11 +118,11 @@
# Writes the document to the given file or does nothing if +out_file+ is +nil+.
def write_document(doc, out_file)
if out_file
doc.validate(auto_correct: true) do |object, msg, correctable|
if command_parser.strict && !correctable
- raise "Validation error: #{msg}"
+ raise "Validation error for object (#{object.oid},#{object.gen}): #{msg}"
elsif command_parser.verbosity_info?
$stderr.puts "#{correctable ? 'Corrected' : 'Ignored'} validation problem " \
"for object (#{object.oid},#{object.gen}): #{msg}"
end
end
@@ -245,25 +245,29 @@
}.freeze
# Applies the chosen stream mode to the given object.
def optimize_stream(obj)
return if @out_options.streams == :preserve || !obj.respond_to?(:set_filter) ||
- Array(obj[:Filter]).any? {|f| IGNORED_FILTERS[f] }
+ Array(obj[:Filter]).any? {|f| IGNORED_FILTERS[f] }
obj.set_filter(@out_options.streams == :compress ? :FlateDecode : nil)
end
# Optimize the object if it is a font object.
def optimize_font(obj)
return unless @out_options.optimize_fonts && obj.kind_of?(HexaPDF::Type::Font) &&
- (obj[:Subtype] == :TrueType ||
- (obj[:Subtype] == :Type0 && obj.descendant_font[:Subtype] == :CIDFontType2)) &&
- obj.embedded?
+ (obj[:Subtype] == :TrueType ||
+ (obj[:Subtype] == :Type0 && obj.descendant_font[:Subtype] == :CIDFontType2)) &&
+ obj.embedded?
font = HexaPDF::Font::TrueType::Font.new(StringIO.new(obj.font_file.stream))
data = HexaPDF::Font::TrueType::Optimizer.build_for_pdf(font)
obj.font_file.stream = data
obj.font_file[:Length1] = data.size
+ rescue StandardError => e
+ if command_parser.verbosity_info?
+ $stderr.puts "Error optimizing font object (#{obj.oid},#{obj.gen}): #{e.message}"
+ end
end
# Applies the encryption related options to the given HexaPDF::Document instance.
#
# See: #define_encryption_options