/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include using namespace com::sun::star; namespace drawinglayer { namespace primitive2d { BasePrimitive2D::BasePrimitive2D() : BasePrimitive2DImplBase(m_aMutex) { } BasePrimitive2D::~BasePrimitive2D() { } bool BasePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const { return (getPrimitive2DID() == rPrimitive.getPrimitive2DID()); } basegfx::B2DRange BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const { return get2DDecomposition(rViewInformation).getB2DRange(rViewInformation); } Primitive2DContainer BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const { return Primitive2DContainer(); } Primitive2DSequence SAL_CALL BasePrimitive2D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException, std::exception ) { const geometry::ViewInformation2D aViewInformation(rViewParameters); return comphelper::containerToSequence(get2DDecomposition(aViewInformation)); } css::geometry::RealRectangle2D SAL_CALL BasePrimitive2D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException, std::exception ) { const geometry::ViewInformation2D aViewInformation(rViewParameters); return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation)); } sal_Int64 SAL_CALL BasePrimitive2D::estimateUsage() throw (css::uno::RuntimeException) { return 0; // for now ignore the objects themselves } } // end of namespace primitive2d } // end of namespace drawinglayer namespace drawinglayer { namespace primitive2d { Primitive2DContainer BufferedDecompositionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const { return Primitive2DContainer(); } BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D() : BasePrimitive2D(), maBuffered2DDecomposition() { } Primitive2DContainer BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const { ::osl::MutexGuard aGuard( m_aMutex ); if(getBuffered2DDecomposition().empty()) { const Primitive2DContainer aNewSequence(create2DDecomposition(rViewInformation)); const_cast< BufferedDecompositionPrimitive2D* >(this)->setBuffered2DDecomposition(aNewSequence); } return getBuffered2DDecomposition(); } } // end of namespace primitive2d } // end of namespace drawinglayer // tooling namespace drawinglayer { namespace primitive2d { Primitive2DContainer Primitive2DContainer::maybeInvert(bool bInvert) const { const sal_uInt32 nSize(size()); Primitive2DContainer aRetval; aRetval.resize(nSize); for(sal_uInt32 a(0); a < nSize; a++) { aRetval[bInvert ? nSize - 1 - a : a] = (*this)[a]; } // all entries taken over to Uno References as owners. To avoid // errors with users of this mechanism to delete pointers to BasePrimitive2D // itself, clear given vector const_cast< Primitive2DContainer& >(*this).clear(); return aRetval; } // get B2DRange from a given Primitive2DReference basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation) { basegfx::B2DRange aRetval; if(rCandidate.is()) { // try to get C++ implementation base const BasePrimitive2D* pCandidate(dynamic_cast< BasePrimitive2D* >(rCandidate.get())); if(pCandidate) { // use it if possible aRetval.expand(pCandidate->getB2DRange(aViewInformation)); } else { // use UNO API call instead const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence()); aRetval.expand(basegfx::unotools::b2DRectangleFromRealRectangle2D(rCandidate->getRange(rViewParameters))); } } return aRetval; } // get B2DRange from a given Primitive2DSequence basegfx::B2DRange Primitive2DContainer::getB2DRange(const geometry::ViewInformation2D& aViewInformation) const { basegfx::B2DRange aRetval; if(!empty()) { const sal_Int32 nCount(this->size()); for(sal_Int32 a(0L); a < nCount; a++) { aRetval.expand(getB2DRangeFromPrimitive2DReference((*this)[a], aViewInformation)); } } return aRetval; } bool arePrimitive2DReferencesEqual(const Primitive2DReference& rxA, const Primitive2DReference& rxB) { const bool bAIs(rxA.is()); if(bAIs != rxB.is()) { return false; } if(!bAIs) { return true; } const BasePrimitive2D* pA(dynamic_cast< const BasePrimitive2D* >(rxA.get())); const BasePrimitive2D* pB(dynamic_cast< const BasePrimitive2D* >(rxB.get())); const bool bAEqualZero(pA == nullptr); if(bAEqualZero != (pB == nullptr)) { return false; } if(bAEqualZero) { return false; } return (pA->operator==(*pB)); } bool Primitive2DContainer::operator==(const Primitive2DContainer& rB) const { const bool bAHasElements(!empty()); if(bAHasElements != !rB.empty()) { return false; } if(!bAHasElements) { return true; } const size_t nCount(size()); if(nCount != rB.size()) { return false; } for(size_t a(0L); a < nCount; a++) { if(!arePrimitive2DReferencesEqual((*this)[a], rB[a])) { return false; } } return true; } void Primitive2DContainer::append(const Primitive2DContainer& rSource) { insert(end(), rSource.begin(), rSource.end()); } void Primitive2DContainer::append(Primitive2DContainer&& rSource) { size_t n = size(); resize(n + rSource.size()); for (size_t i = 0; i> 16) & 0xFF) + "|" + OUString::number(nId & 0xFF); } } } // end of namespace primitive2d } // end of namespace drawinglayer /* vim:set shiftwidth=4 softtabstop=4 expandtab: */