Class Magick::RVG::Image
In: lib/rvg/embellishable.rb
Parent: Object
Enum GeometryValue Stylable RVG\n[lib/rvg/clippath.rb\nlib/rvg/container.rb\nlib/rvg/deep_equal.rb\nlib/rvg/describable.rb\nlib/rvg/embellishable.rb\nlib/rvg/misc.rb\nlib/rvg/paint.rb\nlib/rvg/pathdata.rb\nlib/rvg/rvg.rb\nlib/rvg/stretchable.rb\nlib/rvg/stylable.rb\nlib/rvg/text.rb\nlib/rvg/transformable.rb\nlib/rvg/units.rb] Transformable Stretchable Embellishable Describable Duplicatable Comparable Image ImageList Array Geometry HatchFill Draw lib/RMagick.rb lib/rvg/rvg.rb Magick Module: Magick

Methods

Included Modules

Stylable Transformable Describable PreserveAspectRatio Duplicatable

Public Class methods

Composite a raster image in the viewport defined by [x,y] and width and height. Use the RVG::ImageConstructors#image method to create Text objects in a container.

[Source]

     # File lib/rvg/embellishable.rb, line 236
236:         def initialize(image, width=nil, height=nil, x=0, y=0)
237:             super()             # run module initializers
238:             @image = image.copy # use a copy of the image in case app. re-uses the argument
239:             @x, @y, @width, @height = Magick::RVG.convert_to_float(x, y, width || @image.columns, height || @image.rows)
240:             if @width < 0 || @height < 0
241:                 raise ArgumentError, "width, height must be >= 0"
242:             end
243:             init_viewbox()
244:         end

Private Instance methods

[Source]

     # File lib/rvg/embellishable.rb, line 202
202:         def add_composite_primitive(gc)
203:             if @align == 'none'
204:                 # Let RMagick do the scaling
205:                 scale = 1.0
206:                 width, height = @width, @height
207:             elsif @meet_or_slice == 'meet'
208:                 scale = [@width/@image.columns, @height/@image.rows].min
209:                 width, height = @image.columns, @image.rows
210:             else
211:                 # Establish clipping path around the current viewport
212:                 name = __id__.to_s
213:                 gc.define_clip_path(name) do
214:                     gc.path("M#{@x},#{@y} l#{@width},0 l0,#{@height} l-#{@width},0 l0,-#{@height}z")
215:                 end
216: 
217:                 gc.clip_path(name)
218:                 scale = [@width/@image.columns, @height/@image.rows].max
219:                 width, height = @image.columns, @image.rows
220:             end
221:             tx, ty = align_to_viewport(scale)
222:             gc.composite(@x+tx, @y+ty, width*scale, height*scale, @image)
223:         end

[Source]

     # File lib/rvg/embellishable.rb, line 181
181:         def align_to_viewport(scale)
182:             tx = case @align
183:                     when 'none', /\AxMin/
184:                         0
185:                     when NilClass, /\AxMid/
186:                         (@width - @image.columns*scale) / 2.0
187:                     when /\AxMax/
188:                         @width - @image.columns*scale
189:             end
190: 
191:             ty = case @align
192:                     when 'none', /YMin\z/
193:                         0
194:                     when NilClass, /YMid\z/
195:                         (@height - @image.rows*scale) / 2.0
196:                     when /YMax\z/
197:                         @height - @image.rows*scale
198:             end
199:             return [tx, ty]
200:         end

[Source]

     # File lib/rvg/embellishable.rb, line 225
225:         def init_viewbox()
226:             @align = nil
227:             @vbx_width, @vbx_height = @image.columns, @image.rows
228:             @meet_or_slice = 'meet'
229:         end

[Validate]