pdf-writer 1.0.0
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.
- data/ChangeLog +44 -0
- data/LICENCE +118 -0
- data/README +32 -0
- data/bin/loader +54 -0
- data/bin/manual +22 -0
- data/bin/manual.bat +2 -0
- data/demo/chunkybacon.rb +28 -0
- data/demo/code.rb +63 -0
- data/demo/colornames.rb +843 -0
- data/demo/demo.rb +65 -0
- data/demo/gettysburg.rb +58 -0
- data/demo/hello.rb +18 -0
- data/demo/individual-i.rb +81 -0
- data/demo/pac.rb +62 -0
- data/demo/pagenumber.rb +67 -0
- data/demo/qr-language.rb +573 -0
- data/demo/qr-library.rb +371 -0
- data/images/chunkybacon.jpg +0 -0
- data/images/chunkybacon.png +0 -0
- data/images/pdfwriter-icon.jpg +0 -0
- data/images/pdfwriter-small.jpg +0 -0
- data/lib/pdf/charts.rb +13 -0
- data/lib/pdf/charts/stddev.rb +431 -0
- data/lib/pdf/grid.rb +135 -0
- data/lib/pdf/math.rb +108 -0
- data/lib/pdf/quickref.rb +330 -0
- data/lib/pdf/simpletable.rb +946 -0
- data/lib/pdf/techbook.rb +890 -0
- data/lib/pdf/writer.rb +2661 -0
- data/lib/pdf/writer/arc4.rb +63 -0
- data/lib/pdf/writer/fontmetrics.rb +201 -0
- data/lib/pdf/writer/fonts/Courier-Bold.afm +342 -0
- data/lib/pdf/writer/fonts/Courier-BoldOblique.afm +342 -0
- data/lib/pdf/writer/fonts/Courier-Oblique.afm +342 -0
- data/lib/pdf/writer/fonts/Courier.afm +342 -0
- data/lib/pdf/writer/fonts/Helvetica-Bold.afm +2827 -0
- data/lib/pdf/writer/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/lib/pdf/writer/fonts/Helvetica-Oblique.afm +3051 -0
- data/lib/pdf/writer/fonts/Helvetica.afm +3051 -0
- data/lib/pdf/writer/fonts/MustRead.html +1 -0
- data/lib/pdf/writer/fonts/Symbol.afm +213 -0
- data/lib/pdf/writer/fonts/Times-Bold.afm +2588 -0
- data/lib/pdf/writer/fonts/Times-BoldItalic.afm +2384 -0
- data/lib/pdf/writer/fonts/Times-Italic.afm +2667 -0
- data/lib/pdf/writer/fonts/Times-Roman.afm +2419 -0
- data/lib/pdf/writer/fonts/ZapfDingbats.afm +225 -0
- data/lib/pdf/writer/graphics.rb +727 -0
- data/lib/pdf/writer/graphics/imageinfo.rb +365 -0
- data/lib/pdf/writer/lang.rb +43 -0
- data/lib/pdf/writer/lang/en.rb +77 -0
- data/lib/pdf/writer/object.rb +23 -0
- data/lib/pdf/writer/object/action.rb +40 -0
- data/lib/pdf/writer/object/annotation.rb +42 -0
- data/lib/pdf/writer/object/catalog.rb +39 -0
- data/lib/pdf/writer/object/contents.rb +68 -0
- data/lib/pdf/writer/object/destination.rb +40 -0
- data/lib/pdf/writer/object/encryption.rb +53 -0
- data/lib/pdf/writer/object/font.rb +76 -0
- data/lib/pdf/writer/object/fontdescriptor.rb +34 -0
- data/lib/pdf/writer/object/fontencoding.rb +39 -0
- data/lib/pdf/writer/object/image.rb +168 -0
- data/lib/pdf/writer/object/info.rb +55 -0
- data/lib/pdf/writer/object/outline.rb +30 -0
- data/lib/pdf/writer/object/outlines.rb +30 -0
- data/lib/pdf/writer/object/page.rb +195 -0
- data/lib/pdf/writer/object/pages.rb +115 -0
- data/lib/pdf/writer/object/procset.rb +46 -0
- data/lib/pdf/writer/object/viewerpreferences.rb +74 -0
- data/lib/pdf/writer/ohash.rb +58 -0
- data/lib/pdf/writer/oreader.rb +25 -0
- data/lib/pdf/writer/state.rb +48 -0
- data/lib/pdf/writer/strokestyle.rb +138 -0
- data/manual.pwd +5151 -0
- metadata +147 -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: object.rb,v 1.3 2005/05/25 11:19:50 austin Exp $
|
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,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: action.rb,v 1.5 2005/05/24 22:19:42 austin Exp $
|
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
|
+
@parent.arc4.prepare(self) if @parent.encrypted?
|
26
|
+
res = "\n#{@oid} 0 obj\n<< /Type /Action"
|
27
|
+
if @type == :ilink
|
28
|
+
res << "\n/S /GoTo\n/D #{@parent.destinations[@label].oid} 0 R"
|
29
|
+
elsif @type == 'URI'
|
30
|
+
res << "\n/S /URI\n/URI ("
|
31
|
+
if @parent.encrypted?
|
32
|
+
res << PDF::Writer.escape(@parent.arc4.encrypt(@label))
|
33
|
+
else
|
34
|
+
res << PDF::Writer.escape(@label)
|
35
|
+
end
|
36
|
+
res << ")\n"
|
37
|
+
end
|
38
|
+
res << ">>\nendobj"
|
39
|
+
end
|
40
|
+
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: annotation.rb,v 1.2 2005/05/16 03:59:21 austin Exp $
|
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: catalog.rb,v 1.2 2005/05/16 03:59:21 austin Exp $
|
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,68 @@
|
|
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: contents.rb,v 1.2 2005/05/16 03:59:21 austin Exp $
|
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 = ""
|
17
|
+
@info = {}
|
18
|
+
@raw = false
|
19
|
+
@on_page = nil
|
20
|
+
|
21
|
+
if page.kind_of?(PDF::Writer::Object::Page)
|
22
|
+
@on_page = page
|
23
|
+
elsif page == :raw
|
24
|
+
@raw = true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :on_page
|
29
|
+
|
30
|
+
def size
|
31
|
+
@data.size
|
32
|
+
end
|
33
|
+
|
34
|
+
def each
|
35
|
+
@contents.each { |c| yield c }
|
36
|
+
end
|
37
|
+
|
38
|
+
def <<(v)
|
39
|
+
raise TypeError unless v.kind_of?(PDF::Writer::Object) or v.kind_of?(String)
|
40
|
+
@data << v
|
41
|
+
end
|
42
|
+
|
43
|
+
def add(a)
|
44
|
+
a.each { |k, v| @info[k] = v }
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
tmp = @data.dup
|
49
|
+
res = "\n#{@oid} 0 obj\n"
|
50
|
+
if @raw
|
51
|
+
res << tmp
|
52
|
+
else
|
53
|
+
res << "<<"
|
54
|
+
if PDF::Writer::Compression and @parent.compressed?
|
55
|
+
res << " /Filter /FlateDecode"
|
56
|
+
tmp = Zlib::Deflate.deflate(tmp)
|
57
|
+
end
|
58
|
+
if (@parent.encrypted?)
|
59
|
+
@parent.arc4.prepare(self)
|
60
|
+
tmp = @parent.arc4.encrypt(tmp)
|
61
|
+
end
|
62
|
+
@info.each { |k, v| res << "\n/#{k} #{v}" }
|
63
|
+
res << "\n/Length #{tmp.size} >>\nstream\n#{tmp}\nendstream"
|
64
|
+
end
|
65
|
+
res << "\nendobj\n"
|
66
|
+
res
|
67
|
+
end
|
68
|
+
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: destination.rb,v 1.2 2005/05/16 03:59:21 austin Exp $
|
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: encryption.rb,v 1.2 2005/05/16 03:59:21 austin Exp $
|
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,76 @@
|
|
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: font.rb,v 1.3 2005/05/25 11:19:50 austin Exp $
|
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
|
+
@encoding = encoding
|
21
|
+
|
22
|
+
@font_id = @parent.__send__(:generate_font_id)
|
23
|
+
|
24
|
+
if encoding.kind_of?(PDF::Writer::Object::FontEncoding)
|
25
|
+
@encoding = nil
|
26
|
+
@encodingDictionary = encoding
|
27
|
+
elsif encoding == 'none' or encoding.nil?
|
28
|
+
@encoding = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
@parent.pages << self
|
32
|
+
|
33
|
+
@encodingDictionary = nil
|
34
|
+
@firstchar = nil
|
35
|
+
@lastchar = nil
|
36
|
+
@widths = nil
|
37
|
+
@fontdescriptor = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_reader :font_id
|
41
|
+
attr_accessor :subtype
|
42
|
+
# Valid values: WinAnsiEncoding, MacRomanEncoding, MacExpertEncoding,
|
43
|
+
# none, +nil+
|
44
|
+
attr_accessor :encoding
|
45
|
+
attr_reader :encodingDictionary
|
46
|
+
def encodingDictionary=(ed)
|
47
|
+
@encodingDictionary = ed
|
48
|
+
end
|
49
|
+
|
50
|
+
def basefont
|
51
|
+
@name
|
52
|
+
end
|
53
|
+
|
54
|
+
def basefont=(b)
|
55
|
+
@name = basefont
|
56
|
+
end
|
57
|
+
|
58
|
+
Details.each do |d|
|
59
|
+
attr_accessor d.downcase.intern
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s
|
63
|
+
res = "\n#{@oid} 0 obj\n<< /Type /Font\n/Subtype /#{@subtype}\n"
|
64
|
+
res << "/Name /F#{@font_id}\n/BaseFont /#{@name}\n"
|
65
|
+
if @encodingDictionary.nil?
|
66
|
+
res << "/Encoding /#{@encoding}\n"
|
67
|
+
else
|
68
|
+
res << "/Encoding #{@encodingDictionary.oid} 0 R\n"
|
69
|
+
end
|
70
|
+
res << "/FirstChar #{@firstchar}\n" unless @firstchar.nil?
|
71
|
+
res << "/LastChar #{@lastchar}\n" unless @lastchar.nil?
|
72
|
+
res << "/Widths #{@widths} 0 R\n" unless @widths.nil?
|
73
|
+
res << "/FontDescriptor #{@fontdescriptor} 0 R\n" unless @fontdescriptor.nil?
|
74
|
+
res << ">>\nendobj"
|
75
|
+
end
|
76
|
+
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: fontdescriptor.rb,v 1.2 2005/05/16 03:59:21 austin Exp $
|
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 << "\n>>\nendobj"
|
33
|
+
end
|
34
|
+
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: fontencoding.rb,v 1.2 2005/05/16 03:59:21 austin Exp $
|
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
|
+
res << "/Differences \n["
|
28
|
+
n = -100
|
29
|
+
differences.each do |k, v|
|
30
|
+
if k != (n + 1)
|
31
|
+
res << "\n#{k} /#{v}" # Cannot make use of consecutive numbering
|
32
|
+
else
|
33
|
+
res << " /#{v}"
|
34
|
+
end
|
35
|
+
n = k
|
36
|
+
end
|
37
|
+
res << "\n]\n>>\nendobj"
|
38
|
+
end
|
39
|
+
end
|