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 Enumerable Geometry HatchFill Draw lib/RMagick.rb lib/rvg/misc.rb ObjectData Application Pre_ObjectData_Descriptor Envelope Post_ObjectData_Descriptor IPTC Magick dot/m_14_0.png

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

Private Instance methods

[Source]

     # 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

[Source]

     # 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

[Source]

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

[Validate]