summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJos Hirth <github@kaioa.com>2007-01-09 09:24:59 +0000
committeramphi <amphi@users.sourceforge.net>2007-01-09 09:24:59 +0000
commit1304e4e8f9675a73496d9e50e4781dc3fb86a5fb (patch)
tree9a841453a66d2d20b4d33c2437ad739741f6e450
parentadded a "selected only" checkbox for fixing some obscure usability issue (diff)
downloadinkscape-1304e4e8f9675a73496d9e50e4781dc3fb86a5fb.tar.gz
inkscape-1304e4e8f9675a73496d9e50e4781dc3fb86a5fb.zip
working around the additional issue (broken embed/extract/embed cycle) from #1427736 2006-02-08 17:57 (by bactisme)
(bzr r2166)
-rw-r--r--share/extensions/embedimage.py32
-rw-r--r--share/extensions/extractimage.py6
2 files changed, 30 insertions, 8 deletions
diff --git a/share/extensions/embedimage.py b/share/extensions/embedimage.py
index 964d1a5ec..81380c165 100644
--- a/share/extensions/embedimage.py
+++ b/share/extensions/embedimage.py
@@ -45,8 +45,30 @@ class MyEffect(inkex.Effect):
xlink = node.attributes.getNamedItemNS(inkex.NSS[u'xlink'],'href')
if (xlink.value[:4]!='data'):
absref=node.attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'absref')
- if (os.path.isfile(absref.value)):
- file = open(absref.value,"rb").read()
+ href=node.attributes.getNamedItemNS(inkex.NSS[u'xlink'],'href')
+ svg=self.document.getElementsByTagName('svg')[0]
+ docbase=svg.attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'docbase')
+
+ path=''
+ #path selection strategy:
+ # 1. absref
+ # 2. href if absolute
+ # 3. sodipodi:docbase + href
+ # 4. realpath-ified href
+ if (absref != None):
+ path=absref.value
+ elif (href != None):
+ if (os.path.isabs(href.value)):
+ path=os.path.realpath(href.value)
+ elif (docbase != None):
+ path=os.path.join(docbase.value,href.value)
+ else:
+ path=os.path.realpath(href.value)
+ else:
+ inkex.debug('No xlink:href or sodipodi:absref attributes found! Unable to embed image.')
+
+ if (os.path.isfile(path)):
+ file = open(path,"rb").read()
embed=True
if (file[:4]=='\x89PNG'):
type='image/png'
@@ -57,7 +79,7 @@ class MyEffect(inkex.Effect):
elif (file[:6]=='GIF87a' or file[:6]=='GIF89a'):
type='image/gif'
#ico files lack any magic... therefore we check the filename instead
- elif(absref.value.endswith('.ico')):
+ elif(path.endswith('.ico')):
type='image/x-icon' #official IANA registered MIME is 'image/vnd.microsoft.icon' tho
else:
embed=False
@@ -65,8 +87,8 @@ class MyEffect(inkex.Effect):
xlink.value = 'data:%s;base64,%s' % (type, base64.encodestring(file))
node.removeAttributeNS(inkex.NSS[u'sodipodi'],'absref')
else:
- inkex.debug("%s is not of type image/png, image/jpeg, image/bmp, image/gif or image/x-icon" % absref.value)
+ inkex.debug("%s is not of type image/png, image/jpeg, image/bmp, image/gif or image/x-icon" % path)
else:
- inkex.debug("Sorry we could not locate %s" % absref.value)
+ inkex.debug("Sorry we could not locate %s" % path)
e = MyEffect()
e.affect()
diff --git a/share/extensions/extractimage.py b/share/extensions/extractimage.py
index 5807c9e5b..f0540ac50 100644
--- a/share/extensions/extractimage.py
+++ b/share/extensions/extractimage.py
@@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
-import inkex, base64
+import inkex, base64, os
class MyEffect(inkex.Effect):
def __init__(self):
@@ -36,7 +36,7 @@ class MyEffect(inkex.Effect):
'icon':'.ico',
'gif' :'.gif'
}
- ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)
+ #ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)
# exbed the first embedded image
path = self.options.filepath
@@ -60,7 +60,7 @@ class MyEffect(inkex.Effect):
#save
data = base64.decodestring(xlink.value[comma:])
open(path,'wb').write(data)
- xlink.value = path
+ xlink.value = os.path.realpath(path) #absolute for making in-mem cycles work
else:
inkex.debug('Difficulty finding the image data.')
break