gamba 4.2.0 → 4.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 416eabb781116e0c1200b9d205f0dce7097fe40d354a2a912f77c43d0a59fbce
4
- data.tar.gz: 5109eb51bc7227c6345d81b320fe3beb2a2b680c3ed286c821e760bc5589254e
3
+ metadata.gz: feaec5a34c9127ac470cecb23df57f2c2aedb85ec88510458c64c681902edc69
4
+ data.tar.gz: 1c53b588d8793d07ba81ff203b1a534a6ddbc2f23233b663c2b4ffa83d619118
5
5
  SHA512:
6
- metadata.gz: 18ebb380ad100426f618c52491fd62cbc120cf5d83a696c09a8d9dd244ca4a8b7536219736723d75c9fff7648fb2b33c7ffe9d30dc039ad94cf2b55f7fe3c301
7
- data.tar.gz: d42da2d8e6b4980d1b126ee7c52c9d0f8514ccb58c9cb8c09eced898260215663ae41c0ecc741669c20ad9d04c165fcc859b9c8117341c439e039bdf8732e1f9
6
+ metadata.gz: cd1b6ef9411ca35ef0b825c757f7a4416f49217ec21ce137434a26e6e8553e0e03893afce913c4e15fc16f2f859b1c0585ed3ca12fe3af75386f37d2b5a0b23c
7
+ data.tar.gz: 406e6bb968ac4c5d1bb1c3f7785a4d0353ce7f6a4064ac41bd56a16f643e8b42e2d213555ac084b38418a1c1d4aa59ca09d0ea89ba2eb90a003558f3da19949c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [4.3.0] — 2026-12-03
6
+
7
+ A list that runs over several pages keeps its title on each of them.
8
+
9
+ **New**
10
+ - `stack(header: true)` draws the stack's first box again at the top of each page the stack goes on to, as a table does its header row, with the stack's `gap` below it. The header goes to the next page with the start of what follows it; in a tagged document its copies are artifacts and its headings are bookmarked once. A header leaving no room under it raises `CannotFit`.
11
+
5
12
  ## [4.2.0] — 2026-12-03
6
13
 
7
14
  A native document lays out, styles and draws without reaching for `document.prawn`: no more text measured by hand, and nothing drawn that PDF/UA refuses.
@@ -308,7 +315,8 @@ speed. Same API and same pages as Prawn, pixel for pixel, in lighter files.
308
315
  place of combine_pdf.
309
316
  - `Gamba::VERSION` is the gem's; `Prawn::VERSION` stays 2.5.0, the API reproduced.
310
317
 
311
- [Unreleased]: https://github.com/levups/gamba/compare/v4.2.0...HEAD
318
+ [Unreleased]: https://github.com/levups/gamba/compare/v4.3.0...HEAD
319
+ [4.3.0]: https://github.com/levups/gamba/compare/v4.2.0...v4.3.0
312
320
  [4.2.0]: https://github.com/levups/gamba/compare/v4.1.1...v4.2.0
313
321
  [4.1.1]: https://github.com/levups/gamba/compare/v4.1.0...v4.1.1
314
322
  [4.1.0]: https://github.com/levups/gamba/compare/v4.0.0...v4.1.0
data/README.md CHANGED
@@ -111,7 +111,8 @@ document.table(lines, columns: {sku: {title: "SKU", width: 60}, description: {},
111
111
  ```
112
112
 
113
113
  Pages break where a reader expects them: a paragraph leaves no single line at the bottom or the top of a page
114
- (`widows` and `orphans`, 2 unless told), and a heading with `keep_with_next: true` moves with what follows it.
114
+ (`widows` and `orphans`, 2 unless told), a heading with `keep_with_next: true` moves with what follows it, and a
115
+ stack with `header: true` draws its first box again at the top of each page it goes on to.
115
116
 
116
117
  Text, styles, components, stacks, rows, grids, tables, images, SVGs, codes, headers, footers, these page breaks
117
118
  and semantic roles are there today; forms, signatures and complex scripts come next
@@ -3,16 +3,12 @@
3
3
  module Gamba
4
4
  module PDF::Core
5
5
  module Annotations
6
- # Tagged documents would need each annotation in the structure tree, which Gamba does not write yet.
6
+ # A tagged document takes only the links of a text's words, each in the structure tree with its words.
7
7
  def annotate(options)
8
- if tagged?
9
- raise tagging_violation, "#{tagging_standard} tags annotations and links, which Gamba does not do yet: leave them out"
10
- end
11
-
12
8
  options = options.merge(Type: :Annot)
13
9
  options[:F] ||= Gamba::PdfA::PRINT_FLAG if pdf_a?
14
10
  options[:Dest] = PDF::Core::LiteralString.new(options[:Dest]) if options[:Dest].is_a?(String)
15
- (page.dictionary.data[:Annots] ||= []) << ref!(options)
11
+ tag_annotation(options) { add_annotation(options) }
16
12
  options
17
13
  end
18
14
 
@@ -23,6 +19,12 @@ module Gamba
23
19
  def link_annotation(rect, options = {})
24
20
  annotate(options.merge(Subtype: :Link, Rect: rect))
25
21
  end
22
+
23
+ private
24
+
25
+ def add_annotation(options)
26
+ ref!(options).tap { (page.dictionary.data[:Annots] ||= []) << _1 }
27
+ end
26
28
  end
27
29
  end
28
30
  end
@@ -67,21 +67,14 @@ module Gamba
67
67
  end
68
68
  end
69
69
 
70
- # The bounds of a stack with a background or a border while it flows across pages: its padding kept clear at
71
- # the top and the bottom of each page, its decoration drawn on each page beneath what that page holds of it,
72
- # as CSS's box-decoration-break: clone does. Text and tables break pages through these bounds, so each break
73
- # closes the stack's part on one page and opens it on the next.
74
- class DecoratedBounds < Prawn::Document::BoundingBox
75
- def initialize(prawn, stack, left, width, padding_top, padding_bottom)
70
+ # The bounds a stack's children flow in across pages, within those of what holds the stack. Text and tables
71
+ # break pages through them, so a stack sees every break of its children, however deep.
72
+ class FlowingBounds < Prawn::Document::BoundingBox
73
+ def initialize(prawn)
76
74
  parent = prawn.bounds
77
75
  super(prawn, parent, [parent.absolute_left, parent.absolute_top], width: parent.width, height: 0)
78
76
  # The margin box is made anew on each page: bounds within it follow the current one.
79
77
  @within_margins = parent.equal?(prawn.margin_box)
80
- @stack = stack
81
- @left = left
82
- @box_width = width
83
- @padding_top = padding_top
84
- @padding_bottom = padding_bottom
85
78
  end
86
79
 
87
80
  def outer
@@ -96,12 +89,8 @@ module Gamba
96
89
  outer.width - total_left_padding - total_right_padding
97
90
  end
98
91
 
99
- def absolute_top
100
- outer.absolute_top - @padding_top
101
- end
102
-
103
92
  def absolute_bottom
104
- outer_bottom + @padding_bottom
93
+ outer_bottom
105
94
  end
106
95
 
107
96
  def height
@@ -112,6 +101,73 @@ module Gamba
112
101
  false
113
102
  end
114
103
 
104
+ private
105
+
106
+ def outer_bottom
107
+ outer.stretchy? ? @document.margin_box.absolute_bottom : outer.absolute_bottom
108
+ end
109
+ end
110
+
111
+ # The bounds of a stack's children after its header: each page they go on to starts with the header drawn
112
+ # again, as an artifact, and they flow on below it, as a table's rows do below its header row.
113
+ class HeaderBounds < FlowingBounds
114
+ def initialize(prawn, header, left, width, gap, bookmarks)
115
+ super(prawn)
116
+ @header = header
117
+ @left = left
118
+ @header_width = width
119
+ @header_height = header.height(prawn, width) + gap
120
+ @bookmarks = bookmarks
121
+ end
122
+
123
+ def absolute_top
124
+ outer.absolute_top - @header_height
125
+ end
126
+
127
+ def move_past_bottom
128
+ outer.move_past_bottom
129
+ @document.tag_artifact(:Pagination, :Header) do
130
+ @document.save_graphics_state { paint_header }
131
+ end
132
+ @document.y = absolute_top
133
+ end
134
+
135
+ private
136
+
137
+ # Its headings are in the outline once, where the stack starts.
138
+ def paint_header
139
+ return draw_header unless @bookmarks
140
+
141
+ @bookmarks.paused { draw_header }
142
+ end
143
+
144
+ def draw_header
145
+ @header.paint(@document, @left, outer.absolute_top, @header_width)
146
+ end
147
+ end
148
+
149
+ # The bounds of a stack with a background or a border while it flows across pages: its padding kept clear at
150
+ # the top and the bottom of each page, its decoration drawn on each page beneath what that page holds of it,
151
+ # as CSS's box-decoration-break: clone does. Each break closes the stack's part on one page and opens it on the
152
+ # next.
153
+ class DecoratedBounds < FlowingBounds
154
+ def initialize(prawn, stack, left, width, padding_top, padding_bottom)
155
+ super(prawn)
156
+ @stack = stack
157
+ @left = left
158
+ @box_width = width
159
+ @padding_top = padding_top
160
+ @padding_bottom = padding_bottom
161
+ end
162
+
163
+ def absolute_top
164
+ outer.absolute_top - @padding_top
165
+ end
166
+
167
+ def absolute_bottom
168
+ outer_bottom + @padding_bottom
169
+ end
170
+
115
171
  # The stack's part on this page reaches down to the bottom of what holds it, and its next part starts at the
116
172
  # top of the next page.
117
173
  def move_past_bottom
@@ -133,12 +189,6 @@ module Gamba
133
189
 
134
190
  @stack.decorate_beneath(@document, @offset, @graphic_state, @left, @top, @box_width, @top - bottom)
135
191
  end
136
-
137
- private
138
-
139
- def outer_bottom
140
- outer.stretchy? ? @document.margin_box.absolute_bottom : outer.absolute_bottom
141
- end
142
192
  end
143
193
 
144
194
  # A box. Its role says what it is to a reader, for tagged PDF: a heading of a level, a paragraph, a list and
@@ -1265,11 +1315,14 @@ module Gamba
1265
1315
  end
1266
1316
 
1267
1317
  class Stack < Container
1268
- OPTIONS = (Container::OPTIONS + %i[keep_together]).freeze
1318
+ OPTIONS = (Container::OPTIONS + %i[keep_together header]).freeze
1269
1319
 
1270
1320
  def initialize(styles, **options)
1271
1321
  Styles.check_options(options, OPTIONS)
1272
1322
  @keep_together = options.delete(:keep_together)
1323
+ @header = options.delete(:header) { false }
1324
+ raise ArgumentError, "header is #{@header.inspect}: give true to draw the first box again at the top of each page the stack goes on to" unless [true, false].include?(@header)
1325
+
1273
1326
  super
1274
1327
  end
1275
1328
 
@@ -1309,17 +1362,15 @@ module Gamba
1309
1362
  bounds.end_part(cursor.y)
1310
1363
  end
1311
1364
 
1312
- # A page can start with the top of this stack's first child, unless the stack moves as one box. A decorated
1313
- # stack keeps its padding clear on every page: its bottom padding comes with that start, and its children
1314
- # have that much less of a page.
1365
+ # A page can start with the top of this stack's first child, or with its header and the top of the child
1366
+ # after it, unless the stack moves as one box. A decorated stack keeps its padding clear on every page: its
1367
+ # bottom padding comes with that start, and its children have that much less of a page.
1315
1368
  def first_height(prawn, width, page_height)
1316
1369
  return height(prawn, width) if @children.empty? || moves_whole?(prawn, width, page_height)
1317
-
1318
- first = @children.first
1319
- return @padding_top + first.first_height(prawn, child_width(first, width), page_height) unless decorated?
1370
+ return @padding_top + opening_height(prawn, width, page_height) unless decorated?
1320
1371
 
1321
1372
  inner_page_height = page_height - @padding_top - @padding_bottom
1322
- @padding_top + first.first_height(prawn, child_width(first, width), inner_page_height) + @padding_bottom
1373
+ @padding_top + opening_height(prawn, width, inner_page_height) + @padding_bottom
1323
1374
  end
1324
1375
 
1325
1376
  # A stack given a height never breaks: higher than a page, it raises.
@@ -1329,16 +1380,30 @@ module Gamba
1329
1380
 
1330
1381
  private
1331
1382
 
1332
- # The first child opens its page when the stack does; another one when it starts the page, or when the child
1333
- # before is kept with it.
1383
+ def opening_height(prawn, width, page_height)
1384
+ first = @children.first
1385
+ return first.first_height(prawn, child_width(first, width), page_height) unless repeats_header?
1386
+
1387
+ header_height = first.height(prawn, child_width(first, width)) + @gap
1388
+ following = @children[1]
1389
+ header_height + following.first_height(prawn, child_width(following, width), page_height - header_height)
1390
+ end
1391
+
1392
+ # A header is drawn again only above children that follow it.
1393
+ def repeats_header?
1394
+ @header && @children.size > 1
1395
+ end
1396
+
1397
+ # After the header, the children flow within bounds that draw it again at the top of each page they go on to.
1334
1398
  def flow_children(prawn, cursor, left, width)
1335
1399
  opening = cursor.opening?
1336
1400
  cursor.y -= @padding_top
1337
- @children.each_with_index do |child, index|
1338
- cursor.y -= @gap unless index.zero? || cursor.at_page_top?
1339
- keep_with_what_follows(prawn, cursor, width, index)
1340
- cursor.opening = (index.zero? && opening) || (index.positive? && @children[index - 1].keep_with_next)
1341
- child.flow_tagged(prawn, cursor, left + @padding_left, child_width(child, width))
1401
+ if repeats_header?
1402
+ bounds = header_bounds(prawn, cursor, left, width)
1403
+ flow_child(prawn, cursor, left, width, 0, opening)
1404
+ cursor.within(bounds) { (1...@children.size).each { flow_child(prawn, cursor, left, width, _1, opening) } }
1405
+ else
1406
+ @children.each_index { flow_child(prawn, cursor, left, width, _1, opening) }
1342
1407
  end
1343
1408
  # The bottom padding of a plain stack ends with the page, so that a decorated stack holding it is not drawn
1344
1409
  # past the page. A decorated stack's own is kept clear on every page, and the gap below its last line ends
@@ -1351,16 +1416,46 @@ module Gamba
1351
1416
  end
1352
1417
  end
1353
1418
 
1419
+ # The first child opens its page when the stack does; another one when it starts the page, or when the child
1420
+ # before is kept with it.
1421
+ def flow_child(prawn, cursor, left, width, index, opening)
1422
+ child = @children[index]
1423
+ cursor.y -= @gap unless index.zero? || cursor.at_page_top?
1424
+ keep_with_what_follows(prawn, cursor, width, index)
1425
+ cursor.opening = (index.zero? && opening) || (index.positive? && kept_with_next?(index - 1))
1426
+ child.flow_tagged(prawn, cursor, left + @padding_left, child_width(child, width))
1427
+ end
1428
+
1429
+ # A header leaves room on a page for what follows it.
1430
+ def header_bounds(prawn, cursor, left, width)
1431
+ header = @children.first
1432
+ header_width = child_width(header, width)
1433
+ header_height = header.height(prawn, header_width) + @gap
1434
+ if header_height >= cursor.page_height
1435
+ raise Prawn::Errors::CannotFit, "page #{cursor.page_number}: a stack's header is #{header_height.to_f.round(1)} pt high with the gap " \
1436
+ "below it, the page has #{cursor.page_height.to_f.round(1)} pt: nothing would fit under it on the next pages"
1437
+ end
1438
+
1439
+ HeaderBounds.new(prawn, header, left + @padding_left, header_width, @gap, @styles.bookmarks)
1440
+ end
1441
+
1442
+ # A header is kept with the child after it: never alone at the bottom of a page.
1443
+ def kept_with_next?(index)
1444
+ @children[index].keep_with_next || (index.zero? && repeats_header?)
1445
+ end
1446
+
1354
1447
  # Children kept with the next go to the next page together with the start of the one after them, when this
1355
1448
  # page is too short for all of it and a page is not. One kept but higher than a page ends the chain: only its
1356
1449
  # start goes with them.
1357
1450
  def keep_with_what_follows(prawn, cursor, width, index)
1358
- return if cursor.at_page_top? || (index.positive? && @children[index - 1].keep_with_next)
1451
+ return if cursor.at_page_top? || (index.positive? && kept_with_next?(index - 1))
1359
1452
 
1360
1453
  page_height = cursor.page_height
1361
- kept = @children[index..].take_while do |child|
1362
- child.keep_with_next && !child.too_high_to_keep?(prawn, child_width(child, width), page_height)
1454
+ kept_indexes = (index...@children.size).take_while do |kept_index|
1455
+ child = @children[kept_index]
1456
+ kept_with_next?(kept_index) && !child.too_high_to_keep?(prawn, child_width(child, width), page_height)
1363
1457
  end
1458
+ kept = @children.values_at(*kept_indexes)
1364
1459
  following = @children[index + kept.size]
1365
1460
  return if kept.empty? || following.nil?
1366
1461
 
@@ -1515,7 +1610,7 @@ module Gamba
1515
1610
  # Cells in lines of `columns`: a stack of rows whose cells are all as wide, the last line's included. Pages
1516
1611
  # break between lines, never inside one. gap is one number, or [between lines, between columns].
1517
1612
  class Grid < Stack
1518
- OPTIONS = (Stack::OPTIONS + %i[columns]).freeze
1613
+ OPTIONS = (Stack::OPTIONS - %i[header] + %i[columns]).freeze
1519
1614
 
1520
1615
  def initialize(styles, columns:, gap: 0, **options)
1521
1616
  unless columns.is_a?(Integer) && columns.positive?
@@ -1728,6 +1823,8 @@ module Gamba
1728
1823
 
1729
1824
  # Prawn's outline adds after its current item: it is pointed at the parent, then back at the end of the root.
1730
1825
  def add(level, title, top)
1826
+ return if @paused
1827
+
1731
1828
  @open.pop while @open.any? && @open.last.first >= level
1732
1829
  outline = @prawn.outline
1733
1830
  root = @prawn.outlines_reference
@@ -1742,6 +1839,15 @@ module Gamba
1742
1839
  end
1743
1840
  @open << [level, parent.data.last]
1744
1841
  end
1842
+
1843
+ # The headings of what the block draws again, a stack's header on the pages it goes on to, are not added.
1844
+ def paused
1845
+ paused = @paused
1846
+ @paused = true
1847
+ yield
1848
+ ensure
1849
+ @paused = paused
1850
+ end
1745
1851
  end
1746
1852
 
1747
1853
  # Named text attributes, and what they come to for Prawn once a call's own are added.
@@ -1800,7 +1906,7 @@ module Gamba
1800
1906
  FONT_STYLES[((weight == :bold) ? 1 : 0) + (italic ? 2 : 0)]
1801
1907
  end
1802
1908
 
1803
- attr_reader :prawn
1909
+ attr_reader :prawn, :bookmarks
1804
1910
 
1805
1911
  # prawn_code: the document is Prawn's, with native blocks in it (Prawn::Document#gamba): what Prawn's code set,
1806
1912
  # its font and size, is where a native table starts from, as it did before the block.
data/lib/gamba/tagging.rb CHANGED
@@ -37,6 +37,25 @@ module Gamba
37
37
  end
38
38
  end
39
39
 
40
+ # The words of a link and the annotations that open it (ISO 14289-1 §7.18.5): a link wrapped over several lines
41
+ # is one element, each line's words and annotation in it. Its text describes each annotation, as /Contents.
42
+ class Link < Element
43
+ attr_reader :target, :words
44
+
45
+ def initialize(parent, target)
46
+ super(:Link, parent)
47
+ @target = target
48
+ @words = []
49
+ end
50
+
51
+ def text
52
+ @words.join(" ").split.join(" ")
53
+ end
54
+ end
55
+
56
+ # An annotation in the element of the link it opens, an OBJR kid of that element.
57
+ Annotation = Struct.new(:reference, :page)
58
+
40
59
  # A marked-content sequence: around an element's content, or an artifact when element is nil. page is the page
41
60
  # it is open on, nil once a page break closed it there: it opens again on the next page, when something is drawn.
42
61
  Mark = Struct.new(:element, :properties, :page)
@@ -136,8 +155,51 @@ module Gamba
136
155
  tag_artifact(&)
137
156
  end
138
157
 
158
+ # What the block draws, the words of a link to target, is the content of a Link element under the current
159
+ # element, the one drawn just before when it opens the same target: a link wrapped over several lines. The
160
+ # current element's sequences close around it, a marked-content sequence holding no other with an MCID, and
161
+ # open again with what is drawn after it.
162
+ def tag_link(target, words, &)
163
+ return yield unless tagged?
164
+
165
+ unless tagging_structure? && !@tagging.last.whole?
166
+ raise tagging_violation, "#{tagging_standard} reads each link with the content, and this one is in an " \
167
+ "artifact or a figure: draw it in a box of the content, or leave the link out (#{words.strip.inspect})"
168
+ end
169
+
170
+ link = continued_link(target) || Tagging::Link.new(@tagging.last, target)
171
+ link.words << words
172
+ close_marks_on_page
173
+ outer_marks = @marks
174
+ @marks = []
175
+ within_element(link) { within_mark(Tagging::Mark.new(link), &) }
176
+ ensure
177
+ @marks = outer_marks if outer_marks
178
+ end
179
+
180
+ # An annotation goes in the Link element whose words are being drawn: no other can be tagged yet.
181
+ def tag_annotation(options)
182
+ return yield unless tagged?
183
+
184
+ link = @marks.last&.element
185
+ unless options[:Subtype] == :Link && link.is_a?(Tagging::Link)
186
+ raise tagging_violation, "#{tagging_standard} tags the links of a text's words, and no other annotation " \
187
+ "yet: give a span a link, or leave the annotation out"
188
+ end
189
+
190
+ reference = yield
191
+ link.kids << Tagging::Annotation.new(reference, page)
192
+ (@tagged_annotations ||= []) << [reference, link, page]
193
+ reference
194
+ end
195
+
139
196
  private
140
197
 
198
+ def continued_link(target)
199
+ last = @tagging.last.kids.last
200
+ last if last.is_a?(Tagging::Link) && last.target == target
201
+ end
202
+
141
203
  def initialize_tagging(options)
142
204
  pdf = options.delete(:pdf)
143
205
  raise ArgumentError, "pdf is #{pdf.inspect}: :ua is the only conformance level, PDF/UA-1" unless [nil, false, :ua].include?(pdf)
@@ -294,6 +356,7 @@ module Gamba
294
356
  page.dictionary.data[:StructParents] = nums.size / 2
295
357
  nums << (nums.size / 2) << elements.map { references.fetch(_1) }
296
358
  end
359
+ finalize_annotations(nums, references, kept_pages)
297
360
  tree.data[:ParentTree] = (@parent_tree ||= ref!({})).tap { _1.data.replace(Nums: nums) }
298
361
  tree.data[:ParentTreeNextKey] = nums.size / 2
299
362
  @root.data[:StructTreeRoot] = tree
@@ -301,14 +364,30 @@ module Gamba
301
364
  @root.data[:ViewerPreferences] = {**(@root.data[:ViewerPreferences] || {}), DisplayDocTitle: true}
302
365
  end
303
366
 
367
+ # Each annotation maps back to its Link element, after the pages in the parent tree, and is described by the
368
+ # link's words. A page with annotations orders them as its structure does (ISO 14289-1 §7.18.3).
369
+ def finalize_annotations(nums, references, kept_pages)
370
+ @tagged_annotations&.each do |annotation, link, page|
371
+ next unless kept_pages[page]
372
+
373
+ annotation.data[:StructParent] = nums.size / 2
374
+ annotation.data[:Contents] = link.text.empty? ? link.target : link.text
375
+ nums << (nums.size / 2) << references.fetch(link)
376
+ page.dictionary.data[:Tabs] = :S
377
+ end
378
+ end
379
+
304
380
  def structure_reference(element, parent, references, kept_pages)
305
381
  reference = (references[element] ||= ref!({}))
306
382
  reference.data.replace(Type: :StructElem, S: element.type, P: parent, **element.attributes)
307
383
  reference.data[:K] = element.kids.filter_map do |kid|
308
- next structure_reference(kid, reference, references, kept_pages) if kid.is_a?(Tagging::Element)
309
-
310
- page, mcid = kid
311
- {Type: :MCR, Pg: page.dictionary, MCID: mcid} if kept_pages[page]
384
+ case kid
385
+ when Tagging::Element then structure_reference(kid, reference, references, kept_pages)
386
+ when Tagging::Annotation then {Type: :OBJR, Obj: kid.reference, Pg: kid.page.dictionary} if kept_pages[kid.page]
387
+ else
388
+ page, mcid = kid
389
+ {Type: :MCR, Pg: page.dictionary, MCID: mcid} if kept_pages[page]
390
+ end
312
391
  end
313
392
  reference
314
393
  end
@@ -151,6 +151,19 @@ module Gamba
151
151
  fragment.baseline = y
152
152
  return unless @inked
153
153
 
154
+ target = fragment.link || fragment.anchor || fragment.local
155
+ return ink_fragment(fragment, x, y, word_spacing) unless target
156
+
157
+ @document.tag_link(target, fragment.text) { ink_fragment(fragment, x, y, word_spacing) }
158
+ end
159
+
160
+ def valid_options
161
+ VALID_OPTIONS
162
+ end
163
+
164
+ private
165
+
166
+ def ink_fragment(fragment, x, y, word_spacing)
154
167
  fragment.callback_objects.each { |callback| callback.render_behind(fragment) if callback.respond_to?(:render_behind) }
155
168
  map_soft_hyphen(fragment) if @hyphenation
156
169
  @document.word_spacing(word_spacing) do
@@ -163,12 +176,6 @@ module Gamba
163
176
  draw_fragment_overlays(fragment)
164
177
  end
165
178
 
166
- def valid_options
167
- VALID_OPTIONS
168
- end
169
-
170
- private
171
-
172
179
  def with_text_settings(&)
173
180
  @document.save_font do
174
181
  @document.character_spacing(@character_spacing) do
data/lib/gamba/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamba
4
- VERSION = "4.2.0"
4
+ VERSION = "4.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamba
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Level UP Solutions