pdf_margins 0.2.0 → 0.2.1
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 +9 -1
- data/lib/pdf/margins/version.rb +1 -1
- data/test/checker_test.rb +10 -0
- data/test/pdfs/16-page-mini.pdf +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93ac8cfc2af90e3b2b6029e1da808127946bdff8
|
4
|
+
data.tar.gz: fdacb1fbf0720aba657351b072820ff220833880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b98d030553e32b3f719225347d5ff5b062aca530fcc91d811f85626c3cc806c4593d5c631b2ce77542a4ad26b6557649c0c5d17d049d77820abcabe298bb5ad6
|
7
|
+
data.tar.gz: 5bb64bddeee28f85607b75ddb6c5f606ad193b2da1551e7057c895008b2ba9c535a5973978874de573844ed6437cb04be8213485187eb18f8eea55c59f2e61b5
|
data/lib/pdf/margins/checker.rb
CHANGED
@@ -37,7 +37,11 @@ module PDF
|
|
37
37
|
|
38
38
|
issues = []
|
39
39
|
|
40
|
-
Dir.glob("#{temp_dir_path}/*.png")
|
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
|
data/lib/pdf/margins/version.rb
CHANGED
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.
|
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
|