preflight 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v0.0.3 (7th April 2011)
2
+ - added some additional rules to the pdfx1a profile
3
+
1
4
  v0.0.2 (1st April 2011)
2
5
  * fix possible execption in MinPpi rule
3
6
 
data/README.rdoc CHANGED
@@ -45,7 +45,7 @@ and friends, but hopefully it'll get you most of the way with less stress.
45
45
  rule Preflight::Rules::DocumentId
46
46
  end
47
47
 
48
- preflight = MyPreflight
48
+ preflight = MyPreflight.new
49
49
 
50
50
  puts preflight.check("somefile.pdf").inspect
51
51
 
@@ -65,7 +65,7 @@ and friends, but hopefully it'll get you most of the way with less stress.
65
65
  rule Preflight::Rules::DocumentId
66
66
  end
67
67
 
68
- preflight = MyPreflight
68
+ preflight = MyPreflight.new
69
69
 
70
70
  puts preflight.check("somefile.pdf").inspect
71
71
 
data/lib/preflight.rb CHANGED
@@ -7,5 +7,5 @@ require 'preflight/rules'
7
7
  require 'preflight/profiles'
8
8
 
9
9
  module Preflight
10
- VERSION = "0.0.2"
10
+ VERSION = "0.0.3"
11
11
  end
@@ -81,7 +81,8 @@ module Preflight
81
81
 
82
82
  def hash_rules
83
83
  self.class.rules.select { |arr|
84
- arr.first.rule_type == :hash
84
+ meth = arr.first.instance_method(:messages)
85
+ meth && meth.arity == 1
85
86
  }.map { |arr|
86
87
  klass = arr[0]
87
88
  klass.new(*arr[1,10])
@@ -90,7 +91,8 @@ module Preflight
90
91
 
91
92
  def receiver_rules
92
93
  self.class.rules.select { |arr|
93
- arr.first.rule_type == :receiver
94
+ meth = arr.first.instance_method(:messages)
95
+ meth && meth.arity == 0
94
96
  }.map { |arr|
95
97
  klass = arr[0]
96
98
  klass.new(*arr[1,10])
@@ -15,10 +15,13 @@ module Preflight
15
15
  rule Preflight::Rules::CompressionAlgorithms, :CCITTFaxDecode, :DCTDecode, :FlateDecode, :RunLengthDecode
16
16
  rule Preflight::Rules::DocumentId
17
17
  rule Preflight::Rules::NoEncryption
18
+ rule Preflight::Rules::NoFilespecs
18
19
  rule Preflight::Rules::OnlyEmbeddedFonts
19
20
  rule Preflight::Rules::BoxNesting
20
21
  rule Preflight::Rules::MaxVersion, 1.4
21
22
  rule Preflight::Rules::PrintBoxes
23
+ rule Preflight::Rules::OutputIntentForPdfx
24
+ rule Preflight::Rules::PdfxOutputIntentHasKeys, :OutputConditionIdentifier, :Info
22
25
 
23
26
  end
24
27
  end
@@ -7,8 +7,11 @@ require 'preflight/rules/match_info_entries'
7
7
  require 'preflight/rules/max_version'
8
8
  require 'preflight/rules/min_ppi'
9
9
  require 'preflight/rules/no_encryption'
10
+ require 'preflight/rules/no_filespecs'
10
11
  require 'preflight/rules/no_font_subsets'
11
12
  require 'preflight/rules/no_proprietary_fonts'
12
13
  require 'preflight/rules/only_embedded_fonts'
14
+ require 'preflight/rules/output_intent_for_pdfx'
15
+ require 'preflight/rules/pdfx_output_intent_has_keys'
13
16
  require 'preflight/rules/print_boxes'
14
17
  require 'preflight/rules/root_has_keys'
@@ -14,10 +14,6 @@ module Preflight
14
14
  @page_num = 0
15
15
  end
16
16
 
17
- def self.rule_type
18
- :receiver
19
- end
20
-
21
17
  def begin_page(hash = {})
22
18
  @page_num += 1
23
19
 
@@ -11,10 +11,6 @@ module Preflight
11
11
  @algorithms = algorithms.flatten
12
12
  end
13
13
 
14
- def self.rule_type
15
- :hash
16
- end
17
-
18
14
  def messages(ohash)
19
15
  algorithms = banned_algorithms(ohash)
20
16
 
@@ -4,10 +4,6 @@ module Preflight
4
4
  module Rules
5
5
  class DocumentId
6
6
 
7
- def self.rule_type
8
- :hash
9
- end
10
-
11
7
  def messages(ohash)
12
8
  if ohash.trailer[:ID].nil?
13
9
  ["Document ID missing"]
@@ -10,10 +10,6 @@ module Preflight
10
10
  @keys = keys.flatten
11
11
  end
12
12
 
13
- def self.rule_type
14
- :hash
15
- end
16
-
17
13
  def messages(ohash)
18
14
  info = ohash.object(ohash.trailer[:Info])
19
15
  missing = @keys - info.keys
@@ -4,10 +4,6 @@ module Preflight
4
4
  module Rules
5
5
  class InfoSpecifiesTrapping
6
6
 
7
- def self.rule_type
8
- :hash
9
- end
10
-
11
7
  def messages(ohash)
12
8
  info = ohash.object(ohash.trailer[:Info])
13
9
 
@@ -8,10 +8,6 @@ module Preflight
8
8
  @matches = matches
9
9
  end
10
10
 
11
- def self.rule_type
12
- :hash
13
- end
14
-
15
11
  def messages(ohash)
16
12
  array = []
17
13
  info = ohash.object(ohash.trailer[:Info])
@@ -10,10 +10,6 @@ module Preflight
10
10
  @max_version = max_version.to_f
11
11
  end
12
12
 
13
- def self.rule_type
14
- :hash
15
- end
16
-
17
13
  def messages(ohash)
18
14
  if ohash.pdf_version > @max_version
19
15
  ["PDF version should be #{@max_version} or lower (value: #{ohash.pdf_version})"]
@@ -18,10 +18,6 @@ module Preflight
18
18
  @page_num = 0
19
19
  end
20
20
 
21
- def self.rule_type
22
- :receiver
23
- end
24
-
25
21
  # store sample width and height for each image on the current page
26
22
  #
27
23
  def resource_xobject(label, stream)
@@ -4,10 +4,6 @@ module Preflight
4
4
  module Rules
5
5
  class NoEncryption
6
6
 
7
- def self.rule_type
8
- :hash
9
- end
10
-
11
7
  def messages(ohash)
12
8
  if ohash.trailer[:Encrypt]
13
9
  ["File is encrypted"]
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ module Preflight
4
+ module Rules
5
+
6
+ # PDF/X files are not allowed to use Filespecs to refer
7
+ # to external files.
8
+ #
9
+ class NoFilespecs
10
+
11
+ def messages(ohash)
12
+ if count_filespec_dicts(ohash) > 0
13
+ ["File uses at least 1 Filespec to refer to an external file"]
14
+ else
15
+ []
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def count_filespec_dicts(ohash)
22
+ ohash.select { |key, obj|
23
+ obj.is_a?(::Hash) && (obj[:Type] == :Filespec || obj[:Type] == :F)
24
+ }.size
25
+ end
26
+ end
27
+ end
28
+ end
@@ -9,10 +9,6 @@ module Preflight
9
9
  #
10
10
  class NoFontSubsets
11
11
 
12
- def self.rule_type
13
- :hash
14
- end
15
-
16
12
  def messages(ohash)
17
13
  array = []
18
14
  ohash.each do |key, obj|
@@ -10,10 +10,6 @@ module Preflight
10
10
  #
11
11
  class NoProprietaryFonts
12
12
 
13
- def self.rule_type
14
- :hash
15
- end
16
-
17
13
  def messages(ohash)
18
14
  array = []
19
15
  ohash.each do |key, obj|
@@ -7,10 +7,6 @@ module Preflight
7
7
  #
8
8
  class OnlyEmbeddedFonts
9
9
 
10
- def self.rule_type
11
- :hash
12
- end
13
-
14
10
  def messages(ohash)
15
11
  array = []
16
12
  ohash.each do |key, obj|
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ module Preflight
4
+ module Rules
5
+
6
+ class OutputIntentForPdfx
7
+
8
+ def messages(ohash)
9
+ intents = output_intents(ohash).select { |dict|
10
+ dict[:S] == :GTS_PDFX
11
+ }
12
+
13
+ if intents.size != 1
14
+ ["There must be exactly 1 OutputIntent with a subtype of GTS_PDFX"]
15
+ else
16
+ []
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def output_intents(ohash)
23
+ root = ohash.object(ohash.trailer[:Root])
24
+ intents = ohash.object(root[:OutputIntents])
25
+ intents || []
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+
3
+ module Preflight
4
+ module Rules
5
+
6
+ # All PDFX files MUST have a GTS_PDFX OutputIntent with certain keys
7
+ # GTS_PDFX OutputIntent.
8
+ #
9
+ # This doesn't raise an error if there is no GTS_PDFX, that's another
10
+ # rules job.
11
+ #
12
+ class PdfxOutputIntentHasKeys
13
+
14
+ def initialize(*keys)
15
+ @keys = keys.flatten
16
+ end
17
+
18
+ def messages(ohash)
19
+ oi = pdfx_output_intent(ohash)
20
+
21
+ return [] if oi.nil?
22
+
23
+ missing = @keys - oi.keys
24
+ missing.map { |key|
25
+ "The GTS_PDFX OutputIntent missing require key #{key}"
26
+ }
27
+ end
28
+
29
+ private
30
+
31
+ def pdfx_output_intent(ohash)
32
+ output_intents(ohash).map { |dict|
33
+ ohash.object(dict)
34
+ }.detect { |dict|
35
+ dict[:S] == :GTS_PDFX
36
+ }
37
+ end
38
+
39
+ def output_intents(ohash)
40
+ root = ohash.object(ohash.trailer[:Root])
41
+ intents = ohash.object(root[:OutputIntents])
42
+ intents || []
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -14,10 +14,6 @@ module Preflight
14
14
  @page_num = 0
15
15
  end
16
16
 
17
- def self.rule_type
18
- :receiver
19
- end
20
-
21
17
  def begin_page(hash = {})
22
18
  @page_num += 1
23
19
 
@@ -10,10 +10,6 @@ module Preflight
10
10
  @keys = keys.flatten
11
11
  end
12
12
 
13
- def self.rule_type
14
- :hash
15
- end
16
-
17
13
  def messages(ohash)
18
14
  root = ohash.object(ohash.trailer[:Root])
19
15
  missing = @keys - root.keys
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Healy
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-01 00:00:00 +11:00
17
+ date: 2011-04-07 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -87,6 +87,7 @@ files:
87
87
  - lib/preflight/rules/root_has_keys.rb
88
88
  - lib/preflight/rules/min_ppi.rb
89
89
  - lib/preflight/rules/print_boxes.rb
90
+ - lib/preflight/rules/no_filespecs.rb
90
91
  - lib/preflight/rules/info_specifies_trapping.rb
91
92
  - lib/preflight/rules/only_embedded_fonts.rb
92
93
  - lib/preflight/rules/compression_algorithms.rb
@@ -95,6 +96,8 @@ files:
95
96
  - lib/preflight/rules/match_info_entries.rb
96
97
  - lib/preflight/rules/max_version.rb
97
98
  - lib/preflight/rules/no_proprietary_fonts.rb
99
+ - lib/preflight/rules/pdfx_output_intent_has_keys.rb
100
+ - lib/preflight/rules/output_intent_for_pdfx.rb
98
101
  - lib/preflight/rules/info_has_keys.rb
99
102
  - lib/preflight/rules/document_id.rb
100
103
  - lib/preflight/rules/box_nesting.rb