1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_svx.hxx"
29 #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
30 #include <vcl/bmpacc.hxx>
31 #include <osl/mutex.hxx>
32 #include <vcl/lazydelete.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 // helper methods
36 
37 namespace drawinglayer
38 {
39 	namespace primitive2d
40 	{
41 		BitmapEx createDefaultCross_3x3(const basegfx::BColor& rBColor)
42 		{
43 			static vcl::DeleteOnDeinit< BitmapEx > aRetVal(0);
44 			static basegfx::BColor aColor;
45 		    ::osl::Mutex m_mutex;
46 
47 			if(!aRetVal.get() || rBColor != aColor)
48 			{
49 				// copy values
50 				aColor = rBColor;
51 
52 				// create bitmap
53 				Bitmap aContent(Size(3, 3), 24);
54 				Bitmap aMask(Size(3, 3), 1);
55 				BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
56 				BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
57 				OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
58 				const Color aVCLColor(aColor);
59 				const BitmapColor aPixColor(aVCLColor);
60 				const BitmapColor aMaskColor(0x01);
61 
62 				// Y,X unusual order (!)
63 				pWContent->SetPixel(0, 1, aPixColor);
64 				pWContent->SetPixel(1, 0, aPixColor);
65 				pWContent->SetPixel(1, 1, aPixColor);
66 				pWContent->SetPixel(1, 2, aPixColor);
67 				pWContent->SetPixel(2, 1, aPixColor);
68 
69 				pWMask->SetPixel(0, 0, aMaskColor);
70 				pWMask->SetPixel(0, 2, aMaskColor);
71 				pWMask->SetPixel(2, 0, aMaskColor);
72 				pWMask->SetPixel(2, 2, aMaskColor);
73 
74 				aContent.ReleaseAccess(pWContent);
75 				aMask.ReleaseAccess(pWMask);
76 
77 				// create and exchange at aRetVal
78 				delete aRetVal.set(new BitmapEx(aContent, aMask));
79 			}
80 
81 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
82 		}
83 
84 		BitmapEx createDefaultGluepoint_7x7(const basegfx::BColor& rBColorA, const basegfx::BColor& rBColorB)
85 		{
86 			static vcl::DeleteOnDeinit< BitmapEx > aRetVal(0);
87 			static basegfx::BColor aColorA;
88 			static basegfx::BColor aColorB;
89 		    ::osl::Mutex m_mutex;
90 
91 			if(!aRetVal.get() || rBColorA != aColorA || rBColorB != aColorB)
92 			{
93 				// copy values
94 				aColorA = rBColorA;
95 				aColorB = rBColorB;
96 
97 				// create bitmap
98 				Bitmap aContent(Size(7, 7), 24);
99 				Bitmap aMask(Size(7, 7), 1);
100 				BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
101 				BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
102 				OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
103 				const Color aColA(aColorA);
104 				const Color aColB(aColorB);
105 				const BitmapColor aPixColorA(aColA);
106 				const BitmapColor aPixColorB(aColB);
107 				const BitmapColor aMaskColor(0x01);
108 
109 				// Y,X unusual order (!)
110 				pWContent->SetPixel(0, 1, aPixColorA);
111 				pWContent->SetPixel(0, 5, aPixColorA);
112 				pWContent->SetPixel(1, 0, aPixColorA);
113 				pWContent->SetPixel(1, 2, aPixColorA);
114 				pWContent->SetPixel(1, 4, aPixColorA);
115 				pWContent->SetPixel(1, 6, aPixColorA);
116 				pWContent->SetPixel(2, 1, aPixColorA);
117 				pWContent->SetPixel(2, 3, aPixColorA);
118 				pWContent->SetPixel(2, 5, aPixColorA);
119 				pWContent->SetPixel(3, 2, aPixColorA);
120 				pWContent->SetPixel(3, 4, aPixColorA);
121 				pWContent->SetPixel(4, 1, aPixColorA);
122 				pWContent->SetPixel(4, 3, aPixColorA);
123 				pWContent->SetPixel(4, 5, aPixColorA);
124 				pWContent->SetPixel(5, 0, aPixColorA);
125 				pWContent->SetPixel(5, 2, aPixColorA);
126 				pWContent->SetPixel(5, 4, aPixColorA);
127 				pWContent->SetPixel(5, 6, aPixColorA);
128 				pWContent->SetPixel(6, 1, aPixColorA);
129 				pWContent->SetPixel(6, 5, aPixColorA);
130 
131 				pWContent->SetPixel(1, 1, aPixColorB);
132 				pWContent->SetPixel(1, 5, aPixColorB);
133 				pWContent->SetPixel(2, 2, aPixColorB);
134 				pWContent->SetPixel(2, 4, aPixColorB);
135 				pWContent->SetPixel(3, 3, aPixColorB);
136 				pWContent->SetPixel(4, 2, aPixColorB);
137 				pWContent->SetPixel(4, 4, aPixColorB);
138 				pWContent->SetPixel(5, 1, aPixColorB);
139 				pWContent->SetPixel(5, 5, aPixColorB);
140 
141 				pWMask->SetPixel(0, 0, aMaskColor);
142 				pWMask->SetPixel(0, 2, aMaskColor);
143 				pWMask->SetPixel(0, 3, aMaskColor);
144 				pWMask->SetPixel(0, 4, aMaskColor);
145 				pWMask->SetPixel(0, 6, aMaskColor);
146 				pWMask->SetPixel(1, 3, aMaskColor);
147 				pWMask->SetPixel(2, 0, aMaskColor);
148 				pWMask->SetPixel(2, 6, aMaskColor);
149 				pWMask->SetPixel(3, 0, aMaskColor);
150 				pWMask->SetPixel(3, 1, aMaskColor);
151 				pWMask->SetPixel(3, 5, aMaskColor);
152 				pWMask->SetPixel(3, 6, aMaskColor);
153 				pWMask->SetPixel(4, 0, aMaskColor);
154 				pWMask->SetPixel(4, 6, aMaskColor);
155 				pWMask->SetPixel(5, 3, aMaskColor);
156 				pWMask->SetPixel(6, 0, aMaskColor);
157 				pWMask->SetPixel(6, 2, aMaskColor);
158 				pWMask->SetPixel(6, 3, aMaskColor);
159 				pWMask->SetPixel(6, 4, aMaskColor);
160 				pWMask->SetPixel(6, 6, aMaskColor);
161 
162 				aContent.ReleaseAccess(pWContent);
163 				aMask.ReleaseAccess(pWMask);
164 
165 				// create and exchange at aRetVal
166 				delete aRetVal.set(new BitmapEx(aContent, aMask));
167 			}
168 
169 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
170 		}
171 
172 	} // end of namespace primitive2d
173 } // end of namespace drawinglayer
174 
175 //////////////////////////////////////////////////////////////////////////////
176 // eof
177