1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <sdr/contact/viewobjectcontactofmasterpagedescriptor.hxx>
22 #include <sdr/contact/viewcontactofmasterpagedescriptor.hxx>
23 #include <svx/sdr/contact/displayinfo.hxx>
24 #include <svx/sdr/contact/objectcontact.hxx>
25 #include <svx/svdpage.hxx>
26 #include <svx/svdpagv.hxx>
27 #include <svx/svdview.hxx>
28 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
29 #include <basegfx/polygon/b2dpolygontools.hxx>
30 #include <basegfx/polygon/b2dpolygon.hxx>
33 namespace sdr::contact
35 ViewObjectContactOfMasterPageDescriptor::ViewObjectContactOfMasterPageDescriptor(ObjectContact
& rObjectContact
, ViewContact
& rViewContact
)
36 : ViewObjectContact(rObjectContact
, rViewContact
)
40 ViewObjectContactOfMasterPageDescriptor::~ViewObjectContactOfMasterPageDescriptor()
44 bool ViewObjectContactOfMasterPageDescriptor::isPrimitiveVisible(const DisplayInfo
& rDisplayInfo
) const
46 if(rDisplayInfo
.GetControlLayerProcessingActive())
51 // display mster page content?
52 if (!GetObjectContact().isMasterPageActive())
60 void ViewObjectContactOfMasterPageDescriptor::getPrimitive2DSequenceHierarchy(DisplayInfo
& rDisplayInfo
, drawinglayer::primitive2d::Primitive2DDecompositionVisitor
& rVisitor
) const
62 drawinglayer::primitive2d::Primitive2DContainer xMasterPageSequence
;
63 const sdr::MasterPageDescriptor
& rDescriptor
= static_cast< ViewContactOfMasterPageDescriptor
& >(GetViewContact()).GetMasterPageDescriptor();
65 // used range (retval) is fixed here, it's the MasterPage fill range
66 const SdrPage
& rOwnerPage
= rDescriptor
.GetOwnerPage();
67 const basegfx::B2DRange
aInnerRange(
68 rOwnerPage
.GetLeftBorder(), rOwnerPage
.GetUpperBorder(),
69 rOwnerPage
.GetWidth() - rOwnerPage
.GetRightBorder(), rOwnerPage
.GetHeight() - rOwnerPage
.GetLowerBorder());
70 const basegfx::B2DRange
aOuterRange(
71 0, 0, rOwnerPage
.GetWidth(), rOwnerPage
.GetHeight());
72 // ??? somehow only the master page's bit is used
73 bool const isFullSize(rDescriptor
.GetUsedPage().IsBackgroundFullSize());
74 basegfx::B2DRange
const& rPageFillRange(isFullSize
? aOuterRange
: aInnerRange
);
76 // Modify DisplayInfo for MasterPageContent collection; remember original layers and
77 // set combined SdrLayerIDSet; set MasterPagePaint flag
78 const SdrLayerIDSet
aRememberedLayers(rDisplayInfo
.GetProcessLayers());
79 SdrLayerIDSet
aPreprocessedLayers(aRememberedLayers
);
80 aPreprocessedLayers
&= rDescriptor
.GetVisibleLayers();
81 rDisplayInfo
.SetProcessLayers(aPreprocessedLayers
);
82 rDisplayInfo
.SetSubContentActive(true);
83 const SdrPageView
* pSdrPageView
= GetObjectContact().TryToGetSdrPageView();
84 bool bHideBackground
= pSdrPageView
? pSdrPageView
->GetView().getHideBackground() : false;
85 // check layer visibility (traditionally was member of layer 1)
86 if(aPreprocessedLayers
.IsSet(SdrLayerID(1)))
88 // hide PageBackground for special DrawModes; historical reasons
89 if (!bHideBackground
&& !GetObjectContact().isDrawModeGray() && !GetObjectContact().isDrawModeHighContrast())
91 // if visible, create the default background primitive sequence
92 static_cast< ViewContactOfMasterPageDescriptor
& >(GetViewContact()).getViewIndependentPrimitive2DContainer(rVisitor
);
96 // hide MasterPage content? Test self here for hierarchy
97 if(isPrimitiveVisible(rDisplayInfo
))
99 // get the VOC of the Master-SdrPage and get its object hierarchy
100 ViewContact
& rViewContactOfMasterPage(rDescriptor
.GetUsedPage().GetViewContact());
101 ViewObjectContact
& rVOCOfMasterPage(rViewContactOfMasterPage
.GetViewObjectContact(GetObjectContact()));
103 rVOCOfMasterPage
.getPrimitive2DSequenceHierarchy(rDisplayInfo
, xMasterPageSequence
);
106 // reset DisplayInfo changes for MasterPage paint
107 rDisplayInfo
.SetProcessLayers(aRememberedLayers
);
108 rDisplayInfo
.SetSubContentActive(false);
110 if(!xMasterPageSequence
.empty())
112 // get range of MasterPage sub hierarchy
113 const drawinglayer::geometry::ViewInformation2D
& rViewInformation2D(GetObjectContact().getViewInformation2D());
114 basegfx::B2DRange
aSubHierarchyRange(xMasterPageSequence
.getB2DRange(rViewInformation2D
));
116 if (rPageFillRange
.isInside(aSubHierarchyRange
))
118 // completely inside, just render MasterPage content. Add to target
119 rVisitor
.visit(xMasterPageSequence
);
121 else if (rPageFillRange
.overlaps(aSubHierarchyRange
))
123 // overlapping, compute common area
124 basegfx::B2DRange
aCommonArea(rPageFillRange
);
125 aCommonArea
.intersect(aSubHierarchyRange
);
127 // need to create a clip primitive, add clipped list to target
128 const drawinglayer::primitive2d::Primitive2DReference
xReference(new drawinglayer::primitive2d::MaskPrimitive2D(
129 basegfx::B2DPolyPolygon(basegfx::utils::createPolygonFromRect(aCommonArea
)), std::move(xMasterPageSequence
)));
130 rVisitor
.visit(xReference
);
134 } // end of namespace
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */