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 
23 
24 #include "precompiled_svx.hxx"
25 #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
26 #include <vcl/bmpacc.hxx>
27 #include <osl/mutex.hxx>
28 #include <vcl/lazydelete.hxx>
29 
30 //////////////////////////////////////////////////////////////////////////////
31 // helper methods
32 
33 namespace drawinglayer
34 {
35 	namespace primitive2d
36 	{
createDefaultCross_3x3(const basegfx::BColor & rBColor)37 		BitmapEx createDefaultCross_3x3(const basegfx::BColor& rBColor)
38 		{
39 			static vcl::DeleteOnDeinit< BitmapEx > aRetVal(0);
40 			static basegfx::BColor aColor;
41 		    ::osl::Mutex m_mutex;
42 
43 			if(!aRetVal.get() || rBColor != aColor)
44 			{
45 				// copy values
46 				aColor = rBColor;
47 
48 				// create bitmap
49 				Bitmap aContent(Size(3, 3), 24);
50 				Bitmap aMask(Size(3, 3), 1);
51 				BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
52 				BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
53 				OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
54 				const Color aVCLColor(aColor);
55 				const BitmapColor aPixColor(aVCLColor);
56 				const BitmapColor aMaskColor(0x01);
57 
58 				// Y,X unusual order (!)
59 				pWContent->SetPixel(0, 1, aPixColor);
60 				pWContent->SetPixel(1, 0, aPixColor);
61 				pWContent->SetPixel(1, 1, aPixColor);
62 				pWContent->SetPixel(1, 2, aPixColor);
63 				pWContent->SetPixel(2, 1, aPixColor);
64 
65 				pWMask->SetPixel(0, 0, aMaskColor);
66 				pWMask->SetPixel(0, 2, aMaskColor);
67 				pWMask->SetPixel(2, 0, aMaskColor);
68 				pWMask->SetPixel(2, 2, aMaskColor);
69 
70 				aContent.ReleaseAccess(pWContent);
71 				aMask.ReleaseAccess(pWMask);
72 
73 				// create and exchange at aRetVal
74 				delete aRetVal.set(new BitmapEx(aContent, aMask));
75 			}
76 
77 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
78 		}
79 
createDefaultGluepoint_7x7(const basegfx::BColor & rBColorA,const basegfx::BColor & rBColorB)80 		BitmapEx createDefaultGluepoint_7x7(const basegfx::BColor& rBColorA, const basegfx::BColor& rBColorB)
81 		{
82 			static vcl::DeleteOnDeinit< BitmapEx > aRetVal(0);
83 			static basegfx::BColor aColorA;
84 			static basegfx::BColor aColorB;
85 		    ::osl::Mutex m_mutex;
86 
87 			if(!aRetVal.get() || rBColorA != aColorA || rBColorB != aColorB)
88 			{
89 				// copy values
90 				aColorA = rBColorA;
91 				aColorB = rBColorB;
92 
93 				// create bitmap
94 				Bitmap aContent(Size(7, 7), 24);
95 				Bitmap aMask(Size(7, 7), 1);
96 				BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
97 				BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
98 				OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
99 				const Color aColA(aColorA);
100 				const Color aColB(aColorB);
101 				const BitmapColor aPixColorA(aColA);
102 				const BitmapColor aPixColorB(aColB);
103 				const BitmapColor aMaskColor(0x01);
104 
105 				// Y,X unusual order (!)
106 				pWContent->SetPixel(0, 1, aPixColorA);
107 				pWContent->SetPixel(0, 5, aPixColorA);
108 				pWContent->SetPixel(1, 0, aPixColorA);
109 				pWContent->SetPixel(1, 2, aPixColorA);
110 				pWContent->SetPixel(1, 4, aPixColorA);
111 				pWContent->SetPixel(1, 6, aPixColorA);
112 				pWContent->SetPixel(2, 1, aPixColorA);
113 				pWContent->SetPixel(2, 3, aPixColorA);
114 				pWContent->SetPixel(2, 5, aPixColorA);
115 				pWContent->SetPixel(3, 2, aPixColorA);
116 				pWContent->SetPixel(3, 4, aPixColorA);
117 				pWContent->SetPixel(4, 1, aPixColorA);
118 				pWContent->SetPixel(4, 3, aPixColorA);
119 				pWContent->SetPixel(4, 5, aPixColorA);
120 				pWContent->SetPixel(5, 0, aPixColorA);
121 				pWContent->SetPixel(5, 2, aPixColorA);
122 				pWContent->SetPixel(5, 4, aPixColorA);
123 				pWContent->SetPixel(5, 6, aPixColorA);
124 				pWContent->SetPixel(6, 1, aPixColorA);
125 				pWContent->SetPixel(6, 5, aPixColorA);
126 
127 				pWContent->SetPixel(1, 1, aPixColorB);
128 				pWContent->SetPixel(1, 5, aPixColorB);
129 				pWContent->SetPixel(2, 2, aPixColorB);
130 				pWContent->SetPixel(2, 4, aPixColorB);
131 				pWContent->SetPixel(3, 3, aPixColorB);
132 				pWContent->SetPixel(4, 2, aPixColorB);
133 				pWContent->SetPixel(4, 4, aPixColorB);
134 				pWContent->SetPixel(5, 1, aPixColorB);
135 				pWContent->SetPixel(5, 5, aPixColorB);
136 
137 				pWMask->SetPixel(0, 0, aMaskColor);
138 				pWMask->SetPixel(0, 2, aMaskColor);
139 				pWMask->SetPixel(0, 3, aMaskColor);
140 				pWMask->SetPixel(0, 4, aMaskColor);
141 				pWMask->SetPixel(0, 6, aMaskColor);
142 				pWMask->SetPixel(1, 3, aMaskColor);
143 				pWMask->SetPixel(2, 0, aMaskColor);
144 				pWMask->SetPixel(2, 6, aMaskColor);
145 				pWMask->SetPixel(3, 0, aMaskColor);
146 				pWMask->SetPixel(3, 1, aMaskColor);
147 				pWMask->SetPixel(3, 5, aMaskColor);
148 				pWMask->SetPixel(3, 6, aMaskColor);
149 				pWMask->SetPixel(4, 0, aMaskColor);
150 				pWMask->SetPixel(4, 6, aMaskColor);
151 				pWMask->SetPixel(5, 3, aMaskColor);
152 				pWMask->SetPixel(6, 0, aMaskColor);
153 				pWMask->SetPixel(6, 2, aMaskColor);
154 				pWMask->SetPixel(6, 3, aMaskColor);
155 				pWMask->SetPixel(6, 4, aMaskColor);
156 				pWMask->SetPixel(6, 6, aMaskColor);
157 
158 				aContent.ReleaseAccess(pWContent);
159 				aMask.ReleaseAccess(pWMask);
160 
161 				// create and exchange at aRetVal
162 				delete aRetVal.set(new BitmapEx(aContent, aMask));
163 			}
164 
165 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
166 		}
167 
168 	} // end of namespace primitive2d
169 } // end of namespace drawinglayer
170 
171 //////////////////////////////////////////////////////////////////////////////
172 // eof
173