Modify

Opened 15 years ago

Closed 7 years ago

#6448 closed defect (wontfix)

Link to Attachment folder seems to be broken

Reported by: anonymous Owned by: Richard Liao
Priority: normal Component: TracImageSvgMacro
Severity: normal Keywords: link, attachment, size
Cc: Sam Halliday Trac Release: 0.11

Description

I tried to use this Macro with trac 0.11 but my SVG files aren't displayed there seems to be a Problem with the attachment path. The html Sourcecode which is created links to

/svg/attachments/wiki/

but my attachments are in

/attachments/wiki/

without the svg in front of it

Attachments (0)

Change History (10)

comment:1 Changed 15 years ago by Richard Liao

Status: newassigned

Try the following to figure out the problem:

  1. Check http://xxxx/YourTrac/attachment/wiki/YourPage/YourSvg.svg
    • If failed, then the svg file does not exist. Upload one then retry.
    • BTW, attachment is in
      /attachment/wiki/
      
      instead of in
      /attachments/wiki/
      
  2. Check http://xxxx/YourTrac/svg/attachments/wiki/YourPage/YourSvg.svg
    • If failed, maybe the macro is not activated. Check if the macro is installed properly.

comment:2 Changed 15 years ago by anonymous

I tried the second link and the svg is displayed properly, but when I try to display it in a wiki page no Picture is displayed: Opera 10 says

Enviroment not loaded

and IE 8 display a empty picture frame with no picture but with the correct size FireFox 3.5 displays nothing

I tried to switch render_unsafe_content on but nothing changed

comment:3 Changed 14 years ago by anonymous

any news on this ticket? actually I've been subject to the same issue. A direct access to the svg attachment is ok but the ImageSvg macro returns always Environment not found.

Is there any dependency that we need to install?

Thanks.

comment:4 Changed 14 years ago by Nelso G. Jost

I have the same problem. A wiki page was created in a html frame, where I supose the image should be showed. However, what I have is a red box warning from Trac saying:

Error: Not Found

No handler matched request to /svg/attachments/ticket/187/Warning.svg

The output of the macro [[ImageSvg(Warning.svg)]] (is an attachment) on the comment preview for this ticket is:

Error: Macro ImageSvg(Warning.svg) failed

Cannot use this macro in this module (len(parts)=2, file=Warning.svg, path_info=/wiki_render, parts=[u'', u'wiki_render'])

I also try to modify the lines on web_ui.py with the content /svg/attachments, which I think might be the problem (I my Trac, attachments addresses are just <env>/attachment/wiki/<page_name>/<atach_file>.

comment:5 Changed 13 years ago by Markus Kohler

You need to replace the src= attribute of the embed tag from:

src="%(base_url)s/svg/attachments/%(module)s/%(id)s/%(file)s"

to:

src="%(base_url)s/%(module)s/%(id)s/%(file)s"

Also the adobe plugin is not needed anymore since all browsers can now draw svg, so the pluginspage attribute of the embed tag can be removed:

pluginspage="http://www.adobe.com/svg/viewer/install/">

comment:6 Changed 13 years ago by Markus Kohler

Keywords: link attachment size added

Did some patches, one of which repairs this link attachment problem. Here first the readme since I also restructured code:

The following description and the patches apply to version 0.11 of tracimagesvgmacro!

How to apply the patches:

  1. unzip tracimagesvgmacro-r10185.zip
  2. Enter the unzipped archive: cd tracimagesvgmacro/0.11/imagesvg
  3. call: patch < ../../../patch1to6.diff
  4. call: patch < ../../../patchURL.diff
  5. call: patch < ../../../patchBrowser.diff

For easier understanding I try to comment the different steps I took:

  1. I added a python description to the expand_macro with Usage and some examples
  1. I took the try... except block for the width, height calculation out of the try ... except of the attachment=Attachment(self.env...) block (they were nested. The nesting is not necessary and makes it easier to add support for browser module which I try in the next steps. This results in a very short

try

attachment = Attachment(self.env, module, id, file) org_path = attachment.path

except:

return '%s not found' % (filespec)

and try:

if targetSize is None:

...

except

dimensions =...

for the calculation of the dimensions.

  1. In the calculation of the dimensions I fixed the regular expression (replaced a '?' by '*') because the old one split:

8.2663in into (w_val, w_unit) = (8.2, 663in)

  1. In the calculation of the dimensions I made two if statements out of the one directly after the import math command, because in theory the width may have different units than the height

For item 3. and 4. see ticket #8973

  1. I removed the style="margin: 0pt; padding: 0pt" and pluginspage="http://www.adobe.com..../" attributes from the <embed tag, since I did not see a difference and since new browsers all seem to support svg and the adobe plugin is no more necessary
  1. I changed the src=" ..." attribute, because it simply did not work the old way. I found that src="%(base_url)s/raw-attachment/%(module)s/%(id)s/%(file)s" does the job, however, for laters browser inclusion I prepended the raw-attachment to the module variable ending up in

src="%(base_url)s/%(module)s/%(id)s/%(file)s"

Because of unnesting the dimension's try except block from the attachment try except, some of the above changes are not immediately visible in the diff of the patch, which is why I explained the stuff in 1.-6. I put all the above changes into patch1to6.diff

as reported in ticket #8976:

Now, I am currently working over several ssh tunnels and have port forwarding setup. For instance with http://localhost:8080/qm I get my main page where I use ImageSvg. Using the original version where base_url is set to self.env.base_url causes a replacement of http://localhost:8080/qm to (changed) http://www.somewhere.com/qm. This is wrong in my case (double tunneling). What I found is: setting base_url to simply "/qm" works better and should also work in other cases. "/qm" acutally is formatter.href(). This results in patchURL.diff.

Finally I tried to add browser module support, i.e. that svg graphics can be retrieved from a svn repository or so. The necessary changes resulted in patchBrowser.diff. However, I could not get it to display the SVG. I do not completely know why but I guess, that in the browser module the output is generated temporarily when clicked on a link. If I have a graphics in SVN and click on the link original format, I get a URL that contains .../export/25/... and I verified that I build exactly that URL but still no SVG is displayed when accessing it in the browser module. Maybe you have an idea how to do it.

I also prefer a centered graphics and added <center> around the <embed ...>

The changes for browser module support (i.e. ImageSvg(browser:trunk/some/other.svg)) is reflected in patchBrowser.diff

  • imagesvg/web_ui.py

    old new  
    4141        return inspect.getdoc(self.__class__)
    4242
    4343    def expand_macro(self, formatter, name, content):
     44        '''
     45        Usage:
     46
     47        [[ImageSvg(module:path:file, width, height)]], width and height optional
     48
     49        direct attachment:
     50        [[ImageSvg(directattachment.svg)]]
     51        with 50% scaling in width and 60% in height
     52        [[ImageSvg(directattachment.svg, 50%, 60%)]]
     53        with 3in in width and 6in in height
     54        [[ImageSvg(directattachment.svg, 3in, 6in)]]
     55        reference to attachment on other page:
     56        [[ImageSvg(othersite/diagrams:attachment.svg)]]
     57        '''
    4458        # args will be null if the macro is called without parenthesis.
    4559        if not content:
    4660            return ''
     
    92106        try:
    93107            attachment = Attachment(self.env, module, id, file)
    94108            org_path = attachment.path
    95             try:
    96                 if targetSize is None:
    97                     f = open(org_path, 'r')
    98                     svg = f.readlines()
    99                     f.close()
    100                     svg = "".join(svg).replace('\n', '')
    101                 else:
    102                     svg = targetSize
    103                 w = re.search('''width=["']([0-9]+\.?[0-9]?)(.*?)["']''', svg)
    104                 h = re.search('''height=["']([0-9]+\.?[0-9]?)(.*?)["']''', svg)
    105                 (w_val, w_unit) = w.group(1,2)
    106                 (h_val, h_unit) = h.group(1,2)
    107                 w_unit = w_unit.strip()
    108                 h_unit = h_unit.strip()
    109 
    110                 unitMapping = {
    111                     "cm": 72 / 2.54,
    112                     "mm": 72 / 25.4,
    113                     "in": 72 / 1,
    114                     "pc": 72 / 6,
    115                     "": 1,
    116                 }
     109        except:
     110            return '%s not found' % (filespec)
    117111
    118                 import math
    119                 if w_unit in unitMapping.keys():
    120                     w_val = int(math.ceil(float(w_val) * unitMapping[w_unit]))
    121                     h_val = int(math.ceil(float(h_val) * unitMapping[w_unit]))
    122                     w_unit = "pt"
    123                     h_unit = "pt"
     112        module = 'raw-attachment/' + module
    124113
     114        try:
     115            if targetSize is None:
     116                f = open(org_path, 'r')
     117                svg = f.readlines()
     118                f.close()
     119                svg = "".join(svg).replace('\n', '')
     120            else:
     121                svg = targetSize
     122            # Fixed regular expressions:
     123            w = re.search('''width=["']([0-9]+\.?[0-9]*)(.*?)["']''', svg)
     124            h = re.search('''height=["']([0-9]+\.?[0-9]*)(.*?)["']''', svg)
     125            (w_val, w_unit) = w.group(1,2)
     126            (h_val, h_unit) = h.group(1,2)
     127            w_unit = w_unit.strip()
     128            h_unit = h_unit.strip()
     129           
     130            unitMapping = {
     131                "cm": 72 / 2.54,
     132                "mm": 72 / 25.4,
     133                "in": 72 / 1,
     134                "pc": 72 / 6,
     135                "": 1,
     136                }
    125137
    126                 dimensions = 'width="%(w_val)s%(w_unit)s" height="%(h_val)s%(h_unit)s"' % locals()
    127             except:
    128                 dimensions = 'width="100%" height="100%"'
     138            # made two if from one: you cannot expect that the units of the
     139            # width is always the same as of the height
     140            import math
     141            if w_unit in unitMapping.keys():
     142                w_val = int(math.ceil(float(w_val) * unitMapping[w_unit]))
     143                w_unit = "pt"
     144            if h_unit in unitMapping.keys():
     145                h_val = int(math.ceil(float(h_val) * unitMapping[h_unit]))
     146                h_unit = "pt"
    129147
    130             data = {
    131                 "base_url": self.env.base_url,
    132                 "module": module,
    133                 "id": id,
    134                 "file": file,
    135                 "dimensions": dimensions,
    136                 }
    137             s = '''
     148            dimensions = 'width="%(w_val)s%(w_unit)s" height="%(h_val)s%(h_unit)s"' % locals()
     149        except:
     150            dimensions = 'width="100%" height="100%"'
     151
     152        data = {
     153            "base_url": self.env.base_url,
     154            "module": module,
     155            "id": id,
     156            "file": file,
     157            "dimensions": dimensions,
     158            }
     159        s = '''
    138160            <div>
    139161            <embed  type="image/svg+xml"
    140                 style="margin: 0pt; padding: 0pt;"
    141                 src="%(base_url)s/svg/attachments/%(module)s/%(id)s/%(file)s" 
    142                 %(dimensions)s
    143                 pluginspage="http://www.adobe.com/svg/viewer/install/">
     162                src="%(base_url)s/%(module)s/%(id)s/%(file)s" 
     163                %(dimensions)s>
    144164            </embed>
    145165            </div>
    146166            ''' % data
    147             return s
    148         except:
    149             return '%s not found' % (filespec)
     167        return s
    150168
    151169    # IRequestHandler methods
    152170    def match_request(self, req):

comment:7 in reply to:  4 Changed 13 years ago by Dmitri

Replying to nelsojost:

The output of the macro [[ImageSvg(Warning.svg)]] (is an attachment) on the comment preview for this ticket is:

Error: Macro ImageSvg(Warning.svg) failed

Cannot use this macro in this module (len(parts)=2, file=Warning.svg, path_info=/wiki_render, parts=[u'', u'wiki_render'])

I see the same behavior in trac-0.12.2 (it was probably OK in trac-0.12.0). Maybe it is a separate bug.

comment:8 Changed 12 years ago by Sam Halliday

I set up a fresh 0.11.7 install (OS X) and when I serve with tracd and build/install the EGG from the ZIP download, I get exactly the same problem for inline placement. Clicking on the attachment, I am able to see the rendered SVG, but I don't need a plugin for that!

comment:9 Changed 12 years ago by Sam Halliday

Cc: Sam Halliday added; anonymous removed

comment:10 Changed 7 years ago by Ryan J Ollos

Resolution: wontfix
Status: assignedclosed

Plugin is deprecated.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Richard Liao.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.