[Libreoffice-commits] .: 5 commits - oox/inc oox/source

Muthu Subramanian sumuthu at kemper.freedesktop.org
Sat Oct 16 09:20:45 PDT 2010


 oox/inc/oox/xls/commentsbuffer.hxx               |   14 +++
 oox/source/drawingml/chart/chartconverter.cxx    |   76 ++++++++++++++++
 oox/source/drawingml/chart/datasourcecontext.cxx |   12 ++
 oox/source/drawingml/chart/objectformatter.cxx   |    2 
 oox/source/token/properties.txt                  |    2 
 oox/source/token/tokens.txt                      |   11 ++
 oox/source/vml/vmlinputstream.cxx                |    4 
 oox/source/xls/commentsbuffer.cxx                |  106 ++++++++++++++++++++++-
 oox/source/xls/commentsfragment.cxx              |   23 ++++
 9 files changed, 245 insertions(+), 5 deletions(-)

New commits:
commit a3492ace1800fa0a77ec40d71d3f25bf0e1bf326
Author: Muthu Subramanian K <sumuthu at novell.com>
Date:   Sat Oct 16 13:05:04 2010 +0530

    Adding missing header for Rectangle.

diff --git a/oox/inc/oox/xls/commentsbuffer.hxx b/oox/inc/oox/xls/commentsbuffer.hxx
index d29f5f8..ab5a2af 100644
--- a/oox/inc/oox/xls/commentsbuffer.hxx
+++ b/oox/inc/oox/xls/commentsbuffer.hxx
@@ -30,6 +30,7 @@
 
 #include "oox/xls/richstring.hxx"
 #include "oox/xls/worksheethelper.hxx"
+#include <com/sun/star/awt/Rectangle.hpp>
 
 namespace oox {
 namespace xls {
commit 98be3b9b003d8c56f76d90597ed61762c33e65fe
Author: Muthu Subramanian K <sumuthu at novell.com>
Date:   Fri Oct 15 15:42:10 2010 +0530

    PPTX chart import feature.
    
    This is similar to xlsx chart importer.

diff --git a/oox/source/drawingml/chart/chartconverter.cxx b/oox/source/drawingml/chart/chartconverter.cxx
index f238645..c84a4f9 100644
--- a/oox/source/drawingml/chart/chartconverter.cxx
+++ b/oox/source/drawingml/chart/chartconverter.cxx
@@ -41,6 +41,9 @@ using ::com::sun::star::chart2::XChartDocument;
 using ::com::sun::star::chart2::data::XDataProvider;
 using ::com::sun::star::chart2::data::XDataSequence;
 using ::oox::core::XmlFilterBase;
+using ::oox::drawingml::chart::DataSequenceModel;
+using ::com::sun::star::uno::Any;
+using ::rtl::OUStringBuffer;
 
 namespace oox {
 namespace drawingml {
@@ -48,6 +51,50 @@ namespace chart {
 
 // ============================================================================
 
+static const sal_Unicode API_TOKEN_ARRAY_OPEN      = '{';
+static const sal_Unicode API_TOKEN_ARRAY_CLOSE     = '}';
+static const sal_Unicode API_TOKEN_ARRAY_ROWSEP    = '|';
+static const sal_Unicode API_TOKEN_ARRAY_COLSEP    = ';';
+
+// Code similar to oox/source/xls/FormulaParser.cxx
+static OUString lclGenerateApiString( const OUString& rString )
+{
+    OUString aRetString = rString;
+    sal_Int32 nQuotePos = aRetString.getLength();
+    while( (nQuotePos = aRetString.lastIndexOf( '"', nQuotePos )) >= 0 )
+        aRetString = aRetString.replaceAt( nQuotePos, 1, CREATE_OUSTRING( "\"\"" ) );
+    return OUStringBuffer().append( sal_Unicode( '"' ) ).append( aRetString ).append( sal_Unicode( '"' ) ).makeStringAndClear();
+}
+
+static OUString lclGenerateApiArray( const Matrix< Any >& rMatrix )
+{
+    OSL_ENSURE( !rMatrix.empty(), "ChartConverter::lclGenerateApiArray - missing matrix values" );
+    OUStringBuffer aBuffer;
+    aBuffer.append( API_TOKEN_ARRAY_OPEN );
+    for( size_t nRow = 0, nHeight = rMatrix.height(); nRow < nHeight; ++nRow )
+    {
+        if( nRow > 0 )
+            aBuffer.append( API_TOKEN_ARRAY_ROWSEP );
+        for( Matrix< Any >::const_iterator aBeg = rMatrix.row_begin( nRow ), aIt = aBeg, aEnd = rMatrix.row_end( nRow ); aIt != aEnd; ++aIt )
+        {
+            double fValue = 0.0;
+            OUString aString;
+            if( aIt != aBeg )
+                aBuffer.append( API_TOKEN_ARRAY_COLSEP );
+            if( *aIt >>= fValue )
+                aBuffer.append( fValue );
+            else if( *aIt >>= aString )
+                aBuffer.append( lclGenerateApiString( aString ) );
+            else
+                aBuffer.appendAscii( "\"\"" );
+        }
+    }
+    aBuffer.append( API_TOKEN_ARRAY_CLOSE );
+    return aBuffer.makeStringAndClear();
+}
+
+// ============================================================================
+
 ChartConverter::ChartConverter()
 {
 }
@@ -81,8 +128,35 @@ void ChartConverter::createDataProvider( const Reference< XChartDocument >& rxCh
     }
 }
 
-Reference< XDataSequence > ChartConverter::createDataSequence( const Reference< XDataProvider >&, const DataSequenceModel& )
+Reference< XDataSequence > ChartConverter::createDataSequence( const Reference< XDataProvider >& rxDataProvider, const DataSequenceModel& rDataSeq )
 {
+    Reference< XDataSequence > xDataSeq;
+    if( rxDataProvider.is() )
+    {
+        OUString aRangeRep;
+        if( !rDataSeq.maData.empty() )
+        {
+            // create a single-row array from constant source data
+            Matrix< Any > aMatrix( rDataSeq.maData.size(), 1 );
+            Matrix< Any >::iterator aMIt = aMatrix.begin();
+            // TODO: how to handle missing values in the map?
+            for( DataSequenceModel::AnyMap::const_iterator aDIt = rDataSeq.maData.begin(), aDEnd = rDataSeq.maData.end(); aDIt != aDEnd; ++aDIt, ++aMIt )
+                *aMIt = aDIt->second;
+            aRangeRep = lclGenerateApiArray( aMatrix );
+        }
+
+        if( aRangeRep.getLength() > 0 ) try
+        {
+            // create the data sequence
+            xDataSeq = rxDataProvider->createDataSequenceByRangeRepresentation( aRangeRep );
+            return xDataSeq;
+        }
+        catch( Exception& )
+        {
+            OSL_ENSURE( false, "ExcelChartConverter::createDataSequence - cannot create data sequence" );
+        }
+    }
+
     return 0;
 }
 
diff --git a/oox/source/drawingml/chart/datasourcecontext.cxx b/oox/source/drawingml/chart/datasourcecontext.cxx
index 82898be..f69383c 100644
--- a/oox/source/drawingml/chart/datasourcecontext.cxx
+++ b/oox/source/drawingml/chart/datasourcecontext.cxx
@@ -100,7 +100,17 @@ void DoubleSequenceContext::onEndElement( const OUString& rChars )
         break;
         case C_TOKEN( v ):
             if( mnPtIndex >= 0 )
-                mrModel.maData[ mnPtIndex ] <<= rChars.toDouble();
+            {
+                /* Import categories as String even though it could
+                 * be values.
+                 * TODO: NumberFormat conversion, remove the check then.
+                 */
+                if( isPreviousElement( C_TOKEN( cat ), 4 ) ||
+                    isPreviousElement( C_TOKEN( xVal ), 4 ) )
+                    mrModel.maData[ mnPtIndex ] <<= rChars;
+                else
+                    mrModel.maData[ mnPtIndex ] <<= rChars.toDouble();
+            }
         break;
     }
 }
diff --git a/oox/source/drawingml/chart/objectformatter.cxx b/oox/source/drawingml/chart/objectformatter.cxx
index 0fc9890..bbacd36 100644
--- a/oox/source/drawingml/chart/objectformatter.cxx
+++ b/oox/source/drawingml/chart/objectformatter.cxx
@@ -1050,7 +1050,7 @@ ObjectFormatterData::ObjectFormatterData( const XmlFilterBase& rFilter, const Re
 
     try
     {
-        Reference< XNumberFormatsSupplier > xNumFmtsSupp( mrFilter.getModel(), UNO_QUERY_THROW );
+        Reference< XNumberFormatsSupplier > xNumFmtsSupp( rxChartDoc, UNO_QUERY_THROW );
         mxNumFmts = xNumFmtsSupp->getNumberFormats();
         mxNumTypes.set( mxNumFmts, UNO_QUERY );
     }
commit 999d25b55db316636fb04f95fe6ed6a256c89385
Author: Muthu Subramanian K <sumuthu at novell.com>
Date:   Fri Oct 15 15:25:52 2010 +0530

    commentPr import feature.

diff --git a/oox/inc/oox/xls/commentsbuffer.hxx b/oox/inc/oox/xls/commentsbuffer.hxx
index e46794d..d29f5f8 100644
--- a/oox/inc/oox/xls/commentsbuffer.hxx
+++ b/oox/inc/oox/xls/commentsbuffer.hxx
@@ -42,6 +42,15 @@ struct CommentModel
                         maRange;            /// Position of the comment in the worksheet.
     RichStringRef       mxText;             /// Formatted text of the comment.
     sal_Int32           mnAuthorId;         /// Identifier of the comment's author.
+    sal_Bool            mbAutoFill;         /// Auto Selection of comment object's fill style
+    sal_Bool            mbAutoScale;        /// Auto Scale comment text
+    sal_Bool            mbColHidden;        /// Comment cell's Column is Hidden
+    sal_Bool            mbLocked;           /// Comment changes Locked
+    sal_Bool            mbRowHidden;        /// Comment cell's Row is Hidden
+    sal_Int32           mnTHA;              /// Horizontal Alignment
+    sal_Int32           mnTVA;              /// Vertical Alignment
+    ::com::sun::star::awt::Rectangle
+                        maAnchor;           /// Anchor parameters
 
     explicit            CommentModel();
 };
@@ -55,6 +64,10 @@ public:
 
     /** Imports a cell comment from the passed attributes of the comment element. */
     void                importComment( const AttributeList& rAttribs );
+    /** Imports a cell comment Properties from the passed attributes of the comment element. */
+    void                importCommentPr( const AttributeList& rAttribs );
+    /** Imports the anchor points in CommentPr */
+    void                importAnchor( bool bFrom, sal_Int32 nWhich, const ::rtl::OUString &rChars );
     /** Imports a cell comment from the passed stream of a COMMENT record. */
     void                importComment( RecordInputStream& rStrm );
 
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index 2a7960a..98f712f 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -267,6 +267,7 @@ MirroredY
 MissingValueTreatment
 Model
 ModifyPasswordHash
+MoveProtect
 MultiLine
 MultiPageValue
 MultiSelection
@@ -384,6 +385,7 @@ ShowPositiveError
 ShowZeroValues
 ShrinkToFit
 Size
+SizeProtect
 SortInfo
 Sound
 SoundOn
diff --git a/oox/source/xls/commentsbuffer.cxx b/oox/source/xls/commentsbuffer.cxx
index b1dceea..276c91a 100644
--- a/oox/source/xls/commentsbuffer.cxx
+++ b/oox/source/xls/commentsbuffer.cxx
@@ -36,7 +36,9 @@
 #include "oox/vml/vmlshape.hxx"
 #include "oox/xls/addressconverter.hxx"
 #include "oox/xls/drawingfragment.hxx"
-
+#include "properties.hxx"
+#include "svx/sdtaitm.hxx"
+#include "oox/xls/unitconverter.hxx"
 
 #include <com/sun/star/text/XText.hpp>
 #include <com/sun/star/text/XTextRange.hpp>
@@ -56,7 +58,41 @@ using ::com::sun::star::sheet::XSheetAnnotationsSupplier;
 
 using ::com::sun::star::text::XText;
 using ::com::sun::star::text::XTextRange;
+using ::com::sun::star::awt::Size;
+using ::com::sun::star::awt::Point;
+
+
+static sal_Int32 lcl_ToHorizAlign( sal_Int32 nAlign )
+{
+    switch( nAlign )
+    {
+        case XML_left:
+            return SDRTEXTHORZADJUST_LEFT;
+        case XML_right:
+            return SDRTEXTHORZADJUST_RIGHT;
+        case XML_center:
+            return SDRTEXTHORZADJUST_CENTER;
+        default:
+            return SDRTEXTHORZADJUST_BLOCK;
+    }
+    return SDRTEXTHORZADJUST_LEFT;
+}
 
+static sal_Int32 lcl_ToVertAlign( sal_Int32 nAlign )
+{
+    switch( nAlign )
+    {
+        case XML_top:
+            return SDRTEXTVERTADJUST_TOP;
+        case XML_center:
+            return SDRTEXTVERTADJUST_CENTER;
+        case XML_bottom:
+            return SDRTEXTVERTADJUST_BOTTOM;
+        default:
+            return SDRTEXTVERTADJUST_BLOCK;
+    }
+    return SDRTEXTVERTADJUST_TOP;
+}
 
 namespace oox {
 namespace xls {
@@ -82,6 +118,61 @@ void Comment::importComment( const AttributeList& rAttribs )
     getAddressConverter().convertToCellRangeUnchecked( maModel.maRange, rAttribs.getString( XML_ref, OUString() ), getSheetIndex() );
 }
 
+void Comment::importCommentPr( const AttributeList& rAttribs )
+{
+    maModel.mbAutoFill  = rAttribs.getBool( XML_autoFill, true );
+    maModel.mbAutoScale = rAttribs.getBool( XML_autoScale, false );
+    maModel.mbColHidden = rAttribs.getBool( XML_colHidden, false );
+    maModel.mbLocked    = rAttribs.getBool( XML_locked, false );
+    maModel.mbRowHidden = rAttribs.getBool( XML_rowHidden, false );
+    maModel.mnTHA       = rAttribs.getToken( XML_textHAlign, XML_left );
+    maModel.mnTVA       = rAttribs.getToken( XML_textVAlign, XML_top );
+}
+
+void Comment::importAnchor( bool bFrom, sal_Int32 nWhich, const OUString &rChars )
+{
+    sal_Int32 nRow, nCol;
+    Point aPoint;
+    UnitConverter& rUnitConv = getUnitConverter();
+    if( bFrom )
+    {
+        nCol = maModel.maAnchor.X;
+        nRow = maModel.maAnchor.Y;
+    }
+    else
+    {
+        nCol = maModel.maAnchor.Width + maModel.maAnchor.X ;
+        nRow = maModel.maAnchor.Height + maModel.maAnchor.Y;
+    }
+    switch( nWhich )
+    {
+        case XDR_TOKEN( col ):
+            aPoint = getCellPosition( rChars.toInt32(), 1 );
+            nCol = aPoint.X;
+            break;
+        case XDR_TOKEN( colOff ):
+            nCol += rUnitConv.scaleToMm100( static_cast< double >( rChars.toInt32() ), UNIT_SCREENX );
+            break;
+        case XDR_TOKEN( row ):
+            aPoint = getCellPosition( 1, rChars.toInt32() );
+            nRow = aPoint.Y;
+            break;
+        case XDR_TOKEN( rowOff ):
+            nRow += rUnitConv.scaleToMm100( static_cast< double >( rChars.toInt32() ), UNIT_SCREENY );
+            break;
+    }
+    if( bFrom )
+    {
+        maModel.maAnchor.X = nCol;
+        maModel.maAnchor.Y = nRow;
+    }
+    else
+    {
+        maModel.maAnchor.Width  = nCol - maModel.maAnchor.X;
+        maModel.maAnchor.Height = nRow - maModel.maAnchor.Y;
+    }
+}
+
 void Comment::importComment( RecordInputStream& rStrm )
 {
     BinRange aBinRange;
@@ -123,6 +214,19 @@ void Comment::finalizeImport()
             xTextRange->setString( OUString::createFromAscii("") ); // Clear contents
             maModel.mxText->convert( xText, -1 );
 
+            // Add shape formatting properties (autoFill, colHidden and rowHidden are dropped)
+            PropertySet aCommentPr( xAnnoShape );
+            aCommentPr.setProperty( PROP_TextFitToSize, maModel.mbAutoScale );
+            aCommentPr.setProperty( PROP_MoveProtect, maModel.mbLocked );
+            aCommentPr.setProperty( PROP_TextHorizontalAdjust, lcl_ToHorizAlign( maModel.mnTHA ) );
+            aCommentPr.setProperty( PROP_TextVerticalAdjust, lcl_ToVertAlign( maModel.mnTVA ) );
+            if( maModel.maAnchor.Width > 0 && maModel.maAnchor.Height > 0 )
+            {
+                xAnnoShape->setPosition( Point( maModel.maAnchor.X, maModel.maAnchor.Y ) );
+                xAnnoShape->setSize( Size( maModel.maAnchor.Width, maModel.maAnchor.Height ) );
+            }
+
+
             // convert shape formatting
             if( const ::oox::vml::ShapeBase* pNoteShape = getVmlDrawing().getNoteShape( aNotePos ) )
             {
diff --git a/oox/source/xls/commentsfragment.cxx b/oox/source/xls/commentsfragment.cxx
index bcb5de9..437db5f 100644
--- a/oox/source/xls/commentsfragment.cxx
+++ b/oox/source/xls/commentsfragment.cxx
@@ -62,9 +62,21 @@ ContextHandlerRef OoxCommentsFragment::onCreateContext( sal_Int32 nElement, cons
         case XLS_TOKEN( commentList ):
             if( nElement == XLS_TOKEN( comment ) ) { importComment( rAttribs ); return this; }
         break;
+        case XLS_TOKEN( commentPr ):
+            if( nElement == XLS_TOKEN( anchor ) )
+                return this;
+            break;
+        case XLS_TOKEN( anchor ):
+            if( nElement == XDR_TOKEN( from ) || nElement == XDR_TOKEN( to ) )
+                return this;
+            break;
+        case XDR_TOKEN( from ):
+        case XDR_TOKEN( to ):
+            return this;
         case XLS_TOKEN( comment ):
             if( (nElement == XLS_TOKEN( text )) && mxComment.get() )
                 return new OoxRichStringContext( *this, mxComment->createText() );
+            if( nElement == XLS_TOKEN( commentPr ) ) { mxComment->importCommentPr( rAttribs ); return this; }
         break;
     }
     return 0;
@@ -72,11 +84,20 @@ ContextHandlerRef OoxCommentsFragment::onCreateContext( sal_Int32 nElement, cons
 
 void OoxCommentsFragment::onEndElement( const OUString& rChars )
 {
+    bool bFrom = false;
+    if( getPreviousElement() == XDR_TOKEN( from ) )
+        bFrom = true;
     switch( getCurrentElement() )
     {
         case XLS_TOKEN( author ):
             getComments().appendAuthor( rChars );
-        break;
+            break;
+        case XDR_TOKEN( col ):
+        case XDR_TOKEN( colOff ):
+        case XDR_TOKEN( row ):
+        case XDR_TOKEN( rowOff ):
+            mxComment->importAnchor( bFrom, getCurrentElement(), rChars );
+            break;
         case XLS_TOKEN( comment ):
             mxComment.reset();
         break;
commit ec2ae20b0ccd33b7c52aabe7b6d5eec165cb13b0
Author: Muthu Subramanian K <sumuthu at novell.com>
Date:   Fri Oct 15 15:11:22 2010 +0530

    Adding commentPr tokens.

diff --git a/oox/source/token/tokens.txt b/oox/source/token/tokens.txt
index 582805b..5497d15 100644
--- a/oox/source/token/tokens.txt
+++ b/oox/source/token/tokens.txt
@@ -653,11 +653,13 @@ autoCaptions
 autoCompressPictures
 autoEnd
 autoExp
+autoFill
 autoFilter
 autoFilterDateGrouping
 autoFormatId
 autoFormatOverride
 autoHyphenation
+autoLine
 autoLoad
 autoNoTable
 autoPage
@@ -666,6 +668,7 @@ autoRecover
 autoRedefine
 autoRepublish
 autoRev
+autoScale
 autoShow
 autoSortScope
 autoSpaceDE
@@ -1210,6 +1213,7 @@ colFields
 colFirst
 colGrandTotals
 colHeaderCaption
+colHidden
 colHierarchiesUsage
 colHierarchyUsage
 colId
@@ -1248,6 +1252,7 @@ command
 commandType
 comment
 commentList
+commentPr
 commentRangeEnd
 commentRangeStart
 commentReference
@@ -1650,6 +1655,7 @@ defaultGridColor
 defaultMemberUniqueName
 defaultPivotStyle
 defaultRowHeight
+defaultSize
 defaultSubtotal
 defaultTabStop
 defaultTableStyle
@@ -3348,6 +3354,7 @@ moveTo
 moveToRangeEnd
 moveToRangeStart
 moveWith
+moveWithCells
 movie
 movingAvg
 mp
@@ -4239,6 +4246,7 @@ rowDrillCount
 rowFields
 rowGrandTotals
 rowHeaderCaption
+rowHidden
 rowHierarchiesUsage
 rowHierarchyUsage
 rowItems
@@ -4599,6 +4607,7 @@ singleclick
 size
 sizeAuto
 sizeRepresents
+sizeWithCells
 skew
 skewamt
 skewangle
@@ -5059,6 +5068,7 @@ textField
 textFields
 textFile
 textFit
+textHAlign
 textInflate
 textInflateBottom
 textInflateTop
@@ -5075,6 +5085,7 @@ textSlantUp
 textStop
 textTriangle
 textTriangleInverted
+textVAlign
 textWave1
 textWave2
 textWave4
commit 11de020c341a184dd4db1ed038cd349af5f7be55
Author: Muthu Subramanian K <sumuthu at novell.com>
Date:   Fri Oct 15 14:56:33 2010 +0530

    '\n' at the end of a vml file causes hang+memory fillup.

diff --git a/oox/source/vml/vmlinputstream.cxx b/oox/source/vml/vmlinputstream.cxx
index b52fda0..7541e48 100644
--- a/oox/source/vml/vmlinputstream.cxx
+++ b/oox/source/vml/vmlinputstream.cxx
@@ -255,6 +255,10 @@ StreamDataContainer::StreamDataContainer( const Reference< XInputStream >& rxInS
                     }
                 }
             }
+            else
+            {
+                pcCurr = pcEnd;
+            }
         }
 
         // set the final data sequence


More information about the Libreoffice-commits mailing list