1# usage: runpy.sh fixtures/alien-attrs/make.py <port> <outdir> (office saving ODF 1.2 Extended) 2# Preserved alien attributes in ODF namespaces and in a foreign namespace on the carriers that keep them: 3# Writer paragraph, character, section, table and table cell (item-set export path), Draw shape, Calc cell. 4import sys, os, uno 5from unohelp import connect, desktop, pv 6from com.sun.star.awt import Size, Point 7 8port, outdir = int(sys.argv[1]), sys.argv[2] 9d = desktop(connect(port)) 10NS = {"text": "urn:oasis:names:tc:opendocument:xmlns:text:1.0", 11 "style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0", 12 "draw": "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0", 13 "table": "urn:oasis:names:tc:opendocument:xmlns:table:1.0", 14 "office": "urn:oasis:names:tc:opendocument:xmlns:office:1.0", 15 "svg": "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0", 16 "fo": "http://www.w3.org/1999/XSL/Format", 17 "ex": "urn:example:foreign"} 18ATTRS = (("text", "enable-numbering"), ("style", "alien-style"), ("draw", "alien-draw"), ("table", "alien-table"), 19 ("office", "alien-office"), ("svg", "alien-svg"), ("fo", "alien-fo"), ("ex", "alien-foreign")) 20 21def put(container): 22 for p, n in ATTRS: 23 a = uno.createUnoStruct("com.sun.star.xml.AttributeData") 24 a.Namespace = NS[p]; a.Type = "CDATA"; a.Value = "v-" + p 25 container.insertByName(p + ":" + n, a) 26 27def new(kind): 28 return d.loadComponentFromURL("private:factory/" + kind, "_blank", 0, (pv("Hidden", True),)) 29 30def save(doc, name, flt): 31 doc.storeToURL(uno.systemPathToFileUrl(os.path.join(outdir, name)), (pv("FilterName", flt),)) 32 doc.close(True) 33 34doc = new("swriter") 35text = doc.Text 36cur = text.createTextCursor() 37text.insertString(cur, "para text", False) 38text.insertControlCharacter(cur, 0, False) 39cur.gotoStart(False); cur.goRight(4, True) 40cont = cur.ParaUserDefinedAttributes 41put(cont); cur.ParaUserDefinedAttributes = cont 42cont = cur.TextUserDefinedAttributes 43put(cont); cur.TextUserDefinedAttributes = cont 44cur.gotoEnd(False) 45tbl = doc.createInstance("com.sun.star.text.TextTable") 46tbl.initialize(2, 2) 47text.insertTextContent(cur, tbl, False) 48for tgt in (tbl, tbl.getCellByName("A1")): 49 cont = tgt.UserDefinedAttributes 50 put(cont); tgt.UserDefinedAttributes = cont 51sec = doc.createInstance("com.sun.star.text.TextSection") 52text.insertTextContent(text.End, sec, False) 53cont = sec.UserDefinedAttributes 54put(cont); sec.UserDefinedAttributes = cont 55save(doc, "alien-writer.odt", "writer8") 56 57doc = new("sdraw") 58page = doc.DrawPages.getByIndex(0) 59s = doc.createInstance("com.sun.star.drawing.RectangleShape") 60page.add(s); s.Position = Point(2000, 2000); s.Size = Size(4000, 2000); s.String = "alien" 61cont = s.UserDefinedAttributes 62put(cont); s.UserDefinedAttributes = cont 63save(doc, "alien-draw.odg", "draw8") 64 65doc = new("scalc") 66c = doc.Sheets.getByIndex(0).getCellByPosition(0, 0) 67c.Value = 1 68cont = c.UserDefinedAttributes 69put(cont); c.UserDefinedAttributes = cont 70save(doc, "alien-calc.ods", "calc8") 71