| Class | Magick::RVG::Image |
| In: |
lib/rvg/embellishable.rb
|
| Parent: | Object |
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.
# File lib/rvg/embellishable.rb, line 237
237: def initialize(image, width=nil, height=nil, x=0, y=0)
238: super() # run module initializers
239: @image = image.copy # use a copy of the image in case app. re-uses the argument
240: @x, @y, @width, @height = Magick::RVG.convert_to_float(x, y, width || @image.columns, height || @image.rows)
241: if @width < 0 || @height < 0
242: raise ArgumentError, "width, height must be >= 0"
243: end
244: init_viewbox()
245: end
# File lib/rvg/embellishable.rb, line 203
203: def add_composite_primitive(gc)
204: if @align == 'none'
205: # Let RMagick do the scaling
206: scale = 1.0
207: width, height = @width, @height
208: elsif @meet_or_slice == 'meet'
209: scale = [@width/@image.columns, @height/@image.rows].min
210: width, height = @image.columns, @image.rows
211: else
212: # Establish clipping path around the current viewport
213: name = __id__.to_s
214: gc.define_clip_path(name) do
215: gc.path("M#{@x},#{@y} l#{@width},0 l0,#{@height} l-#{@width},0 l0,-#{@height}z")
216: end
217:
218: gc.clip_path(name)
219: scale = [@width/@image.columns, @height/@image.rows].max
220: width, height = @image.columns, @image.rows
221: end
222: tx, ty = align_to_viewport(scale)
223: gc.composite(@x+tx, @y+ty, width*scale, height*scale, @image)
224: end
# File lib/rvg/embellishable.rb, line 182
182: def align_to_viewport(scale)
183: tx = case @align
184: when 'none', /\AxMin/
185: 0
186: when NilClass, /\AxMid/
187: (@width - @image.columns*scale) / 2.0
188: when /\AxMax/
189: @width - @image.columns*scale
190: end
191:
192: ty = case @align
193: when 'none', /YMin\z/
194: 0
195: when NilClass, /YMid\z/
196: (@height - @image.rows*scale) / 2.0
197: when /YMax\z/
198: @height - @image.rows*scale
199: end
200: return [tx, ty]
201: end