Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / crsr / overlayrangesoutline.cxx
blob265509a055ab8ba9883ad7fa37a7cec22b85e0f5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "overlayrangesoutline.hxx"
20 #include <svx/sdr/overlay/overlaymanager.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolypolygon.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
25 #include <drawinglayer/primitive2d/PolyPolygonHairlinePrimitive2D.hxx>
27 namespace
29 // combine ranges geometrically to a single, ORed polygon
30 basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
32 const sal_uInt32 nCount(rRanges.size());
33 basegfx::B2DPolyPolygon aRetval;
35 for(sal_uInt32 a(0); a < nCount; a++)
37 const basegfx::B2DPolygon aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges[a]));
39 if(0 == a)
41 aRetval.append(aDiscretePolygon);
43 else
45 aRetval = basegfx::utils::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
49 return aRetval;
53 namespace sw::overlay
55 drawinglayer::primitive2d::Primitive2DContainer OverlayRangesOutline::createOverlayObjectPrimitive2DSequence()
57 drawinglayer::primitive2d::Primitive2DContainer aRetval;
58 const sal_uInt32 nCount(getRanges().size());
60 if( nCount )
62 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
63 basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
64 const drawinglayer::primitive2d::Primitive2DReference aOutline(
65 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
66 std::move(aPolyPolygon),
67 aRGBColor));
69 aRetval.resize(1);
70 aRetval[0] = aOutline;
73 return aRetval;
76 OverlayRangesOutline::OverlayRangesOutline(
77 const Color& rColor,
78 std::vector< basegfx::B2DRange >&& rRanges )
79 : sdr::overlay::OverlayObject(rColor)
80 , maRanges(std::move(rRanges))
82 // no AA for highlight overlays
83 allowAntiAliase(false);
86 OverlayRangesOutline::~OverlayRangesOutline()
88 if( getOverlayManager() )
90 getOverlayManager()->remove(*this);
94 void OverlayRangesOutline::setRanges(std::vector< basegfx::B2DRange >&& rNew)
96 if(rNew != maRanges)
98 maRanges = std::move(rNew);
99 objectChange();
102 } // end of namespace sw::overlay
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */