Opened 12 years ago

Closed 3 years ago

# Link to Attachment folder seems to be broken

Reported by: Owned by: anonymous Richard Liao normal TracImageSvgMacro normal link, attachment, size Sam Halliday 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

### comment:1 Changed 12 years ago by Richard Liao

Status: new → assigned

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/

/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 12 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 10 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 follow-up:  7 Changed 10 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 10 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:

### comment:6 Changed 10 years ago by Markus Kohler

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:

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 return inspect.getdoc(self.__class__) def expand_macro(self, formatter, name, content): ''' Usage: [[ImageSvg(module:path:file, width, height)]], width and height optional direct attachment: [[ImageSvg(directattachment.svg)]] with 50% scaling in width and 60% in height [[ImageSvg(directattachment.svg, 50%, 60%)]] with 3in in width and 6in in height [[ImageSvg(directattachment.svg, 3in, 6in)]] reference to attachment on other page: [[ImageSvg(othersite/diagrams:attachment.svg)]] ''' # args will be null if the macro is called without parenthesis. if not content: return '' try: attachment = Attachment(self.env, module, id, file) org_path = attachment.path try: if targetSize is None: f = open(org_path, 'r') svg = f.readlines() f.close() svg = "".join(svg).replace('\n', '') else: svg = targetSize w = re.search('''width=["']([0-9]+\.?[0-9]?)(.*?)["']''', svg) h = re.search('''height=["']([0-9]+\.?[0-9]?)(.*?)["']''', svg) (w_val, w_unit) = w.group(1,2) (h_val, h_unit) = h.group(1,2) w_unit = w_unit.strip() h_unit = h_unit.strip() unitMapping = { "cm": 72 / 2.54, "mm": 72 / 25.4, "in": 72 / 1, "pc": 72 / 6, "": 1, } except: return '%s not found' % (filespec) import math if w_unit in unitMapping.keys(): w_val = int(math.ceil(float(w_val) * unitMapping[w_unit])) h_val = int(math.ceil(float(h_val) * unitMapping[w_unit])) w_unit = "pt" h_unit = "pt" module = 'raw-attachment/' + module try: if targetSize is None: f = open(org_path, 'r') svg = f.readlines() f.close() svg = "".join(svg).replace('\n', '') else: svg = targetSize # Fixed regular expressions: w = re.search('''width=["']([0-9]+\.?[0-9]*)(.*?)["']''', svg) h = re.search('''height=["']([0-9]+\.?[0-9]*)(.*?)["']''', svg) (w_val, w_unit) = w.group(1,2) (h_val, h_unit) = h.group(1,2) w_unit = w_unit.strip() h_unit = h_unit.strip() unitMapping = { "cm": 72 / 2.54, "mm": 72 / 25.4, "in": 72 / 1, "pc": 72 / 6, "": 1, } dimensions = 'width="%(w_val)s%(w_unit)s" height="%(h_val)s%(h_unit)s"' % locals() except: dimensions = 'width="100%" height="100%"' # made two if from one: you cannot expect that the units of the # width is always the same as of the height import math if w_unit in unitMapping.keys(): w_val = int(math.ceil(float(w_val) * unitMapping[w_unit])) w_unit = "pt" if h_unit in unitMapping.keys(): h_val = int(math.ceil(float(h_val) * unitMapping[h_unit])) h_unit = "pt" data = { "base_url": self.env.base_url, "module": module, "id": id, "file": file, "dimensions": dimensions, } s = ''' dimensions = 'width="%(w_val)s%(w_unit)s" height="%(h_val)s%(h_unit)s"' % locals() except: dimensions = 'width="100%" height="100%"' data = { "base_url": self.env.base_url, "module": module, "id": id, "file": file, "dimensions": dimensions, } s = '''
src="%(base_url)s/%(module)s/%(id)s/%(file)s" %(dimensions)s>
''' % data return s except: return '%s not found' % (filespec) return s # IRequestHandler methods def match_request(self, req):

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

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 9 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 9 years ago by Sam Halliday

Cc: Sam Halliday added; anonymous removed

### comment:10 Changed 3 years ago by Ryan J Ollos

Resolution: → wontfix assigned → closed

Plugin is deprecated.

### Modify Ticket

Change Properties