[Libreoffice-commits] core.git: oox/inc oox/source

Vinaya vinaya.mandke at synerzip.com
Wed Mar 13 02:27:39 PDT 2013


 oox/inc/oox/ppt/comments.hxx                    |  195 ++++++++++++++++++++++++
 oox/inc/oox/ppt/presentationfragmenthandler.hxx |    5 
 oox/inc/oox/ppt/slidefragmenthandler.hxx        |    7 
 oox/inc/oox/ppt/slidepersist.hxx                |   11 +
 oox/source/ppt/presentationfragmenthandler.cxx  |   46 +++++
 oox/source/ppt/slidefragmenthandler.cxx         |   34 ++++
 6 files changed, 295 insertions(+), 3 deletions(-)

New commits:
commit 856756ec77ac64d1caee6c1b80c3641d4e487b2d
Author: Vinaya <vinaya.mandke at synerzip.com>
Date:   Fri Feb 8 19:19:38 2013 +0530

    Changes to enable display of comments annotations in pptx files
    
    Change-Id: Ibf7dc0c61dc46d1568abe47285662810f79410e7
    Change-Id: I965798cd3a539ab8deffcdf4a8e2c52c9e8e8fc1
    Reviewed-on: https://gerrit.libreoffice.org/2048
    Reviewed-by: Fridrich Strba <fridrich at documentfoundation.org>
    Tested-by: Fridrich Strba <fridrich at documentfoundation.org>

diff --git a/oox/inc/oox/ppt/comments.hxx b/oox/inc/oox/ppt/comments.hxx
new file mode 100644
index 0000000..44ea442
--- /dev/null
+++ b/oox/inc/oox/ppt/comments.hxx
@@ -0,0 +1,195 @@
+/* -*- 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/.
+ */
+
+
+#ifndef OOX_PPT_COMMENTS_HXX
+#define OOX_PPT_COMMENTS_HXX
+
+#define ELEMENT_NOT_FOUND 0
+
+using rtl::OUString;
+#include <vector>
+#include <boost/algorithm/string.hpp> //split function to tokenize for date time
+
+#include <com/sun/star/util/DateTime.hpp>
+
+
+struct commentAuthor
+{
+    ::rtl::OUString clrIdx;
+    ::rtl::OUString id;
+    ::rtl::OUString initials;
+    ::rtl::OUString lastIdx;
+    ::rtl::OUString name;
+};
+
+class commentAuthorList
+{
+    private:
+        std::vector<commentAuthor> cmAuthorLst;
+    public:
+        void setValues( commentAuthorList list)
+        {
+            std::vector<commentAuthor>::iterator it;
+            for(it=list.cmAuthorLst.begin();it!=list.cmAuthorLst.end();it++)
+            {
+                commentAuthor temp;
+                cmAuthorLst.push_back(temp);
+                cmAuthorLst.back().clrIdx = it->clrIdx;
+                cmAuthorLst.back().id = it->id;
+                cmAuthorLst.back().initials = it->initials;
+                cmAuthorLst.back().lastIdx = it->lastIdx;
+                cmAuthorLst.back().name = it->name;
+            }
+        }
+
+        std::vector<commentAuthor> getCmAuthorLst()
+        {
+            return cmAuthorLst;
+        }
+        void addAuthor(commentAuthor _author)
+        {
+            cmAuthorLst.push_back(_author);
+        }
+        friend class comment;
+};
+
+class comment
+{
+    private:
+        ::rtl::OUString authorId;
+        ::rtl::OUString dt;
+        ::rtl::OUString idx;
+        ::rtl::OUString x;
+        ::rtl::OUString y;
+        ::rtl::OUString text;
+        ::com::sun::star::util::DateTime aDateTime;
+
+    public:
+        void setAuthorId(::rtl::OUString _aId)
+        {
+            authorId = _aId;
+        }
+        void setdt(::rtl::OUString _dt)
+        {
+            dt=_dt;
+            setDateTime(_dt);
+        }
+        void setidx(::rtl::OUString _idx)
+        {
+            idx=_idx;
+        }
+        void setPoint(::rtl::OUString _x, ::rtl::OUString _y)
+        {
+            x=_x;
+            y=_y;
+        }
+        void setText(std::string _text)
+        {
+            text = rtl::OUString::createFromAscii (  _text.c_str() );
+        }
+        void setText(rtl::OUString _text)
+        {
+            text = _text;
+        }
+
+    private:
+    //DateTime is saved as : 2013-01-10T15:53:26.000
+        void setDateTime (::rtl::OUString datetime)
+        {
+            std::string _datetime = rtl::OUStringToOString(datetime, RTL_TEXTENCODING_UTF8).getStr();
+            std::vector<std::string> _dt;
+            boost::split( _dt, _datetime, boost::is_any_of( "-:T" ) );
+            aDateTime.Year = atoi(_dt.at(0).c_str());
+            aDateTime.Month = atoi(_dt.at(1).c_str());
+            aDateTime.Day = atoi(_dt.at(2).c_str());
+            aDateTime.Hours = atoi(_dt.at(3).c_str());
+            aDateTime.Minutes = atoi(_dt.at(4).c_str());
+            aDateTime.HundredthSeconds = atoi(_dt.at(5).c_str());
+            std::vector<std::string>::iterator i;
+        }
+
+    public:
+        ::rtl::OUString getAuthorId()
+        {
+            return authorId;
+        }
+        ::rtl::OUString getdt()
+        {
+            return dt;
+        }
+        ::rtl::OUString getidx()
+        {
+            return idx;
+        }
+        ::rtl::OUString get_X()
+        {
+            return x;
+        }
+        ::rtl::OUString get_Y()
+        {
+            return y;
+        }
+        ::rtl::OUString get_text()
+        {
+            return text;
+        }
+        ::com::sun::star::util::DateTime getDateTime()
+        {
+            return aDateTime;
+        }
+        int getIntX()
+        {
+            std::string temp = rtl::OUStringToOString(get_X(), RTL_TEXTENCODING_UTF8).getStr();
+            return atoi(temp.c_str());
+        }
+        int getIntY()
+        {
+            std::string temp = rtl::OUStringToOString(get_Y(), RTL_TEXTENCODING_UTF8).getStr();
+            return atoi(temp.c_str());
+        }
+        OUString getAuthor ( commentAuthorList list )
+        {
+            std::string temp = rtl::OUStringToOString(authorId, RTL_TEXTENCODING_UTF8).getStr();
+            int aId = atoi(temp.c_str());
+            std::vector<commentAuthor>::iterator it;
+            for(it = list.cmAuthorLst.begin(); it != list.cmAuthorLst.end(); it++)
+            {
+                temp = rtl::OUStringToOString(it->id, RTL_TEXTENCODING_UTF8).getStr();
+
+                int list_aId = atoi(temp.c_str());
+                std::string temp_a =rtl::OUStringToOString(it->name, RTL_TEXTENCODING_UTF8).getStr();
+                if(list_aId == aId)
+                {    return it->name;
+                }
+
+            }
+            OUString _unknown = "Anonymous";
+            return _unknown;
+        }
+};
+
+class commentList
+{
+    public:
+        std::vector<comment> cmLst;
+        int getSize ()
+        {
+            return (int)cmLst.size();
+        }
+        comment getCommentAtIndex (int index)
+        {
+            if(index < (int)cmLst.size() && index >= 0)
+                return cmLst.at(index);
+            else
+                throw ELEMENT_NOT_FOUND;
+        }
+};
+
+#endif
\ No newline at end of file
diff --git a/oox/inc/oox/ppt/presentationfragmenthandler.hxx b/oox/inc/oox/ppt/presentationfragmenthandler.hxx
index bb94884..8730352 100644
--- a/oox/inc/oox/ppt/presentationfragmenthandler.hxx
+++ b/oox/inc/oox/ppt/presentationfragmenthandler.hxx
@@ -29,7 +29,7 @@
 #include "oox/core/fragmenthandler2.hxx"
 #include "oox/core/relations.hxx"
 #include "oox/ppt/customshowlistcontext.hxx"
-
+#include "oox/ppt/comments.hxx"
 #include <stack>
 #include <vector>
 
@@ -42,6 +42,9 @@ public:
     virtual ~PresentationFragmentHandler() throw();
     virtual void finalizeImport();
     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs );
+private:
+    commentAuthorList AuthorList;
+    int readCommentAuthors; // read commentAuthors.xml only once
 
 protected:
     bool importSlide( const ::oox::core::FragmentHandlerRef& rxSlideFragmentHandler,
diff --git a/oox/inc/oox/ppt/slidefragmenthandler.hxx b/oox/inc/oox/ppt/slidefragmenthandler.hxx
index 4bca8cc..6cd50ab 100644
--- a/oox/inc/oox/ppt/slidefragmenthandler.hxx
+++ b/oox/inc/oox/ppt/slidefragmenthandler.hxx
@@ -39,7 +39,7 @@ public:
 
     virtual void finalizeImport();
     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs );
-
+    void        onCharacters( const ::rtl::OUString& rChars );
 protected:
     SlidePersistPtr     mpSlidePersistPtr;
     ShapeLocation       meShapeLocation;
@@ -47,6 +47,11 @@ protected:
 private:
     ::rtl::OUString     maSlideName;
     PropertyMap         maSlideProperties;
+private:
+    ::std::vector< rtl::OUString> charVector; // handle char in OnCharacters
+public:
+    ::std::vector< rtl::OUString> getCharVector(void) { return charVector; }
+
 };
 
 } }
diff --git a/oox/inc/oox/ppt/slidepersist.hxx b/oox/inc/oox/ppt/slidepersist.hxx
index 3c8bf33..68caa18 100644
--- a/oox/inc/oox/ppt/slidepersist.hxx
+++ b/oox/inc/oox/ppt/slidepersist.hxx
@@ -32,6 +32,8 @@
 #include <com/sun/star/animations/XAnimationNode.hpp>
 #include "oox/core/fragmenthandler.hxx"
 
+#include "oox/ppt/comments.hxx"
+
 #include <list>
 
 namespace oox { namespace vml { class Drawing; } }
@@ -116,6 +118,15 @@ public:
     ::oox::drawingml::ShapePtr getShape( const ::rtl::OUString & id ) { return maShapeMap[ id ]; }
     ::oox::drawingml::ShapeIdMap& getShapeMap() { return maShapeMap; }
 
+    //comments
+private:
+    commentList commentsList;
+    commentAuthorList commentAuthors;
+
+public:
+    commentList* getCommentsList() { return &commentsList; }
+    commentAuthorList* getCommentAuthors() { return &commentAuthors; }
+
 private:
     rtl::OUString                                                           maPath;
     rtl::OUString                                                           maLayoutPath;
diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx
index c2fdf53..bbf8267 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -42,6 +42,9 @@
 #include "oox/ppt/layoutfragmenthandler.hxx"
 #include "oox/ppt/pptimport.hxx"
 
+#include <com/sun/star/office/XAnnotation.hpp>
+#include <com/sun/star/office/XAnnotationAccess.hpp> //for comments
+
 using namespace ::com::sun::star;
 using namespace ::oox::core;
 using namespace ::oox::drawingml;
@@ -160,6 +163,7 @@ void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, sal_Bool bFirst
 
             // importing the corresponding masterpage/layout
             OUString aLayoutFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "slideLayout" ) );
+            OUString aCommentFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "comments" ) );
             if ( !aLayoutFragmentPath.isEmpty() )
             {
                 // importing layout
@@ -271,6 +275,47 @@ void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, sal_Bool bFirst
                     }
                 }
             }
+
+            if( !aCommentFragmentPath.isEmpty() && readCommentAuthors == 0 )
+                {// Comments are present and commentAuthors.xml has still not been read
+                    readCommentAuthors = 1; //set to true
+                    rtl::OUString aCommentAuthorsFragmentPath = "ppt/commentAuthors.xml";
+                    Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
+                    Reference< XDrawPage > xCommentAuthorsPage( xPresentationPage->getNotesPage() );
+                    SlidePersistPtr pCommentAuthorsPersistPtr( new SlidePersist( rFilter, sal_False, sal_True, xCommentAuthorsPage,
+                                ShapePtr( new PPTShape( Slide, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
+                    FragmentHandlerRef xCommentAuthorsFragmentHandler( new SlideFragmentHandler( getFilter(), aCommentAuthorsFragmentPath, pCommentAuthorsPersistPtr, Slide ) );
+
+                    importSlide( xCommentAuthorsFragmentHandler, pCommentAuthorsPersistPtr );
+                    AuthorList.setValues(*(pCommentAuthorsPersistPtr->getCommentAuthors()));
+                }
+                if( !aCommentFragmentPath.isEmpty() )
+                {   Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
+                    Reference< XDrawPage > xCommentsPage( xPresentationPage->getNotesPage() );
+                    SlidePersistPtr pCommentsPersistPtr( new SlidePersist( rFilter, sal_False, sal_True, xCommentsPage,
+                                ShapePtr( new PPTShape( Slide, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
+                    FragmentHandlerRef xCommentsFragmentHandler( new SlideFragmentHandler( getFilter(), aCommentFragmentPath, pCommentsPersistPtr, Slide ) );
+                    pCommentsPersistPtr->getCommentsList()->cmLst.clear();
+                    importSlide( xCommentsFragmentHandler, pCommentsPersistPtr );
+                    SlideFragmentHandler *comment_handler = dynamic_cast<SlideFragmentHandler*>(xCommentsFragmentHandler.get());
+                    pCommentsPersistPtr->getCommentsList()->cmLst.back().setText( comment_handler->getCharVector().back() );//set comment chars for last comment on slide
+
+                    pCommentsPersistPtr->getCommentAuthors()->setValues(AuthorList);
+                    //insert all comments from commentsList
+                    for(int i=0;   i<pCommentsPersistPtr->getCommentsList()->getSize();   i++)
+                    {
+                        uno::Reference< office::XAnnotationAccess > xAnnotationAccess( xSlide, UNO_QUERY_THROW );
+                        uno::Reference< office::XAnnotation > xAnnotation( xAnnotationAccess->createAndInsertAnnotation() );
+                        int nPosX = pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).getIntX();
+                        int nPosY = pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).getIntY();
+                        xAnnotation->setPosition( geometry::RealPoint2D( ::oox::drawingml::convertEmuToHmm( nPosX ) * 15.87 , ::oox::drawingml::convertEmuToHmm( nPosY ) * 15.87 ) );
+                        xAnnotation->setAuthor( pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).getAuthor(AuthorList) );
+                        xAnnotation->setDateTime( pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).getDateTime() );
+                        uno::Reference< text::XText > xText( xAnnotation->getTextRange() );
+                        xText->setString( pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).get_text());
+                    }
+
+                }
         }
     }
     catch( uno::Exception& )
@@ -320,6 +365,7 @@ void PresentationFragmentHandler::finalizeImport()
         try
         {
             int nPagesImported = 0;
+            readCommentAuthors = 0; // as commentAuthors.xml has not been read still
             while (aIter!=aEnd)
             {
                 if ( rxStatusIndicator.is() )
diff --git a/oox/source/ppt/slidefragmenthandler.cxx b/oox/source/ppt/slidefragmenthandler.cxx
index 12b0ebb..5d69d34 100644
--- a/oox/source/ppt/slidefragmenthandler.cxx
+++ b/oox/source/ppt/slidefragmenthandler.cxx
@@ -39,6 +39,7 @@
 #include "oox/ppt/pptimport.hxx"
 
 
+using rtl::OUString;
 using namespace ::com::sun::star;
 using namespace ::oox::core;
 using namespace ::oox::drawingml;
@@ -188,11 +189,42 @@ SlideFragmentHandler::~SlideFragmentHandler() throw()
     case PPT_TOKEN( custDataLst ):      // CT_CustomerDataList
     case PPT_TOKEN( tagLst ):           // CT_TagList
         return this;
+
+    //for Comments
+    case PPT_TOKEN( cmLst ):
+    break;
+    case PPT_TOKEN( cm ):
+
+        if(!mpSlidePersistPtr->getCommentsList()->cmLst.empty())
+        {    mpSlidePersistPtr->getCommentsList()->cmLst.back().setText( getCharVector().back() ); // set comment text for earlier comment
+        }
+        mpSlidePersistPtr->getCommentsList()->cmLst.push_back(comment()); // insert a new comment in vector commentsList
+        mpSlidePersistPtr->getCommentsList()->cmLst.back().setAuthorId(rAttribs.getString(XML_authorId, OUString())); //set AuthorId
+        mpSlidePersistPtr->getCommentsList()->cmLst.back().setdt(rAttribs.getString(XML_dt, OUString())); //set dt
+        mpSlidePersistPtr->getCommentsList()->cmLst.back().setidx(rAttribs.getString(XML_idx, OUString()));  //set idx
+        break;
+
+    case PPT_TOKEN( pos ):
+        mpSlidePersistPtr->getCommentsList()->cmLst.back().setPoint(rAttribs.getString(XML_x, OUString()),rAttribs.getString(XML_y, OUString())); //set x , set y
+        break;
+   //case PPT_TOKEN( text ):
+
+    case PPT_TOKEN( cmAuthor ):
+        commentAuthor _author;
+        _author.clrIdx = rAttribs.getString(XML_clrIdx, OUString()); //set clrIdx
+        _author.id = rAttribs.getString(XML_id, OUString()); // set id
+        _author.initials = rAttribs.getString(XML_initials, OUString()); // set initials
+        _author.lastIdx = rAttribs.getString(XML_lastIdx, OUString()); // set lastIdx
+        _author.name = rAttribs.getString(XML_name, OUString()); //set name
+        mpSlidePersistPtr->getCommentAuthors()->addAuthor(_author); // insert a new comment Author in cmAuthorList
     }
 
     return this;
 }
-
+void SlideFragmentHandler::onCharacters( const OUString& rChars)
+{
+    charVector.push_back(rChars);
+}
 void SlideFragmentHandler::finalizeImport()
 {
     try


More information about the Libreoffice-commits mailing list