asciidoctor-pdf 2.0.7 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +55 -0
- data/README.adoc +8 -14
- data/lib/asciidoctor/pdf/converter.rb +144 -58
- data/lib/asciidoctor/pdf/ext/asciidoctor/section.rb +4 -0
- data/lib/asciidoctor/pdf/ext/prawn/document/column_box.rb +21 -6
- data/lib/asciidoctor/pdf/ext/prawn/extensions.rb +40 -35
- data/lib/asciidoctor/pdf/formatted_string.rb +13 -0
- data/lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb +5 -0
- data/lib/asciidoctor/pdf/formatted_text/text_background_and_border_renderer.rb +3 -3
- data/lib/asciidoctor/pdf/formatted_text/transform.rb +3 -0
- data/lib/asciidoctor/pdf/theme_loader.rb +1 -1
- data/lib/asciidoctor/pdf/version.rb +1 -1
- 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: bfcc8354e8152f540a4510dbddc39d38d577ee958aa51fbfb10b92d965abaa0c
|
4
|
+
data.tar.gz: 68848a664ded97d88c45e2d8357f3880a5e10f4b6cc0f0c44b014cd85088d1ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1fb4074705e06fb70c188278e677c69f696e832d28d5ad49e6135b218ef36416abfaebfdedd980ff094579ae509d5006b59a52c57cf62374e9bdd69822b3714
|
7
|
+
data.tar.gz: 07acff80d3d5c04e5ba8fbf591bbf3d952685bd0de605ac0e60645bbe478eafd1013451d4085abf8e2a41a996f5c4d8bba885377a1878a301ad75e144c0d2316
|
data/CHANGELOG.adoc
CHANGED
@@ -5,6 +5,61 @@
|
|
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 {url-repo}/commits/main[commit history] on GitHub.
|
7
7
|
|
8
|
+
== 2.1.1 (2022-06-15) - @mojavelinux
|
9
|
+
|
10
|
+
Improvements::
|
11
|
+
|
12
|
+
* store zero-based column on Extent for extensions to use to position cursor at start of extent
|
13
|
+
|
14
|
+
Bug Fixes::
|
15
|
+
|
16
|
+
* place block image in SVG format in correct column when align is left and page columns are enabled (#2241)
|
17
|
+
* accurately trap LoadError from CodeRay if source language is not recognized on code block
|
18
|
+
* only draw rounded rectangle around phrase if `border-radius` is > 0
|
19
|
+
* use `base-border-color` value if border width is set on role for inline phrase but not border color
|
20
|
+
|
21
|
+
=== Details
|
22
|
+
|
23
|
+
{url-repo}/releases/tag/v2.1.1[git tag] | {url-repo}/compare/v2.1.0\...v2.1.1[full diff]
|
24
|
+
|
25
|
+
== 2.1.0 (2022-06-11) - @mojavelinux
|
26
|
+
|
27
|
+
Enhancements::
|
28
|
+
|
29
|
+
* arrange body of article or manpage doctype into multiple columns if `page-columns` key is set in theme (#327)
|
30
|
+
* allow column gap to be specified using `page-column-gap` key (#327)
|
31
|
+
* introduce `convert_index_categories` method to handle rendering of categories for index inside column box (#327)
|
32
|
+
* rename `convert_index_list` method to `convert_index_term` to make its purpose more clear (#327)
|
33
|
+
* add `save_theme` helper to work with a copy of the theme within a scope (#2196)
|
34
|
+
* add support for `scale` attribute or `iw` unit on `pdfwidth` attribute on image macros (#1933)
|
35
|
+
* add backlink from bibref on bibliography entry to first reference to that entry in the document (#1737)
|
36
|
+
* preserve text formatting on index term in index section (#897)
|
37
|
+
* don't insert page break between part and first chapter if `heading-part-break-after` key in theme is `avoid` (#1795)
|
38
|
+
|
39
|
+
=== Details
|
40
|
+
|
41
|
+
{url-repo}/releases/tag/v2.1.0[git tag] | {url-repo}/compare/v2.0.8\...v2.1.0[full diff]
|
42
|
+
|
43
|
+
== 2.0.8 (2022-06-08) - @mojavelinux
|
44
|
+
|
45
|
+
Improvements::
|
46
|
+
|
47
|
+
* encapsulate logic to adjust column box inside float and dry run
|
48
|
+
* automatically set height on column box if not specified; update value automatically when reflowing margins
|
49
|
+
|
50
|
+
Bug Fixes::
|
51
|
+
|
52
|
+
* correctly compute value of to cursor on extent when column box starts below top of page (#2230)
|
53
|
+
* fix crash in `ColumnBox#move_past_bottom` when `:reflow_margins` option is not set
|
54
|
+
* fix x position of SVG when advanced to next column of column box
|
55
|
+
* `at_page_top?` should consider top of column box to be top of page
|
56
|
+
* prevent SVG image taller than column from being advanced to next column
|
57
|
+
* don't push section that follows index section in article to new page if last page of index does not extend to bottom of page
|
58
|
+
|
59
|
+
=== Details
|
60
|
+
|
61
|
+
{url-repo}/releases/tag/v2.0.8[git tag] | {url-repo}/compare/v2.0.7\...v2.0.8[full diff]
|
62
|
+
|
8
63
|
== 2.0.7 (2022-06-03) - @mojavelinux
|
9
64
|
|
10
65
|
Improvements::
|
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
|
-
v2.
|
3
|
+
v2.1.1, 2022-06-15
|
4
4
|
// Settings:
|
5
5
|
:experimental:
|
6
6
|
:idprefix:
|
@@ -23,8 +23,7 @@ endif::[]
|
|
23
23
|
:project-name: Asciidoctor PDF
|
24
24
|
:project-handle: asciidoctor-pdf
|
25
25
|
// Variables:
|
26
|
-
:release-line: 2.
|
27
|
-
:release-version: 2.0.7
|
26
|
+
:release-line: 2.1.x
|
28
27
|
// URLs:
|
29
28
|
:url-gem: https://rubygems.org/gems/asciidoctor-pdf
|
30
29
|
:url-project: https://github.com/asciidoctor/asciidoctor-pdf
|
@@ -47,7 +46,7 @@ The aim of this library is to take the pain out of creating PDF documents from A
|
|
47
46
|
|
48
47
|
[NOTE]
|
49
48
|
====
|
50
|
-
The documentation for Asciidoctor PDF
|
49
|
+
The documentation for the latest, stable release of Asciidoctor PDF is available at {url-project-docs}/.
|
51
50
|
|
52
51
|
If you're looking for the documentation for Asciidoctor PDF 1.6, refer to the {url-project-repo}/tree/v1.6.x#readme[README] in the v1.6.x branch.
|
53
52
|
Asciidoctor PDF 1.6 is no longer being developed and will reach EOL later this year.
|
@@ -62,7 +61,7 @@ Asciidoctor PDF converts an AsciiDoc document directly to a PDF document.
|
|
62
61
|
The style and layout of the PDF are controlled by a dedicated theme file.
|
63
62
|
To the degree possible, Asciidoctor PDF supports all the features of AsciiDoc that are supported by Asciidoctor.
|
64
63
|
It also provides {url-project-docs}/features/[PDF-specific features].
|
65
|
-
However, there are {url-project-docs}/features/#limitations[certain
|
64
|
+
However, there are {url-project-docs}/features/#limitations[certain limitations] imposed by the PDF format and the PDF library this extension uses.
|
66
65
|
|
67
66
|
Asciidoctor PDF uses the Prawn gem and Prawn's extensions, such as prawn-svg and prawn-table, to generate a PDF document.
|
68
67
|
{url-prawn}[Prawn] is a general purpose PDF generator for Ruby that features high-level APIs for common needs like setting up the page and inserting images and low-level APIs for positioning and rendering text and graphics.
|
@@ -114,11 +113,11 @@ There are several optional features of this converter that require additional ge
|
|
114
113
|
Those features are as follows.
|
115
114
|
|
116
115
|
Source highlighting::
|
117
|
-
You'll need to {url-project-
|
116
|
+
You'll need to {url-project-docs}/syntax-highlighting/[install a syntax highlighter] to use source highlighting (build-time only).
|
118
117
|
|
119
118
|
PDF optimization::
|
120
119
|
If you want to optimize your PDF, you'll need rghost or hexapdf.
|
121
|
-
See {url-project-
|
120
|
+
See {url-project-docs}/optimize-pdf/[Optimize the PDF] for installation and usage instructions.
|
122
121
|
|
123
122
|
Automatic hyphenation::
|
124
123
|
To turn on automatic hyphenation using the `hyphens` attribute, you'll need to install the `text-hyphen` gem:
|
@@ -128,7 +127,7 @@ To turn on automatic hyphenation using the `hyphens` attribute, you'll need to i
|
|
128
127
|
Accelerated image decoding::
|
129
128
|
Ruby is not particularly fast at decoding images, and the image formats it supports are limited.
|
130
129
|
To help, you can install prawn-gmagick, which delegates the work of decoding images to GraphicsMagick.
|
131
|
-
Refer to {url-project-
|
130
|
+
Refer to {url-project-docs}/image-paths-and-formats/#other-image-formats[Supporting additional image file formats] for instructions about how to enable this integration.
|
132
131
|
|
133
132
|
Check the {url-project-docs}/install/#table-minimum-version[minimum supported version table] to make sure you're using a supported version of the dependency.
|
134
133
|
|
@@ -182,7 +181,7 @@ Asciidoctor creates the output file in the same directory as the input file by d
|
|
182
181
|
Open the [.path]_basic-example.pdf_ file with a PDF viewer to see the result.
|
183
182
|
|
184
183
|
.Example PDF document rendered in a PDF viewer
|
185
|
-
image::docs/modules/ROOT/images/basic-example-pdf-screenshot.png[Screenshot of PDF document,960,
|
184
|
+
image::docs/modules/ROOT/images/basic-example-pdf-screenshot.png[Screenshot of PDF document,960,pdfwidth=100%]
|
186
185
|
|
187
186
|
For more information about how to use Asciidoctor PDF and PDF-specific AsciiDoc syntax, see the {url-project-docs}/[Asciidoctor PDF documentation].
|
188
187
|
|
@@ -197,11 +196,6 @@ ifndef::env-site[]
|
|
197
196
|
See the <<CONTRIBUTING.adoc#,contributing guide>>.
|
198
197
|
To help develop {project-name}, or to simply use the development version, refer to the <<CONTRIBUTING-CODE.adoc#,developing and contributing code guide>>.
|
199
198
|
|
200
|
-
[[resources,Links]]
|
201
|
-
== Resources
|
202
|
-
|
203
|
-
* https://groups.google.com/forum/#!msg/prawn-ruby/MbMsCx862iY/6ImCsvLGfVcJ[Discussion about image quality in PDFs]
|
204
|
-
|
205
199
|
== Authors
|
206
200
|
|
207
201
|
{project-name} was written by https://github.com/mojavelinux[Dan Allen] and https://github.com/graphitefriction[Sarah White] of OpenDevise Inc. on behalf of the Asciidoctor Project.
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'formatted_string'
|
3
4
|
require_relative 'formatted_text'
|
4
5
|
require_relative 'index_catalog'
|
5
6
|
require_relative 'pdfmark'
|
@@ -124,6 +125,7 @@ module Asciidoctor
|
|
124
125
|
DropAnchorRx = %r(<(?:a\b[^>]*|/a)>)
|
125
126
|
SourceHighlighters = %w(coderay pygments rouge).to_set
|
126
127
|
ViewportWidth = ::Module.new
|
128
|
+
ImageWidth = ::Module.new
|
127
129
|
(TitleStyles = {
|
128
130
|
'toc' => [:numbered_title],
|
129
131
|
'basic' => [:title],
|
@@ -162,7 +164,6 @@ module Asciidoctor
|
|
162
164
|
doc.attributes['outline'] = '' unless (doc.attribute_locked? 'outline') || ((doc.instance_variable_get :@attributes_modified).include? 'outline')
|
163
165
|
doc.attributes['outline-title'] = '' unless (doc.attribute_locked? 'outline-title') || ((doc.instance_variable_get :@attributes_modified).include? 'outline-title')
|
164
166
|
doc.attributes['pagenums'] = '' unless (doc.attribute_locked? 'pagenums') || ((doc.instance_variable_get :@attributes_modified).include? 'pagenums')
|
165
|
-
#assign_missing_section_ids doc
|
166
167
|
|
167
168
|
on_page_create(&(method :init_page))
|
168
169
|
|
@@ -170,7 +171,8 @@ module Asciidoctor
|
|
170
171
|
# NOTE: a new page will already be started (page_number = 2) if the front cover image is a PDF
|
171
172
|
ink_cover_page doc, :front
|
172
173
|
has_front_cover = page_number > marked_page_number
|
173
|
-
|
174
|
+
doctype = doc.doctype
|
175
|
+
if (has_title_page = (title_page_on = doctype == 'book' || (doc.attr? 'title-page')) && (start_title_page doc))
|
174
176
|
# NOTE: the base font must be set before any content is written to the main or scratch document
|
175
177
|
font @theme.base_font_family, size: @root_font_size, style: @theme.base_font_style
|
176
178
|
if perform_on_single_page { ink_title_page doc }
|
@@ -279,12 +281,19 @@ module Asciidoctor
|
|
279
281
|
doc.set_attr 'pdf-anchor', (derive_anchor_from_id doc.id, 'top')
|
280
282
|
doc.set_attr 'pdf-page-start', page_number
|
281
283
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
284
|
+
if doctype == 'book' || (columns = @theme.page_columns || 1) < 2
|
285
|
+
convert_section generate_manname_section doc if doctype == 'manpage' && (doc.attr? 'manpurpose')
|
286
|
+
traverse doc
|
287
|
+
# NOTE: for a book, these are leftover footnotes; for an article this is everything
|
288
|
+
outdent_section { ink_footnotes doc }
|
289
|
+
else
|
290
|
+
column_box [bounds.left, cursor], columns: columns, width: bounds.width, reflow_margins: true, spacer: @theme.page_column_gap do
|
291
|
+
convert_section generate_manname_section doc if doctype == 'manpage' && (doc.attr? 'manpurpose')
|
292
|
+
traverse doc
|
293
|
+
# NOTE: for a book, these are leftover footnotes; for an article this is everything
|
294
|
+
outdent_section { ink_footnotes doc }
|
295
|
+
end
|
296
|
+
end
|
288
297
|
|
289
298
|
if (toc_extent = @toc_extent)
|
290
299
|
if title_page_on && !insert_toc
|
@@ -403,6 +412,7 @@ module Asciidoctor
|
|
403
412
|
@list_bullets = []
|
404
413
|
@bottom_gutters = [{}]
|
405
414
|
@rendered_footnotes = []
|
415
|
+
@bibref_refs = ::Set.new
|
406
416
|
@conum_glyphs = ConumSets[@theme.conum_glyphs || 'circled'] || (@theme.conum_glyphs.split ',').map do |r|
|
407
417
|
from, to = r.lstrip.split '-', 2
|
408
418
|
to ? ((get_char from)..(get_char to)).to_a : [(get_char from)]
|
@@ -576,6 +586,8 @@ module Asciidoctor
|
|
576
586
|
theme.base_font_style = theme.base_font_style&.to_sym || :normal
|
577
587
|
theme.page_numbering_start_at ||= 'body'
|
578
588
|
theme.running_content_start_at ||= 'body'
|
589
|
+
theme.heading_chapter_break_before ||= 'always'
|
590
|
+
theme.heading_part_break_before ||= 'always'
|
579
591
|
theme.heading_margin_page_top ||= 0
|
580
592
|
theme.heading_margin_top ||= 0
|
581
593
|
theme.heading_margin_bottom ||= 0
|
@@ -610,6 +622,13 @@ module Asciidoctor
|
|
610
622
|
theme
|
611
623
|
end
|
612
624
|
|
625
|
+
def save_theme
|
626
|
+
@theme = (original_theme = theme).dup
|
627
|
+
yield
|
628
|
+
ensure
|
629
|
+
@theme = original_theme
|
630
|
+
end
|
631
|
+
|
613
632
|
def indent_section
|
614
633
|
if (values = @section_indent)
|
615
634
|
indent(values[0], values[1]) { yield }
|
@@ -648,13 +667,14 @@ module Asciidoctor
|
|
648
667
|
hidden = sect.option? 'notitle'
|
649
668
|
hopts = { align: text_align, level: hlevel, part: part, chapterlike: chapterlike, outdent: !(part || chapterlike) }
|
650
669
|
if part
|
651
|
-
|
670
|
+
if @theme.heading_part_break_before == 'always'
|
652
671
|
started_new = true
|
653
672
|
start_new_part sect
|
654
673
|
end
|
655
674
|
elsif chapterlike
|
656
|
-
if @theme.heading_chapter_break_before
|
657
|
-
(@theme.heading_part_break_after == '
|
675
|
+
if (@theme.heading_chapter_break_before == 'always' &&
|
676
|
+
!(@theme.heading_part_break_after == 'avoid' && sect.first_section_of_part?)) ||
|
677
|
+
(@theme.heading_part_break_after == 'always' && sect.first_section_of_part?)
|
658
678
|
started_new = true
|
659
679
|
start_new_chapter sect
|
660
680
|
end
|
@@ -701,49 +721,74 @@ module Asciidoctor
|
|
701
721
|
end
|
702
722
|
|
703
723
|
def convert_index_section node
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
inline_format: false,
|
712
|
-
margin_bottom: @theme.description_list_term_spacing,
|
713
|
-
style: @theme.description_list_term_font_style&.to_sym
|
714
|
-
category.terms.each {|term| convert_index_list_item term, pagenum_sequence_style }
|
715
|
-
@theme.prose_margin_bottom > cursor ? bounds.move_past_bottom : (move_down @theme.prose_margin_bottom)
|
724
|
+
if ColumnBox === bounds || (columns = @theme.index_columns || 1) < 2
|
725
|
+
convert_index_categories @index.categories, (node.document.attr 'index-pagenum-sequence-style')
|
726
|
+
else
|
727
|
+
end_cursor = nil
|
728
|
+
column_box [bounds.left, cursor], columns: columns, width: bounds.width, reflow_margins: true, spacer: @theme.index_column_gap do
|
729
|
+
convert_index_categories @index.categories, (node.document.attr 'index-pagenum-sequence-style')
|
730
|
+
end_cursor = cursor if bounds.current_column == 0
|
716
731
|
end
|
732
|
+
# Q: could we move this logic into column_box?
|
733
|
+
move_cursor_to end_cursor if end_cursor
|
717
734
|
end
|
718
735
|
nil
|
719
736
|
end
|
720
737
|
|
721
|
-
def
|
722
|
-
|
738
|
+
def convert_index_categories categories, pagenum_sequence_style = nil
|
739
|
+
space_needed_for_category = @theme.description_list_term_spacing + (2 * (height_of_typeset_text 'A'))
|
740
|
+
categories.each do |category|
|
741
|
+
bounds.move_past_bottom if space_needed_for_category > cursor
|
742
|
+
ink_prose category.name,
|
743
|
+
align: :left,
|
744
|
+
inline_format: false,
|
745
|
+
margin_bottom: @theme.description_list_term_spacing,
|
746
|
+
style: @theme.description_list_term_font_style&.to_sym
|
747
|
+
category.terms.each {|term| convert_index_term term, pagenum_sequence_style }
|
748
|
+
@theme.prose_margin_bottom > cursor ? bounds.move_past_bottom : (move_down @theme.prose_margin_bottom)
|
749
|
+
end
|
750
|
+
end
|
751
|
+
|
752
|
+
def convert_index_term term, pagenum_sequence_style = nil
|
753
|
+
term_fragments = term.name.fragments
|
723
754
|
unless term.container?
|
755
|
+
pagenum_fragment = (parse_text %(<a>#{DummyText}</a>), inline_format: true)[0]
|
724
756
|
if @media == 'screen'
|
725
757
|
case pagenum_sequence_style
|
726
758
|
when 'page'
|
727
|
-
pagenums = term.dests.uniq {|dest| dest[:page] }.map {|dest|
|
759
|
+
pagenums = term.dests.uniq {|dest| dest[:page] }.map {|dest| pagenum_fragment.merge anchor: dest[:anchor], text: dest[:page] }
|
728
760
|
when 'range'
|
729
761
|
first_anchor_per_page = {}.tap {|accum| term.dests.each {|dest| accum[dest[:page]] ||= dest[:anchor] } }
|
730
762
|
pagenums = (consolidate_ranges first_anchor_per_page.keys).map do |range|
|
731
763
|
anchor = first_anchor_per_page[(range.include? '-') ? (range.partition '-')[0] : range]
|
732
|
-
|
764
|
+
pagenum_fragment.merge text: range, anchor: anchor
|
733
765
|
end
|
734
766
|
else # term
|
735
|
-
pagenums = term.dests.map {|dest|
|
767
|
+
pagenums = term.dests.map {|dest| pagenum_fragment.merge text: dest[:page], anchor: dest[:anchor] }
|
736
768
|
end
|
737
769
|
else
|
738
770
|
pagenums = consolidate_ranges term.dests.map {|dest| dest[:page] }.uniq
|
739
771
|
end
|
740
|
-
|
772
|
+
pagenums.each do |pagenum|
|
773
|
+
# NOTE: addresses a very minor kerning issue for text adjacent to the comma
|
774
|
+
if (prev_fragment = term_fragments[-1]).size == 1
|
775
|
+
if ::String === pagenum
|
776
|
+
term_fragments[-1] = prev_fragment.merge text: %(#{prev_fragment[:text]}, #{pagenum})
|
777
|
+
next
|
778
|
+
else
|
779
|
+
term_fragments[-1] = prev_fragment.merge text: %(#{prev_fragment[:text]}, )
|
780
|
+
end
|
781
|
+
else
|
782
|
+
term_fragments << ({ text: ', ' })
|
783
|
+
end
|
784
|
+
term_fragments << (::String === pagenum ? { text: pagenum } : pagenum)
|
785
|
+
end
|
741
786
|
end
|
742
787
|
subterm_indent = @theme.description_list_description_indent
|
743
|
-
|
788
|
+
typeset_formatted_text term_fragments, (calc_line_metrics @base_line_height), align: :left, color: @font_color, hanging_indent: subterm_indent * 2
|
744
789
|
indent subterm_indent do
|
745
790
|
term.subterms.each do |subterm|
|
746
|
-
|
791
|
+
convert_index_term subterm, pagenum_sequence_style
|
747
792
|
end
|
748
793
|
end unless term.leaf?
|
749
794
|
end
|
@@ -1063,7 +1108,10 @@ module Asciidoctor
|
|
1063
1108
|
srclang = node.attr 'language', 'text'
|
1064
1109
|
begin
|
1065
1110
|
::CodeRay::Scanners[(srclang = (srclang.start_with? 'html+') ? (srclang.slice 5, srclang.length).to_sym : srclang.to_sym)]
|
1066
|
-
rescue
|
1111
|
+
rescue
|
1112
|
+
until ::LoadError === (cause ||= $!) || ::ArgumentError === cause
|
1113
|
+
raise $! unless (cause = cause.cause)
|
1114
|
+
end
|
1067
1115
|
srclang = :text
|
1068
1116
|
end
|
1069
1117
|
fragments = (::CodeRay.scan source_string, srclang).to_prawn
|
@@ -1712,9 +1760,14 @@ module Asciidoctor
|
|
1712
1760
|
return on_image_error :missing, node, target, (opts.merge align: alignment) unless image_path
|
1713
1761
|
|
1714
1762
|
# TODO: support cover (aka canvas) image layout using "canvas" (or "cover") role
|
1715
|
-
width = resolve_explicit_width node.attributes, bounds_width: (available_w = bounds.width), support_vw: true, use_fallback: true, constrain_to_bounds: true
|
1716
|
-
|
1717
|
-
|
1763
|
+
case (width = resolve_explicit_width node.attributes, bounds_width: (available_w = bounds.width), support_vw: true, use_fallback: true, constrain_to_bounds: true)
|
1764
|
+
when ViewportWidth
|
1765
|
+
# TODO: add `to_pt page_width` method to ViewportWidth type
|
1766
|
+
width = page_width * (width.to_f / 100)
|
1767
|
+
when ImageWidth
|
1768
|
+
scale = width.to_f / 100
|
1769
|
+
width = nil
|
1770
|
+
end
|
1718
1771
|
|
1719
1772
|
caption_end = @theme.image_caption_end&.to_sym || :bottom
|
1720
1773
|
caption_max_width = @theme.image_caption_max_width
|
@@ -1737,14 +1790,15 @@ module Asciidoctor
|
|
1737
1790
|
file_request_root = { base: (::File.dirname image_path), root: @jail_dir }
|
1738
1791
|
end
|
1739
1792
|
svg_obj = ::Prawn::SVG::Interface.new svg_data, self,
|
1740
|
-
position: alignment,
|
1741
1793
|
width: width,
|
1742
1794
|
fallback_font_name: fallback_svg_font_name,
|
1743
1795
|
enable_web_requests: allow_uri_read ? (method :load_open_uri).to_proc : false,
|
1744
1796
|
enable_file_requests_with_root: file_request_root,
|
1745
1797
|
cache_images: cache_uri
|
1746
1798
|
rendered_w = (svg_size = svg_obj.document.sizing).output_width
|
1747
|
-
if
|
1799
|
+
if scale
|
1800
|
+
svg_size = svg_obj.resize width: (rendered_w = [available_w, rendered_w * scale].min)
|
1801
|
+
elsif !width && (svg_obj.document.root.attributes.key? 'width') && rendered_w > available_w
|
1748
1802
|
# NOTE: restrict width to available width (prawn-svg already coerces to pixels)
|
1749
1803
|
svg_size = svg_obj.resize width: (rendered_w = available_w)
|
1750
1804
|
end
|
@@ -1762,7 +1816,16 @@ module Asciidoctor
|
|
1762
1816
|
update_colors if graphic_state.color_space.empty?
|
1763
1817
|
ink_caption node, category: :image, end: :top, block_align: alignment, block_width: rendered_w, max_width: caption_max_width if caption_end == :top && node.title?
|
1764
1818
|
image_y = y
|
1765
|
-
|
1819
|
+
# NOTE: prawn-svg does not compute :at for alignment correctly in column box, so resort to our own logic
|
1820
|
+
case alignment
|
1821
|
+
when :center
|
1822
|
+
left = bounds.left + (available_w - rendered_w) * 0.5
|
1823
|
+
when :right
|
1824
|
+
left = bounds.left + available_w - rendered_w
|
1825
|
+
else
|
1826
|
+
left = bounds.left
|
1827
|
+
end
|
1828
|
+
svg_obj.options[:at] = [left, (image_cursor = cursor)]
|
1766
1829
|
svg_obj.draw # NOTE: cursor advances automatically
|
1767
1830
|
svg_obj.document.warnings.each do |img_warning|
|
1768
1831
|
log :warn, %(problem encountered in image: #{image_path}; #{img_warning})
|
@@ -1777,8 +1840,10 @@ module Asciidoctor
|
|
1777
1840
|
image_obj, image_info = ::Base64 === image_path ?
|
1778
1841
|
::StringIO.open((::Base64.decode64 image_path), 'rb') {|fd| build_image_object fd } :
|
1779
1842
|
::File.open(image_path, 'rb') {|fd| build_image_object fd }
|
1843
|
+
actual_w = to_pt image_info.width, :px
|
1844
|
+
width = actual_w * scale if scale
|
1780
1845
|
# NOTE: if width is not specified, scale native width & height from px to pt and restrict width to available width
|
1781
|
-
rendered_w, rendered_h = image_info.calc_image_dimensions width: (width || [available_w,
|
1846
|
+
rendered_w, rendered_h = image_info.calc_image_dimensions width: (width || [available_w, actual_w].min)
|
1782
1847
|
# NOTE: shrink image so it fits within available space; group image & caption
|
1783
1848
|
if rendered_h > (available_h = cursor - caption_h)
|
1784
1849
|
unless pinned || at_page_top?
|
@@ -2376,9 +2441,12 @@ module Asciidoctor
|
|
2376
2441
|
if (text = ref.xreftext node.attr 'xrefstyle', nil, true)&.include? '<a'
|
2377
2442
|
text = text.gsub DropAnchorRx, ''
|
2378
2443
|
end
|
2444
|
+
if ref.inline? && ref.type == :bibref && !scratch? && (@bibref_refs.add? refid)
|
2445
|
+
anchor = %(<a id="_bibref_ref_#{refid}">#{DummyText}</a>)
|
2446
|
+
end
|
2379
2447
|
@resolving_xref = nil
|
2380
2448
|
end
|
2381
|
-
%(<a anchor="#{derive_anchor_from_id refid}">#{text || "[#{refid}]"}</a>).gsub ']', ']'
|
2449
|
+
%(#{anchor || ''}<a anchor="#{derive_anchor_from_id refid}">#{text || "[#{refid}]"}</a>).gsub ']', ']'
|
2382
2450
|
else
|
2383
2451
|
%(<a anchor="#{doc.attr 'pdf-anchor'}">#{node.text || '[^top]'}</a>)
|
2384
2452
|
end
|
@@ -2386,10 +2454,12 @@ module Asciidoctor
|
|
2386
2454
|
# NOTE: destination is created inside callback registered by FormattedTextTransform#build_fragment
|
2387
2455
|
%(<a id="#{node.id}">#{DummyText}</a>)
|
2388
2456
|
when :bibref
|
2389
|
-
|
2457
|
+
id = node.id
|
2390
2458
|
# NOTE: technically node.text should be node.reftext, but subs have already been applied to text
|
2391
|
-
reftext = (reftext = node.reftext) ? %([#{reftext}]) : %([#{
|
2392
|
-
%(<a
|
2459
|
+
reftext = (reftext = node.reftext) ? %([#{reftext}]) : %([#{id}])
|
2460
|
+
reftext = %(<a anchor="_bibref_ref_#{id}">#{reftext}</a>) if @bibref_refs.include? id
|
2461
|
+
# NOTE: destination is created inside callback registered by FormattedTextTransform#build_fragment
|
2462
|
+
%(<a id="#{id}">#{DummyText}</a>#{reftext})
|
2393
2463
|
else
|
2394
2464
|
log :warn, %(unknown anchor type: #{node.type.inspect})
|
2395
2465
|
nil
|
@@ -2511,12 +2581,18 @@ module Asciidoctor
|
|
2511
2581
|
class_attr = (role = node.role) ? %( class="#{role}") : ''
|
2512
2582
|
fit_attr = (fit = node.attr 'fit') ? %( fit="#{fit}") : ''
|
2513
2583
|
if (width = resolve_explicit_width node.attributes)
|
2514
|
-
if
|
2515
|
-
|
2584
|
+
if ImageWidth === width
|
2585
|
+
if state # check that converter is initialized
|
2586
|
+
width = (intrinsic_image_width image_path, image_format) * (width.to_f / 100)
|
2587
|
+
else
|
2588
|
+
width = %(auto*#{width})
|
2589
|
+
end
|
2590
|
+
elsif node.parent.context == :table_cell && ::String === width && (width.end_with? '%')
|
2591
|
+
width += (intrinsic_image_width image_path, image_format).to_s
|
2516
2592
|
end
|
2517
2593
|
width_attr = %( width="#{width}")
|
2518
2594
|
elsif state # check that converter is initialized
|
2519
|
-
width_attr = %( width="#{
|
2595
|
+
width_attr = %( width="#{intrinsic_image_width image_path, image_format}")
|
2520
2596
|
else
|
2521
2597
|
width_attr = ' width="auto"' # defer operation until arranger runs
|
2522
2598
|
end
|
@@ -2537,17 +2613,20 @@ module Asciidoctor
|
|
2537
2613
|
if scratch?
|
2538
2614
|
visible ? node.text : ''
|
2539
2615
|
else
|
2540
|
-
|
2541
|
-
|
2616
|
+
unless defined? @index
|
2617
|
+
# NOTE: initialize index and text formatter in case converter is called before PDF is initialized
|
2618
|
+
@index = IndexCatalog.new
|
2619
|
+
@text_formatter = FormattedText::Formatter.new theme: (load_theme node.document)
|
2620
|
+
end
|
2542
2621
|
# NOTE: page number (:page key) is added by InlineDestinationMarker
|
2543
2622
|
dest = { anchor: (anchor_name = @index.next_anchor_name) }
|
2544
2623
|
anchor = %(<a id="#{anchor_name}" type="indexterm"#{visible ? ' visible="true"' : ''}>#{DummyText}</a>)
|
2545
2624
|
if visible
|
2546
2625
|
visible_term = node.text
|
2547
|
-
@index.store_primary_term (
|
2626
|
+
@index.store_primary_term (FormattedString.new parse_text visible_term, inline_format: [normalize: true]), dest
|
2548
2627
|
%(#{anchor}#{visible_term})
|
2549
2628
|
else
|
2550
|
-
@index.store_term (node.attr 'terms').map {|term|
|
2629
|
+
@index.store_term (node.attr 'terms').map {|term| FormattedString.new parse_text term, inline_format: [normalize: true] }, dest
|
2551
2630
|
anchor
|
2552
2631
|
end
|
2553
2632
|
end
|
@@ -2574,8 +2653,6 @@ module Asciidoctor
|
|
2574
2653
|
end
|
2575
2654
|
|
2576
2655
|
def convert_inline_quoted node
|
2577
|
-
theme = load_theme node.document
|
2578
|
-
|
2579
2656
|
case node.type
|
2580
2657
|
when :emphasis
|
2581
2658
|
open, close, is_tag = ['<em>', '</em>', true]
|
@@ -2588,25 +2665,26 @@ module Asciidoctor
|
|
2588
2665
|
when :subscript
|
2589
2666
|
open, close, is_tag = ['<sub>', '</sub>', true]
|
2590
2667
|
when :double
|
2591
|
-
open, close
|
2668
|
+
open, close = (load_theme node.document).quotes.slice 0, 2
|
2592
2669
|
quotes = true
|
2593
2670
|
when :single
|
2594
|
-
open, close
|
2671
|
+
open, close = (load_theme node.document).quotes.slice 2, 2
|
2595
2672
|
quotes = true
|
2596
2673
|
when :mark
|
2597
2674
|
open, close, is_tag = ['<mark>', '</mark>', true]
|
2598
2675
|
else
|
2599
|
-
open
|
2676
|
+
open = close = ''
|
2600
2677
|
end
|
2601
2678
|
|
2602
2679
|
inner_text = node.text
|
2603
2680
|
|
2604
|
-
if quotes && (len = inner_text.length) > 3 &&
|
2605
|
-
|
2681
|
+
if quotes && (len = inner_text.length) > 3 && (inner_text.end_with? '...') &&
|
2682
|
+
!((inner_text_trunc = inner_text.slice 0, len - 3).end_with? ?\\)
|
2606
2683
|
inner_text = inner_text_trunc + '…'
|
2607
2684
|
end
|
2608
2685
|
|
2609
2686
|
if (roles = node.role)
|
2687
|
+
theme = load_theme node.document
|
2610
2688
|
roles.split.each do |role|
|
2611
2689
|
if (text_transform = theme[%(role_#{role}_text_transform)])
|
2612
2690
|
inner_text = transform_text inner_text, text_transform
|
@@ -3867,6 +3945,10 @@ module Asciidoctor
|
|
3867
3945
|
{ width: 0, height: 0 }
|
3868
3946
|
end
|
3869
3947
|
|
3948
|
+
def intrinsic_image_width path, format
|
3949
|
+
(intrinsic_image_dimensions path, format)[:width]
|
3950
|
+
end
|
3951
|
+
|
3870
3952
|
# Sends the specified message to the log unless this method is called from the scratch document
|
3871
3953
|
def log severity, message = nil, &block
|
3872
3954
|
logger.send severity, message, &block unless scratch?
|
@@ -4038,11 +4120,15 @@ module Asciidoctor
|
|
4038
4120
|
if attrs.key? 'pdfwidth'
|
4039
4121
|
if (width = attrs['pdfwidth']).end_with? '%'
|
4040
4122
|
bounds_width ? (width.to_f / 100) * bounds_width : width
|
4123
|
+
elsif width.end_with? 'iw'
|
4124
|
+
(width.chomp 'iw').extend ImageWidth
|
4041
4125
|
elsif opts[:support_vw] && (width.end_with? 'vw')
|
4042
4126
|
(width.chomp 'vw').extend ViewportWidth
|
4043
4127
|
else
|
4044
4128
|
str_to_pt width
|
4045
4129
|
end
|
4130
|
+
elsif attrs.key? 'scale'
|
4131
|
+
attrs['scale'].dup.extend ImageWidth
|
4046
4132
|
elsif attrs.key? 'scaledwidth'
|
4047
4133
|
# NOTE: the parser automatically appends % if value is unitless
|
4048
4134
|
if (width = attrs['scaledwidth']).end_with? '%'
|
@@ -4313,7 +4399,7 @@ module Asciidoctor
|
|
4313
4399
|
b_shift, b_gap_color = (b_width ||= 0.5) * 0.5, @page_bg_color
|
4314
4400
|
end
|
4315
4401
|
ink_caption node_with_caption, category: category if node_with_caption
|
4316
|
-
extent.from.page
|
4402
|
+
extent.from.page = page_number unless extent.from.page == page_number # sanity check
|
4317
4403
|
float do
|
4318
4404
|
extent.each_page do |first_page, last_page|
|
4319
4405
|
advance_page unless first_page
|
@@ -30,4 +30,8 @@ class Asciidoctor::Section
|
|
30
30
|
end
|
31
31
|
opts[:formal] ? @cached_formal_numbered_title : @cached_numbered_title
|
32
32
|
end unless method_defined? :numbered_title
|
33
|
+
|
34
|
+
def first_section_of_part?
|
35
|
+
(par = @parent).context == :section && par.sectname == 'part' && self == par.blocks.find {|it| it.context == :section }
|
36
|
+
end unless method_defined? :first_section_of_part?
|
33
37
|
end
|
@@ -1,20 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Prawn::Document::ColumnBox.prepend (Module.new do
|
4
|
-
|
5
|
-
stretchy? ? @parent.absolute_bottom : super
|
6
|
-
end
|
4
|
+
attr_accessor :current_column
|
7
5
|
|
8
6
|
def move_past_bottom
|
9
7
|
(doc = @document).y = @y
|
10
8
|
return if (@current_column = (@current_column + 1) % @columns) > 0
|
11
|
-
|
9
|
+
par = @parent
|
10
|
+
if (reset_y = @reflow_margins) && (reset_y == true || reset_y > doc.page_number)
|
11
|
+
@y = par.absolute_top
|
12
|
+
@height = par.height unless stretchy?
|
13
|
+
end
|
12
14
|
initial_margins = doc.page.margins
|
13
15
|
par.move_past_bottom
|
14
16
|
if doc.page.margins != initial_margins
|
15
|
-
doc.bounds = self.class.new doc, par, (margin_box = doc.margin_box).
|
16
|
-
columns: @columns, reflow_margins:
|
17
|
+
doc.bounds = self.class.new doc, par, [(margin_box = doc.margin_box).absolute_left, @y],
|
18
|
+
columns: @columns, reflow_margins: @reflow_margins, spacer: @spacer, width: margin_box.width, height: @height
|
19
|
+
end
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
# Rearranges the column box into a single column, where the original columns are in a single file. Used
|
24
|
+
# for the purpose of computing the extent of content in a scratch document.
|
25
|
+
def single_file
|
26
|
+
if @reflow_margins && @parent.absolute_top > @y && @columns > @current_column + 1
|
27
|
+
# defer reflow margins until all columns on current page have been exhausted
|
28
|
+
@reflow_margins = @document.page_number + (@columns - @current_column)
|
17
29
|
end
|
30
|
+
@width = bare_column_width
|
31
|
+
@columns = 1
|
32
|
+
@current_column = 0
|
18
33
|
nil
|
19
34
|
end
|
20
35
|
end)
|
@@ -34,13 +34,14 @@ module Asciidoctor
|
|
34
34
|
# - :final_gap determines whether a gap is added below the last line
|
35
35
|
LineMetrics = ::Struct.new :height, :leading, :padding_top, :padding_bottom, :final_gap
|
36
36
|
|
37
|
-
Position = ::Struct.new :page, :cursor
|
37
|
+
Position = ::Struct.new :page, :column, :cursor
|
38
38
|
|
39
39
|
Extent = ::Struct.new :current, :from, :to do
|
40
|
-
def initialize current_page, current_cursor,
|
41
|
-
self.
|
42
|
-
self.from = Position.new
|
43
|
-
self.
|
40
|
+
def initialize current_page, current_column, current_cursor, from_page, from_column, from_cursor, to_page, to_cursor
|
41
|
+
self.current = Position.new current_page, current_column, current_cursor
|
42
|
+
self.from = Position.new from_page, from_column, from_cursor
|
43
|
+
self.from = current if from == current
|
44
|
+
self.to = Position.new to_page, nil, to_cursor
|
44
45
|
end
|
45
46
|
|
46
47
|
def each_page
|
@@ -64,23 +65,23 @@ module Asciidoctor
|
|
64
65
|
|
65
66
|
ScratchExtent = ::Struct.new :from, :to do
|
66
67
|
def initialize start_page, start_cursor, end_page, end_cursor
|
67
|
-
self.from = Position.new start_page, start_cursor
|
68
|
-
self.to = Position.new end_page, end_cursor
|
68
|
+
self.from = Position.new start_page, 0, start_cursor
|
69
|
+
self.to = Position.new end_page, 0, end_cursor
|
69
70
|
end
|
70
71
|
|
71
72
|
def position_onto pdf, keep_together = nil
|
72
73
|
current_page = pdf.page_number
|
74
|
+
current_column = ColumnBox === pdf.bounds ? (column_box = pdf.bounds).current_column : 0
|
73
75
|
current_cursor = pdf.cursor
|
74
|
-
|
75
|
-
to_page = current_page + (to.page - 1)
|
76
|
-
if advance_by > 0
|
76
|
+
if (advance_by = from.page - 1) > 0
|
77
77
|
advance_by.times { pdf.advance_page }
|
78
78
|
elsif keep_together && single_page? && !(try_to_fit_on_previous current_cursor)
|
79
79
|
pdf.advance_page
|
80
|
-
from_page += 1
|
81
|
-
to_page += 1
|
82
80
|
end
|
83
|
-
|
81
|
+
from_page = pdf.page_number
|
82
|
+
from_column = column_box&.current_column || 0
|
83
|
+
to_page = from_page + (to.page - from.page)
|
84
|
+
Extent.new current_page, current_column, current_cursor, from_page, from_column, from.cursor, to_page, to.cursor
|
84
85
|
end
|
85
86
|
|
86
87
|
def single_page?
|
@@ -251,16 +252,17 @@ module Asciidoctor
|
|
251
252
|
# Returns whether the cursor is at the top of the page (i.e., margin box).
|
252
253
|
#
|
253
254
|
def at_page_top?
|
254
|
-
@y == @margin_box.absolute_top
|
255
|
+
@y == (ColumnBox === bounds ? bounds : @margin_box).absolute_top
|
255
256
|
end
|
256
257
|
|
257
258
|
# Prevents at_page_top? from returning true while yielding to the specified block.
|
258
259
|
#
|
259
260
|
def conceal_page_top
|
260
|
-
|
261
|
+
old_top = (outer_bounds = ColumnBox === bounds ? bounds : @margin_box).absolute_top
|
262
|
+
outer_bounds.instance_variable_set :@y, old_top + 0.0001
|
261
263
|
yield
|
262
264
|
ensure
|
263
|
-
|
265
|
+
outer_bounds.instance_variable_set :@y, old_top
|
264
266
|
end
|
265
267
|
|
266
268
|
# Returns whether the current page is the last page in the document.
|
@@ -560,11 +562,11 @@ module Asciidoctor
|
|
560
562
|
def float
|
561
563
|
original_page_number = page_number
|
562
564
|
original_y = y
|
563
|
-
original_column = bounds.
|
565
|
+
original_column = bounds.current_column if ColumnBox === bounds
|
564
566
|
yield
|
565
567
|
go_to_page original_page_number unless page_number == original_page_number
|
566
568
|
self.y = original_y
|
567
|
-
bounds.
|
569
|
+
bounds.current_column = original_column if original_column
|
568
570
|
end
|
569
571
|
|
570
572
|
# Short-circuits the call to the built-in move_up operation
|
@@ -721,6 +723,12 @@ module Asciidoctor
|
|
721
723
|
end
|
722
724
|
end
|
723
725
|
|
726
|
+
# Wraps the column_box method and automatically sets the height unless the :height option is specified.
|
727
|
+
def column_box point, options, &block
|
728
|
+
options[:height] = cursor unless options.key? :height
|
729
|
+
super
|
730
|
+
end
|
731
|
+
|
724
732
|
# A flowing version of bounding_box. If the content runs to another page, the cursor starts at
|
725
733
|
# the top of the page instead of from the original cursor position. Similar to span, except
|
726
734
|
# the :position option is limited to a numeric value and additional options are passed through
|
@@ -965,11 +973,11 @@ module Asciidoctor
|
|
965
973
|
state.on_page_create_callback = saved_callback
|
966
974
|
end
|
967
975
|
|
968
|
-
# This method is a smarter version of start_new_page. It calls start_new_page
|
969
|
-
#
|
970
|
-
#
|
976
|
+
# This method is a smarter version of start_new_page. It only calls start_new_page options are
|
977
|
+
# specified and the current page is the last page in the document. Otherwise, it advances the
|
978
|
+
# cursor to the next page (or column) using Bounds#move_past_bottom.
|
971
979
|
def advance_page options = {}
|
972
|
-
|
980
|
+
options.empty? || !last_page? ? bounds.move_past_bottom : (start_new_page options)
|
973
981
|
end
|
974
982
|
|
975
983
|
# Start a new page without triggering the on_page_create callback
|
@@ -1129,15 +1137,15 @@ module Asciidoctor
|
|
1129
1137
|
# Note that if the block has content that itself requires a dry run, that nested dry run will
|
1130
1138
|
# be performed in a separate scratch document.
|
1131
1139
|
#
|
1132
|
-
#
|
1133
|
-
#
|
1134
|
-
#
|
1135
|
-
#
|
1136
|
-
#
|
1137
|
-
#
|
1138
|
-
#
|
1139
|
-
#
|
1140
|
-
#
|
1140
|
+
# options - A Hash of options that configure the dry run computation:
|
1141
|
+
# :keep_together - A Boolean indicating whether an attempt should be made to keep
|
1142
|
+
# the content on the same page (optional, default: false).
|
1143
|
+
# :single_page - A Boolean indicating whether the operation should stop if the
|
1144
|
+
# content exceeds the height of a single page.
|
1145
|
+
# :onto - The document onto which to position the scratch extent. If this option is
|
1146
|
+
# set, the method returns an Extent instance (optional, default: false)
|
1147
|
+
# :pages_advanced - The number of pages the content has been advanced during this
|
1148
|
+
# operation (internal only) (optional, default: 0)
|
1141
1149
|
#
|
1142
1150
|
# Returns an Extent or ScratchExtent object that describes the bounds of the content block.
|
1143
1151
|
def dry_run keep_together: nil, pages_advanced: 0, single_page: nil, onto: nil, &block
|
@@ -1146,10 +1154,7 @@ module Asciidoctor
|
|
1146
1154
|
scratch_pdf.bounds = bounds.dup.tap do |bounds_copy|
|
1147
1155
|
bounds_copy.instance_variable_set :@document, scratch_pdf
|
1148
1156
|
bounds_copy.instance_variable_set :@parent, saved_bounds
|
1149
|
-
if ColumnBox === bounds_copy
|
1150
|
-
bounds_copy.instance_variable_set :@width, bounds_copy.bare_column_width
|
1151
|
-
bounds_copy.instance_variable_set :@current_column, (bounds_copy.instance_variable_set :@columns, 1) - 1
|
1152
|
-
end
|
1157
|
+
bounds_copy.single_file if ColumnBox === bounds_copy
|
1153
1158
|
end
|
1154
1159
|
scratch_pdf.move_cursor_to cursor unless (scratch_start_at_top = keep_together || pages_advanced > 0 || at_page_top?)
|
1155
1160
|
scratch_start_cursor = scratch_pdf.cursor
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FormattedString < String
|
4
|
+
attr_reader :fragments
|
5
|
+
|
6
|
+
def initialize fragments
|
7
|
+
super [].tap {|accum| (@fragments = fragments).each {|it| accum << it[:text] } }.join
|
8
|
+
end
|
9
|
+
|
10
|
+
def eql? other
|
11
|
+
super && (FormattedString === other ? (@fragments ||= nil) == other.fragments : true)
|
12
|
+
end
|
13
|
+
end
|
@@ -51,6 +51,9 @@ module Asciidoctor::PDF::FormattedText
|
|
51
51
|
image_format = fragment[:image_format]
|
52
52
|
if (image_w = fragment[:image_width] || '100%') == 'auto'
|
53
53
|
image_w = nil # use intrinsic width
|
54
|
+
elsif image_w.start_with? 'auto*'
|
55
|
+
image_scale = (image_w.slice 5, image_w.length).to_f
|
56
|
+
image_w = nil # use intrinsic width
|
54
57
|
elsif (pctidx = image_w.index '%') && pctidx + 1 < image_w.length
|
55
58
|
# NOTE: intrinsic width is stored behind % symbol
|
56
59
|
pct = (image_w.slice 0, pctidx).to_f / 100
|
@@ -79,6 +82,7 @@ module Asciidoctor::PDF::FormattedText
|
|
79
82
|
image_w = svg_size.output_width
|
80
83
|
else
|
81
84
|
fragment[:image_width] = (image_w = svg_size.output_width).to_s
|
85
|
+
image_w *= image_scale if image_scale
|
82
86
|
image_w = available_w if image_w > available_w
|
83
87
|
end
|
84
88
|
fragment[:image_obj] = svg_obj
|
@@ -88,6 +92,7 @@ module Asciidoctor::PDF::FormattedText
|
|
88
92
|
image_obj, image_info = ::File.open(image_path, 'rb') {|fd| doc.build_image_object fd }
|
89
93
|
unless image_w
|
90
94
|
fragment[:image_width] = (image_w = to_pt image_info.width, :px).to_s
|
95
|
+
image_w *= image_scale if image_scale
|
91
96
|
image_w = available_w if image_w > available_w
|
92
97
|
end
|
93
98
|
if (image_h = image_w * (image_info.height.fdiv image_info.width)) > max_image_h
|
@@ -25,11 +25,11 @@ module Asciidoctor::PDF::FormattedText
|
|
25
25
|
width = fragment.width
|
26
26
|
height = fragment.height
|
27
27
|
end
|
28
|
-
border_radius = data[:border_radius]
|
28
|
+
border_radius = data[:border_radius] || 0
|
29
29
|
if (background_color = data[:background_color])
|
30
30
|
prev_fill_color = pdf.fill_color
|
31
31
|
pdf.fill_color background_color
|
32
|
-
if border_radius
|
32
|
+
if border_radius > 0
|
33
33
|
pdf.fill_rounded_rectangle at, width, height, border_radius
|
34
34
|
else
|
35
35
|
pdf.fill_rectangle at, width, height
|
@@ -41,7 +41,7 @@ module Asciidoctor::PDF::FormattedText
|
|
41
41
|
prev_line_width = pdf.line_width
|
42
42
|
pdf.stroke_color border_color
|
43
43
|
pdf.line_width border_width
|
44
|
-
border_radius ? (pdf.stroke_rounded_rectangle at, width, height, border_radius) : (pdf.stroke_rectangle at, width, height)
|
44
|
+
border_radius > 0 ? (pdf.stroke_rounded_rectangle at, width, height, border_radius) : (pdf.stroke_rectangle at, width, height)
|
45
45
|
pdf.stroke_color prev_stroke_color
|
46
46
|
pdf.line_width prev_line_width
|
47
47
|
end
|
@@ -102,6 +102,9 @@ module Asciidoctor
|
|
102
102
|
role, key = (key.slice 5, key.length).split '_', 2
|
103
103
|
if (prop = ThemeKeyToFragmentProperty[key])
|
104
104
|
(accum[role] ||= {})[prop] = val
|
105
|
+
if key == 'border_width' && val && !(theme[%(role_#{role}_border_color)])
|
106
|
+
accum[role][:border_color] = theme.base_border_color
|
107
|
+
end
|
105
108
|
#elsif key == 'font_kerning'
|
106
109
|
# unless (resolved_val = val == 'none' ? false : (val == 'normal' ? true : nil)).nil?
|
107
110
|
# (accum[role] ||= {})[:kerning] = resolved_val
|
@@ -69,7 +69,7 @@ module Asciidoctor
|
|
69
69
|
# NOTE: base theme is loaded "as is" (no post-processing)
|
70
70
|
def self.load_base_theme
|
71
71
|
::File.open BaseThemePath, mode: 'r:UTF-8' do |io|
|
72
|
-
(::OpenStruct.new ::YAML.safe_load io,
|
72
|
+
(::OpenStruct.new ::YAML.safe_load io, filename: BaseThemePath).tap {|theme| theme.__dir__ = ThemesDir }
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
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: 2.
|
4
|
+
version: 2.1.1
|
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: 2022-06-
|
12
|
+
date: 2022-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: asciidoctor
|
@@ -286,6 +286,7 @@ files:
|
|
286
286
|
- lib/asciidoctor/pdf/ext/rouge.rb
|
287
287
|
- lib/asciidoctor/pdf/ext/rouge/formatters/prawn.rb
|
288
288
|
- lib/asciidoctor/pdf/ext/rouge/themes/asciidoctor_pdf_default.rb
|
289
|
+
- lib/asciidoctor/pdf/formatted_string.rb
|
289
290
|
- lib/asciidoctor/pdf/formatted_text.rb
|
290
291
|
- lib/asciidoctor/pdf/formatted_text/formatter.rb
|
291
292
|
- lib/asciidoctor/pdf/formatted_text/fragment_position_renderer.rb
|