1*ddde725dSArmin Le Grand /**************************************************************
2*ddde725dSArmin Le Grand  *
3*ddde725dSArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
4*ddde725dSArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
5*ddde725dSArmin Le Grand  * distributed with this work for additional information
6*ddde725dSArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
7*ddde725dSArmin Le Grand  * to you under the Apache License, Version 2.0 (the
8*ddde725dSArmin Le Grand  * "License"); you may not use this file except in compliance
9*ddde725dSArmin Le Grand  * with the License.  You may obtain a copy of the License at
10*ddde725dSArmin Le Grand  *
11*ddde725dSArmin Le Grand  *   http:\\www.apache.org\licenses\LICENSE-2.0
12*ddde725dSArmin Le Grand  *
13*ddde725dSArmin Le Grand  * Unless required by applicable law or agreed to in writing,
14*ddde725dSArmin Le Grand  * software distributed under the License is distributed on an
15*ddde725dSArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ddde725dSArmin Le Grand  * KIND, either express or implied.  See the License for the
17*ddde725dSArmin Le Grand  * specific language governing permissions and limitations
18*ddde725dSArmin Le Grand  * under the License.
19*ddde725dSArmin Le Grand  *
20*ddde725dSArmin Le Grand  *************************************************************/
21*ddde725dSArmin Le Grand 
22*ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
23*ddde725dSArmin Le Grand #include "precompiled_drawinglayer.hxx"
24*ddde725dSArmin Le Grand 
25*ddde725dSArmin Le Grand #include <drawinglayer/tools/converters.hxx>
26*ddde725dSArmin Le Grand #include <drawinglayer/geometry/viewinformation2d.hxx>
27*ddde725dSArmin Le Grand #include <drawinglayer/processor2d/vclpixelprocessor2d.hxx>
28*ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
29*ddde725dSArmin Le Grand #include <basegfx/matrix/b2dhommatrixtools.hxx>
30*ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
31*ddde725dSArmin Le Grand #include <vcl/virdev.hxx>
32*ddde725dSArmin Le Grand 
33*ddde725dSArmin Le Grand #ifdef DBG_UTIL
34*ddde725dSArmin Le Grand #include <tools/stream.hxx>
35*ddde725dSArmin Le Grand #endif
36*ddde725dSArmin Le Grand 
37*ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
38*ddde725dSArmin Le Grand 
39*ddde725dSArmin Le Grand namespace drawinglayer
40*ddde725dSArmin Le Grand {
41*ddde725dSArmin Le Grand     namespace tools
42*ddde725dSArmin Le Grand     {
43*ddde725dSArmin Le Grand         BitmapEx DRAWINGLAYER_DLLPUBLIC convertToBitmapEx(
44*ddde725dSArmin Le Grand             const drawinglayer::primitive2d::Primitive2DSequence& rSeq,
45*ddde725dSArmin Le Grand             const geometry::ViewInformation2D& rViewInformation2D,
46*ddde725dSArmin Le Grand             sal_uInt32 nDiscreteWidth,
47*ddde725dSArmin Le Grand             sal_uInt32 nDiscreteHeight,
48*ddde725dSArmin Le Grand             sal_uInt32 nMaxQuadratPixels)
49*ddde725dSArmin Le Grand         {
50*ddde725dSArmin Le Grand             BitmapEx aRetval;
51*ddde725dSArmin Le Grand 
52*ddde725dSArmin Le Grand             if(rSeq.hasElements() && nDiscreteWidth && nDiscreteHeight)
53*ddde725dSArmin Le Grand             {
54*ddde725dSArmin Le Grand                 // get destination size in pixels
55*ddde725dSArmin Le Grand                 const MapMode aMapModePixel(MAP_PIXEL);
56*ddde725dSArmin Le Grand                 const sal_uInt32 nViewVisibleArea(nDiscreteWidth * nDiscreteHeight);
57*ddde725dSArmin Le Grand                 double fReduceFactor(1.0);
58*ddde725dSArmin Le Grand                 drawinglayer::primitive2d::Primitive2DSequence aSequence(rSeq);
59*ddde725dSArmin Le Grand 
60*ddde725dSArmin Le Grand                 if(nViewVisibleArea > nMaxQuadratPixels)
61*ddde725dSArmin Le Grand                 {
62*ddde725dSArmin Le Grand                     // reduce render size
63*ddde725dSArmin Le Grand                     fReduceFactor = sqrt((double)nMaxQuadratPixels / (double)nViewVisibleArea);
64*ddde725dSArmin Le Grand                     nDiscreteWidth = basegfx::fround((double)nDiscreteWidth * fReduceFactor);
65*ddde725dSArmin Le Grand                     nDiscreteHeight = basegfx::fround((double)nDiscreteHeight * fReduceFactor);
66*ddde725dSArmin Le Grand 
67*ddde725dSArmin Le Grand                     const drawinglayer::primitive2d::Primitive2DReference aEmbed(
68*ddde725dSArmin Le Grand                         new drawinglayer::primitive2d::TransformPrimitive2D(
69*ddde725dSArmin Le Grand                             basegfx::tools::createScaleB2DHomMatrix(fReduceFactor, fReduceFactor),
70*ddde725dSArmin Le Grand                             rSeq));
71*ddde725dSArmin Le Grand 
72*ddde725dSArmin Le Grand                     aSequence = drawinglayer::primitive2d::Primitive2DSequence(&aEmbed, 1);
73*ddde725dSArmin Le Grand                 }
74*ddde725dSArmin Le Grand 
75*ddde725dSArmin Le Grand                 const Point aEmptyPoint;
76*ddde725dSArmin Le Grand                 const Size aSizePixel(nDiscreteWidth, nDiscreteHeight);
77*ddde725dSArmin Le Grand                 geometry::ViewInformation2D aViewInformation2D(rViewInformation2D);
78*ddde725dSArmin Le Grand                 VirtualDevice maContent;
79*ddde725dSArmin Le Grand 
80*ddde725dSArmin Le Grand                 // prepare vdev
81*ddde725dSArmin Le Grand                 maContent.SetOutputSizePixel(aSizePixel, false);
82*ddde725dSArmin Le Grand                 maContent.SetMapMode(aMapModePixel);
83*ddde725dSArmin Le Grand                 maContent.SetAntialiasing(true);
84*ddde725dSArmin Le Grand 
85*ddde725dSArmin Le Grand                 // set to all white
86*ddde725dSArmin Le Grand                 maContent.SetBackground(Wallpaper(Color(COL_WHITE)));
87*ddde725dSArmin Le Grand                 maContent.Erase();
88*ddde725dSArmin Le Grand 
89*ddde725dSArmin Le Grand                 // create processor
90*ddde725dSArmin Le Grand                 processor2d::VclPixelProcessor2D aContentProcessor(aViewInformation2D, maContent);
91*ddde725dSArmin Le Grand 
92*ddde725dSArmin Le Grand                 // render content
93*ddde725dSArmin Le Grand                 aContentProcessor.process(aSequence);
94*ddde725dSArmin Le Grand 
95*ddde725dSArmin Le Grand                 // get content
96*ddde725dSArmin Le Grand                 maContent.EnableMapMode(false);
97*ddde725dSArmin Le Grand                 const Bitmap aContent(maContent.GetBitmap(aEmptyPoint, aSizePixel));
98*ddde725dSArmin Le Grand 
99*ddde725dSArmin Le Grand                 // prepare for mask creation
100*ddde725dSArmin Le Grand                 maContent.SetMapMode(aMapModePixel);
101*ddde725dSArmin Le Grand                 maContent.SetAntialiasing(true);
102*ddde725dSArmin Le Grand 
103*ddde725dSArmin Le Grand                 // set alpha to all white (fully transparent)
104*ddde725dSArmin Le Grand                 maContent.Erase();
105*ddde725dSArmin Le Grand 
106*ddde725dSArmin Le Grand                 // embed primitives to paint them black
107*ddde725dSArmin Le Grand                 const primitive2d::Primitive2DReference xRef(
108*ddde725dSArmin Le Grand                     new primitive2d::ModifiedColorPrimitive2D(
109*ddde725dSArmin Le Grand                         aSequence,
110*ddde725dSArmin Le Grand                         basegfx::BColorModifier(
111*ddde725dSArmin Le Grand                             basegfx::BColor(0.0, 0.0, 0.0),
112*ddde725dSArmin Le Grand                             0.5,
113*ddde725dSArmin Le Grand                             basegfx::BCOLORMODIFYMODE_REPLACE)));
114*ddde725dSArmin Le Grand                 const primitive2d::Primitive2DSequence xSeq(&xRef, 1);
115*ddde725dSArmin Le Grand 
116*ddde725dSArmin Le Grand                 // render
117*ddde725dSArmin Le Grand                 aContentProcessor.process(xSeq);
118*ddde725dSArmin Le Grand 
119*ddde725dSArmin Le Grand                 // get alpha cahannel from vdev
120*ddde725dSArmin Le Grand                 maContent.EnableMapMode(false);
121*ddde725dSArmin Le Grand                 const AlphaMask aAlphaMask(maContent.GetBitmap(aEmptyPoint, aSizePixel));
122*ddde725dSArmin Le Grand 
123*ddde725dSArmin Le Grand                 // create BitmapEx result
124*ddde725dSArmin Le Grand                 aRetval = BitmapEx(aContent, aAlphaMask);
125*ddde725dSArmin Le Grand             }
126*ddde725dSArmin Le Grand 
127*ddde725dSArmin Le Grand #ifdef DBG_UTIL
128*ddde725dSArmin Le Grand             static bool bDoSaveForVisualControl(false);
129*ddde725dSArmin Le Grand             if(bDoSaveForVisualControl)
130*ddde725dSArmin Le Grand             {
131*ddde725dSArmin Le Grand                 SvFileStream aNew((const String&)String(ByteString( "c:\\test.png" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC);
132*ddde725dSArmin Le Grand                 aNew << aRetval;
133*ddde725dSArmin Le Grand             }
134*ddde725dSArmin Le Grand #endif
135*ddde725dSArmin Le Grand 
136*ddde725dSArmin Le Grand             return aRetval;
137*ddde725dSArmin Le Grand         }
138*ddde725dSArmin Le Grand 
139*ddde725dSArmin Le Grand     } // end of namespace tools
140*ddde725dSArmin Le Grand } // end of namespace drawinglayer
141*ddde725dSArmin Le Grand 
142*ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
143*ddde725dSArmin Le Grand // eof
144