xref: /trunk/test/odf-validate/fixtures/para-fill/make.py (revision 0e16a31d78a652c56c5c0fc79c752f48b9048df9)
1# usage: runpy.sh fixtures/para-fill/make.py <port> <out.odt>   (run against an office saving ODF 1.2 Extended)
2import sys, uno
3from unohelp import connect, desktop, pv
4from com.sun.star.awt import Gradient
5from com.sun.star.awt.GradientStyle import LINEAR
6from com.sun.star.drawing import Hatch
7from com.sun.star.drawing.HatchStyle import SINGLE
8from com.sun.star.drawing.FillStyle import SOLID, GRADIENT, HATCH, BITMAP
9
10port, out = int(sys.argv[1]), sys.argv[2]
11d = desktop(connect(port))
12doc = d.loadComponentFromURL("private:factory/swriter", "_blank", 0, (pv("Hidden", True),))
13text = doc.Text
14png = uno.systemPathToFileUrl(sys.argv[3]) if len(sys.argv) > 3 else None
15
16def grad():
17    g = Gradient(); g.Style = LINEAR; g.StartColor = 0xFF0000; g.EndColor = 0x0000FF
18    g.Angle = 0; g.Border = 0; g.XOffset = 50; g.YOffset = 50
19    g.StartIntensity = 100; g.EndIntensity = 100; g.StepCount = 0
20    return g
21
22def hatch():
23    h = Hatch(); h.Style = SINGLE; h.Color = 0x00AA00; h.Distance = 200; h.Angle = 450
24    return h
25
26def fill(o, kind):
27    if kind == "solid":
28        o.ParaBackColor = 0xFFCC00; o.ParaBackTransparent = False
29    elif kind == "solid_fill":
30        o.FillStyle = SOLID; o.FillColor = 0x33AA55
31    elif kind == "solid_transp":
32        o.FillStyle = SOLID; o.FillColor = 0x3355AA; o.FillTransparence = 40
33    elif kind == "gradient":
34        o.FillStyle = GRADIENT; o.FillGradient = grad()
35    elif kind == "hatch":
36        o.FillStyle = HATCH; o.FillHatch = hatch(); o.FillColor = 0xFFFFCC; o.FillBackground = True
37    elif kind == "bitmap":
38        o.FillStyle = BITMAP; o.FillBitmapURL = png
39
40kinds = ["solid", "solid_fill", "solid_transp", "gradient", "hatch"] + (["bitmap"] if png else [])
41styles = doc.StyleFamilies.getByName("ParagraphStyles")
42for k in kinds:
43    s = doc.createInstance("com.sun.star.style.ParagraphStyle")
44    s.ParentStyle = "Standard"
45    styles.insertByName("S_" + k, s)
46    fill(s, k)
47
48PB = uno.getConstantByName("com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK")
49cur = text.createTextCursor()
50labels = []
51for k in kinds:
52    for kind in ("direct", "styled"):
53        text.insertString(cur, kind + " " + k, False)
54        text.insertControlCharacter(cur, PB, False)
55        labels.append((kind, k))
56paras = doc.Text.createEnumeration()
57for kind, k in labels:
58    p = paras.nextElement()
59    if kind == "direct":
60        fill(p, k)
61    else:
62        p.ParaStyleName = "S_" + k
63
64doc.storeToURL(uno.systemPathToFileUrl(out), (pv("FilterName", "writer8"),))
65doc.close(True)
66