ypdf-writer 1.3.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.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog +134 -0
  3. data/LICENCE +131 -0
  4. data/bin/techbook +24 -0
  5. data/demo/chunkybacon.rb +40 -0
  6. data/demo/code.rb +71 -0
  7. data/demo/colornames.rb +47 -0
  8. data/demo/demo.rb +73 -0
  9. data/demo/gettysburg.rb +66 -0
  10. data/demo/hello.rb +26 -0
  11. data/demo/individual-i.rb +89 -0
  12. data/demo/pac.rb +70 -0
  13. data/demo/qr-language.rb +580 -0
  14. data/demo/qr-library.rb +380 -0
  15. data/images/bluesmoke.jpg +0 -0
  16. data/images/chunkybacon.jpg +0 -0
  17. data/images/chunkybacon.png +0 -0
  18. data/lib/pdf/charts.rb +13 -0
  19. data/lib/pdf/charts/stddev.rb +431 -0
  20. data/lib/pdf/core_ext/mutex.rb +12 -0
  21. data/lib/pdf/math.rb +108 -0
  22. data/lib/pdf/quickref.rb +333 -0
  23. data/lib/pdf/simpletable.rb +952 -0
  24. data/lib/pdf/techbook.rb +907 -0
  25. data/lib/pdf/writer.rb +2760 -0
  26. data/lib/pdf/writer/arc4.rb +63 -0
  27. data/lib/pdf/writer/fontmetrics.rb +203 -0
  28. data/lib/pdf/writer/fonts/Courier-Bold.afm +342 -0
  29. data/lib/pdf/writer/fonts/Courier-BoldOblique.afm +342 -0
  30. data/lib/pdf/writer/fonts/Courier-Oblique.afm +342 -0
  31. data/lib/pdf/writer/fonts/Courier.afm +342 -0
  32. data/lib/pdf/writer/fonts/Helvetica-Bold.afm +2827 -0
  33. data/lib/pdf/writer/fonts/Helvetica-BoldOblique.afm +2827 -0
  34. data/lib/pdf/writer/fonts/Helvetica-Oblique.afm +3051 -0
  35. data/lib/pdf/writer/fonts/Helvetica.afm +3051 -0
  36. data/lib/pdf/writer/fonts/MustRead.html +19 -0
  37. data/lib/pdf/writer/fonts/Symbol.afm +213 -0
  38. data/lib/pdf/writer/fonts/Times-Bold.afm +2588 -0
  39. data/lib/pdf/writer/fonts/Times-BoldItalic.afm +2384 -0
  40. data/lib/pdf/writer/fonts/Times-Italic.afm +2667 -0
  41. data/lib/pdf/writer/fonts/Times-Roman.afm +2419 -0
  42. data/lib/pdf/writer/fonts/ZapfDingbats.afm +225 -0
  43. data/lib/pdf/writer/graphics.rb +813 -0
  44. data/lib/pdf/writer/graphics/imageinfo.rb +366 -0
  45. data/lib/pdf/writer/lang.rb +43 -0
  46. data/lib/pdf/writer/lang/en.rb +99 -0
  47. data/lib/pdf/writer/object.rb +23 -0
  48. data/lib/pdf/writer/object/action.rb +35 -0
  49. data/lib/pdf/writer/object/annotation.rb +42 -0
  50. data/lib/pdf/writer/object/catalog.rb +39 -0
  51. data/lib/pdf/writer/object/contents.rb +70 -0
  52. data/lib/pdf/writer/object/destination.rb +40 -0
  53. data/lib/pdf/writer/object/encryption.rb +53 -0
  54. data/lib/pdf/writer/object/font.rb +72 -0
  55. data/lib/pdf/writer/object/fontdescriptor.rb +34 -0
  56. data/lib/pdf/writer/object/fontencoding.rb +40 -0
  57. data/lib/pdf/writer/object/image.rb +305 -0
  58. data/lib/pdf/writer/object/info.rb +51 -0
  59. data/lib/pdf/writer/object/outline.rb +30 -0
  60. data/lib/pdf/writer/object/outlines.rb +30 -0
  61. data/lib/pdf/writer/object/page.rb +195 -0
  62. data/lib/pdf/writer/object/pages.rb +115 -0
  63. data/lib/pdf/writer/object/procset.rb +46 -0
  64. data/lib/pdf/writer/object/viewerpreferences.rb +74 -0
  65. data/lib/pdf/writer/ohash.rb +58 -0
  66. data/lib/pdf/writer/oreader.rb +25 -0
  67. data/lib/pdf/writer/state.rb +48 -0
  68. data/lib/pdf/writer/strokestyle.rb +138 -0
  69. data/manual.pwd +5965 -0
  70. data/readme.md +36 -0
  71. metadata +151 -0
@@ -0,0 +1,23 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ class PDF::Writer::Object
12
+ def initialize(parent)
13
+ @parent = parent
14
+ @oid = @parent.__send__(:generate_id)
15
+ @parent.objects << self
16
+ end
17
+
18
+ attr_reader :oid
19
+ end
20
+
21
+ class PDF::Writer::External < PDF::Writer::Object; end
22
+
23
+ class PDF::Writer::Complex < PDF::Writer::Object; end
@@ -0,0 +1,35 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ # An action object, used to link to URLS initially
12
+ class PDF::Writer::Object::Action < PDF::Writer::Object
13
+ def initialize(parent, label, type = "URI")
14
+ super(parent)
15
+
16
+ @type = type
17
+ @label = label
18
+ raise TypeError if @label.nil?
19
+ end
20
+
21
+ attr_accessor :type
22
+ attr_accessor :label
23
+
24
+ def to_s
25
+ res = "\n#{@oid} 0 obj\n<< /Type /Action"
26
+ if @type == :ilink
27
+ res << "\n/S /GoTo\n/D #{@parent.destinations[@label].oid} 0 R"
28
+ elsif @type == 'URI'
29
+ res << "\n/S /URI\n/URI ("
30
+ res << PDF::Writer.escape(@parent.arc4.nil? ? @label : @parent.arc4.encrypt(@label))
31
+ res << ")\n"
32
+ end
33
+ res << ">>\nendobj"
34
+ end
35
+ end
@@ -0,0 +1,42 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ # An annotation object, this will add an annotation to the current page.
12
+ # initially will support just link annotations.
13
+ class PDF::Writer::Object::Annotation < PDF::Writer::Object
14
+ TYPES = [:link, :ilink]
15
+
16
+ def initialize(parent, type, rect, label)
17
+ super(parent)
18
+
19
+ @type = type
20
+ @rect = rect
21
+
22
+ case @type
23
+ when :link
24
+ @action = PDF::Writer::Object::Action.new(parent, label)
25
+ when :ilink
26
+ @action = PDF::Writer::Object::Action.new(parent, label, type)
27
+ end
28
+ parent.current_page.add_annotation(self)
29
+ end
30
+
31
+ attr_accessor :type
32
+ attr_accessor :action
33
+ attr_accessor :rect
34
+
35
+ def to_s
36
+ res = "\n#{@oid} 0 obj\n<< /Type /Annot"
37
+ res << "\n/Subtype /Link" if TYPES.include?(@type)
38
+ res << "\n/A #{@action.oid} 0 R\n/Border [0 0 0]\n/H /I\n/Rect ["
39
+ @rect.each { |v| res << "%.4f " % v }
40
+ res << "]\n>>\nendobj"
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ # Define the document catalog, the overall controller for the document
12
+ class PDF::Writer::Object::Catalog < PDF::Writer::Object
13
+ def initialize(parent)
14
+ super(parent)
15
+
16
+ @outlines = nil
17
+ @pages = nil
18
+ @open_here = nil
19
+ @viewer_preferences = nil
20
+ @page_mode = nil
21
+ end
22
+
23
+ attr_accessor :outlines
24
+ attr_accessor :pages
25
+ attr_accessor :open_here
26
+ attr_accessor :viewer_preferences
27
+ attr_accessor :page_mode
28
+
29
+ def to_s
30
+ res = "\n#{@oid} 0 obj\n<< /Type /Catalog"
31
+ res << "\n/Outlines #{@outlines.oid} 0 R" unless @outlines.nil?
32
+ res << "\n/Pages #{@pages.oid} 0 R" unless @pages.nil?
33
+ res << "\n/ViewerPreferences #{@viewer_preferences.oid} 0 R" if @viewer_preferences and @parent.version >= '1.2'
34
+ res << "\n/OpenAction #{@open_here.oid} 0 R" unless @open_here.nil?
35
+ res << "\n/PageMode /#{@page_mode}" unless @page_mode.nil?
36
+ res << "\n/Version /#{@parent.version}" if @parent.version >= '1.4'
37
+ res << ">>\nendobj"
38
+ end
39
+ end
@@ -0,0 +1,70 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ # The contents objects hold all of the content which appears on pages
12
+ class PDF::Writer::Object::Contents < PDF::Writer::Object
13
+ def initialize(parent, page = nil)
14
+ super(parent)
15
+
16
+ @data = RUBY_VERSION < '1.9' ? "" : "".force_encoding("BINARY")
17
+
18
+ @info = {}
19
+ @raw = false
20
+ @on_page = nil
21
+
22
+ if page.kind_of?(PDF::Writer::Object::Page)
23
+ @on_page = page
24
+ elsif page == :raw
25
+ @raw = true
26
+ end
27
+ end
28
+
29
+ attr_reader :on_page
30
+ attr_accessor :data
31
+
32
+ def size
33
+ @data.size
34
+ end
35
+
36
+ def each
37
+ @contents.each { |c| yield c }
38
+ end
39
+
40
+ def <<(v)
41
+ raise TypeError unless v.kind_of?(PDF::Writer::Object) or v.kind_of?(String)
42
+ if RUBY_VERSION >= '1.9'
43
+ @data.force_encoding 'BINARY'
44
+ v.force_encoding 'BINARY'
45
+ end
46
+ @data << v
47
+ end
48
+
49
+ def add(a)
50
+ a.each { |k, v| @info[k] = v }
51
+ end
52
+
53
+ def to_s
54
+ tmp = @data.dup
55
+ res = "\n#{@oid} 0 obj\n"
56
+ if @raw
57
+ res << tmp
58
+ else
59
+ res << "<<"
60
+ if PDF::Writer::Compression and @parent.compressed?
61
+ res << " /Filter /FlateDecode"
62
+ tmp = Zlib::Deflate.deflate(tmp)
63
+ end
64
+ @info.each { |k, v| res << "\n/#{k} #{v}" }
65
+ res << "\n/Length #{tmp.size} >>\nstream\n#{tmp}\nendstream"
66
+ end
67
+ res << "\nendobj\n"
68
+ res
69
+ end
70
+ end
@@ -0,0 +1,40 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ # Destination object, used to specify the location for the user to jump
12
+ # to; presently, only on opening.
13
+ class PDF::Writer::Object::Destination < PDF::Writer::Object
14
+ def initialize(parent, page, type, *params)
15
+ super(parent)
16
+
17
+ case type
18
+ when "FitR"
19
+ raise TypeError if params.size < 4
20
+ @string = "/#{type} #{params[0..3].join(' ')}"
21
+ when "XYZ"
22
+ params = (params + [ "null" ] * 4).first(4)
23
+ @string = "/#{type} #{params[0..2].join(' ')}"
24
+ when "FitH", "FitV", "FitBH", "FitBV"
25
+ raise TypeError if params.empty?
26
+ @string = "/#{type} #{params[0]}"
27
+ when "Fit", "FitB"
28
+ @string = "/#{type}"
29
+ end
30
+
31
+ @page = page
32
+ end
33
+
34
+ attr_accessor :string
35
+ attr_accessor :page
36
+
37
+ def to_s
38
+ "\n#{@oid} 0 obj\n[#{@page.oid} 0 R #{@string}]\nendobj\n"
39
+ end
40
+ end
@@ -0,0 +1,53 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ # Encryption object
12
+ class PDF::Writer::Object::Encryption < PDF::Writer::Object
13
+ PAD = [ 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
14
+ 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
15
+ 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
16
+ 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A ].pack("C*")
17
+
18
+ def initialize(parent, options)
19
+ super(parent)
20
+
21
+ @parent.encrypt_obj = self
22
+
23
+ # Figure out the additional parameters required.
24
+ @owner = "#{options[:owner_pass]}#{PAD}"[0...32]
25
+ @user = "#{options[:user_pass]}#{PAD}"[0...32]
26
+ @perms = options[:permissions]
27
+
28
+ @parent.arc4.prepare(Digest::MD5.hexdigest(@owner)[0...5])
29
+
30
+ # Get the 'O' value.
31
+ @owner_info = ARC4.encrypt(@user)
32
+ # Get the 'U' value.
33
+ ukey = @user.dup
34
+ ukey << @owner_info
35
+ ukey << [ @perms, 0xFF, 0xFF, 0xFF ].pack("C*")
36
+ ukey << @parent.file_identifier
37
+ @parent.encryption_key = Digest::MD5.hexdigest(ukey)[0...5]
38
+
39
+ @parent.arc4.prepare(@parent.encryption_key)
40
+
41
+ @user_info = @parent.arc4.encrypt(PAD)
42
+ end
43
+
44
+ def to_s
45
+ res = "\n#{@oid} 0 obj\n<<\n/Filter /Standard\n"
46
+ res << "/V 1\n/R 2\n"
47
+ res << "/O (#{PDF::Writer.escape(@owner_info)})\n"
48
+ res << "/U (#{PDF::Writer.escape(@user_info)})\n"
49
+ res << "/P #{(((@perms ^ 255) + 1) * -1)}\n"
50
+ res << ">>\nendobj\n"
51
+ res
52
+ end
53
+ end
@@ -0,0 +1,72 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ # An object to hold the font description
12
+ class PDF::Writer::Object::Font < PDF::Writer::Object
13
+ Details = %w{FirstChar LastChar Widths FontDescriptor SubType}
14
+
15
+ def initialize(parent, name, encoding = 'WinAnsiEncoding', subtype = 'Type1')
16
+ super(parent)
17
+
18
+ @name = name
19
+ @subtype = subtype
20
+ @font_id = @parent.__send__(:generate_font_id)
21
+
22
+ if encoding.kind_of?(PDF::Writer::Object::FontEncoding)
23
+ @encoding = encoding
24
+ elsif encoding == 'none' or encoding.nil?
25
+ @encoding = nil
26
+ else
27
+ @encoding = encoding
28
+ end
29
+
30
+ @parent.pages << self
31
+
32
+ @firstchar = nil
33
+ @lastchar = nil
34
+ @widths = nil
35
+ @fontdescriptor = nil
36
+ end
37
+
38
+ attr_reader :font_id
39
+ # The type of the font: Type1 and TrueType are the only values supported
40
+ # by
41
+ attr_reader :subtype
42
+ # Valid values: WinAnsiEncoding, MacRomanEncoding, MacExpertEncoding,
43
+ # none, +nil+, or an instance of PDF::Writer::Object::FontEncoding.
44
+ attr_reader :encoding
45
+
46
+ def basefont #:nodoc:
47
+ @name
48
+ end
49
+
50
+ def basefont=(val) #:nodoc:
51
+ @name = val
52
+ end
53
+
54
+ Details.each do |d|
55
+ attr_accessor d.downcase.intern
56
+ end
57
+
58
+ def to_s
59
+ res = "\n#{@oid} 0 obj\n<< /Type /Font\n/Subtype /#{@subtype}\n"
60
+ res << "/Name /F#{@font_id}\n/BaseFont /#{@name}\n"
61
+ if @encoding.kind_of?(PDF::Writer::Object::FontEncoding)
62
+ res << "/Encoding #{@encoding.oid} 0 R\n"
63
+ elsif @encoding
64
+ res << "/Encoding /#{@encoding}\n" if @encoding
65
+ end
66
+ res << "/FirstChar #{@firstchar}\n" unless @firstchar.nil?
67
+ res << "/LastChar #{@lastchar}\n" unless @lastchar.nil?
68
+ res << "/Widths #{@widths} 0 R\n" unless @widths.nil?
69
+ res << "/FontDescriptor #{@fontdescriptor} 0 R\n" unless @fontdescriptor.nil?
70
+ res << ">>\nendobj"
71
+ end
72
+ end
@@ -0,0 +1,34 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ # A font descriptor, needed for including additional fonts. +options+ is a
12
+ # Hash with one of the following keys: Ascent, CapHeight, Descent, Flags,
13
+ # ItalicAngle, StemV, AvgWidth, Leading, MaxWidth, MissingWidth, StemH,
14
+ # XHeight, CharSet, FontFile, FontFile2, FontFile3, FontBBox, or FontName.
15
+ class PDF::Writer::Object::FontDescriptor < PDF::Writer::Object
16
+ def initialize(parent, options = nil)
17
+ super(parent)
18
+
19
+ @options = options
20
+ end
21
+
22
+ attr_accessor :options
23
+
24
+ def to_s
25
+ res = "\n#{@oid} 0 obj\n<< /Type /FontDescriptor\n"
26
+ @options.each do |k, v|
27
+ res << "/#{k} #{v}\n" if %w{Ascent CapHeight Descent Flags ItalicAngle StemV AvgWidth Leading MaxWidth MissingWidth StemH XHeight CharSet}.include?(k)
28
+ res << "/#{k} #{v} 0 R\n" if %w{FontFile FontFile2 FontFile3}.include?(k)
29
+ res << "/#{k} [#{v.join(' ')}]\n" if k == "FontBBox"
30
+ res << "/#{k} /#{v}\n" if k == "FontName"
31
+ end
32
+ res << ">>\nendobj"
33
+ end
34
+ end
@@ -0,0 +1,40 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ # The font encoding
12
+ class PDF::Writer::Object::FontEncoding < PDF::Writer::Object
13
+ def initialize(parent, encoding, differences)
14
+ super(parent)
15
+
16
+ @differences = differences
17
+ @encoding = encoding
18
+ end
19
+
20
+ attr_accessor :differences
21
+ attr_accessor :encoding
22
+
23
+ def to_s
24
+ res = "\n#{@oid} 0 obj\n<< /Type /Encoding\n"
25
+ enc = @encoding || 'WinAnsiEncoding'
26
+ res << "/BaseEncoding /#{enc}\n" unless enc == 'none'
27
+ unless @differences.nil? or @differences.empty?
28
+ res << "/Differences \n["
29
+ n = nil
30
+ @differences.keys.sort.each do |k|
31
+ # Cannot make use of consecutive numbering
32
+ res << "\n#{k} " if n.nil? or k != (n + 1)
33
+ res << " /#{@differences[k]}"
34
+ n = k
35
+ end
36
+ res << "\n]"
37
+ end
38
+ res << "\n>>\nendobj"
39
+ end
40
+ end