1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21 22# usage: runpy.sh fixtures/p8/make_drawings.py <port> <outdir> 23# Writes ten small ODF drawings (shapes, text, connectors, groups, gradient and hatch fills, polygons, custom shapes, 24# measure lines, rotation/shadow/transparency, several pages) with the office, as input for the foreign 1.2/1.3 twins 25# of tools13/make-foreign-corpus.py. Prints one line per drawing with its shape count; exit code 1 when one failed. 26import os, sys 27import uno 28from com.sun.star.awt import Point, Size, Gradient 29from com.sun.star.beans import PropertyValue 30from com.sun.star.drawing import Hatch 31from unohelp import connect, desktop, pv 32 33port, out = int(sys.argv[1]), os.path.abspath(sys.argv[2]) 34os.makedirs(out, exist_ok=True) 35ctx = connect(port) 36desk = desktop(ctx) 37E = lambda t, v: uno.Enum(t, v) 38 39 40def new_doc(): 41 return desk.loadComponentFromURL("private:factory/sdraw", "_blank", 0, (pv("Hidden", True),)) 42 43 44def shape(doc, page, kind, x, y, w, h, **props): 45 s = doc.createInstance("com.sun.star.drawing." + kind) 46 page.add(s) 47 s.Position = Point(x, y) 48 s.Size = Size(w, h) 49 for k, v in props.items(): 50 s.setPropertyValue(k, v) 51 return s 52 53 54def d01(doc): 55 p = doc.DrawPages.getByIndex(0) 56 shape(doc, p, "RectangleShape", 1000, 1000, 5000, 3000, FillColor=0xCC3333, LineColor=0x000000, LineWidth=100) 57 shape(doc, p, "EllipseShape", 7000, 1000, 4000, 3000, FillColor=0x3366CC, LineStyle=E("com.sun.star.drawing.LineStyle", "DASH")) 58 shape(doc, p, "LineShape", 1000, 5000, 10000, 0, LineColor=0x00AA00, LineWidth=250) 59 shape(doc, p, "RectangleShape", 1000, 6000, 3000, 2000, CornerRadius=500, FillColor=0xFFCC00) 60 61 62def d02(doc): 63 p = doc.DrawPages.getByIndex(0) 64 for i, (txt, size, adj) in enumerate((("Left aligned text", 18, "LEFT"), ("Centered heading", 28, "CENTER"), ("Right aligned small", 10, "RIGHT"))): 65 s = shape(doc, p, "TextShape", 1000, 1000 + i * 2500, 12000, 2000) 66 s.String = txt 67 s.CharHeight = size 68 s.CharFontName = "Helvetica" 69 s.CharWeight = 150.0 if i == 1 else 100.0 70 s.ParaAdjust = E("com.sun.star.style.ParagraphAdjust", adj) 71 r = shape(doc, p, "RectangleShape", 1000, 9000, 8000, 2500, FillColor=0xEEEEEE) 72 r.String = "Text inside a rectangle" 73 r.CharColor = 0x0000CC 74 75 76def d03(doc): 77 p = doc.DrawPages.getByIndex(0) 78 a = shape(doc, p, "RectangleShape", 1000, 1000, 3000, 2000, FillColor=0xCCCCFF) 79 b = shape(doc, p, "RectangleShape", 8000, 5000, 3000, 2000, FillColor=0xCCFFCC) 80 c = shape(doc, p, "EllipseShape", 1000, 9000, 3000, 2000, FillColor=0xFFCCCC) 81 for kind, s, e in (("STANDARD", a, b), ("CURVE", b, c), ("LINE", c, a)): 82 con = doc.createInstance("com.sun.star.drawing.ConnectorShape") 83 p.add(con) 84 con.StartShape, con.EndShape = s, e 85 con.EdgeKind = E("com.sun.star.drawing.ConnectorType", kind) 86 con.LineEndName = "Arrow" 87 88 89def d04(doc): 90 p = doc.DrawPages.getByIndex(0) 91 inner = [] 92 for i in range(3): 93 inner.append(shape(doc, p, "RectangleShape", 1000 + i * 1500, 1000, 1200, 1200, FillColor=0x336699 + i * 0x2020)) 94 col = ctx.ServiceManager.createInstanceWithContext("com.sun.star.drawing.ShapeCollection", ctx) 95 for s in inner: 96 col.add(s) 97 g1 = p.group(col) 98 e = shape(doc, p, "EllipseShape", 1000, 4000, 3000, 2000, FillColor=0xFFAA00) 99 col2 = ctx.ServiceManager.createInstanceWithContext("com.sun.star.drawing.ShapeCollection", ctx) 100 col2.add(g1) 101 col2.add(e) 102 p.group(col2) 103 104 105def d05(doc): 106 p = doc.DrawPages.getByIndex(0) 107 s = shape(doc, p, "RectangleShape", 1000, 1000, 5000, 3000) 108 g = Gradient() 109 g.Style = E("com.sun.star.awt.GradientStyle", "LINEAR") 110 g.StartColor, g.EndColor, g.Angle, g.Border = 0xFF0000, 0x0000FF, 450, 0 111 g.XOffset = g.YOffset = 50 112 g.StartIntensity = g.EndIntensity = 100 113 s.FillStyle = E("com.sun.star.drawing.FillStyle", "GRADIENT") 114 s.FillGradient = g 115 h = shape(doc, p, "EllipseShape", 7000, 1000, 4000, 3000) 116 hh = Hatch() 117 hh.Style = E("com.sun.star.drawing.HatchStyle", "DOUBLE") 118 hh.Color, hh.Distance, hh.Angle = 0x006600, 150, 300 119 h.FillStyle = E("com.sun.star.drawing.FillStyle", "HATCH") 120 h.FillHatch = hh 121 h.FillBackground = True 122 h.FillColor = 0xFFFFCC 123 124 125def d06(doc): 126 pages = doc.DrawPages 127 pages.insertNewByIndex(1) 128 pages.insertNewByIndex(2) 129 for i in range(3): 130 p = pages.getByIndex(i) 131 p.Name = "Page %d" % (i + 1) 132 for j in range(i + 1): 133 s = shape(doc, p, "RectangleShape", 1000 + j * 3000, 1000, 2500, 2000, FillColor=0x80 * (j + 1) + i * 0x1000) 134 s.String = "p%d s%d" % (i + 1, j + 1) 135 136 137def d07(doc): 138 p = doc.DrawPages.getByIndex(0) 139 s = doc.createInstance("com.sun.star.drawing.PolyPolygonShape") 140 p.add(s) 141 s.PolyPolygon = ((Point(1000, 1000), Point(5000, 1000), Point(3000, 4000)),) 142 s.FillColor = 0x99CC33 143 t = doc.createInstance("com.sun.star.drawing.PolyLineShape") 144 p.add(t) 145 t.PolyPolygon = ((Point(7000, 1000), Point(9000, 3000), Point(7500, 5000), Point(10000, 6000)),) 146 t.LineColor, t.LineWidth = 0xCC0066, 150 147 q = doc.createInstance("com.sun.star.drawing.PolyPolygonShape") 148 p.add(q) 149 q.PolyPolygon = ((Point(1000, 7000), Point(4000, 7000), Point(4000, 9000), Point(1000, 9000)), 150 (Point(1800, 7500), Point(3200, 7500), Point(3200, 8500), Point(1800, 8500))) 151 q.FillColor = 0x3399CC 152 153 154def d08(doc): 155 p = doc.DrawPages.getByIndex(0) 156 for i, kind in enumerate(("diamond", "heart", "star5", "right-arrow", "cloud")): 157 s = doc.createInstance("com.sun.star.drawing.CustomShape") 158 p.add(s) 159 s.Position = Point(1000 + (i % 3) * 4000, 1000 + (i // 3) * 4000) 160 s.Size = Size(3000, 3000) 161 s.CustomShapeGeometry = (PropertyValue("Type", 0, kind, 0),) 162 s.FillColor = 0x6600CC + i * 0x1100 163 s.String = kind 164 165 166def d09(doc): 167 p = doc.DrawPages.getByIndex(0) 168 for i in range(3): 169 m = doc.createInstance("com.sun.star.drawing.MeasureShape") 170 p.add(m) 171 m.StartPosition = Point(1000, 1500 + i * 2500) 172 m.EndPosition = Point(6000 + i * 1500, 1500 + i * 2500) 173 shape(doc, p, "RectangleShape", 1000, 9000, 6000, 1500, FillColor=0xDDDDDD) 174 175 176def d10(doc): 177 p = doc.DrawPages.getByIndex(0) 178 a = shape(doc, p, "RectangleShape", 2000, 2000, 4000, 2500, FillColor=0xCC6600, Shadow=True, ShadowXDistance=300, ShadowYDistance=300) 179 a.RotateAngle = 3000 180 b = shape(doc, p, "EllipseShape", 8000, 2000, 4000, 2500, FillColor=0x0066CC, FillTransparence=50) 181 c = shape(doc, p, "RectangleShape", 2000, 7000, 4000, 2000, FillColor=0x669900) 182 c.ShearAngle = 1500 183 d = shape(doc, p, "RectangleShape", 7000, 7000, 4000, 2000, FillColor=0x990066, LineTransparence=40, LineWidth=300) 184 d.String = "transparent line" 185 186 187fails = 0 188for n, fn in enumerate((d01, d02, d03, d04, d05, d06, d07, d08, d09, d10), 1): 189 name = "draw%02d" % n 190 try: 191 doc = new_doc() 192 fn(doc) 193 npages = doc.DrawPages.Count 194 count = sum(doc.DrawPages.getByIndex(i).Count for i in range(npages)) 195 doc.storeToURL(uno.systemPathToFileUrl(os.path.join(out, name + ".odg")), (pv("FilterName", "draw8"),)) 196 doc.close(True) 197 print("ok %s shapes=%d pages=%d" % (name, count, npages)) 198 except Exception as e: 199 fails += 1 200 print("FAIL %s %s: %s" % (name, type(e).__name__, e)) 201sys.exit(1 if fails else 0) 202