def execute(macro, args):
    formatter = macro.formatter
    macro.request.page.formatter = formatter
    request = macro.request
    _ = request.getText

    if not args:
        args = request.page.page_name

    key = cache_key(request, (macro.name, args, latest_edit(request)))

    map_text = 'usemap="#%s" ' % (key)

    if not cache_exists(request, key):
        succ, data, mappi = draw_topology(request, args, key)
        if not succ:
            return mappi

        mappi = encode_page(mappi)
        cache.put(request, key, data, content_type='image/png')
        cache.put(request, key + '-map', mappi, content_type='text/html')
    else:
        mappifile = cache._get_datafile(request, key + '-map')
        mappi = mappifile.read()
        mappifile.close()

    div = u'<div class="ClarifiedTopology">\n' + \
        u'<img %ssrc="%s" alt="%s">\n</div>\n' % \
        (map_text, cache.url(request, key), _('topology'))

    map = u'<map id="%s" name="%s">\n' % (key, key)
    map += decode_page(mappi)
    map += u'</map>\n'

    return div + map
示例#2
0
    def render(self, formatter):
        """text to image conversion"""
        key = 'aafigure_%s' % (cache.key(self.request,
                                         itemname=self.pagename,
                                         content="%s%s" %
                                         (self.raw, self.args)), )
        if not cache.exists(self.request, key) or not cache.exists(
                self.request, key + '_size'):
            # not in cache, regenerate image
            options = dict(format='svg')
            for arg in self.args.split():
                try:
                    k, v = arg.split('=', 1)
                except ValueError:  # when splitting fails
                    k = arg
                    v = None
                if k == 'aspect':
                    options['aspect'] = float(v)
                elif k == 'scale':
                    options['scale'] = float(v)
                elif k == 'textual':
                    options['textual'] = True
                elif k == 'proportional':
                    options['proportional'] = True
                elif k == 'linewidth':
                    options['linewidth'] = float(v)
                elif k == 'foreground':
                    options['foreground'] = sanitizte_color(v)
                elif k == 'fill':
                    options['fill'] = sanitizte_color(v)
                # no 'background' as SVG backend ignores that
                # no generic options
                # XXX unknown options are ignored with no message

            visitor, output = aafigure.render(self.raw, None, options)
            cache.put(self.request,
                      key,
                      output.getvalue(),
                      content_type="image/svg+xml")
            # need to store the size attributes too
            cache.put(self.request,
                      key + '_size',
                      visitor.get_size_attrs(),
                      content_type="text/plain")

        # get the information from the cache
        #~ return formatter.image(src=cache.url(self.request, key), alt=xxx)
        # XXX this currently only works for HTML, obviously...
        return formatter.rawHTML(
            '<object type="image/svg+xml" data="%s" %s></object>' % (
                cache.url(self.request, key),
                cache._get_datafile(
                    self.request,
                    key + '_size').read()  # XXX no way to directly read cache?
            ))
示例#3
0
    def render(self, formatter):
        """text to image conversion"""
        key = 'aafigure_%s' % (cache.key(self.request, itemname=self.pagename, content="%s%s" % (self.raw, self.args)),)
        if not cache.exists(self.request, key) or not cache.exists(self.request, key+'_size'):
            # not in cache, regenerate image
            options = dict(format='svg')
            for arg in self.args.split():
                try:
                    k, v = arg.split('=', 1)
                except ValueError:  # when splitting fails
                    k = arg
                    v = None
                if k == 'aspect':
                    options['aspect'] = float(v)
                elif k == 'scale':
                    options['scale'] = float(v)
                elif k == 'textual':
                    options['textual'] = True
                elif k == 'proportional':
                    options['proportional'] = True
                elif k == 'linewidth':
                    options['linewidth'] = float(v)
                elif k == 'foreground':
                    options['foreground'] = sanitizte_color(v)
                elif k == 'fill':
                    options['fill'] = sanitizte_color(v)
                # no 'background' as SVG backend ignores that
                # no generic options
                # XXX unknown options are ignored with no message

            visitor, output = aafigure.render(self.raw, None, options)
            cache.put(self.request, key, output.getvalue(), content_type="image/svg+xml")
            # need to store the size attributes too
            cache.put(self.request, key+'_size', visitor.get_size_attrs(), content_type="text/plain")

        # get the information from the cache
        #~ return formatter.image(src=cache.url(self.request, key), alt=xxx)
        # XXX this currently only works for HTML, obviously...
        return formatter.rawHTML('<object type="image/svg+xml" data="%s" %s></object>' % (
            cache.url(self.request, key),
            cache._get_datafile(self.request, key+'_size').read() # XXX no way to directly read cache?
        ))