pdf_margins 0.2.1 → 0.2.2
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/pdf/margins/checker.rb +19 -15
- data/lib/pdf/margins/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 619d5757d93a4628032b0b08bde7c113ff018e09
|
4
|
+
data.tar.gz: 6eb31f07027078ab0781ff5d1af86feb80cc953a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3abcdd54d6ea558cb1bef046e0f8fbb3ea30cd32ec05aecf25779d9e3be6907827dbc6f58adfce17a27e2b0c3901273e19000d240d3816795375673edfecc429
|
7
|
+
data.tar.gz: 3a2d41ebb1c00dff9953dbba82ef3de1c81a3c68bf8bc4a2cb547ba04a0b43c81ac11c52df931c24118a9841764958df01f0ef0df702bfa5ef9b2c600f52ad2b
|
data/lib/pdf/margins/checker.rb
CHANGED
@@ -77,41 +77,45 @@ module PDF
|
|
77
77
|
|
78
78
|
def dirty_top_margin?(image, mm)
|
79
79
|
px = mm_to_pixels(mm)
|
80
|
-
|
81
|
-
dirty_pixels?(image, 0, px-1, 0, image.width-1)
|
80
|
+
dirty_pixels?(image, 0, 0, image.width, px)
|
82
81
|
end
|
83
82
|
|
84
83
|
def dirty_left_margin?(image, mm)
|
85
84
|
px = mm_to_pixels(mm)
|
86
|
-
|
87
|
-
dirty_pixels?(image, 0, image.height-1, 0, px-1)
|
85
|
+
dirty_pixels?(image, 0, 0, px, image.height)
|
88
86
|
end
|
89
87
|
|
90
88
|
def dirty_right_margin?(image, mm)
|
91
89
|
px = mm_to_pixels(mm)
|
92
|
-
return false if px.zero?
|
93
90
|
offset = image.width - px - 1
|
94
|
-
dirty_pixels?(image,
|
91
|
+
dirty_pixels?(image, offset, 0, px, image.height)
|
95
92
|
end
|
96
93
|
|
97
94
|
def dirty_bottom_margin?(image, mm)
|
98
95
|
px = mm_to_pixels(mm)
|
99
|
-
return false if px.zero?
|
100
96
|
offset = image.height - px - 1
|
101
|
-
dirty_pixels?(image, offset, image.
|
97
|
+
dirty_pixels?(image, 0, offset, image.width, px)
|
102
98
|
end
|
103
99
|
|
104
|
-
def dirty_pixels?(image,
|
105
|
-
rows = (row_start..row_end).to_a
|
106
|
-
columns = (column_start..column_end).to_a
|
107
|
-
|
100
|
+
def dirty_pixels?(image, x, y, width, height)
|
108
101
|
white = ChunkyPNG::Color::WHITE
|
102
|
+
found_dirty_pixel = false
|
103
|
+
|
104
|
+
width.times do |x_offset|
|
105
|
+
break if found_dirty_pixel
|
106
|
+
|
107
|
+
height.times do |y_offset|
|
108
|
+
x_position = x + x_offset
|
109
|
+
y_position = y + y_offset
|
109
110
|
|
110
|
-
|
111
|
-
|
112
|
-
|
111
|
+
if image[x_position, y_position] != white
|
112
|
+
found_dirty_pixel = true
|
113
|
+
break
|
114
|
+
end
|
113
115
|
end
|
114
116
|
end
|
117
|
+
|
118
|
+
return found_dirty_pixel
|
115
119
|
end
|
116
120
|
|
117
121
|
end
|
data/lib/pdf/margins/version.rb
CHANGED