Example #1
0
    def draw(self, can=None):
        if can == None:
            can = canvas.default_canvas()
        x = self.loc[0]
        y = self.loc[1]
        text_width = font.text_width(self.text)
        text_height = font.text_height(self.text)[0]
        (halign, valign, angle) = font.get_align(self.text)

        if self.line_style or self.fill_style:
            width = text_width + self.left_fudge + self.right_fudge
            height = text_height + self.bottom_fudge + self.top_fudge
            can.round_rectangle(self.line_style, self.fill_style,
                                x - self.left_fudge, y - self.bottom_fudge,
                                x - self.left_fudge + width,
                                y - self.bottom_fudge + height, self.radius,
                                self.shadow)

        if halign == 'L':
            can.show(x, y, self.text)
        elif halign == 'C':
            can.show(x + text_width / 2.0, y, self.text)
        elif halign == 'R':
            can.show(x + text_width, y, self.text)
        else:
            raise Exception, "Unsupported alignment (" + halign + ")"

        # draw arrows
        for t in self._arrows:
            (tipLoc, tail, arrow) = t
            if tail:
                (x, y, width, height) = self.get_dimension()
                origin = [x, y]
                for ch in tail:
                    if ch == 'l':
                        origin[0] = x
                    elif ch == 'c':
                        origin[0] = x + width / 2.0
                    elif ch == 'r':
                        origin[0] = x + width
                    elif ch == 'b':
                        origin[1] = y
                    elif ch == 'm':
                        origin[1] = y + height / 2.0
                    elif ch == 't':
                        origin[1] = y + height
                    else:
                        raise ValueError, tail + ": unknown tail location spec."
            else:
                origin = self.choose_end_point(tipLoc[0], tipLoc[1])
            arrow.draw((origin, tipLoc), can)
Example #2
0
    def draw(self, can = None):
        if can == None:
            can = canvas.default_canvas()
        x = self.loc[0]
        y = self.loc[1]
        text_width = font.text_width(self.text)
        text_height = font.text_height(self.text)[0]
        (halign, valign, angle) = font.get_align(self.text)
        
        if self.line_style or self.fill_style:
            width = text_width+self.left_fudge+self.right_fudge
            height = text_height+self.bottom_fudge+self.top_fudge
            can.round_rectangle(self.line_style, self.fill_style,
                                   x-self.left_fudge, y-self.bottom_fudge,
                                   x-self.left_fudge+width, y-self.bottom_fudge+height,
                                   self.radius, self.shadow)

        if halign == 'L':
            can.show(x, y, self.text)
        elif halign == 'C':
            can.show(x+text_width/2.0, y, self.text)
        elif halign == 'R':
            can.show(x+text_width, y, self.text)
        else:
            raise Exception, "Unsupported alignment (" + halign + ")"

        # draw arrows
        for t in self._arrows:
            (tipLoc, tail, arrow) = t
            if tail:
                (x, y, width, height) = self.get_dimension()
                origin = [x, y]
                for ch in tail:
                    if ch == 'l':
                        origin[0] = x
                    elif ch == 'c':
                        origin[0] = x+width/2.0
                    elif ch == 'r':
                        origin[0] = x+width
                    elif ch == 'b':
                        origin[1] = y
                    elif ch == 'm':
                        origin[1] = y+height/2.0
                    elif ch == 't':
                        origin[1] = y+height
                    else:
                        raise ValueError, tail +  ": unknown tail location spec."
            else:
                origin = self.choose_end_point(tipLoc[0], tipLoc[1])
            arrow.draw((origin, tipLoc), can)
Example #3
0
    def draw(self, can = None):
        if can == None:
            can = canvas.default_canvas()
        x = self.loc[0]
        y = self.loc[1]
        text_width = font.text_width(self.text)
        text_height = font.text_height(self.text)[0]
        (halign, valign, angle) = font.get_align(self.text)
        
        if self.line_style or self.fill_style:
            if self.callout == False:
                width = text_width+self.left_fudge+self.right_fudge
                height = text_height+self.bottom_fudge+self.top_fudge
                can.round_rectangle(self.line_style, self.fill_style,
                                    x-self.left_fudge, y-self.bottom_fudge,
                                    x-self.left_fudge+width, y-self.bottom_fudge+height,
                                    self.radius, self.shadow)
            else:
                width = text_width+self.left_fudge+self.right_fudge
                height = text_height+self.bottom_fudge+self.top_fudge

                cx = x + self.callout_shift
                cy = y
                csize = self.callout_size

                x1 = x-self.left_fudge
                y1 = y-self.bottom_fudge
                x2 = x-self.left_fudge+width
                y2 = y-self.bottom_fudge+height

                p0 = (cx,y1-csize)
                p1 = (cx-csize,y1)
                p2 = (cx+csize,y1)

                px0,py0 = p0
                px1,py1 = p1
                px2,py2 = p2

                can.polygon(None, self.fill_style,
                            [p0, p1, p2])

                can.line(self.line_style, px0, py0, px1, py1)
                can.line(self.line_style, px0, py0, px2, py2)

                can.round_rectangle(None, self.fill_style,
                                    x-self.left_fudge, y-self.bottom_fudge,
                                    x-self.left_fudge+width, y-self.bottom_fudge+height,
                                    self.radius, self.shadow)

                can.line(self.line_style, x2, y1, x2, y2)
                can.line(self.line_style, x2, y2, x1, y2)
                can.line(self.line_style, x1, y2, x1, y1)
                can.line(self.line_style, x1, y1, px1, y1)
                can.line(self.line_style, px2, y1, x2, y1)



        if halign == 'L':
            can.show(x, y, self.text)
        elif halign == 'C':
            can.show(x+text_width/2.0, y, self.text)
        elif halign == 'R':
            can.show(x+text_width, y, self.text)
        else:
            raise Exception, "Unsupported alignment (" + halign + ")"

        # draw arrows
        for t in self._arrows:
            (tipLoc, tail, arrow) = t
            if tail:
                (x, y, width, height) = self.get_dimension()
                origin = [x, y]
                for ch in tail:
                    if ch == 'l':
                        origin[0] = x
                    elif ch == 'c':
                        origin[0] = x+width/2.0
                    elif ch == 'r':
                        origin[0] = x+width
                    elif ch == 'b':
                        origin[1] = y
                    elif ch == 'm':
                        origin[1] = y+height/2.0
                    elif ch == 't':
                        origin[1] = y+height
                    else:
                        raise ValueError, tail +  ": unknown tail location spec."
            else:
                origin = self.choose_end_point(tipLoc[0], tipLoc[1])
            arrow.draw((origin, tipLoc), can)
Example #4
0
    def show(self, x, y, str):
        global out
        y_org = y
        org_str = str

        if invisible_p(x, y):
            return

        (xmin, xmax, ymin, ymax) = font.get_dimension(str)

        # rectangle(line_style.default, None, x+xmin, y+ymin, x+xmax, y+ymax)
        # ellipsis(line_style.default, None, x, y, 1)
        self.setbb(x + xmin, y + ymin)
        self.setbb(x + xmax, y + ymax)

        (halign, valign, angle) = font.get_align(str)

        base_x = x
        base_y = y

        # Handle vertical alignment
        if valign == "B":
            y = font.unaligned_text_height(str)
        elif valign == "T":
            y = 0
        elif valign == "M":
            y = font.unaligned_text_height(str) / 2.0

        (xmin, xmax, ymin, ymax) = font.get_dimension(org_str)
        self.setbb(x + xmin, y_org + y + ymin)
        self.setbb(x + xmax, y_org + y + ymax)
        itr = font.text_iterator(None)

        max_width = 0

        lines = []
        for line in str.split('\n'):
            cur_width = 0
            cur_height = 0

            itr.reset(line)

            strs = []

            while 1:
                elem = itr.next()
                if not elem:
                    break

                (font_name, size, line_height, color, _h, _v, _a, str) = elem
                cur_width += font.line_width(font_name, size, str)
                max_width = max(cur_width, max_width)
                cur_height = max(cur_height, line_height)

                # replace '(' -> '\(', ')' -> '\)' to make
                # Postscript string parser happy.
                str = str.replace("(", "\\(")
                str = str.replace(")", "\\)")
                strs.append((font_name, size, color, str))
            lines.append((cur_width, cur_height, strs))

        for line in lines:
            cur_width, cur_height, strs = line
            cur_y = y - cur_height
            y = y - cur_height
            self.comment("cury: %d hei %d str %s\n" %
                         (cur_y, cur_height, strs))
            if halign == 'C':
                cur_x = -cur_width / 2.0
            elif halign == 'R':
                cur_x = -cur_width
            else:
                cur_x = 0

            rel_x, rel_y = pychart_util.rotate(cur_x, cur_y, angle)
            self.text_begin()
            self.text_moveto(xscale(base_x + rel_x), yscale(base_y + rel_y),
                             angle)
            for segment in strs:
                font_name, size, color, str = segment
                self.text_show(font_name, nscale(size), color, str)
            self.text_end()
Example #5
0
def show(x, y, str):
    global out
    y_org = y
    org_str = str

    if invisible_p(x, y):
        return

    (xmin, xmax, ymin, ymax) = font.get_dimension(str)
	
    # rectangle(line_style.default, None, x+xmin, y+ymin, x+xmax, y+ymax)
    # ellipsis(line_style.default, None, x, y, 1)
    setbb(x+xmin, y+ymin)
    setbb(x+xmax, y+ymax)
	
    (halign, valign, angle) = font.get_align(str)

    base_x = x
    base_y = y

    # Handle vertical alignment
    if valign == "B":
        y = font.unaligned_text_height(str)
    elif valign == "T":
        y = 0
    elif valign == "M":
        y = font.unaligned_text_height(str) / 2.0
        
    (xmin, xmax, ymin, ymax) = font.get_dimension(org_str)
    # print org_str, xmin, xmax, ymin, ymax, x, y_org, y
    setbb(x+xmin, y_org+y+ymin)
    setbb(x+xmax, y_org+y+ymax)
    
    itr = font.text_iterator(None)
    
    max_width = 0
    
    lines = []
    for line in string.split(str, '\n'):
        cur_width = 0
        cur_height = 0
		
        itr.reset(line)
        
        strs = []
        
        while 1:
            elem = itr.next()
            if not elem:
                break
			
            (font_name, size, line_height, color, _h, _v, _a, str) = elem
            cur_width = cur_width + font.line_width(font_name, size, str)
            max_width = max(cur_width, max_width)
            cur_height = max(cur_height, line_height)
            
            # replace '(' -> '\(', ')' -> '\)' to make
            # Postscript string parser happy.
            str = string.replace(str, "(", "\\(")
            str = string.replace(str, ")", "\\)")
            strs.append((font_name, size, color, str))
        lines.append((cur_width, cur_height, strs))
		
    for line in lines:
        cur_width, cur_height, strs = line
        cur_y = y - cur_height
        y = y - cur_height
        out.comment("cury: %d hei %d str %s\n" % (cur_y, cur_height, strs))
        if halign == 'C':
            cur_x = -cur_width/2.0
        elif halign == 'R':
            cur_x = -cur_width
        else:
            cur_x = 0

	rel_x, rel_y = pychart_util.rotate(cur_x, cur_y, angle)
        out.text_begin()
        out.text_moveto(xscale(base_x + rel_x),
                        yscale(base_y + rel_y), angle)
        for segment in strs:
            font_name, size, color, str = segment
            out.text_show(font_name, nscale(size), color, str)
        out.text_end()