1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="text_TextGraphicObject" script:language="StarBasic">
4cdf0e10cSrcweir
5cdf0e10cSrcweir
6cdf0e10cSrcweir'*************************************************************************
7cdf0e10cSrcweir'
8*f94e042dSAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
9*f94e042dSAndrew Rist'  or more contributor license agreements.  See the NOTICE file
10*f94e042dSAndrew Rist'  distributed with this work for additional information
11*f94e042dSAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
12*f94e042dSAndrew Rist'  to you under the Apache License, Version 2.0 (the
13*f94e042dSAndrew Rist'  "License"); you may not use this file except in compliance
14*f94e042dSAndrew Rist'  with the License.  You may obtain a copy of the License at
15*f94e042dSAndrew Rist'
16*f94e042dSAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
17*f94e042dSAndrew Rist'
18*f94e042dSAndrew Rist'  Unless required by applicable law or agreed to in writing,
19*f94e042dSAndrew Rist'  software distributed under the License is distributed on an
20*f94e042dSAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*f94e042dSAndrew Rist'  KIND, either express or implied.  See the License for the
22*f94e042dSAndrew Rist'  specific language governing permissions and limitations
23*f94e042dSAndrew Rist'  under the License.
24cdf0e10cSrcweir'
25cdf0e10cSrcweir'*************************************************************************
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29*f94e042dSAndrew Rist
30*f94e042dSAndrew Rist
31cdf0e10cSrcweir' Be sure that all variables are dimensioned:
32cdf0e10cSrcweiroption explicit
33cdf0e10cSrcweir
34cdf0e10cSrcweir
35cdf0e10cSrcweir
36cdf0e10cSrcweirSub RunTest()
37cdf0e10cSrcweir
38cdf0e10cSrcweir'*************************************************************************
39cdf0e10cSrcweir' SERVICE:
40cdf0e10cSrcweir' com.sun.star.text.TextGraphicObject
41cdf0e10cSrcweir'*************************************************************************
42cdf0e10cSrcweirOn Error Goto ErrHndl
43cdf0e10cSrcweir    Dim bOK As Boolean
44cdf0e10cSrcweir
45cdf0e10cSrcweir
46cdf0e10cSrcweir    PropertyTester.TestProperty("ContentProtected")
47cdf0e10cSrcweir
48cdf0e10cSrcweir    PropertyTester.TestProperty("SurroundContour")
49cdf0e10cSrcweir
50cdf0e10cSrcweir    PropertyTester.TestProperty("ContourOutside")
51cdf0e10cSrcweir
52cdf0e10cSrcweir    Test.StartMethod("ContourPolyPolygon")
53cdf0e10cSrcweir    ' Because in additional parameters we must to
54cdf0e10cSrcweir    ' pass an array of values, we need such array.
55cdf0e10cSrcweir    Dim aPParr1(1) As Variant
56cdf0e10cSrcweir    Dim aPol1(3) As new com.sun.star.awt.Point
57cdf0e10cSrcweir    Dim gArr As Variant
58cdf0e10cSrcweir
59cdf0e10cSrcweir    bOK = true
60cdf0e10cSrcweir    aPol1(0).x = 0   : aPol1(0).y = 0
61cdf0e10cSrcweir    aPol1(1).x = 101 : aPol1(1).y = 0
62cdf0e10cSrcweir    aPol1(2).x = 101 : aPol1(2).y = 101
63cdf0e10cSrcweir    aPol1(3).x = 0   : aPol1(3).y = 101
64cdf0e10cSrcweir    Dim aPol2(3) As new com.sun.star.awt.Point
65cdf0e10cSrcweir    aPol2(0).x = 11 : aPol2(0).y = 11
66cdf0e10cSrcweir    aPol2(1).x = 90 : aPol2(1).y = 11
67cdf0e10cSrcweir    aPol2(2).x = 90 : aPol2(2).y = 90
68cdf0e10cSrcweir    aPol2(3).x = 11 : aPol2(3).y = 90
69cdf0e10cSrcweir    aPParr1(0) = aPol1() : aPParr1(1) = aPol2()
70cdf0e10cSrcweir    oObj.setPropertyValue("ContourPolyPolygon", aPParr1())
71cdf0e10cSrcweir    gArr = oObj.getPropertyValue("ContourPolyPolygon")
72cdf0e10cSrcweir
73cdf0e10cSrcweir    if isArray(gArr) AND ubound(gArr) &gt;= 1 then
74cdf0e10cSrcweir        Dim aP1 As Variant, aP2 As Variant
75cdf0e10cSrcweir
76cdf0e10cSrcweir        aP1 = gArr(0)
77cdf0e10cSrcweir        aP2 = gArr(1)
78cdf0e10cSrcweir        bOK = bOK AND comparePointArrays(aPol1(), aP1, 0, 0, 4)
79cdf0e10cSrcweir        bOK = bOK AND comparePointArrays(aPol2(), aP2, 0, 0, 4)
80cdf0e10cSrcweir
81cdf0e10cSrcweir        ' One more point must be added to close the polygon
82cdf0e10cSrcweir        bOK = bOK AND comparePointArrays(aPol1(), aP1, 0, 4, 1)
83cdf0e10cSrcweir        bOK = bOK AND comparePointArrays(aPol2(), aP2, 0, 4, 1)
84cdf0e10cSrcweir    else
85cdf0e10cSrcweir        Out.Log("Returned value is invalid")
86cdf0e10cSrcweir        Out.Log = false
87cdf0e10cSrcweir    endif
88cdf0e10cSrcweir
89cdf0e10cSrcweir    Test.MethodTested("ContourPolyPolygon", bOK)
90cdf0e10cSrcweir
91cdf0e10cSrcweir'    PropertyTester.TestProperty("ContourPolyPolygon",testArr())
92cdf0e10cSrcweir
93cdf0e10cSrcweir    Dim aCropArr(1) As Variant
94cdf0e10cSrcweir    Dim Crop1 As Object
95cdf0e10cSrcweir    Dim Crop2 As Object
96cdf0e10cSrcweir
97cdf0e10cSrcweir    Crop1 = createUnoStruct("com.sun.star.text.GraphicCrop")
98cdf0e10cSrcweir    Crop2 = createUnoStruct("com.sun.star.text.GraphicCrop")
99cdf0e10cSrcweir
100cdf0e10cSrcweir    Crop1.Top = 11 : Crop1.Bottom = 11 : Crop1.Left = 11 : Crop1.Right = 11
101cdf0e10cSrcweir    Crop2.Top = -11 : Crop2.Bottom = 11 : Crop2.Left = -11 : Crop2.Right = 11
102cdf0e10cSrcweir
103cdf0e10cSrcweir    aCropArr(0) = Crop1 : aCropArr(1) = Crop2
104cdf0e10cSrcweir    PropertyTester.TestProperty("GraphicCrop",aCropArr())
105cdf0e10cSrcweir
106cdf0e10cSrcweir    PropertyTester.TestProperty("HoriMirroredOnEvenPages")
107cdf0e10cSrcweir
108cdf0e10cSrcweir    PropertyTester.TestProperty("HoriMirroredOnOddPages")
109cdf0e10cSrcweir
110cdf0e10cSrcweir    PropertyTester.TestProperty("VertMirrored")
111cdf0e10cSrcweir
112cdf0e10cSrcweir    PropertyTester.TestProperty("GraphicURL")
113cdf0e10cSrcweir
114cdf0e10cSrcweir    PropertyTester.TestProperty("GraphicFilter")
115cdf0e10cSrcweir
116cdf0e10cSrcweir    PropertyTester.TestProperty("ActualSize")
117cdf0e10cSrcweir
118cdf0e10cSrcweir    Dim oAdjustArr(4) As Integer
119cdf0e10cSrcweir    oAdjustArr(0) = -100
120cdf0e10cSrcweir    oAdjustArr(1) = -50
121cdf0e10cSrcweir    oAdjustArr(2) = 0
122cdf0e10cSrcweir    oAdjustArr(3) = 50
123cdf0e10cSrcweir    oAdjustArr(4) = 100
124cdf0e10cSrcweir
125cdf0e10cSrcweir    PropertyTester.TestProperty("AdjustLuminance",oAdjustArr())
126cdf0e10cSrcweir
127cdf0e10cSrcweir    PropertyTester.TestProperty("AdjustContrast",oAdjustArr())
128cdf0e10cSrcweir
129cdf0e10cSrcweir    PropertyTester.TestProperty("AdjustRed",oAdjustArr())
130cdf0e10cSrcweir
131cdf0e10cSrcweir    PropertyTester.TestProperty("AdjustGreen",oAdjustArr())
132cdf0e10cSrcweir
133cdf0e10cSrcweir    PropertyTester.TestProperty("AdjustBlue",oAdjustArr())
134cdf0e10cSrcweir
135cdf0e10cSrcweir    PropertyTester.TestProperty("Gamma",oAdjustArr())
136cdf0e10cSrcweir
137cdf0e10cSrcweir    PropertyTester.TestProperty("GraphicIsInverted")
138cdf0e10cSrcweir
139cdf0e10cSrcweir    PropertyTester.TestProperty("Transparency",oAdjustArr())
140cdf0e10cSrcweir
141cdf0e10cSrcweir    PropertyTester.TestProperty("GraphicColorMode")
142cdf0e10cSrcweir
143cdf0e10cSrcweir    PropertyTester.TestProperty("ImageMap")
144cdf0e10cSrcweir
145cdf0e10cSrcweir    PropertyTester.TestProperty("ActualSize")
146cdf0e10cSrcweir
147cdf0e10cSrcweirExit Sub
148cdf0e10cSrcweirErrHndl:
149cdf0e10cSrcweir    Test.Exception()
150cdf0e10cSrcweir    bOK = false
151cdf0e10cSrcweir    resume next
152cdf0e10cSrcweirEnd Sub
153cdf0e10cSrcweir
154cdf0e10cSrcweirFunction comparePointArrays(arr1 As Variant, arr2 As Variant, fromIdx1 As Integer, fromIdx2 As Integer, count As Integer) As Boolean
155cdf0e10cSrcweirOn Error Goto ErrHndl
156cdf0e10cSrcweir    Dim bOK As Boolean
157cdf0e10cSrcweir    Dim i As Integer
158cdf0e10cSrcweir
159cdf0e10cSrcweir    if NOT isArray(arr1) then
160cdf0e10cSrcweir        Out.Log("First parameter is not Array.")
161cdf0e10cSrcweir        comparePointArrays() = false
162cdf0e10cSrcweir        exit Function
163cdf0e10cSrcweir    endif
164cdf0e10cSrcweir
165cdf0e10cSrcweir    if NOT isArray(arr2) then
166cdf0e10cSrcweir        Out.Log("Second parameter is not Array.")
167cdf0e10cSrcweir        comparePointArrays() = false
168cdf0e10cSrcweir        exit Function
169cdf0e10cSrcweir    endif
170cdf0e10cSrcweir
171cdf0e10cSrcweir    if (lbound(arr1) &gt; fromIdx1 OR ubound(arr1) &lt; (fromIdx1 + count - 1)) then
172cdf0e10cSrcweir        Out.Log("Invalid bounds of the first array")
173cdf0e10cSrcweir        comparePointArrays() = false
174cdf0e10cSrcweir        exit Function
175cdf0e10cSrcweir    endif
176cdf0e10cSrcweir    if (lbound(arr2) &gt; fromIdx2 OR ubound(arr2) &lt; (fromIdx2 + count - 1)) then
177cdf0e10cSrcweir        Out.Log("Invalid bounds of the second array")
178cdf0e10cSrcweir        comparePointArrays() = false
179cdf0e10cSrcweir        exit Function
180cdf0e10cSrcweir    endif
181cdf0e10cSrcweir
182cdf0e10cSrcweir    bOK = true
183cdf0e10cSrcweir    for i = 0 to count - 1
184cdf0e10cSrcweir        if arr1(fromIdx1 + i).x &lt;&gt; arr2(fromIdx2 + i).x OR _
185cdf0e10cSrcweir           arr1(fromIdx1 + i).y &lt;&gt; arr2(fromIdx2 + i).y then
186cdf0e10cSrcweir
187cdf0e10cSrcweir            Out.Log("Points #" + i + " are different : (" + _
188cdf0e10cSrcweir                arr1(fromIdx1 + i).x + "," + arr1(fromIdx1 + i).y + "), (" + _
189cdf0e10cSrcweir                arr2(fromIdx2 + i).x + "," + arr2(fromIdx2 + i).y + ")."
190cdf0e10cSrcweir
191cdf0e10cSrcweir            bOK = false
192cdf0e10cSrcweir        end if
193cdf0e10cSrcweir    next i
194cdf0e10cSrcweir
195cdf0e10cSrcweir    comparePointArrays() = bOK
196cdf0e10cSrcweir
197cdf0e10cSrcweir    exit Function
198cdf0e10cSrcweirErrHndl:
199cdf0e10cSrcweir    Test.Exception()
200cdf0e10cSrcweir    comparePointArrays() = false
201cdf0e10cSrcweirEnd Function
202cdf0e10cSrcweir</script:module>
203