asciidoctor-pdf 1.5.1 → 1.5.2

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: 65bb6f189bb4f178cc3c92701488d3a8ffed51c607a9dca2d80821e7431c2083
4
- data.tar.gz: 51ab7401ed17a659a0537237bc7a840b261d0218bb3bc18963a33ff346683e13
3
+ metadata.gz: e90846d73d8139ce9e156f4010b8cd4220d9aa318897ec94dcac52ca2b027c61
4
+ data.tar.gz: b519c77487cb7c7b317244342dcb06b40241d511016f6289e3a31b8305798225
5
5
  SHA512:
6
- metadata.gz: 3f486c6c9a9825b87126d910089ba47a2956449e8868e42dfcbca1c29a93f15973f2619e51e911d898855ea80385aceb9bb7b01342d4fd389235a265c02a464e
7
- data.tar.gz: c452eb12b67a7a2daf1575961d7cb23723944a448aa4fb797a300db4e0a72125968e6a54f54adfc0ee9ed3f7e3f77d7c24bc4a09fd192eb02df7c7fe4ad29da5
6
+ metadata.gz: 836351139245d4460ea72c91889276e86484b1f587681ada048ccfa8d0716b7bfb595f28de0862e24556faec53a1b412a5d5f65cf2236b7579523dfd785dd1a6
7
+ data.tar.gz: ae3ca4fbc60ab2f8b0eefab691c8c08dfc2e39f20a2950516a8f2c4d6f9a09420f3b702b063d160592d389d390834148ef14ad173b4b31a8432995b926c27b14
data/CHANGELOG.adoc CHANGED
@@ -5,13 +5,21 @@
5
5
  This document provides a high-level view of the changes to the {project-name} by release.
6
6
  For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub.
7
7
 
8
+ == 1.5.2 (2020-02-21) - @mojavelinux
9
+
10
+ Bug Fixes::
11
+
12
+ * fix crash if btn or kbd macro is used in section title (#1563)
13
+ * ensure background and admonition icon image files are closed after being read (#1566)
14
+ * ensure temporary images generated by running content are cleaned up (#1566)
15
+
8
16
  == 1.5.1 (2020-02-16) - @mojavelinux
9
17
 
10
18
  Enhancements::
11
19
 
12
20
  * allow theme to control font color of first line of abstract
13
21
 
14
- Fixes::
22
+ Bug Fixes::
15
23
 
16
24
  * fix spacing after first line of indented paragraph (#1557)
17
25
 
data/README.adoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Asciidoctor PDF: A native PDF converter for AsciiDoc
2
2
  Dan Allen <https://github.com/mojavelinux[@mojavelinux]>; Sarah White <https://github.com/graphitefriction[@graphitefriction]>
3
- v1.5.1, 2020-02-16
3
+ v1.5.2, 2020-02-21
4
4
  // Settings:
5
5
  :experimental:
6
6
  :idprefix:
@@ -23,7 +23,7 @@ endif::[]
23
23
  :project-name: Asciidoctor PDF
24
24
  :project-handle: asciidoctor-pdf
25
25
  // Variables:
26
- :release-version: 1.5.1
26
+ :release-version: 1.5.2
27
27
  // URIs:
28
28
  :url-asciidoctor: http://asciidoctor.org
29
29
  :url-gem: http://rubygems.org/gems/asciidoctor-pdf
@@ -299,7 +299,7 @@ module Asciidoctor
299
299
 
300
300
  stamp_foreground_image doc, has_front_cover
301
301
  layout_cover_page doc, :back
302
- clean_up_tmp_files
302
+ remove_tmp_files
303
303
  nil
304
304
  end
305
305
 
@@ -836,7 +836,7 @@ module Asciidoctor
836
836
  end
837
837
  else
838
838
  begin
839
- image_obj, image_info = build_image_object icon_path
839
+ image_obj, image_info = ::File.open(icon_path, 'rb') {|fd| build_image_object fd }
840
840
  icon_aspect_ratio = image_info.width.fdiv image_info.height
841
841
  # NOTE: don't scale image up if smaller than label_width
842
842
  icon_width = [(to_pt image_info.width, :px), label_width].min
@@ -2406,7 +2406,7 @@ module Asciidoctor
2406
2406
  end
2407
2407
 
2408
2408
  def convert_inline_button node
2409
- %(<button>#{(@theme.button_content || '%s').sub '%s', node.text}</button>)
2409
+ %(<button>#{((load_theme node.document).button_content || '%s').sub '%s', node.text}</button>)
2410
2410
  end
2411
2411
 
2412
2412
  def convert_inline_callout node
@@ -2538,7 +2538,7 @@ module Asciidoctor
2538
2538
  if (keys = node.attr 'keys').size == 1
2539
2539
  %(<key>#{keys[0]}</key>)
2540
2540
  else
2541
- keys.map {|key| %(<key>#{key}</key>) }.join @theme.key_separator || '+'
2541
+ keys.map {|key| %(<key>#{key}</key>) }.join (load_theme node.document).key_separator || '+'
2542
2542
  end
2543
2543
  end
2544
2544
 
@@ -3237,9 +3237,13 @@ module Asciidoctor
3237
3237
  folio_basis, invert_folio = :virtual, false
3238
3238
  end
3239
3239
  periphery_layout_cache = {}
3240
+ # NOTE: this block is invoked during PDF generation, after convert_document has returned
3240
3241
  repeat (content_start_page..num_pages), dynamic: true do
3241
- # NOTE don't write on pages which are imported / inserts (otherwise we can get a corrupt PDF)
3242
- next if page.imported_page?
3242
+ # NOTE: don't write on pages which are imported / inserts (otherwise we can get a corrupt PDF)
3243
+ if page.imported_page?
3244
+ remove_tmp_files if page_number == num_pages
3245
+ next
3246
+ end
3243
3247
  virtual_pgnum = (pgnum = page_number) - skip_pagenums
3244
3248
  pgnum_label = (virtual_pgnum < 1 ? (RomanNumeral.new pgnum, :lower) : virtual_pgnum).to_s
3245
3249
  side = page_side((folio_basis == :physical ? pgnum : virtual_pgnum), invert_folio)
@@ -3339,6 +3343,7 @@ module Asciidoctor
3339
3343
  end
3340
3344
  end
3341
3345
  end
3346
+ remove_tmp_files if pgnum == num_pages
3342
3347
  end
3343
3348
 
3344
3349
  go_to_page prev_page_number
@@ -4063,17 +4068,17 @@ module Asciidoctor
4063
4068
  image_format ||= ::Asciidoctor::Image.format image_path, (::Asciidoctor::Image === node ? node.attributes : nil)
4064
4069
  # NOTE base64 logic currently used for inline images
4065
4070
  if ::Base64 === image_path
4066
- return (tmp_file = @tmp_files[image_path]) && tmp_file.path if @tmp_files.key? image_path
4067
- @tmp_files[image_path] = tmp_image = ::Tempfile.create ['image-', image_format && %(.#{image_format})]
4071
+ return @tmp_files[image_path] if @tmp_files.key? image_path
4072
+ tmp_image = ::Tempfile.create ['image-', image_format && %(.#{image_format})]
4068
4073
  tmp_image.binmode unless image_format == 'svg'
4069
4074
  begin
4070
4075
  tmp_image.write ::Base64.decode64 image_path
4071
4076
  tmp_image.close
4072
- tmp_image.path
4077
+ @tmp_files[image_path] = tmp_image.path
4073
4078
  rescue
4074
4079
  @tmp_files[image_path] = nil
4075
4080
  tmp_image.close
4076
- unlink_tmp_file tmp_image
4081
+ unlink_tmp_file tmp_image.path
4077
4082
  nil
4078
4083
  end
4079
4084
  # handle case when image is a URI
@@ -4084,23 +4089,23 @@ module Asciidoctor
4084
4089
  return
4085
4090
  end
4086
4091
  if @tmp_files.key? image_path
4087
- return (tmp_file = @tmp_files[image_path]) && tmp_file.path
4092
+ return @tmp_files[image_path]
4088
4093
  elsif cache_uri
4089
4094
  Helpers.require_library 'open-uri/cached', 'open-uri-cached' unless defined? ::OpenURI::Cache
4090
4095
  else
4091
4096
  ::OpenURI
4092
4097
  end
4093
- @tmp_files[image_path] = tmp_image = ::Tempfile.create ['image-', image_format && %(.#{image_format})]
4098
+ tmp_image = ::Tempfile.create ['image-', image_format && %(.#{image_format})]
4094
4099
  tmp_image.binmode if (binary = image_format != 'svg')
4095
4100
  begin
4096
4101
  ::OpenURI.open_uri(image_path, (binary ? 'rb' : 'r')) {|fd| tmp_image.write fd.read }
4097
4102
  tmp_image.close
4098
- tmp_image.path
4103
+ @tmp_files[image_path] = tmp_image.path
4099
4104
  rescue
4100
- logger.warn %(could not retrieve remote image: #{image_path}; #{$!.message}) unless scratch?
4101
4105
  @tmp_files[image_path] = nil
4106
+ logger.warn %(could not retrieve remote image: #{image_path}; #{$!.message}) unless scratch?
4102
4107
  tmp_image.close
4103
- unlink_tmp_file tmp_image
4108
+ unlink_tmp_file tmp_image.path
4104
4109
  nil
4105
4110
  end
4106
4111
  # handle case when image is a local file
@@ -4343,16 +4348,16 @@ module Asciidoctor
4343
4348
  link_annotation [image_x, (image_y - image_height), (image_x + image_width), image_y], Border: [0, 0, 0], A: { Type: :Action, S: :URI, URI: uri.as_pdf }
4344
4349
  end
4345
4350
 
4346
- def clean_up_tmp_files
4347
- @tmp_files.values.each {|tmp_file| unlink_tmp_file tmp_file if tmp_file }
4348
- @tmp_files.clear
4351
+ def remove_tmp_files
4352
+ @tmp_files.reject! {|_, path| path ? (unlink_tmp_file path) : true }
4349
4353
  end
4350
4354
 
4351
- def unlink_tmp_file file
4352
- path = file.path
4355
+ def unlink_tmp_file path
4353
4356
  ::File.unlink path if ::File.exist? path
4357
+ true
4354
4358
  rescue
4355
4359
  logger.warn %(could not delete temporary file: #{path}; #{$!.message}) unless scratch?
4360
+ false
4356
4361
  end
4357
4362
 
4358
4363
  def apply_subs_discretely doc, value, opts = {}
@@ -4461,14 +4466,11 @@ module Asciidoctor
4461
4466
  def init_scratch_prototype
4462
4467
  @save_state = nil
4463
4468
  @scratch_depth = 0
4464
- # NOTE can't marshall tmp_files, so clear them before creating prototype
4465
- saved_tmp_files, @tmp_files = @tmp_files, {}
4466
4469
  # IMPORTANT don't set font before using Marshal, it causes serialization to fail
4467
4470
  @prototype = ::Marshal.load ::Marshal.dump self
4468
4471
  @prototype.state.store.info.data[:Scratch] = @prototype.text_formatter.scratch = true
4469
4472
  # NOTE we're now starting a new page each time, so no need to do it here
4470
4473
  #@prototype.start_new_page if @prototype.page_number == 0
4471
- @tmp_files = saved_tmp_files
4472
4474
  end
4473
4475
 
4474
4476
  def push_scratch doc
@@ -12,19 +12,23 @@ module Asciidoctor
12
12
  # Dispatch to suitable image method in Prawn based on file extension.
13
13
  def image file, opts = {}
14
14
  # FIXME: handle case when SVG is an IO object
15
- if ::String === file && (((opts = opts.dup).delete :format) == 'svg' || (file.downcase.end_with? '.svg'))
16
- #opts[:enable_file_requests_with_root] = (::File.dirname file) unless opts.key? :enable_file_requests_with_root
17
- #opts[:enable_web_requests] = allow_uri_read if !(opts.key? :enable_web_requests) && (respond_to? :allow_uri_read)
18
- #opts[:cache_images] = cache_uri if !(opts.key? :cache_images) && (respond_to? :cache_uri)
19
- #opts[:fallback_font_name] = fallback_svg_font_name if !(opts.key? :fallback_font_name) && (respond_to? :fallback_svg_font_name)
20
- if (opts.key? :fit) && (fit = opts.delete :fit) && !opts[:width] && !opts[:height]
21
- svg (::File.read file, mode: 'r:UTF-8'), opts do |svg_doc|
22
- max_width, max_height = fit
23
- svg_doc.calculate_sizing requested_width: max_width if max_width && svg_doc.sizing.output_width != max_width
24
- svg_doc.calculate_sizing requested_height: max_height if max_height && svg_doc.sizing.output_height > max_height
15
+ if ::String === file
16
+ if ((opts = opts.dup).delete :format) == 'svg' || (file.downcase.end_with? '.svg')
17
+ #opts[:enable_file_requests_with_root] = (::File.dirname file) unless opts.key? :enable_file_requests_with_root
18
+ #opts[:enable_web_requests] = allow_uri_read if !(opts.key? :enable_web_requests) && (respond_to? :allow_uri_read)
19
+ #opts[:cache_images] = cache_uri if !(opts.key? :cache_images) && (respond_to? :cache_uri)
20
+ #opts[:fallback_font_name] = fallback_svg_font_name if !(opts.key? :fallback_font_name) && (respond_to? :fallback_svg_font_name)
21
+ if (opts.key? :fit) && (fit = opts.delete :fit) && !opts[:width] && !opts[:height]
22
+ svg (::File.read file, mode: 'r:UTF-8'), opts do |svg_doc|
23
+ max_width, max_height = fit
24
+ svg_doc.calculate_sizing requested_width: max_width if max_width && svg_doc.sizing.output_width != max_width
25
+ svg_doc.calculate_sizing requested_height: max_height if max_height && svg_doc.sizing.output_height > max_height
26
+ end
27
+ else
28
+ svg (::File.read file, mode: 'r:UTF-8'), opts
25
29
  end
26
30
  else
27
- svg (::File.read file, mode: 'r:UTF-8'), opts
31
+ ::File.open(file, 'rb') {|fd| _initial_image fd, opts }
28
32
  end
29
33
  else
30
34
  _initial_image file, opts
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module PDF
5
- VERSION = '1.5.1'
5
+ VERSION = '1.5.2'
6
6
  end
7
7
  Pdf = PDF unless const_defined? :Pdf, false
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-16 00:00:00.000000000 Z
12
+ date: 2020-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: asciidoctor