Beispiel #1
0
 def set_dpi(self, dpi=0):
     if isinstance(dpi, Real):
         rsvg.rsvg_handle_set_dpi(self._rsvgobj, dpi)
     elif isinstance(dpi, (Vector, tuple, list)):
         dpi = Vector.from_tuple(dpi)
         rsvg.rsvg_handle_set_dpi_x_y(self._rsvgobj, dpi.x, dpi.y)
     else:
         raise TypeError("dpi must be a Real or a Vector")
Beispiel #2
0
def check_dimensions_ok(dimensions, where = None) :
    "checks that the Vector dimensions is suitable as the dimensions of an image" \
    " for Frei0r to operate on."
    width, height = Vector.from_tuple(dimensions).assert_isint()
    assert max_image_dimension >= width > 0 and max_image_dimension >= height > 0 and width % image_dimension_modulo == 0 and height % image_dimension_modulo == 0, \
        "invalid image dimensions%s" % (lambda : "", lambda : " %s" % where)[where != None]()
    return \
        Vector(width, height)
Beispiel #3
0
 def render(self, g, at_time, from_pos, from_extent, to_pos, to_extent) :
     "updates the current state of the pattern and draws it into destination qahirah.Context" \
     " g. The line from Vectors from_pos to to_pos defines the starting and ending" \
     " points of the animation trajectory, while from_extent and to_extent define the extents" \
     " of the image perpendicular to this direction at these points, the ratio of the values" \
     " defining the amount of perspective foreshortening."
     from_pos = Vector.from_tuple(from_pos)
     to_pos = Vector.from_tuple(to_pos)
     base_offset = self.time_to_offset(at_time)
     if self.last_draw_time != at_time :
         if self.last_draw_time == None :
             self.last_draw_time = - self.duration / self.steps
         #end if
         this_offset = self.time_to_offset(self.last_draw_time)
         time_steps = 0
         while this_offset != base_offset :
             time_steps += 1
             this_offset -= 1
             if this_offset < 0 :
                 this_offset += self.steps
             #end if
             this_time = self.last_draw_time + time_steps * self.duration / self.steps
             self.draw(self.get_context(this_time), this_time)
         #end while
         self.last_draw_time = at_time
     #end if
     angle = (to_pos - from_pos).angle()
     self.pix.flush()
     g.save()
     g.translate(from_pos)
     g.rotate(angle) # orient source pattern parallel to x-axis
     g.translate(- from_pos)
     span = abs(to_pos - from_pos)
     for i in range(0, math.ceil(span)) :
         dst_width = min(span - i, 1)
         dst_extent = i / span * (to_extent - from_extent) + from_extent
         dst_extent2 = (i + dst_width) / span * (to_extent - from_extent) + from_extent
         # conversion from coords in destination image to offsets in source image
         # uses reciprocals to simulate perspective foreshortening. Note offsets
         # are from base_offset - 1, not base_offset, because column of pixels
         # drawn at time t = 0 is at far right (x = steps - 1).
         this_offset = \
             (
                 (
                         (1 / dst_extent - 1 / from_extent)
                     /
                         (1 / to_extent - 1 / from_extent)
                     *
                         self.steps
                 +
                     base_offset
                 -
                     1
                 )
             %
                 self.steps
             )
         this_offset2 = \
             (
                 (
                         (1 / dst_extent2 - 1 / from_extent)
                     /
                         (1 / to_extent - 1 / from_extent)
                     *
                         self.steps
                 +
                     base_offset
                 -
                     1
                 )
             %
                 self.steps
             )
         if this_offset2 < this_offset :
             this_offset2 += self.steps
         #end if
         dst_x = from_pos.x + i
         src_rect = Rect(this_offset, 0, this_offset2 - this_offset, self.extent)
         dst_rect = Rect(dst_x, from_pos.y - dst_extent / 2, dst_width, dst_extent)
         self.pat.matrix = dst_rect.transform_to(src_rect)
         g.set_source(self.pat)
         g.new_path()
         g.rectangle(dst_rect)
         g.fill()
     #end for
     g.restore()