Anonymous avatar Anonymous committed a0cb8ce

writerfilter09: WrapPolygonHandler: use WrapPolygon and correctWordWrapPolygon

Comments (0)

Files changed (3)

writerfilter/source/dmapper/GraphicImport.cxx

     sal_Int32 nWrap;
     bool      bOpaque;
     bool      bContour;
-    drawing::PointSequenceSequence mContourPolyPolygon;
+    WrapPolygon::Pointer_t mpWrapPolygon;
     bool      bIgnoreWRK;
 
     sal_Int32 nLeftMargin;
         ,nWrap(0)
         ,bOpaque( true )
         ,bContour(false)
-        ,mContourPolyPolygon(0)
         ,bIgnoreWRK(true)
         ,nLeftMargin(319)
         ,nRightMargin(319)
                 
                 resolveSprmProps(aHandler, rSprm);
 
-                m_pImpl->mContourPolyPolygon = aHandler.getPolygon(); 
+                m_pImpl->mpWrapPolygon = aHandler.getPolygon(); 
             }
             break;
         case NS_ooxml::LN_CT_Anchor_positionH: // 90976;
                 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 )
                     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
                     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)

writerfilter/source/dmapper/WrapPolygonHandler.cxx

 
 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)
 {
 }
 
             resolveSprmProps(*this, sprm);
             
             awt::Point aPoint(mnX, mnY);
-            mPoints.push_back(aPoint);
+            mpPolygon->addPoint(aPoint);
         }
         break;
     default:
     }
 }
 
-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;
 }
 
 }}

writerfilter/source/dmapper/WrapPolygonHandler.hxx

 
 #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
 {
     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;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.