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 +4 -4
- data/lib/pdfrb/content/operators/inline_image.rb +6 -13
- data/lib/pdfrb/content/processor.rb +6 -0
- data/lib/pdfrb/layout/box_fitter.rb +35 -20
- data/lib/pdfrb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ebb3cb6d645dd2e4f01dbfdcfc49e51ed0857281fc996a38ddb29afb18aef4e7
|
|
4
|
+
data.tar.gz: 9b359396f34164f661bebece73f26dd92fc9ea804c8edd802e53d80c6fccb334
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
14
|
-
#
|
|
15
|
-
#
|
|
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(
|
|
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
|
-
|
|
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