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 close_rect(self):
     border = self.border_width()
     rc = Rect(border, border, self.width(), self.caption_height())
     margin = self.system_control_margin()
     side = rc.height() - 2 * margin
     rc.set_top(rc.top() + margin)
     rc.set_bottom(rc.bottom() - margin)
     rc.set_left(rc.right() - side)
     rc.translate(-margin, 0)
     return rc
Esempio n. 3
0
class MathColumn(MultiItem):
    """Container for inline maths"""
    def __init__(self, *items):
        MultiItem.__init__(self)
        self.style = ('math-var',1)
        for item in items:
            self.appendItem(item)
        
    def resizePDF(self, pdf, x = 0, y = 0):
        self.rect = Rect(x,y,x,y)
        for item in self.items:
            self.setFontPDF(pdf, item)
            item.resizePDF(pdf,x,y)
            item.rect.translate(0,self.rect.height())
            self.rect.unite(item.rect)
                
        self.refit()
Esempio n. 4
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. 5
0
    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
        y_vector_bbox.height=bbox.height

    # --- Game logic should go here
    # --- Drawing code should go here
    # First, clear the screen to white. Don't put other drawing commands
    # above this, or they will be erased with this command.
#    surf.fill(RED)

    for i in range(0, 13):
        for j in range(0,10):