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 // MARKER(update_precomp.py): autogen include statement, do not remove
24 #include "precompiled_sw.hxx"
25 
26 #include <overlayrangesoutline.hxx>
27 #include <svx/sdr/overlay/overlaymanager.hxx>
28 #include <basegfx/polygon/b2dpolygon.hxx>
29 #include <basegfx/polygon/b2dpolypolygon.hxx>
30 #include <basegfx/polygon/b2dpolygontools.hxx>
31 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
32 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace
37 {
38     // combine ranges geometrically to a single, ORed polygon
impCombineRangesToPolyPolygon(const std::vector<basegfx::B2DRange> & rRanges)39     basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
40     {
41         const sal_uInt32 nCount(rRanges.size());
42         basegfx::B2DPolyPolygon aRetval;
43 
44         for(sal_uInt32 a(0); a < nCount; a++)
45         {
46             const basegfx::B2DPolygon aDiscretePolygon(basegfx::tools::createPolygonFromRect(rRanges[a]));
47 
48             if(0 == a)
49             {
50                 aRetval.append(aDiscretePolygon);
51             }
52             else
53             {
54                 aRetval = basegfx::tools::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
55             }
56         }
57 
58         return aRetval;
59     }
60 }
61 
62 namespace sw
63 {
64     namespace overlay
65     {
createOverlayObjectPrimitive2DSequence()66         drawinglayer::primitive2d::Primitive2DSequence OverlayRangesOutline::createOverlayObjectPrimitive2DSequence()
67         {
68             drawinglayer::primitive2d::Primitive2DSequence aRetval;
69             const sal_uInt32 nCount(getRanges().size());
70 
71             if( nCount )
72             {
73                 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
74                 const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
75                 const drawinglayer::primitive2d::Primitive2DReference aOutline(
76                     new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
77                     aPolyPolygon,
78                     aRGBColor));
79 
80                 aRetval.realloc(1);
81                 aRetval[0] = aOutline;
82             }
83 
84             return aRetval;
85         }
86 
OverlayRangesOutline(const Color & rColor,const std::vector<basegfx::B2DRange> & rRanges)87         OverlayRangesOutline::OverlayRangesOutline(
88             const Color& rColor,
89             const std::vector< basegfx::B2DRange >& rRanges )
90             : sdr::overlay::OverlayObject(rColor)
91             , maRanges(rRanges)
92         {
93             // no AA for highlight overlays
94             allowAntiAliase(false);
95         }
96 
~OverlayRangesOutline()97         OverlayRangesOutline::~OverlayRangesOutline()
98         {
99             if( getOverlayManager() )
100             {
101                 getOverlayManager()->remove(*this);
102             }
103         }
104 
setRanges(const std::vector<basegfx::B2DRange> & rNew)105         void OverlayRangesOutline::setRanges(const std::vector< basegfx::B2DRange >& rNew)
106         {
107             if(rNew != maRanges)
108             {
109                 maRanges = rNew;
110                 objectChange();
111             }
112         }
113     } // end of namespace overlay
114 } // end of namespace sdr
115 
116 //////////////////////////////////////////////////////////////////////////////
117 // eof
118