pdfrb 0.7.12 → 0.7.13

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: 26e34e7b8d5b74f8a2f8a89b36b3ea7ae028b0cf8944707aeed0a3ddde8270fc
4
- data.tar.gz: 9bae4c50eff54052d0cc173559625fb0de3ff782bb567b9ac0bf7f85be951aea
3
+ metadata.gz: ebb3cb6d645dd2e4f01dbfdcfc49e51ed0857281fc996a38ddb29afb18aef4e7
4
+ data.tar.gz: 9b359396f34164f661bebece73f26dd92fc9ea804c8edd802e53d80c6fccb334
5
5
  SHA512:
6
- metadata.gz: 3c12a6ae1950e81e8bb5fc181dc35aa63fcb6c0671bf0ab9e3becc92b3ebbb28e2210eb0be966ca4cefb6baf97688b1e7ba8115629d08647493680f5f42c6588
7
- data.tar.gz: 87eb412507356b781a33f96f3d58aa6a14acb5284664091879c23c699e70bd3a2ee4e5f0dbd64c7958361544e1ecc3a23f71b00e2d95b3fe9f2805ab9ad441ed
6
+ metadata.gz: a3eb6c87f3e7b10fdb310669943b3f61cf206c10f3ad61a998673b83f94dc6aef3082a22ef8f56632dad2e75a858b39c7a969a0590779f8ae3b7320c6c78ff90
7
+ data.tar.gz: 9a1453e1556d9c968b3176aa207773e4083687441f7f8025941d82b4f34394a68fba1b3f7a386b4fb73743fb4770ca7c055276f28100b9686f40f6165eb69c76
@@ -10,10 +10,9 @@ module Pdfrb
10
10
  # needed, but the bytes live in the content stream so they
11
11
  # can't be reused.
12
12
  #
13
- # The serialise path emits the BI dict, ID marker, raw bytes,
14
- # and EI marker. The invoke path is intentionally a no-op; the
15
- # content Parser handles BI/ID/EI as a single bounded block
16
- # rather than via the operator dispatch table.
13
+ # The Parser detects BI ... ID ... EI and yields a single
14
+ # BeginInlineImage invocation with the parsed image Hash as
15
+ # the operand. The invoke hook calls Processor#inline_image.
17
16
  class BeginInlineImage < Base
18
17
  class << self
19
18
  def name; "BI"; end
@@ -27,7 +26,9 @@ module Pdfrb
27
26
  buf
28
27
  end
29
28
 
30
- def invoke(_processor, *_operands); end
29
+ def invoke(processor, image = nil)
30
+ processor.inline_image(image) if image
31
+ end
31
32
  register
32
33
  end
33
34
  end
@@ -36,14 +37,6 @@ module Pdfrb
36
37
  class << self
37
38
  def name; "EI"; end
38
39
 
39
- # The byte payload sits between ID and EI. The serializer
40
- # for inline images writes the payload directly via
41
- # Canvas#inline_image; this method is here so the registry
42
- # knows about EI.
43
- def serialize(_serializer, *_operands)
44
- "EI\n"
45
- end
46
-
47
40
  def invoke(_processor, *_operands); end
48
41
  register
49
42
  end
@@ -76,6 +76,12 @@ module Pdfrb
76
76
  def begin_marked_content(_tag, _properties = nil); end
77
77
  def end_marked_content; end
78
78
  def marked_content_point(_tag, _properties = nil); end
79
+
80
+ # Called when a BI/ID/EI inline image is encountered in the
81
+ # content stream. +image+ is a Hash with :header (the image
82
+ # dict keys, expanded from abbreviations) and :data (the raw
83
+ # byte payload). Subclasses override to render or extract.
84
+ def inline_image(_image); end
79
85
  end
80
86
  end
81
87
  end
@@ -3,7 +3,9 @@
3
3
  module Pdfrb
4
4
  module Layout
5
5
  # Fits an ordered list of boxes into a Frame, flowing to a new
6
- # Frame (provided by a block) when one fills up.
6
+ # Frame (provided by a block) when one fills up. Delegates area
7
+ # tracking to the Frame (which now properly tracks removed areas
8
+ # and returns non-overlapping positions).
7
9
  class BoxFitter
8
10
  attr_reader :boxes, :frame, :result, :overflow
9
11
 
@@ -16,26 +18,8 @@ module Pdfrb
16
18
 
17
19
  def fit
18
20
  current_frame = @frame
19
- cursor_y = current_frame.top
20
21
  @boxes.each do |box|
21
- loop do
22
- position = current_frame.find_available_area(box.width || current_frame.width, box.height || (cursor_y - current_frame.bottom))
23
- if position && box.fit?(position[2] || current_frame.width, position[3] || (cursor_y - current_frame.bottom))
24
- @result << [box, position]
25
- current_frame.remove_area(position[0], position[1] - box.height, box.width, box.height)
26
- cursor_y = position[1] - box.height
27
- break
28
- else
29
- next_frame = yield if block_given?
30
- if next_frame
31
- current_frame = next_frame
32
- cursor_y = current_frame.top
33
- else
34
- @overflow << box
35
- break
36
- end
37
- end
38
- end
22
+ current_frame = fit_box(box, current_frame)
39
23
  end
40
24
  self
41
25
  end
@@ -49,6 +33,37 @@ module Pdfrb
49
33
  def fit_complete?
50
34
  @overflow.empty?
51
35
  end
36
+
37
+ private
38
+
39
+ def fit_box(box, frame)
40
+ loop do
41
+ return frame if place?(box, frame)
42
+
43
+ next_frame = yield if block_given?
44
+ unless next_frame
45
+ @overflow << box
46
+ return frame
47
+ end
48
+
49
+ frame = next_frame
50
+ end
51
+ end
52
+
53
+ def place?(box, frame)
54
+ box_w = box.width || frame.width
55
+ box_h = box.height || frame.available_height
56
+ position = frame.find_available_area(box_w, box_h)
57
+ return false unless position
58
+
59
+ actual_w = position[2] || frame.width
60
+ actual_h = position[3] || frame.available_height
61
+ return false unless box.fit?(actual_w, actual_h)
62
+
63
+ @result << [box, position]
64
+ frame.remove_area(position[0], position[1], actual_w, box.height || actual_h)
65
+ true
66
+ end
52
67
  end
53
68
  end
54
69
  end
data/lib/pdfrb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pdfrb
4
- VERSION = "0.7.12"
4
+ VERSION = "0.7.13"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.12
4
+ version: 0.7.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.