| 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 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
# 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
# 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