'''
An extention which collects all images to the documents directory and
creates a zip archive containing all images and the document
Copyright (C) 2005 Pim Snel, pim@lingewoud.com
Copyright (C) 2008 Aaron Spike, aaron@ekips.org
Copyright (C) 2011 Nicolas Dufour, nicoduf@yahoo.fr
* Fix for a bug related to special caracters in the path (LP #456248).
* Fix for Windows support (LP #391307 ).
* Font list and image directory features.
this is the first Python script ever created
its based on embedimage.py
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
TODOs
- fix bug: not saving existing .zip after a Collect for Output is run
this bug occurs because after running an effect extention the inkscape:output_extension is reset to svg.inkscape
the file name is still xxx.zip. after saving again the file xxx.zip is written with a plain .svg which
looks like a corrupt zip
- maybe add better extention
- consider switching to lzma in order to allow cross platform compression with no encoding problem...
'''
# standard library
import urlparse
import urllib
import string
import zipfile
import shutil
import sys
import tempfile
import locale
# local library
import inkex
import simplestyle
else:
'{http://www.w3.org/2000/svg}text',
'{http://www.w3.org/2000/svg}flowRoot',
'{http://www.w3.org/2000/svg}flowPara',
'{http://www.w3.org/2000/svg}flowSpan']
help="Image directory")
help="Add font list")
dest="tab",
help="The selected UI-tab when OK was pressed")
'''
Writes the temporary compressed file to its destination
and removes the temporary directory.
'''
try:
import msvcrt
except:
pass
'''
Collects all images in the document
and copy them to the temporary directory.
'''
if locale.getpreferredencoding():
else:
dir_locale = "UTF-8"
if (href != None):
# TODO: please explain why this clause is necessary
else:
#node.set(inkex.addNS('absref',u'sodipodi'), image_path)
'''
Copy SVG document to the temporary directory
and add it to the temporary compressed file
'''
'''
Returns true if the tag in question is an element that
can hold text.
'''
'''
Given a node, returns a list containing all the fonts that
the node is using.
'''
fonts = []
s = ''
if not s:
return fonts
if s.has_key('font-family'):
if s.has_key('font-weight'):
else:
elif s.has_key('-inkscape-font-specification'):
return fonts
'''
Walks through nodes, building a list of all fonts found, then
reports to the user with that list.
Based on Craig Marshall's replace_font.py
'''
items = []
nodes = []
fonts_found = []
if not f in fonts_found:
# Write list to the temporary compressed file
filename = 'fontlist.txt'
else:
else:
#inkex.errormsg(_('Locale: %s') % locale.getpreferredencoding())
if docname is None:
# TODO: replace whatever extention
# Create os temp dir
# Create destination zip in same directory as the document
self.list_fonts(z)
z.close()
e = CompressedMediaOutput()
e.affect()
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99