Class: Chem::PDFWriter
Constant Summary collapse
- PDFHeader =
<<EOL %PDF-1.3 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [ 4 0 R] /Count 1 >> endobj 4 0 obj << /Type /Page /Parent 3 0 R EOL
- PDFMiddle =
<<EOL /Contents 5 0 R /Resources << /ProcSet 6 0 R /Font << /F1 7 0 R >> >> >> endobj 5 0 obj EOL
<<EOL endstream endobj 6 0 obj [ /PDF /Text ] endobj 7 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Helvetica /Encoding /MacRomanEncoding >> endobj xref 0 8 0000000000 65535 f 0000000009 00000 n 0000000074 00000 n 0000000120 00000 n 0000000179 00000 n 0000000364 00000 n 0000000466 00000 n 0000000496 00000 n trailer << /Size 8 /Root 1 0 R >> startxref 625 %%EOF EOL
Instance Method Summary collapse
- #fill(nodes, color) ⇒ Object
-
#initialize(mol, params) ⇒ PDFWriter
constructor
A new instance of PDFWriter.
- #line(from, to, color) ⇒ Object
- #save(out) ⇒ Object
- #text(str, x, y, params = {}) ⇒ Object
Methods included from Writer
Constructor Details
#initialize(mol, params) ⇒ PDFWriter
Returns a new instance of PDFWriter.
76 77 78 79 80 81 82 |
# File 'lib/chem/db/pdf.rb', line 76 def initialize mol, params params[:size] ||= [180, 200] params[:orig_point] ||= [0, 0] params[:margin] ||= [10, 10] @default_pointsize = (params[:pointsize] ? params[:pointsize] : 14) super end |
Instance Method Details
#fill(nodes, color) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/chem/db/pdf.rb', line 91 def fill(nodes, color) @vect << "0 w" # setline width @vect << color.join(' ') + " RG" # set setrgbcolor @vect << "%d %d m" % [nodes[0][0], nodes[0][1]] nodes[1..-1].each do |vect| @vect << "%d %d l" % [vect[0], vect[1]] end @vect << "b" @vect << "1 w" # setline width end |
#line(from, to, color) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/chem/db/pdf.rb', line 84 def line(from, to, color) @vect << color.join(' ') + " RG" @vect << "#{from[0]} #{from[1]} m" @vect << "#{to[0]} #{to[1]} l" @vect << "S" end |
#save(out) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/chem/db/pdf.rb', line 110 def save out @out = out @params[:font] ||= 12.0 @params[:orig_point] ||= [0, 0] @vect = ["q"] @vect << "1 0 0 1 #{@params[:orig_point][0]} #{@params[:orig_point][1]} cm" @out.puts(PDFHeader) @out.puts "/MediaBox [ 0 0 %d %d]" % @params[:size] @out.puts PDFMiddle draw_body @vect << "Q" str = @vect.join("\n") @out.puts "<< /Length #{str.length} >> stream" @out.puts str @out.puts PDFFooter end |
#text(str, x, y, params = {}) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/chem/db/pdf.rb', line 102 def text(str, x, y, params = {}) @vect << "BT" @vect << "/F1 #{@params[:font]} Tf" @vect << "1 0 0 1 #{x - @params[:font] * 0.4} #{y - @params[:font] * 0.4} Tm" @vect << "(#{str}) Tj" @vect << "ET" end |