diff options
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/GraphicImport.cxx | 29 | ||||
-rw-r--r-- | writerfilter/source/dmapper/WrapPolygonHandler.cxx | 132 | ||||
-rw-r--r-- | writerfilter/source/dmapper/WrapPolygonHandler.hxx | 35 |
3 files changed, 169 insertions, 27 deletions
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx index 6988ac7752c7..39382a009f2b 100644 --- a/writerfilter/source/dmapper/GraphicImport.cxx +++ b/writerfilter/source/dmapper/GraphicImport.cxx @@ -225,7 +225,7 @@ public: sal_Int32 nWrap; bool bOpaque; bool bContour; - drawing::PointSequenceSequence mContourPolyPolygon; + WrapPolygon::Pointer_t mpWrapPolygon; bool bIgnoreWRK; sal_Int32 nLeftMargin; @@ -288,7 +288,6 @@ public: ,nWrap(0) ,bOpaque( true ) ,bContour(false) - ,mContourPolyPolygon(0) ,bIgnoreWRK(true) ,nLeftMargin(319) ,nRightMargin(319) @@ -1396,7 +1395,7 @@ void GraphicImport::lcl_sprm(Sprm & rSprm) resolveSprmProps(aHandler, rSprm); - m_pImpl->mContourPolyPolygon = aHandler.getPolygon(); + m_pImpl->mpWrapPolygon = aHandler.getPolygon(); } break; case NS_ooxml::LN_CT_Anchor_positionH: // 90976; @@ -1636,13 +1635,6 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_BOTTOM_MARGIN ), uno::makeAny(m_pImpl->nBottomMargin)); - uno::Any aContourPolyPolygon; - if (m_pImpl->mContourPolyPolygon.getLength() >0) - aContourPolyPolygon <<= m_pImpl->mContourPolyPolygon; - - xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_CONTOUR_POLY_POLYGON), - aContourPolyPolygon); - if( m_pImpl->eColorMode == drawing::ColorMode_STANDARD && m_pImpl->nContrast == -70 && m_pImpl->nBrightness == 70 ) @@ -1670,16 +1662,31 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_MIRRORED_ON_ODD_PAGES ), uno::makeAny( m_pImpl->bHoriFlip )); } + if( m_pImpl->bVertFlip ) xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_MIRRORED ), uno::makeAny( m_pImpl->bVertFlip )); xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_BACK_COLOR ), uno::makeAny( m_pImpl->nFillColor )); + //there seems to be no way to detect the original size via _real_ API uno::Reference< beans::XPropertySet > xGraphicProperties( xGraphic, uno::UNO_QUERY_THROW ); awt::Size aGraphicSize, aGraphicSizePixel; xGraphicProperties->getPropertyValue(rPropNameSupplier.GetName( PROP_SIZE100th_M_M )) >>= aGraphicSize; xGraphicProperties->getPropertyValue(rPropNameSupplier.GetName( PROP_SIZE_PIXEL )) >>= aGraphicSizePixel; + + uno::Any aContourPolyPolygon; + if( aGraphicSize.Width && aGraphicSize.Height && + m_pImpl->mpWrapPolygon.get() != NULL) + { + awt::Size aDstSize(m_pImpl->getXSize(), m_pImpl->getYSize()); + WrapPolygon::Pointer_t pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygon(aGraphicSize, aDstSize); + aContourPolyPolygon <<= pCorrected->getPointSequenceSequence(); + } + + xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_CONTOUR_POLY_POLYGON), + aContourPolyPolygon); + if( aGraphicSize.Width && aGraphicSize.Height ) { //todo: i71651 graphic size is not provided by the GraphicDescriptor @@ -1688,9 +1695,11 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b lcl_CalcCrop( m_pImpl->nLeftCrop, aGraphicSize.Width ); lcl_CalcCrop( m_pImpl->nRightCrop, aGraphicSize.Width ); + xGraphicProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_GRAPHIC_CROP ), uno::makeAny(text::GraphicCrop(m_pImpl->nTopCrop, m_pImpl->nBottomCrop, m_pImpl->nLeftCrop, m_pImpl->nRightCrop))); } + } if(m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_INLINE || m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR) diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.cxx b/writerfilter/source/dmapper/WrapPolygonHandler.cxx index 14a750388e30..452eb9d66473 100644 --- a/writerfilter/source/dmapper/WrapPolygonHandler.cxx +++ b/writerfilter/source/dmapper/WrapPolygonHandler.cxx @@ -40,8 +40,123 @@ using resourcemodel::resolveSprmProps; namespace dmapper { +WrapPolygon::WrapPolygon() +{ +} + +WrapPolygon::~WrapPolygon() +{ +} + +void WrapPolygon::addPoint(const awt::Point & rPoint) +{ + mPoints.push_back(rPoint); +} + +WrapPolygon::Points_t::const_iterator WrapPolygon::begin() const +{ + return mPoints.begin(); +} + +WrapPolygon::Points_t::const_iterator WrapPolygon::end() const +{ + return mPoints.end(); +} + +WrapPolygon::Points_t::iterator WrapPolygon::begin() +{ + return mPoints.begin(); +} + +WrapPolygon::Points_t::iterator WrapPolygon::end() +{ + return mPoints.end(); +} + +size_t WrapPolygon::size() const +{ + return mPoints.size(); +} + +WrapPolygon::Pointer_t WrapPolygon::move(const awt::Point & rPoint) +{ + WrapPolygon::Pointer_t pResult(new WrapPolygon); + + Points_t::iterator aIt = begin(); + Points_t::iterator aItEnd = end(); + + while (aIt != aItEnd) + { + awt::Point aPoint(aIt->X + rPoint.X, aIt->Y + rPoint.Y); + pResult->addPoint(aPoint); + aIt++; + } + + return pResult; +} + +WrapPolygon::Pointer_t WrapPolygon::scale(const Fraction & rFractionX, const Fraction & rFractionY) +{ + WrapPolygon::Pointer_t pResult(new WrapPolygon); + + Points_t::iterator aIt = begin(); + Points_t::iterator aItEnd = end(); + + while (aIt != aItEnd) + { + awt::Point aPoint(Fraction(aIt->X) * rFractionX, Fraction(aIt->Y) * rFractionY); + pResult->addPoint(aPoint); + aIt++; + } + + return pResult; +} + +WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSrcSize, const awt::Size & rDstSize) +{ + WrapPolygon::Pointer_t pResult; + + const sal_uInt32 nWrap100Percent = 21600; + + Fraction aMove(nWrap100Percent, rSrcSize.Width); + aMove = aMove * Fraction(15, 1); + awt::Point aMovePoint(aMove, 0); + pResult = move(aMovePoint); + + Fraction aScaleX(nWrap100Percent, Fraction(nWrap100Percent) + aMove); + Fraction aScaleY(nWrap100Percent, Fraction(nWrap100Percent) - aMove); + pResult = pResult->scale(aScaleX, aScaleY); + + Fraction aScaleDestX(rDstSize.Width, nWrap100Percent); + Fraction aScaleDestY(rDstSize.Height, nWrap100Percent); + pResult = pResult->scale(aScaleDestX, aScaleDestY); + + return pResult; +} + +drawing::PointSequenceSequence WrapPolygon::getPointSequenceSequence() const +{ + drawing::PointSequenceSequence aPolyPolygon(1L); + drawing::PointSequence * pPolygon = aPolyPolygon.getArray(); + pPolygon->realloc(size()); + + sal_uInt32 n = 0; + Points_t::const_iterator aIt = begin(); + Points_t::const_iterator aItEnd = end(); + + while (aIt != aItEnd) + { + (*pPolygon)[n] = *aIt; + ++n; + aIt++; + } + + return aPolyPolygon; +} + WrapPolygonHandler::WrapPolygonHandler() : LoggedProperties(dmapper_logger, "WrapPolygonHandler") +, mpPolygon(new WrapPolygon) { } @@ -82,7 +197,7 @@ void WrapPolygonHandler::lcl_sprm(Sprm & sprm) resolveSprmProps(*this, sprm); awt::Point aPoint(mnX, mnY); - mPoints.push_back(aPoint); + mpPolygon->addPoint(aPoint); } break; default: @@ -93,20 +208,9 @@ void WrapPolygonHandler::lcl_sprm(Sprm & sprm) } } -drawing::PointSequenceSequence WrapPolygonHandler::getPolygon() +WrapPolygon::Pointer_t WrapPolygonHandler::getPolygon() { - drawing::PointSequenceSequence aPolyPolygon(1L); - drawing::PointSequence * pPolygon = aPolyPolygon.getArray(); - pPolygon->realloc(mPoints.size()); - - sal_uInt32 n = 0; - for (Points_t::const_iterator aIt = mPoints.begin(); aIt != mPoints.end(); aIt++) - { - (*pPolygon)[n] = *aIt; - ++n; - } - - return aPolyPolygon; + return mpPolygon; } }} diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.hxx b/writerfilter/source/dmapper/WrapPolygonHandler.hxx index 5bbeab891859..05161096f81a 100644 --- a/writerfilter/source/dmapper/WrapPolygonHandler.hxx +++ b/writerfilter/source/dmapper/WrapPolygonHandler.hxx @@ -30,11 +30,41 @@ #include <com/sun/star/drawing/PointSequenceSequence.hpp> #include <resourcemodel/LoggedResources.hxx> +#include <resourcemodel/Fraction.hxx> namespace writerfilter { namespace dmapper { using namespace ::com::sun::star; +using resourcemodel::Fraction; + +class WrapPolygon +{ +public: + typedef ::std::deque<awt::Point> Points_t; + typedef ::boost::shared_ptr<WrapPolygon> Pointer_t; + +private: + Points_t mPoints; + +public: + WrapPolygon(); + virtual ~WrapPolygon(); + + void addPoint(const awt::Point & rPoint); + + Points_t::const_iterator begin() const; + Points_t::const_iterator end() const; + Points_t::iterator begin(); + Points_t::iterator end(); + + size_t size() const; + + WrapPolygon::Pointer_t move(const awt::Point & rMove); + WrapPolygon::Pointer_t scale(const Fraction & rFractionX, const Fraction & rFractionY); + WrapPolygon::Pointer_t correctWordWrapPolygon(const awt::Size & rSrcSize, const awt::Size & rDstSize); + drawing::PointSequenceSequence getPointSequenceSequence() const; +}; class WrapPolygonHandler : public LoggedProperties { @@ -42,11 +72,10 @@ public: WrapPolygonHandler(); virtual ~WrapPolygonHandler(); - drawing::PointSequenceSequence getPolygon(); + WrapPolygon::Pointer_t getPolygon(); private: - typedef ::std::deque<awt::Point> Points_t; - Points_t mPoints; + WrapPolygon::Pointer_t mpPolygon; sal_uInt32 mnX; sal_uInt32 mnY; |