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# usage: run-in-mode.sh <mode> <port> <outdir> fixtures/t14/table_cell_fill.py [<file.odp>] 21# no file: writes <outdir>/table-cell-fill-<mode>.odp with an Impress table whose cells carry a solid fill with 22# transparency, a gradient, a hatch and no fill, in the office's current save mode. 23# file: loads that file and prints the fill of those cells. 24import os, sys 25import uno 26from unohelp import FILTERS, connect, desktop, pv 27 28port, out, tag = int(sys.argv[1]), os.path.abspath(sys.argv[2]), sys.argv[3] 29os.makedirs(out, exist_ok=True) 30desk = desktop(connect(port)) 31dst = os.path.abspath(sys.argv[4]) if len(sys.argv) > 4 else os.path.join(out, "table-cell-fill-%s.odp" % tag) 32phase = "reload" if len(sys.argv) > 4 else "make" 33url = uno.systemPathToFileUrl 34 35 36def fe(name): 37 return uno.Enum("com.sun.star.drawing.FillStyle", name) 38 39 40def show(label, cell): 41 kind = cell.FillStyle.value 42 line = [label, kind] 43 if kind == "SOLID": 44 line += ["0x%06x" % cell.FillColor, cell.FillTransparence] 45 elif kind == "GRADIENT": 46 g = cell.FillGradient 47 line += [g.Style.value, hex(g.StartColor), hex(g.EndColor), g.Angle] 48 elif kind == "HATCH": 49 h = cell.FillHatch 50 line += [h.Style.value, hex(h.Color), h.Distance, h.Angle] 51 print(*line) 52 53 54def cells(shape): 55 tbl = shape.Model 56 return [("c%d" % i, tbl.getCellByPosition(i % 2, i // 2)) for i in range(4)] 57 58 59if phase == "make": 60 doc = desk.loadComponentFromURL("private:factory/simpress", "_blank", 0, (pv("Hidden", True),)) 61 page = doc.DrawPages.getByIndex(0) 62 shape = doc.createInstance("com.sun.star.drawing.TableShape") 63 page.add(shape) 64 shape.Position = uno.createUnoStruct("com.sun.star.awt.Point", 2000, 2000) 65 shape.Size = uno.createUnoStruct("com.sun.star.awt.Size", 12000, 6000) 66 tbl = shape.Model 67 tbl.Columns.insertByIndex(1, 1) 68 tbl.Rows.insertByIndex(1, 1) 69 print("table", tbl.Columns.Count, "x", tbl.Rows.Count) 70 cs = cells(shape) 71 c0, c1, c2, c3 = [c for _, c in cs] 72 c0.FillStyle = fe("SOLID"); c0.FillColor = 0x3355aa; c0.FillTransparence = 40 73 g = uno.createUnoStruct("com.sun.star.awt.Gradient") 74 g.Style = uno.Enum("com.sun.star.awt.GradientStyle", "LINEAR") 75 g.StartColor, g.EndColor, g.Angle = 0xff0000, 0x0000ff, 300 76 g.Border, g.XOffset, g.YOffset, g.StartIntensity, g.EndIntensity, g.StepCount = 5, 50, 50, 100, 100, 0 77 c1.FillStyle = fe("GRADIENT"); c1.FillGradient = g 78 h = uno.createUnoStruct("com.sun.star.drawing.Hatch") 79 h.Style = uno.Enum("com.sun.star.drawing.HatchStyle", "SINGLE") 80 h.Color, h.Distance, h.Angle = 0x00aa00, 200, 450 81 c2.FillStyle = fe("HATCH"); c2.FillHatch = h 82 c3.FillStyle = fe("NONE") 83 for n, c in cs: 84 show(n, c) 85 if os.path.exists(dst): 86 os.remove(dst) 87 doc.storeToURL(url(dst), (pv("FilterName", FILTERS["odp"]), pv("Overwrite", True))) 88 doc.close(True) 89 print("stored", dst) 90else: 91 doc = desk.loadComponentFromURL(url(dst), "_blank", 0, (pv("Hidden", True),)) 92 page = doc.DrawPages.getByIndex(0) 93 shape = [page.getByIndex(i) for i in range(page.Count) if page.getByIndex(i).ShapeType.endswith("TableShape")][0] 94 for n, c in cells(shape): 95 show(n, c) 96 doc.close(True) 97