pdf_margins 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93ac8cfc2af90e3b2b6029e1da808127946bdff8
4
- data.tar.gz: fdacb1fbf0720aba657351b072820ff220833880
3
+ metadata.gz: 619d5757d93a4628032b0b08bde7c113ff018e09
4
+ data.tar.gz: 6eb31f07027078ab0781ff5d1af86feb80cc953a
5
5
  SHA512:
6
- metadata.gz: b98d030553e32b3f719225347d5ff5b062aca530fcc91d811f85626c3cc806c4593d5c631b2ce77542a4ad26b6557649c0c5d17d049d77820abcabe298bb5ad6
7
- data.tar.gz: 5bb64bddeee28f85607b75ddb6c5f606ad193b2da1551e7057c895008b2ba9c535a5973978874de573844ed6437cb04be8213485187eb18f8eea55c59f2e61b5
6
+ metadata.gz: 3abcdd54d6ea558cb1bef046e0f8fbb3ea30cd32ec05aecf25779d9e3be6907827dbc6f58adfce17a27e2b0c3901273e19000d240d3816795375673edfecc429
7
+ data.tar.gz: 3a2d41ebb1c00dff9953dbba82ef3de1c81a3c68bf8bc4a2cb547ba04a0b43c81ac11c52df931c24118a9841764958df01f0ef0df702bfa5ef9b2c600f52ad2b
@@ -77,41 +77,45 @@ module PDF
77
77
 
78
78
  def dirty_top_margin?(image, mm)
79
79
  px = mm_to_pixels(mm)
80
- return false if px.zero?
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
- return false if px.zero?
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, 0, image.height-1, offset, image.width-1)
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.height-1, 0, image.width-1)
97
+ dirty_pixels?(image, 0, offset, image.width, px)
102
98
  end
103
99
 
104
- def dirty_pixels?(image, row_start, row_end, column_start, column_end)
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
- rows.any? do |row|
111
- columns.any? do |column|
112
- image[column, row] != white
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
@@ -1,5 +1,5 @@
1
1
  module PDF
2
2
  module Margins
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf_margins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Taylor