pdf_margins 0.2.0 → 0.2.1

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: d41e2247fb4dead96b77524b5c4524bfc3802692
4
- data.tar.gz: 73d2bd7d01f22f3232716376e64ee52a63c81a20
3
+ metadata.gz: 93ac8cfc2af90e3b2b6029e1da808127946bdff8
4
+ data.tar.gz: fdacb1fbf0720aba657351b072820ff220833880
5
5
  SHA512:
6
- metadata.gz: 2231c4e3028feddc1b17ce1413d938518b27b11e14e84913683e90a1187c21b2ec47c91c1927116f063d11096d04822301b0c86fda17d3559b83cc3d2430e3b9
7
- data.tar.gz: 1fe63baac8954e2b26774d7aa644ffaab0754c936a64fffca2c1f0e7edd3158995cf98a0d77a118c61695eee1d1b770ff799d752332dcf99470ed4e7564c9627
6
+ metadata.gz: b98d030553e32b3f719225347d5ff5b062aca530fcc91d811f85626c3cc806c4593d5c631b2ce77542a4ad26b6557649c0c5d17d049d77820abcabe298bb5ad6
7
+ data.tar.gz: 5bb64bddeee28f85607b75ddb6c5f606ad193b2da1551e7057c895008b2ba9c535a5973978874de573844ed6437cb04be8213485187eb18f8eea55c59f2e61b5
@@ -37,7 +37,11 @@ module PDF
37
37
 
38
38
  issues = []
39
39
 
40
- Dir.glob("#{temp_dir_path}/*.png").each_with_index do |png_path, index|
40
+ files = Dir.glob("#{temp_dir_path}/*.png")
41
+ # ensure the files are sorted naturally
42
+ files = files.sort_by{ |f| f.split('/').last.to_i }
43
+
44
+ files.each_with_index do |png_path, index|
41
45
  image = ChunkyPNG::Image.from_file(png_path)
42
46
  page_number = index + 1
43
47
 
@@ -73,22 +77,26 @@ module PDF
73
77
 
74
78
  def dirty_top_margin?(image, mm)
75
79
  px = mm_to_pixels(mm)
80
+ return false if px.zero?
76
81
  dirty_pixels?(image, 0, px-1, 0, image.width-1)
77
82
  end
78
83
 
79
84
  def dirty_left_margin?(image, mm)
80
85
  px = mm_to_pixels(mm)
86
+ return false if px.zero?
81
87
  dirty_pixels?(image, 0, image.height-1, 0, px-1)
82
88
  end
83
89
 
84
90
  def dirty_right_margin?(image, mm)
85
91
  px = mm_to_pixels(mm)
92
+ return false if px.zero?
86
93
  offset = image.width - px - 1
87
94
  dirty_pixels?(image, 0, image.height-1, offset, image.width-1)
88
95
  end
89
96
 
90
97
  def dirty_bottom_margin?(image, mm)
91
98
  px = mm_to_pixels(mm)
99
+ return false if px.zero?
92
100
  offset = image.height - px - 1
93
101
  dirty_pixels?(image, offset, image.height-1, 0, image.width-1)
94
102
  end
@@ -1,5 +1,5 @@
1
1
  module PDF
2
2
  module Margins
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
data/test/checker_test.rb CHANGED
@@ -76,4 +76,14 @@ class CheckerTest < Test::Unit::TestCase
76
76
  ], checker.issues
77
77
  end
78
78
 
79
+ test "PDF with all dirty margins being checked as pages with a margin width of 0" do
80
+ checker = PDF::Margins::Checker.new(pdf_path('16-page-mini.pdf'), 0, 0, 0, 0, false)
81
+ assert_equal [], checker.issues
82
+ end
83
+
84
+ test "PDF with all dirty margins being checked as spreads with a margin width of 0" do
85
+ checker = PDF::Margins::Checker.new(pdf_path('16-page-mini.pdf'), 0, 0, 0, 0, true)
86
+ assert_equal [], checker.issues
87
+ end
88
+
79
89
  end
Binary file
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.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Taylor
@@ -80,6 +80,7 @@ files:
80
80
  - Rakefile
81
81
  - README.md
82
82
  - test/checker_test.rb
83
+ - test/pdfs/16-page-mini.pdf
83
84
  - test/pdfs/bottom-margin-only.pdf
84
85
  - test/pdfs/clear-margins-pages.pdf
85
86
  - test/pdfs/clear-margins-spreads.pdf
@@ -114,6 +115,7 @@ specification_version: 4
114
115
  summary: Simple library to checks whether the margins are clear in a PDF
115
116
  test_files:
116
117
  - test/checker_test.rb
118
+ - test/pdfs/16-page-mini.pdf
117
119
  - test/pdfs/bottom-margin-only.pdf
118
120
  - test/pdfs/clear-margins-pages.pdf
119
121
  - test/pdfs/clear-margins-spreads.pdf