Ejemplo n.º 1
0
 def draw(self, context):
     Text.draw(self, context)
     cr = context.cairo
     w, h = text_extents(cr, self.text, multiline=self.multiline)
     cr.rectangle(0, 0, w, h)
     cr.set_source_rgba(0.3, 0.3, 1.0, 0.6)
     cr.stroke()
Ejemplo n.º 2
0
    def pre_update(self, context):
        """
        Pre update, determine width and height of the compartment.
        """
        self.width = self.height = 0
        cr = context.cairo
        for item in self:
            item.pre_update(context)
        
        if self:
            # self (=list) contains items
            sizes = [ (0, 0) ] # to not throw exceptions by max and sum
            if self.title:
                w, h = text_extents(cr, self.title)
                self.title_height = h
                sizes.append((w, h))
            sizes.extend(f.get_size(True) for f in self)
            self.width = max(size[0] for size in sizes)
            self.height = sum(size[1] for size in sizes)
            vspacing = self.owner.style.compartment_vspacing
            self.height += vspacing * (len(sizes) - 1)

        padding = self.owner.style.compartment_padding
        self.width += padding[1] + padding[3]
        self.height += padding[0] + padding[2]
Ejemplo n.º 3
0
 def draw(self, context):
     Text.draw(self, context)
     cr = context.cairo
     w, h = text_extents(cr, self.text, multiline=self.multiline)
     cr.rectangle(0, 0, w, h)
     cr.set_source_rgba(.3, .3, 1., .6)
     cr.stroke()
Ejemplo n.º 4
0
 def pre_update(self, context):
     cr = context.cairo
     text = self.subject.name
     if text:
         width, height = text_extents(cr, text)
         self.min_width, self.min_height = width + 10, height + 20
     super(UseCaseItem, self).pre_update(context)
Ejemplo n.º 5
0
 def pre_update(self, context):
     if not self.subject:
         return
     cr = context.cairo
     w, h = text_extents(cr, self.subject.body, multiline=True, padding=2)
     e2 = self.EAR * 2
     self.min_width = w + e2 + self.OFFSET
     self.min_height = h + e2
     ElementItem.pre_update(self, context)
Ejemplo n.º 6
0
 def _get_text_align_hint(self, cr, txt):
     """
     Calculate hint value for text element depending on
     ``text_align_str`` style property.
     """
     style = txt.style
     chunks = txt.text.split(style.text_align_str, 1)
     hint = 0
     if len(chunks) > 1:
         hint, _ = text_extents(cr, chunks[0], font=txt.style.font)
     return hint
Ejemplo n.º 7
0
    def _set_text_sizes(self, context, texts):
        """
        Calculate size for every text in the list.

        Parameters:
         - context: cairo context
         - texts:   list of texts
        """
        cr = context.cairo
        for txt in texts:
            w, h = text_extents(cr, txt.text, font=txt.style.font, multiline=True)
            txt.bounds.width = max(15, w)
            txt.bounds.height = max(10, h)
Ejemplo n.º 8
0
    def post_update(self, context, p1, p2):
        """
        Update label placement for association's name and
        multiplicity label. p1 is the line end and p2 is the last
        but one point of the line.
        """
        cr = context.cairo
        ofs = 5

        name_dx = 0.0
        name_dy = 0.0
        mult_dx = 0.0
        mult_dy = 0.0

        dx = float(p2[0]) - float(p1[0])
        dy = float(p2[1]) - float(p1[1])

        name_w, name_h = map(max, text_extents(cr, self._name, multiline=True), (10, 10))
        mult_w, mult_h = map(max, text_extents(cr, self._mult, multiline=True), (10, 10))

        if dy == 0:
            rc = 1000.0  # quite a lot...
        else:
            rc = dx / dy
        abs_rc = abs(rc)
        h = dx > 0  # right side of the box
        v = dy > 0  # bottom side

        if abs_rc > 6:
            # horizontal line
            if h:
                name_dx = ofs
                name_dy = -ofs - name_h
                mult_dx = ofs
                mult_dy = ofs
            else:
                name_dx = -ofs - name_w
                name_dy = -ofs - name_h
                mult_dx = -ofs - mult_w
                mult_dy = ofs
        elif 0 <= abs_rc <= 0.2:
            # vertical line
            if v:
                name_dx = -ofs - name_w
                name_dy = ofs
                mult_dx = ofs
                mult_dy = ofs
            else:
                name_dx = -ofs - name_w
                name_dy = -ofs - name_h
                mult_dx = ofs
                mult_dy = -ofs - mult_h
        else:
            # Should both items be placed on the same side of the line?
            r = abs_rc < 1.0

            # Find out alignment of text (depends on the direction of the line)
            align_left = (h and not r) or (r and not h)
            align_bottom = (v and not r) or (r and not v)
            if align_left:
                name_dx = ofs
                mult_dx = ofs
            else:
                name_dx = -ofs - name_w
                mult_dx = -ofs - mult_w
            if align_bottom:
                name_dy = -ofs - name_h
                mult_dy = -ofs - name_h - mult_h
            else:
                name_dy = ofs
                mult_dy = ofs + mult_h

        self._name_bounds = Rectangle(p1[0] + name_dx, p1[1] + name_dy, width=name_w, height=name_h)

        self._mult_bounds = Rectangle(p1[0] + mult_dx, p1[1] + mult_dy, width=mult_w, height=mult_h)
Ejemplo n.º 9
0
 def update_size(self, text, context):
     if text:
         cr = context.cairo
         self.width, self.height = text_extents(cr, text)
     else:
         self.width, self.height = 0, 0
Ejemplo n.º 10
0
 def draw(self, context):
     Gaphas_Text.draw(self, context)
     cr = context.cairo
     w, h = text_extents(cr, self.text, multiline=self.multiline)
     cr.rectangle(-25, -15, w + 50, h + 30)
     cr.stroke()