mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Update odfpy (used to conver OpenOffice documents)
This commit is contained in:
parent
dc06ef85cf
commit
062fb907e3
@ -16,7 +16,6 @@ from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \
|
||||
from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog
|
||||
from calibre.gui2.dialogs.fetch_metadata import FetchMetadata
|
||||
from calibre.gui2.dialogs.tag_editor import TagEditor
|
||||
from calibre.gui2.dialogs.password import PasswordDialog
|
||||
from calibre.gui2.widgets import ProgressIndicator
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
from calibre.ebooks.metadata import authors_to_sort_string, string_to_authors, authors_to_string
|
||||
@ -360,26 +359,8 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
||||
tag_string = ', '.join(d.tags)
|
||||
self.tags.setText(tag_string)
|
||||
|
||||
def lt_password_dialog(self):
|
||||
return PasswordDialog(self, 'LibraryThing account',
|
||||
_('<p>Enter your username and password for '
|
||||
'<b>LibraryThing.com</b>. This is <b>optional</b>. It will '
|
||||
'make fetching of covers faster and more reliable.<br/>If '
|
||||
'you do not have an account, you can '
|
||||
'<a href=\'http://www.librarything.com\'>register</a> for '
|
||||
'free.</p>'))
|
||||
|
||||
def change_password(self):
|
||||
d = self.lt_password_dialog()
|
||||
d.exec_()
|
||||
|
||||
def fetch_cover(self):
|
||||
isbn = unicode(self.isbn.text()).strip()
|
||||
#d = self.lt_password_dialog()
|
||||
#if not gui_conf['asked_library_thing_password'] and \
|
||||
# (not d.username() or not d.password()):
|
||||
# d.exec_()
|
||||
# gui_conf['asked_library_thing_password'] = True
|
||||
self.fetch_cover_button.setEnabled(False)
|
||||
self.setCursor(Qt.WaitCursor)
|
||||
title, author = map(unicode, (self.title.text(), self.authors.text()))
|
||||
|
@ -182,11 +182,6 @@ def cnv_points(attribute, arg, element):
|
||||
raise ValueError, "Points must be string or [(0,0),(1,1)] - not %s" % arg
|
||||
return strarg
|
||||
|
||||
def cnv_position(attribute, arg, element):
|
||||
if element == (STYLENS,u'tab-stop'):
|
||||
return cnv_length(attribute, arg, element)
|
||||
return cnv_string(attribute, arg, element)
|
||||
|
||||
def cnv_positiveInteger(attribute, arg, element):
|
||||
return str(arg)
|
||||
|
||||
@ -253,7 +248,7 @@ attrconverters = {
|
||||
((CHARTNS,u'gap-width'), None): cnv_string,
|
||||
((CHARTNS,u'interpolation'), None): cnv_string,
|
||||
((CHARTNS,u'interval-major'), None): cnv_string,
|
||||
((CHARTNS,u'interval-minor'), None): cnv_string,
|
||||
((CHARTNS,u'interval-minor-divisor'), None): cnv_string,
|
||||
((CHARTNS,u'japanese-candle-stick'), None): cnv_boolean,
|
||||
((CHARTNS,u'label-arrangement'), None): cnv_string,
|
||||
((CHARTNS,u'label-cell-address'), None): cnv_string,
|
||||
@ -352,6 +347,7 @@ attrconverters = {
|
||||
((DRAWNS,u'caption-line-length'), None): cnv_length,
|
||||
((DRAWNS,u'caption-point-x'), None): cnv_string,
|
||||
((DRAWNS,u'caption-point-y'), None): cnv_string,
|
||||
((DRAWNS,u'caption-id'), None): cnv_IDREF,
|
||||
((DRAWNS,u'caption-type'), None): cnv_string,
|
||||
((DRAWNS,u'chain-next-name'), None): cnv_string,
|
||||
((DRAWNS,u'class-id'), None): cnv_string,
|
||||
@ -476,6 +472,7 @@ attrconverters = {
|
||||
((DRAWNS,u'modifiers'), None): cnv_string,
|
||||
((DRAWNS,u'name'), None): cnv_NCName,
|
||||
# ((DRAWNS,u'name'), None): cnv_string,
|
||||
((DRAWNS,u'nav-order'), None): cnv_IDREF,
|
||||
((DRAWNS,u'nohref'), None): cnv_string,
|
||||
((DRAWNS,u'notify-on-update-of-ranges'), None): cnv_string,
|
||||
((DRAWNS,u'object'), None): cnv_string,
|
||||
@ -683,7 +680,7 @@ attrconverters = {
|
||||
((MANIFESTNS,'initialisation-vector'), None): cnv_string,
|
||||
((MANIFESTNS,'iteration-count'), None): cnv_nonNegativeInteger,
|
||||
((MANIFESTNS,'key-derivation-name'), None): cnv_string,
|
||||
((MANIFESTNS,'manifest:media-type'), None): cnv_string,
|
||||
((MANIFESTNS,'media-type'), None): cnv_string,
|
||||
((MANIFESTNS,'salt'), None): cnv_string,
|
||||
((MANIFESTNS,'size'), None): cnv_nonNegativeInteger,
|
||||
((METANS,u'cell-count'), None): cnv_nonNegativeInteger,
|
||||
@ -746,6 +743,7 @@ attrconverters = {
|
||||
((OFFICENS,u'target-frame'), None): cnv_string,
|
||||
((OFFICENS,u'target-frame-name'), None): cnv_string,
|
||||
((OFFICENS,u'time-value'), None): cnv_duration,
|
||||
((OFFICENS,u'title'), None): cnv_string,
|
||||
((OFFICENS,u'value'), None): cnv_double,
|
||||
((OFFICENS,u'value-type'), None): cnv_string,
|
||||
((OFFICENS,u'version'), None): cnv_string,
|
||||
@ -783,6 +781,7 @@ attrconverters = {
|
||||
((PRESENTATIONNS,u'preset-id'), None): cnv_string,
|
||||
((PRESENTATIONNS,u'preset-sub-type'), None): cnv_string,
|
||||
((PRESENTATIONNS,u'show'), None): cnv_string,
|
||||
((PRESENTATIONNS,u'show-end-of-presentation-slide'), None): cnv_boolean,
|
||||
((PRESENTATIONNS,u'show-logo'), None): cnv_boolean,
|
||||
((PRESENTATIONNS,u'source'), None): cnv_string,
|
||||
((PRESENTATIONNS,u'speed'), None): cnv_string,
|
||||
@ -873,6 +872,8 @@ attrconverters = {
|
||||
((STYLENS,u'flow-with-text'), None): cnv_boolean,
|
||||
((STYLENS,u'font-adornments'), None): cnv_string,
|
||||
((STYLENS,u'font-charset'), None): cnv_string,
|
||||
((STYLENS,u'font-charset-asian'), None): cnv_string,
|
||||
((STYLENS,u'font-charset-complex'), None): cnv_string,
|
||||
((STYLENS,u'font-family-asian'), None): cnv_string,
|
||||
((STYLENS,u'font-family-complex'), None): cnv_string,
|
||||
((STYLENS,u'font-family-generic-asian'), None): cnv_string,
|
||||
@ -949,7 +950,8 @@ attrconverters = {
|
||||
((STYLENS,u'page-usage'), None): cnv_string,
|
||||
((STYLENS,u'paper-tray-name'), None): cnv_string,
|
||||
((STYLENS,u'parent-style-name'), None): cnv_StyleNameRef,
|
||||
((STYLENS,u'position'), None): cnv_position,
|
||||
((STYLENS,u'position'), (STYLENS,u'tab-stop')): cnv_length,
|
||||
((STYLENS,u'position'), None): cnv_string,
|
||||
((STYLENS,u'print'), None): cnv_string,
|
||||
((STYLENS,u'print-content'), None): cnv_boolean,
|
||||
((STYLENS,u'print-orientation'), None): cnv_string,
|
||||
@ -1015,7 +1017,7 @@ attrconverters = {
|
||||
((STYLENS,u'wrap'), None): cnv_string,
|
||||
((STYLENS,u'wrap-contour'), None): cnv_boolean,
|
||||
((STYLENS,u'wrap-contour-mode'), None): cnv_string,
|
||||
((STYLENS,u'wrap-dynamic-treshold'), None): cnv_string,
|
||||
((STYLENS,u'wrap-dynamic-threshold'), None): cnv_length,
|
||||
((STYLENS,u'writing-mode-automatic'), None): cnv_boolean,
|
||||
((STYLENS,u'writing-mode'), None): cnv_string,
|
||||
((SVGNS,u'accent-height'), None): cnv_integer,
|
||||
@ -1122,7 +1124,7 @@ attrconverters = {
|
||||
((TABLENS,u'database-table-name'), None): cnv_string,
|
||||
((TABLENS,u'date-end'), None): cnv_string,
|
||||
((TABLENS,u'date-start'), None): cnv_string,
|
||||
((TABLENS,u'date-value-type'), None): cnv_date,
|
||||
((TABLENS,u'date-value'), None): cnv_date,
|
||||
((TABLENS,u'default-cell-style-name'), None): cnv_StyleNameRef,
|
||||
((TABLENS,u'direction'), None): cnv_string,
|
||||
((TABLENS,u'display-border'), None): cnv_boolean,
|
||||
@ -1304,7 +1306,7 @@ attrconverters = {
|
||||
((TEXTNS,u'database-name'), None): cnv_string,
|
||||
((TEXTNS,u'date-adjust'), None): cnv_duration,
|
||||
((TEXTNS,u'date-value'), None): cnv_date,
|
||||
((TEXTNS,u'date-value'), None): cnv_dateTime,
|
||||
# ((TEXTNS,u'date-value'), None): cnv_dateTime,
|
||||
((TEXTNS,u'default-style-name'), None): cnv_StyleNameRef,
|
||||
((TEXTNS,u'description'), None): cnv_string,
|
||||
((TEXTNS,u'display'), None): cnv_string,
|
||||
@ -1366,6 +1368,7 @@ attrconverters = {
|
||||
((TEXTNS,u'outline-level'), None): cnv_string,
|
||||
((TEXTNS,u'page-adjust'), None): cnv_integer,
|
||||
((TEXTNS,u'pages'), None): cnv_string,
|
||||
((TEXTNS,u'paragraph-style-name'), None): cnv_StyleNameRef,
|
||||
((TEXTNS,u'placeholder-type'), None): cnv_string,
|
||||
((TEXTNS,u'prefix'), None): cnv_string,
|
||||
((TEXTNS,u'protected'), None): cnv_boolean,
|
||||
@ -1417,6 +1420,7 @@ attrconverters = {
|
||||
((TEXTNS,u'use-objects'), None): cnv_boolean,
|
||||
((TEXTNS,u'use-other-objects'), None): cnv_boolean,
|
||||
((TEXTNS,u'use-outline-level'), None): cnv_boolean,
|
||||
((TEXTNS,u'use-soft-page-breaks'), None): cnv_boolean,
|
||||
((TEXTNS,u'use-spreadsheet-objects'), None): cnv_boolean,
|
||||
((TEXTNS,u'use-tables'), None): cnv_boolean,
|
||||
((TEXTNS,u'value'), None): cnv_nonNegativeInteger,
|
||||
|
@ -258,10 +258,7 @@ class Element(Node):
|
||||
self.ownerDocument = None
|
||||
self.childNodes=[]
|
||||
self.allowed_children = grammar.allowed_children.get(self.qname)
|
||||
namespace = self.qname[0]
|
||||
prefix = _nsassign(namespace)
|
||||
if not self.namespaces.has_key(namespace):
|
||||
self.namespaces[namespace] = prefix
|
||||
prefix = self.get_nsprefix(self.qname[0])
|
||||
self.tagName = prefix + ":" + self.qname[1]
|
||||
if text is not None:
|
||||
self.addText(text)
|
||||
@ -296,6 +293,13 @@ class Element(Node):
|
||||
if self.getAttrNS(r[0],r[1]) is None:
|
||||
raise AttributeError, "Required attribute missing: %s in <%s>" % (r[1].lower().replace('-',''), self.tagName)
|
||||
|
||||
def get_nsprefix(self, namespace):
|
||||
if namespace is None: namespace = ""
|
||||
prefix = _nsassign(namespace)
|
||||
if not self.namespaces.has_key(namespace):
|
||||
self.namespaces[namespace] = prefix
|
||||
return prefix
|
||||
|
||||
def allowed_attributes(self):
|
||||
return grammar.allowed_attributes.get(self.qname)
|
||||
|
||||
@ -378,24 +382,18 @@ class Element(Node):
|
||||
Must overwrite, If attribute already exists.
|
||||
"""
|
||||
allowed_attrs = self.allowed_attributes()
|
||||
prefix = _nsassign(namespace)
|
||||
if not self.namespaces.has_key(namespace):
|
||||
self.namespaces[namespace] = prefix
|
||||
prefix = self.get_nsprefix(namespace)
|
||||
# if allowed_attrs and (namespace, localpart) not in allowed_attrs:
|
||||
# raise AttributeError, "Attribute %s:%s is not allowed in element <%s>" % ( prefix, localpart, self.tagName)
|
||||
c = AttrConverters()
|
||||
self.attributes[prefix + ":" + localpart] = c.convert((namespace, localpart), value, self.qname)
|
||||
|
||||
def getAttrNS(self, namespace, localpart):
|
||||
prefix = _nsassign(namespace)
|
||||
if not self.namespaces.has_key(namespace):
|
||||
self.namespaces[namespace] = prefix
|
||||
prefix = self.get_nsprefix(namespace)
|
||||
return self.attributes.get(prefix + ":" + localpart)
|
||||
|
||||
def removeAttrNS(self, namespace, localpart):
|
||||
prefix = _nsassign(namespace)
|
||||
if not self.namespaces.has_key(namespace):
|
||||
self.namespaces[namespace] = prefix
|
||||
prefix = self.get_nsprefix(namespace)
|
||||
del self.attributes[prefix + ":" + localpart]
|
||||
|
||||
def getAttribute(self, attr):
|
||||
|
@ -109,11 +109,6 @@ inline_elements = (
|
||||
)
|
||||
|
||||
|
||||
struct_elements = (
|
||||
(CONFIGNS,'config-item-set'),
|
||||
(TABLENS,u'table-cell'),
|
||||
)
|
||||
|
||||
# It is almost impossible to determine what elements are block elements.
|
||||
# There are so many that don't fit the form
|
||||
block_elements = (
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -29,12 +29,7 @@ from xml.sax.xmlreader import InputSource
|
||||
import xml.sax.saxutils
|
||||
from element import Element
|
||||
from namespaces import OFFICENS
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
|
||||
|
||||
#
|
||||
# Parse the XML files
|
||||
@ -70,7 +65,7 @@ class LoadParser(handler.ContentHandler):
|
||||
# Add any accumulated text content
|
||||
content = ''.join(self.data).strip()
|
||||
if len(content) > 0:
|
||||
self.parent.addText(content)
|
||||
self.parent.addText(content, check_grammar=False)
|
||||
self.data = []
|
||||
# Create the element
|
||||
attrdict = {}
|
||||
@ -109,7 +104,7 @@ class LoadParser(handler.ContentHandler):
|
||||
self.level = self.level - 1
|
||||
str = ''.join(self.data)
|
||||
if len(str.strip()) > 0:
|
||||
self.curr.addText(str)
|
||||
self.curr.addText(str, check_grammar=False)
|
||||
self.data = []
|
||||
self.curr = self.curr.parentNode
|
||||
self.parent = self.curr
|
||||
|
@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2006-2007 Søren Roug, European Environment Agency
|
||||
# Copyright (C) 2006-2009 Søren Roug, European Environment Agency
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
@ -17,7 +17,7 @@
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
TOOLSVERSION = u"ODFPY/0.8.2dev"
|
||||
TOOLSVERSION = u"ODFPY/0.9.1dev"
|
||||
|
||||
ANIMNS = u"urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
|
||||
DBNS = u"urn:oasis:names:tc:opendocument:xmlns:database:1.0"
|
||||
@ -71,7 +71,7 @@ nsdict = {
|
||||
OFFICENS: u'office',
|
||||
OOONS: u'ooo',
|
||||
OOOWNS: u'ooow',
|
||||
OOOCNS: u'ooc',
|
||||
OOOCNS: u'oooc',
|
||||
PRESENTATIONNS: u'presentation',
|
||||
RDFANS: u'rdfa',
|
||||
SCRIPTNS: u'script',
|
||||
|
@ -25,11 +25,7 @@ import xml.sax
|
||||
from xml.sax import handler, expatreader
|
||||
from xml.sax.xmlreader import InputSource
|
||||
from xml.sax.saxutils import escape, quoteattr
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
|
||||
from namespaces import ANIMNS, CHARTNS, CONFIGNS, DCNS, DR3DNS, DRAWNS, FONS, \
|
||||
FORMNS, MATHNS, METANS, NUMBERNS, OFFICENS, PRESENTATIONNS, SCRIPTNS, \
|
||||
|
@ -24,12 +24,7 @@ import zipfile
|
||||
from xml.sax import make_parser,handler
|
||||
from xml.sax.xmlreader import InputSource
|
||||
import xml.sax.saxutils
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
|
||||
|
||||
MANIFESTNS="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
|
||||
|
||||
|
@ -44,19 +44,19 @@ def Chart(**args):
|
||||
def DdeSource(**args):
|
||||
return Element(qname = (OFFICENS,'dde-source'), **args)
|
||||
|
||||
def Document(version="1.0", **args):
|
||||
def Document(version="1.1", **args):
|
||||
return Element(qname = (OFFICENS,'document'), version=version, **args)
|
||||
|
||||
def DocumentContent(version="1.0", **args):
|
||||
def DocumentContent(version="1.1", **args):
|
||||
return Element(qname = (OFFICENS, 'document-content'), version=version, **args)
|
||||
|
||||
def DocumentMeta(version="1.0", **args):
|
||||
def DocumentMeta(version="1.1", **args):
|
||||
return Element(qname = (OFFICENS, 'document-meta'), version=version, **args)
|
||||
|
||||
def DocumentSettings(version="1.0", **args):
|
||||
def DocumentSettings(version="1.1", **args):
|
||||
return Element(qname = (OFFICENS, 'document-settings'), version=version, **args)
|
||||
|
||||
def DocumentStyles(version="1.0", **args):
|
||||
def DocumentStyles(version="1.1", **args):
|
||||
return Element(qname = (OFFICENS, 'document-styles'), version=version, **args)
|
||||
|
||||
def Drawing(**args):
|
||||
|
@ -1,71 +0,0 @@
|
||||
from style import Style, ParagraphProperties, TextProperties
|
||||
|
||||
def addOOoStandardStyles(styles):
|
||||
style = Style(name="Standard", family="paragraph", attributes={'class':"text"})
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Text_20_body", displayname="Text body", family="paragraph", parentstylename="Standard", attributes={'class':"text"})
|
||||
p = ParagraphProperties(margintop="0cm", marginbottom="0.212cm")
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Text_20_body_20_indent", displayname="Text body indent", family="paragraph", parentstylename="Text_20_body", attributes={'class':"text"})
|
||||
p = ParagraphProperties(marginleft="0.499cm", marginright="0cm", textindent="0cm", autotextindent="false")
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Salutation", family="paragraph", parentstylename="Standard", attributes={'class':"text"})
|
||||
p = ParagraphProperties(numberlines="false", linenumber=0)
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Signature", family="paragraph", parentstylename="Standard", attributes={'class':"text"})
|
||||
p = ParagraphProperties(numberlines="false", linenumber=0)
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Heading", family="paragraph", parentstylename="Standard", nextstylename="Text_20_body", attributes={'class':"text"})
|
||||
p = ParagraphProperties(margintop="0.423cm", marginbottom="0.212cm", keepwithnext="always")
|
||||
style.addElement(p)
|
||||
p = TextProperties(fontname="Nimbus Sans L", fontsize="14pt", fontnameasian="DejaVu LGC Sans", fontsizeasian="14pt", fontnamecomplex="DejaVu LGC Sans", fontsizecomplex="14pt")
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Heading_20_1", displayname="Heading 1", family="paragraph", parentstylename="Heading", nextstylename="Text_20_body", attributes={'class':"text"}, defaultoutlinelevel=1)
|
||||
p = TextProperties(fontsize="115%", fontweight="bold", fontsizeasian="115%", fontweightasian="bold", fontsizecomplex="115%", fontweightcomplex="bold")
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Heading_20_2", displayname="Heading 2", family="paragraph", parentstylename="Heading", nextstylename="Text_20_body", attributes={'class':"text"}, defaultoutlinelevel=2)
|
||||
p = TextProperties(fontsize="14pt", fontstyle="italic", fontweight="bold", fontsizeasian="14pt", fontstyleasian="italic", fontweightasian="bold", fontsizecomplex="14pt", fontstylecomplex="italic", fontweightcomplex="bold")
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Heading_20_3", displayname="Heading 3", family="paragraph", parentstylename="Heading", nextstylename="Text_20_body", attributes={'class':"text"}, defaultoutlinelevel=3)
|
||||
p = TextProperties(fontsize="14pt", fontweight="bold", fontsizeasian="14pt", fontweightasian="bold", fontsizecomplex="14pt", fontweightcomplex="bold")
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="List", family="paragraph", parentstylename="Text_20_body", attributes={'class':"list"})
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Caption", family="paragraph", parentstylename="Standard", attributes={'class':"extra"})
|
||||
p = ParagraphProperties(margintop="0.212cm", marginbottom="0.212cm", numberlines="false", linenumber="0")
|
||||
style.addElement(p)
|
||||
p = TextProperties(fontsize="12pt", fontstyle="italic", fontsizeasian="12pt", fontstyleasian="italic", fontsizecomplex="12pt", fontstylecomplex="italic")
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Index", family="paragraph", parentstylename="Standard", attributes={'class':"index"})
|
||||
p = ParagraphProperties(numberlines="false", linenumber=0)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Source_20_Text", displayname="Source Text", family="text")
|
||||
p = TextProperties(fontname="Courier", fontnameasian="Courier", fontnamecomplex="Courier")
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
||||
|
||||
style = Style(name="Variable", family="text")
|
||||
p = TextProperties(fontstyle="italic", fontstyleasian="italic", fontstylecomplex="italic")
|
||||
style.addElement(p)
|
||||
styles.addElement(style)
|
@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2006-2008 Søren Roug, European Environment Agency
|
||||
# Copyright (C) 2006-2009 Søren Roug, European Environment Agency
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
@ -300,6 +300,37 @@ class OpenDocument:
|
||||
self.Pictures[manifestfn] = (IS_IMAGE, content, mediatype)
|
||||
return manifestfn
|
||||
|
||||
def addPictureFromFile(self, filename, mediatype=None):
|
||||
""" Add a picture
|
||||
It uses the same convention as OOo, in that it saves the picture in
|
||||
the zipfile in the subdirectory 'Pictures'.
|
||||
If mediatype is not given, it will be guessed from the filename
|
||||
extension.
|
||||
"""
|
||||
if mediatype is None:
|
||||
mediatype, encoding = mimetypes.guess_type(filename)
|
||||
if mediatype is None:
|
||||
mediatype = ''
|
||||
try: ext = filename[filename.rindex('.'):]
|
||||
except ValueError: ext=''
|
||||
else:
|
||||
ext = mimetypes.guess_extension(mediatype)
|
||||
manifestfn = "Pictures/%0.0f%s" % ((time.time()*10000000000), ext)
|
||||
self.Pictures[manifestfn] = (IS_FILENAME, filename, mediatype)
|
||||
return manifestfn
|
||||
|
||||
def addPictureFromString(self, content, mediatype):
|
||||
""" Add a picture
|
||||
It uses the same convention as OOo, in that it saves the picture in
|
||||
the zipfile in the subdirectory 'Pictures'. The content variable
|
||||
is a string that contains the binary image data. The mediatype
|
||||
indicates the image format.
|
||||
"""
|
||||
ext = mimetypes.guess_extension(mediatype)
|
||||
manifestfn = "Pictures/%0.0f%s" % ((time.time()*10000000000), ext)
|
||||
self.Pictures[manifestfn] = (IS_IMAGE, content, mediatype)
|
||||
return manifestfn
|
||||
|
||||
def addThumbnail(self, filecontent=None):
|
||||
""" Add a fixed thumbnail
|
||||
The thumbnail in the library is big, so this is pretty useless.
|
||||
@ -394,6 +425,7 @@ class OpenDocument:
|
||||
|
||||
# Write any extra files
|
||||
for op in self._extra:
|
||||
if op.filename == "META-INF/documentsignatures.xml": continue # Don't save signatures
|
||||
self.manifest.addElement(manifest.FileEntry(fullpath=op.filename, mediatype=op.mediatype))
|
||||
zi = zipfile.ZipInfo(op.filename.encode('utf-8'), self._now)
|
||||
zi.compress_type = zipfile.ZIP_DEFLATED
|
||||
|
@ -31,11 +31,7 @@ import xml.sax.saxutils
|
||||
|
||||
from odf.namespaces import OFFICENS, TEXTNS
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
|
||||
|
||||
OUTENCODING = "utf-8"
|
||||
|
||||
|
@ -27,3 +27,8 @@ from element import Element
|
||||
def Model(**args):
|
||||
return Element(qname = (XFORMSNS,'model'), **args)
|
||||
|
||||
def Instance(**args):
|
||||
return Element(qname = (XFORMSNS,'instance'), **args)
|
||||
|
||||
def Bind(**args):
|
||||
return Element(qname = (XFORMSNS,'bind'), **args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user