[PATCH] Changes to enable display of comments annotations in pptx fi...
vinaya mandke (via Code Review)
gerrit at gerrit.libreoffice.org
Fri Feb 8 07:08:40 PST 2013
Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/2048
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/48/2048/1
Changes to enable display of comments annotations in pptx files
Change-Id: I965798cd3a539ab8deffcdf4a8e2c52c9e8e8fc1
---
A oox/inc/oox/ppt/annotation_buffer.h
A oox/inc/oox/ppt/comments.hxx
M oox/inc/oox/ppt/slidepersist.hxx
M oox/source/core/fragmenthandler2.cxx
M oox/source/ppt/presentationfragmenthandler.cxx
M oox/source/ppt/slidefragmenthandler.cxx
6 files changed, 329 insertions(+), 2 deletions(-)
diff --git a/oox/inc/oox/ppt/annotation_buffer.h b/oox/inc/oox/ppt/annotation_buffer.h
new file mode 100644
index 0000000..dcfd0e2
--- /dev/null
+++ b/oox/inc/oox/ppt/annotation_buffer.h
@@ -0,0 +1 @@
+extern std::string commentbuffer_chars;
diff --git a/oox/inc/oox/ppt/comments.hxx b/oox/inc/oox/ppt/comments.hxx
new file mode 100644
index 0000000..922a407
--- /dev/null
+++ b/oox/inc/oox/ppt/comments.hxx
@@ -0,0 +1,214 @@
+#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 "strtk.hpp" //tokenize the text of comments
+
+#include <com/sun/star/util/DateTime.hpp>
+
+
+class commentAuthor
+{
+ private:
+ ::rtl::OUString clrIdx;
+ ::rtl::OUString id;
+ ::rtl::OUString initials;
+ ::rtl::OUString lastIdx;
+ ::rtl::OUString name;
+
+ public:
+ void setclrIdx(::rtl::OUString _clrIdx)
+ {
+ clrIdx = _clrIdx;
+ }
+ void setid(::rtl::OUString _id)
+ {
+ id=_id;
+ }
+ void setinitials(::rtl::OUString _initials)
+ {
+ initials=_initials;
+ }
+ void setlastIdx(::rtl::OUString _lastIdx)
+ {
+ lastIdx=_lastIdx;
+ }
+ void setname(::rtl::OUString _name)
+ {
+ name=_name;
+ }
+ ::rtl::OUString getclrIdx()
+ {
+ return clrIdx;
+ }
+ ::rtl::OUString getid()
+ {
+ return id;
+ }
+ ::rtl::OUString getinitials()
+ {
+ return initials;
+ }
+ ::rtl::OUString getlastIdx()
+ {
+ return lastIdx;
+ }
+ ::rtl::OUString getname()
+ {
+ return name;
+ }
+};
+
+class commentAuthorList
+{
+ public:
+ std::vector<commentAuthor> cmAuthorLst;
+
+ void setValues( commentAuthorList list)
+ {
+ std::vector<commentAuthor>::iterator it;
+ for(it=list.cmAuthorLst.begin();it!=list.cmAuthorLst.end();it++)
+ {
+ cmAuthorLst.push_back(commentAuthor());
+ cmAuthorLst.back().setclrIdx(it->getclrIdx());
+ cmAuthorLst.back().setid(it->getid());
+ cmAuthorLst.back().setinitials(it->getinitials());
+ cmAuthorLst.back().setlastIdx(it->getlastIdx());
+ cmAuthorLst.back().setname(it->getname());
+ }
+ }
+};
+
+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 set_X(::rtl::OUString _x)
+ {
+ x=_x;
+ }
+ void set_Y(::rtl::OUString _y)
+ {
+ y=_y;
+ }
+ void set_text(std::string _text)
+ {
+ text = rtl::OUString::createFromAscii ( _text.c_str() );
+ }
+
+ 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 get_int_X()
+ {
+ std::string temp = rtl::OUStringToOString(get_X(), RTL_TEXTENCODING_UTF8).getStr();
+ return atoi(temp.c_str());
+ }
+ int get_int_Y()
+ {
+ std::string temp = rtl::OUStringToOString(get_Y(), RTL_TEXTENCODING_UTF8).getStr();
+ return atoi(temp.c_str());
+ }
+ commentAuthor 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->getid(), RTL_TEXTENCODING_UTF8).getStr();
+ int list_aId = atoi(temp.c_str());
+ if(list_aId == aId)
+ return *(it);
+ }
+ throw ELEMENT_NOT_FOUND;
+ }
+};
+
+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
diff --git a/oox/inc/oox/ppt/slidepersist.hxx b/oox/inc/oox/ppt/slidepersist.hxx
index 3c8bf33..0af8327 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,13 @@
::oox::drawingml::ShapePtr getShape( const ::rtl::OUString & id ) { return maShapeMap[ id ]; }
::oox::drawingml::ShapeIdMap& getShapeMap() { return maShapeMap; }
+ //comments
+
+ commentList commentsList;
+ commentAuthorList commentAuthors;
+ sal_Bool mbComments;
+ sal_Bool hasComments() const { return mbComments; }
+
private:
rtl::OUString maPath;
rtl::OUString maLayoutPath;
diff --git a/oox/source/core/fragmenthandler2.cxx b/oox/source/core/fragmenthandler2.cxx
index bfc6834..88feb0d 100644
--- a/oox/source/core/fragmenthandler2.cxx
+++ b/oox/source/core/fragmenthandler2.cxx
@@ -19,6 +19,8 @@
#include "oox/core/fragmenthandler2.hxx"
#include "oox/core/xmlfilterbase.hxx"
+#include "oox/ppt/annotation_buffer.h"
+int is_annotation_text;
namespace oox {
namespace core {
@@ -115,12 +117,22 @@
void SAL_CALL FragmentHandler2::startFastElement(
sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
{
+ switch( nElement )
+ {
+ case PPT_TOKEN( text ):
+ is_annotation_text = 1; //set to 1 to handle chars
+ break;
+ }
implStartElement( nElement, rxAttribs );
}
void SAL_CALL FragmentHandler2::characters( const OUString& rChars ) throw( SAXException, RuntimeException )
{
implCharacters( rChars );
+ if ( is_annotation_text == 1)
+ {
+ commentbuffer_chars += rtl::OUStringToOString( rChars , RTL_TEXTENCODING_UTF8).getStr();
+ }
}
void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement ) throw( SAXException, RuntimeException )
@@ -131,8 +143,10 @@
case MCE_TOKEN( AlternateContent ):
aMceState.pop_back();
break;
+ case PPT_TOKEN( text ):
+ is_annotation_text =0; // set to 0 as comment chars are handled
+ break;
}
-
implEndElement( nElement );
}
diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx
index 6d077e7..f0510c1 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -31,6 +31,9 @@
#include <com/sun/star/presentation/XPresentationPage.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <com/sun/star/office/XAnnotation.hpp>
+#include <com/sun/star/office/XAnnotationAccess.hpp> //for comments
+#include <com/sun/star/awt/Point.hpp>
#include "oox/drawingml/theme.hxx"
#include "oox/drawingml/drawingmltypes.hxx"
#include "oox/drawingml/themefragmenthandler.hxx"
@@ -41,6 +44,15 @@
#include "oox/ppt/layoutfragmenthandler.hxx"
#include "oox/ppt/pptimport.hxx"
+
+#include "oox/ppt/annotation_buffer.h"
+#include "oox/ppt/comments.hxx"
+
+commentAuthorList AuthorList;
+std::string commentbuffer_chars; // extern from annotation_buffer to store the annotation text
+int readCommentAuthors; // read commentAuthors.xml only once
+
+using rtl::OUString;
using namespace ::com::sun::star;
using namespace ::oox::core;
using namespace ::oox::drawingml;
@@ -149,6 +161,7 @@
Reference< drawing::XDrawPagesSupplier > xDPS( xModel, uno::UNO_QUERY_THROW );
Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY_THROW );
+ readCommentAuthors = 0; // as commentAuthors.xml has not been read still
for( nSlide = 0; nSlide < maSlidesVector.size(); nSlide++ )
{
if ( rxStatusIndicator.is() )
@@ -162,7 +175,7 @@
OUString aSlideFragmentPath = getFragmentPathFromRelId( maSlidesVector[ nSlide ] );
if( !aSlideFragmentPath.isEmpty() )
{
- OUString aMasterFragmentPath;
+ OUString aMasterFragmentPath;
SlidePersistPtr pMasterPersistPtr;
SlidePersistPtr pSlidePersistPtr( new SlidePersist( rFilter, sal_False, sal_False, xSlide,
ShapePtr( new PPTShape( Slide, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
@@ -171,6 +184,7 @@
// 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
@@ -279,6 +293,49 @@
}
}
}
+
+ 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 ) );
+
+ pCommentAuthorsPersistPtr->commentAuthors.cmAuthorLst.clear();
+ importSlide( xCommentAuthorsFragmentHandler, pCommentAuthorsPersistPtr );
+ AuthorList.cmAuthorLst.clear();
+ AuthorList.setValues(pCommentAuthorsPersistPtr->commentAuthors);
+ }
+ 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->commentsList.cmLst.clear();
+ importSlide( xCommentsFragmentHandler, pCommentsPersistPtr );
+ pCommentsPersistPtr->commentsList.cmLst.back().set_text( commentbuffer_chars ); //set comment chars for last comment on slide
+
+ pCommentsPersistPtr->commentAuthors.setValues(AuthorList);
+ //insert all comments from commentsList
+ for(int i=0; i<pCommentsPersistPtr->commentsList.getSize(); i++)
+ {
+ uno::Reference< office::XAnnotationAccess > xAnnotationAccess( xSlide, UNO_QUERY_THROW );
+ uno::Reference< office::XAnnotation > xAnnotation( xAnnotationAccess->createAndInsertAnnotation() );
+ int nPosX = pCommentsPersistPtr->commentsList.getCommentAtIndex(i).get_int_X();
+ int nPosY = pCommentsPersistPtr->commentsList.getCommentAtIndex(i).get_int_Y();
+ xAnnotation->setPosition( geometry::RealPoint2D( ::oox::drawingml::convertEmuToHmm( nPosX ) * 15.87 , ::oox::drawingml::convertEmuToHmm( nPosY ) * 15.87 ) );
+ xAnnotation->setAuthor( pCommentsPersistPtr->commentsList.getCommentAtIndex(i).getAuthor(pCommentsPersistPtr->commentAuthors).getname() );
+ xAnnotation->setDateTime( pCommentsPersistPtr->commentsList.getCommentAtIndex(i).getDateTime() );
+ uno::Reference< text::XText > xText( xAnnotation->getTextRange() );
+ xText->setString( pCommentsPersistPtr->commentsList.getCommentAtIndex(i).get_text());
+ }
+
+ }
+
}
}
ResolveTextFields( rFilter );
diff --git a/oox/source/ppt/slidefragmenthandler.cxx b/oox/source/ppt/slidefragmenthandler.cxx
index 12b0ebb..2478c98 100644
--- a/oox/source/ppt/slidefragmenthandler.cxx
+++ b/oox/source/ppt/slidefragmenthandler.cxx
@@ -38,7 +38,10 @@
#include "oox/drawingml/clrschemecontext.hxx"
#include "oox/ppt/pptimport.hxx"
+#include "oox/ppt/annotation_buffer.h"
+
+using rtl::OUString;
using namespace ::com::sun::star;
using namespace ::oox::core;
using namespace ::oox::drawingml;
@@ -188,6 +191,35 @@
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->commentsList.cmLst.empty())
+ { mpSlidePersistPtr->commentsList.cmLst.back().set_text( commentbuffer_chars ); // set comment text for earlier comment
+ }
+ mpSlidePersistPtr->commentsList.cmLst.push_back(comment()); // insert a new comment in vector commentsList
+ mpSlidePersistPtr->commentsList.cmLst.back().setAuthorId(rAttribs.getString(XML_authorId, OUString())); //set AuthorId
+ mpSlidePersistPtr->commentsList.cmLst.back().setdt(rAttribs.getString(XML_dt, OUString())); //set dt
+ mpSlidePersistPtr->commentsList.cmLst.back().setidx(rAttribs.getString(XML_idx, OUString())); //set idx
+ commentbuffer_chars = "";
+ break;
+
+ case PPT_TOKEN( pos ):
+ mpSlidePersistPtr->commentsList.cmLst.back().set_X(rAttribs.getString(XML_x, OUString())); //set x
+ mpSlidePersistPtr->commentsList.cmLst.back().set_Y(rAttribs.getString(XML_y, OUString())); //set y
+ break;
+ //case PPT_TOKEN( text ):
+
+ case PPT_TOKEN( cmAuthor ):
+ mpSlidePersistPtr->commentAuthors.cmAuthorLst.push_back(commentAuthor()); // insert a new comment Author in cmAuthorList
+ mpSlidePersistPtr->commentAuthors.cmAuthorLst.back().setclrIdx(rAttribs.getString(XML_clrIdx, OUString())); //set clrIdx
+ mpSlidePersistPtr->commentAuthors.cmAuthorLst.back().setid(rAttribs.getString(XML_id, OUString())); // set id
+ mpSlidePersistPtr->commentAuthors.cmAuthorLst.back().setinitials(rAttribs.getString(XML_initials, OUString())); // set initials
+ mpSlidePersistPtr->commentAuthors.cmAuthorLst.back().setlastIdx(rAttribs.getString(XML_lastIdx, OUString())); // set lastIdx
+ mpSlidePersistPtr->commentAuthors.cmAuthorLst.back().setname(rAttribs.getString(XML_name, OUString())); //set name
}
return this;
--
To view, visit https://gerrit.libreoffice.org/2048
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I965798cd3a539ab8deffcdf4a8e2c52c9e8e8fc1
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: vinaya mandke <vinaya.mandke at synerzip.com>
More information about the LibreOffice
mailing list