vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / sdext / source / minimizer / pagecollector.cxx
blobb1673a18866beccdb9dc4427b50cb74ffa7de6fe
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 .
21 #include "pagecollector.hxx"
22 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
23 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
24 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
25 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/container/XIndexContainer.hpp>
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::awt;
32 using namespace ::com::sun::star::drawing;
33 using namespace ::com::sun::star::frame;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::container;
36 using namespace ::com::sun::star::presentation;
38 void PageCollector::CollectCustomShowPages( const css::uno::Reference< css::frame::XModel >& rxModel, const OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rUsedPageList )
40 try
42 Reference< XCustomPresentationSupplier > aXCPSup( rxModel, UNO_QUERY_THROW );
43 Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
44 if ( aXCont.is() )
46 // creating a list of every page that is used within our customshow
47 const Sequence< OUString> aNameSeq( aXCont->getElementNames() );
48 for ( OUString const & i :aNameSeq )
50 if ( i == rCustomShowName )
52 Reference< container::XIndexContainer > aXIC( aXCont->getByName( i ), UNO_QUERY_THROW );
53 sal_Int32 j, nSlideCount = aXIC->getCount();
54 for ( j = 0; j < nSlideCount; j++ )
56 Reference< XDrawPage > xDrawPage( aXIC->getByIndex( j ), UNO_QUERY_THROW );
57 auto aIter = std::find(rUsedPageList.begin(), rUsedPageList.end(), xDrawPage);
58 if ( aIter == rUsedPageList.end() )
59 rUsedPageList.push_back( xDrawPage );
65 catch( Exception& )
71 void PageCollector::CollectNonCustomShowPages( const css::uno::Reference< css::frame::XModel >& rxModel, const OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rNonUsedPageList )
73 try
75 std::vector< Reference< XDrawPage > > vUsedPageList;
76 PageCollector::CollectCustomShowPages( rxModel, rCustomShowName, vUsedPageList );
77 if ( !vUsedPageList.empty() )
79 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
80 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
81 for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
83 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
84 auto aIter = std::find(vUsedPageList.begin(), vUsedPageList.end(), xDrawPage);
85 if ( aIter == vUsedPageList.end() )
86 rNonUsedPageList.push_back( xDrawPage );
90 catch( Exception& )
96 void PageCollector::CollectMasterPages( const Reference< XModel >& rxModel, std::vector< PageCollector::MasterPageEntity >& rMasterPageList )
98 try
100 // generating list of all master pages
101 Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
102 Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_SET_THROW );
103 for ( sal_Int32 i = 0; i < xMasterPages->getCount(); i++ )
105 Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW );
106 auto aIter = std::find_if(rMasterPageList.begin(), rMasterPageList.end(),
107 [&xMasterPage](const MasterPageEntity& rEntity) { return rEntity.xMasterPage == xMasterPage; });
108 if ( aIter == rMasterPageList.end() )
110 MasterPageEntity aMasterPageEntity;
111 aMasterPageEntity.xMasterPage = xMasterPage;
112 aMasterPageEntity.bUsed = false;
113 rMasterPageList.push_back( aMasterPageEntity );
117 // mark masterpages which are referenced by drawpages
118 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
119 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
120 for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
122 Reference< XMasterPageTarget > xMasterPageTarget( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
123 Reference< XDrawPage > xMasterPage( xMasterPageTarget->getMasterPage(), UNO_SET_THROW );
124 auto aIter = std::find_if(rMasterPageList.begin(), rMasterPageList.end(),
125 [&xMasterPage](const MasterPageEntity& rEntity) { return rEntity.xMasterPage == xMasterPage; });
126 if ( aIter == rMasterPageList.end() )
127 throw uno::RuntimeException();
128 aIter->bUsed = true;
131 catch( Exception& )
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */