Esempio n. 1
0
class TextItem(DocItem):
    """Prints some form of text"""
    def __init__(self, text = '', style = 'body'):
        DocItem.__init__(self)
        self.text = text
        self.style = style

    def writePDF(self, pdf = None):
        """Write itself to a FPDF object.
        
        Args:
            pdf (FPDF): the FPDF object to write to.
        """
        return self.getText()
    
    def resizePDF(self, pdf, x = 0, y = 0):
        """Resize internal Rect according to current settings of pdf"""
        width = pdf.get_string_width( self.getText() )
        height = pdf.font_size_pt / pdf.k
        self.rect = Rect( x, y, x + width, y + height )
    
    def cellPDF(self, pdf, r = None):
        if r:
            x_shift = r.x0()
            y_shift = r.y0()
        else:
            x_shift = 0.0
            y_shift = 0.0
        pdf.set_y( self.rect.y0() - y_shift )
        pdf.set_x( self.rect.x0() - x_shift )
        pdf.cell( self.rect.width(), self.rect.height(), self.getText() )
        
    def refit(self):
        """Doesn't need to do anything as cellPDF uses self.rect to output the content"""
        pass
Esempio n. 2
0
    def _get_rect_tensor_descs_no_overlap(self, rect, window_rect, factor):
        assert isinstance(rect, Rect)
        assert isinstance(window_rect, Rect)

        window_size = window_rect.height()
        map_size = window_size >> (factor + self.num_poolings)

        edge = window_size / map_size

        center = rect.center()
        sx = int(center.x - window_rect.left)
        sy = int(center.y - window_rect.top)
        x = int(sx / edge)
        y = int(sy / edge)

        res = []

        for dx in range(-3, 3):
            for dy in range(-2, 2):
                wx = x + dx
                wy = y + dy
                if 0 <= wx and wx < map_size and 0 <= wy and wy < map_size:
                    # window coord
                    wrect = Rect(wx * edge, wy * edge, (wx + 1) * edge, (wy + 1) * edge)
                    # img coord
                    wrect.move(window_rect.top, window_rect.left)

                    i = wrect.intersection(rect)

                    if i.valid(): #self._check_rect(rect, wrect):
                        # img coord
                        #i = wrect.intersection(rect)
                        qual_out = i.area() / float(wrect.area())
                        # if qual_out <= 0:
                        #     print rect ,wrect, i
                        # window coord
                        i.move(-wrect.top, -wrect.left)
                        # window 0..1 coord
                        i.stretch(1.0 / wrect.height(), 1.0 / wrect.width())

                        if qual_out > 0.01:
                            res.append((wy, wx, i.left, i.top, i.right, i.bottom, qual_out))

        return res
Esempio n. 3
0
    keys=pygame.key.get_pressed()

    controls.update( left=keys[pygame.K_LEFT],
                     right=keys[pygame.K_RIGHT],
                     up=keys[pygame.K_UP],
                     down=keys[pygame.K_DOWN],
                     jump=keys[pygame.K_SPACE])

    player.update( controls, dt )

    bbox.x=player.position.x+4
    bbox.y=player.position.y+8+1

    if player.delta_x_vector.x < 0:
        x_vector_bbox.x = bbox.x-1
        x_vector_bbox.width=bbox.width+1
    elif 0 < player.delta_x_vector.x:
        x_vector_bbox.x = bbox.x
        x_vector_bbox.width = bbox.width+1
    else:
        x_vector_bbox.x = bbox.x
        x_vector_bbox.width=bbox.width

    if player.delta_y_vector.y < 0:
        y_vector_bbox.y = bbox.y-1
        y_vector_bbox.height=bbox.height+1
    elif 0 < player.delta_y_vector.y:
        y_vector_bbox.y = bbox.y
        y_vector_bbox.height=bbox.height+1
    else:
        y_vector_bbox.y = bbox.y