Class: Chem::RMagickWriter
- Inherits:
-
Object
- Object
- Chem::RMagickWriter
- Includes:
- Writer
- Defined in:
- lib/chem/db/rmagick.rb
Class Method Summary collapse
Instance Method Summary collapse
- #draw(filename, params) ⇒ Object
- #fill(nodes, color, params = {}) ⇒ Object
-
#initialize(mol, params) ⇒ RMagickWriter
constructor
Constructor for RMagick Adaptor See chem/db/vector.rb for detail parameters.
-
#line(from, to, color) ⇒ Object
Draws line This method may be invoked from chem/db/vector.rb.
- #text(str, x, y, params = {}) ⇒ Object
Methods included from Writer
Constructor Details
#initialize(mol, params) ⇒ RMagickWriter
Constructor for RMagick Adaptor See chem/db/vector.rb for detail parameters
12 13 14 15 16 17 18 19 |
# File 'lib/chem/db/rmagick.rb', line 12 def initialize mol, params params[:size] ||= [350, 350] params[:orig_point] ||= [10, 10] params[:margin] ||= [10, 10] @default_pointsize = (params[:pointsize] ? params[:pointsize] : 14) params[:upside_down] = params[:upside_down] ? false : true super end |
Class Method Details
.save(mol, filename, params) ⇒ Object
49 50 51 52 |
# File 'lib/chem/db/rmagick.rb', line 49 def self.save(mol, filename, params) writer = self.new(mol, params) writer.draw(filename, params) end |
Instance Method Details
#draw(filename, params) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/chem/db/rmagick.rb', line 54 def draw filename, params @img = Magick::ImageList.new x, y = params[:size] x += params[:margin][0] * 2 y += params[:margin][0] * 2 @img.new_image(x, y) @canvas = Magick::Draw.new draw_body @canvas.draw(@img) @img.write(filename) end |
#fill(nodes, color, params = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/chem/db/rmagick.rb', line 28 def fill(nodes, color, params = {}) @canvas.fill("rgb(%f, %f, %f)" % params[:color]) if params[:color] path = nodes.inject([]){|ret, node| ret << node[0] ; ret << node[1]} @canvas.polygon(* path) end |
#line(from, to, color) ⇒ Object
Draws line This method may be invoked from chem/db/vector.rb
23 24 25 26 |
# File 'lib/chem/db/rmagick.rb', line 23 def line(from, to, color) @canvas.stroke("rgb(%f, %f, %f)" % color) @canvas.line(from[0], from[1], to[0], to[1]) end |
#text(str, x, y, params = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chem/db/rmagick.rb', line 34 def text(str, x, y, params = {}) @canvas.pointsize = @default_pointsize metrics = @canvas.get_type_metrics(@img, str) @canvas.stroke('transparent') @canvas.pointsize(params[:pontsize]) if params[:pointsize] @canvas.fill("rgb(%f, %f, %f)" % params[:color]) if params[:color] @canvas.text(x - metrics.width / 2.0, y + metrics.height / 4.0, str) @canvas.pointsize(@default_pointsize) if params[:pointsize] @canvas.fill('black') if params[:color] end |