File legacy-fragment-import-filters.diff of Package libreoffice

commit 90eab3e2ae27c1f8e308fdba6e32911e272da188
Author: Muthu Subramanian K <sumuthu@suse.com>
Date:   Fri Oct 7 19:36:59 2011 +0530

    n#699334: Legacy Fragment Import.

diff --git a/filter/inc/filter/msfilter/msdffimp.hxx b/filter/inc/filter/msfilter/msdffimp.hxx
index c1a0294..4887bae 100644
--- filter/inc/filter/msfilter/msdffimp.hxx
+++ filter/inc/filter/msfilter/msdffimp.hxx
@@ -531,9 +531,6 @@ protected :
     virtual sal_uLong Calc_nBLIPPos( sal_uLong nOrgVal, sal_uLong nStreamPos ) const;
     virtual bool GetColorFromPalette(sal_uInt16 nNum, Color& rColor) const;
 
-    bool ReadDffString(SvStream& rSt, String& rTxt) const;
-    bool ReadObjText(SvStream& rSt, SdrObject* pObj) const;
-
     // SJ: New implementation of ReadObjText is used by Fontwork objects, because
     // the old one does not properly import multiple paragraphs
     void ReadObjText( const String& rText, SdrObject* pObj ) const;
@@ -626,6 +623,8 @@ public:
     static sal_Bool     MakeContentStream( SotStorage * pStor, const GDIMetaFile & );
     static sal_Bool     ConvertToOle2( SvStream& rStm, sal_uInt32 nLen, const GDIMetaFile*,
                                 const SotStorageRef & rDest );
+    static bool ReadDffString(SvStream& rSt, String& rTxt, DffRecordHeader aStrHd = DffRecordHeader());
+    static bool ReadObjText(SvStream& rSt, SdrObject* pObj);
 
     void SetModel(SdrModel* pModel, long nApplicationScale);
     SdrModel*  GetModel() const { return pSdrModel; }
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index aabba56..5ce5ccb 100644
--- filter/source/msfilter/msdffimp.cxx
+++ filter/source/msfilter/msdffimp.cxx
@@ -3892,11 +3892,10 @@ Color SvxMSDffManager::MSO_CLR_ToColor( sal_uInt32 nColorCode, sal_uInt16 nConte
     return aColor;
 }
 
-bool SvxMSDffManager::ReadDffString(SvStream& rSt, String& rTxt) const
+bool SvxMSDffManager::ReadDffString(SvStream& rSt, String& rTxt, DffRecordHeader aStrHd)
 {
     bool bRet=sal_False;
-    DffRecordHeader aStrHd;
-    if( !ReadCommonRecordHeader(aStrHd, rSt) )
+    if( aStrHd.nRecType == 0x0 && !ReadCommonRecordHeader(aStrHd, rSt) )
         rSt.Seek( aStrHd.nFilePos );
     else if ( aStrHd.nRecType == DFF_PST_TextBytesAtom || aStrHd.nRecType == DFF_PST_TextCharsAtom )
     {
@@ -3983,7 +3982,7 @@ void SvxMSDffManager::ReadObjText( const String& rText, SdrObject* pObj ) const
     }
 }
 
-bool SvxMSDffManager::ReadObjText(SvStream& rSt, SdrObject* pObj) const
+bool SvxMSDffManager::ReadObjText(SvStream& rSt, SdrObject* pObj)
 {
     bool bRet=sal_False;
     SdrTextObj* pText = PTR_CAST(SdrTextObj, pObj);
@@ -3992,7 +3991,7 @@ bool SvxMSDffManager::ReadObjText(SvStream& rSt, SdrObject* pObj) const
         DffRecordHeader aTextHd;
         if( !ReadCommonRecordHeader(aTextHd, rSt) )
             rSt.Seek( aTextHd.nFilePos );
-        else if ( aTextHd.nRecType==DFF_msofbtClientTextbox )
+        else if ( aTextHd.nRecType==DFF_msofbtClientTextbox || aTextHd.nRecType == 0x1022 )
         {
             bRet=sal_True;
             sal_uLong nRecEnd=aTextHd.GetRecEndFilePos();
@@ -4032,15 +4031,14 @@ bool SvxMSDffManager::ReadObjText(SvStream& rSt, SdrObject* pObj) const
                 {
                     switch (aHd.nRecType)
                     {
-                        //case TextHeaderAtom
+                        default:
+                            break;
+                        //case DFF_PST_TextHeaderAtom:
                         //case TextSpecInfoAtom
                         case DFF_PST_TextBytesAtom:
                         case DFF_PST_TextCharsAtom:
-                        {
-                            aHd.SeekToBegOfRecord(rSt);
-                            ReadDffString(rSt, aText);
-                        }
-                        break;
+                            ReadDffString(rSt, aText, aHd);
+                            break;
                         case DFF_PST_TextRulerAtom               :
                         {
                             sal_uInt16 nLen = (sal_uInt16)aHd.nRecLen;
diff --git a/oox/inc/oox/vml/vmlshape.hxx b/oox/inc/oox/vml/vmlshape.hxx
index 332d679..feb2319 100644
--- oox/inc/oox/vml/vmlshape.hxx
+++ oox/inc/oox/vml/vmlshape.hxx
@@ -179,6 +179,7 @@ struct ShapeModel
     PointVector         maPoints;           /// Points for the polyline shape.
     TextBoxPtr          mxTextBox;          /// Text contents and properties.
     ClientDataPtr       mxClientData;       /// Excel specific client data.
+    ::rtl::OUString     maLegacyDiagramPath;/// Legacy Diagram Fragment Path
 
     explicit            ShapeModel();
                         ~ShapeModel();
diff --git a/oox/source/token/namespaces.hxx.tail b/oox/source/token/namespaces.hxx.tail
index 2261c30..f103892 100644
--- oox/source/token/namespaces.hxx.tail
+++ oox/source/token/namespaces.hxx.tail
@@ -27,6 +27,7 @@ inline sal_Int32 getNamespace( sal_Int32 nToken ) { return nToken & NMSP_MASK; }
 #define XLS_TOKEN( token )          (::oox::NMSP_xls | XML_##token)
 #define XM_TOKEN( token )           (::oox::NMSP_xm | XML_##token)
 #define XML_TOKEN( token )          (::oox::NMSP_xml | XML_##token)
+#define VMLPPT_TOKEN( token )       (::oox::NMSP_vmlPowerpoint | XML_##token )
 
 // ============================================================================
 
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index e987fb0..a2c6222 100644
--- oox/source/token/properties.txt
+++ oox/source/token/properties.txt
@@ -251,6 +251,7 @@ LeftBorder
 LeftMargin
 LeftPageFooterContent
 LeftPageHeaderContent
+LegacyFragment
 LineColor
 LineCount
 LineDash
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx
index 32bcea5..ad52676 100644
--- oox/source/vml/vmlshape.cxx
+++ oox/source/vml/vmlshape.cxx
@@ -68,6 +68,7 @@ using namespace ::com::sun::star::awt;
 using namespace ::com::sun::star::drawing;
 using namespace ::com::sun::star::graphic;
 using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::io;
 
 using ::oox::core::XmlFilterBase;
 using ::rtl::OUString;
@@ -424,6 +425,14 @@ Reference< XShape > SimpleShape::implConvertAndInsert( const Reference< XShapes
 {
     Reference< XShape > xShape = mrDrawing.createAndInsertXShape( maService, rxShapes, rShapeRect );
     convertShapeProperties( xShape );
+
+    // Import Legacy Fragments (if any)
+    if( xShape.is() && !maShapeModel.maLegacyDiagramPath.isEmpty() )
+    {
+        Reference< XInputStream > xInStrm( mrDrawing.getFilter().openInputStream( maShapeModel.maLegacyDiagramPath ), UNO_SET_THROW );
+        if( xInStrm.is() )
+            PropertySet( xShape ).setProperty( PROP_LegacyFragment, xInStrm );
+    }
     return xShape;
 }
 
diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx
index 089856a..30aa1c4 100644
--- oox/source/vml/vmlshapecontext.cxx
+++ oox/source/vml/vmlshapecontext.cxx
@@ -365,18 +365,23 @@ ShapeContext::ShapeContext( ContextHandler2Helper& rParent, ShapeBase& rShape, c
 
 ContextHandlerRef ShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
 {
-    // Custom shape in Writer with a textbox are transformed into a frame
-    if ( nElement == ( NMSP_vml + XML_textbox ) )
-        dynamic_cast<SimpleShape&>( mrShape ).setService(
-            OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame")) );
-
     // Excel specific shape client data
     if( isRootElement() ) switch( nElement )
     {
         case VML_TOKEN( textbox ):
+            // Custom shape in Writer with a textbox are transformed into a frame
+            dynamic_cast<SimpleShape&>( mrShape ).setService(
+                    OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame")));
             return new TextBoxContext( *this, mrShapeModel.createTextBox(), rAttribs );
         case VMLX_TOKEN( ClientData ):
             return new ClientDataContext( *this, mrShapeModel.createClientData(), rAttribs );
+        case VMLPPT_TOKEN( textdata ):
+            // Force RectangleShape, this is ugly :(
+            // and is there because of the lines above which change it to TextFrame
+            dynamic_cast< SimpleShape& >( mrShape ).setService(
+                    OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.RectangleShape")));
+            mrShapeModel.maLegacyDiagramPath = getFragmentPathFromRelId(rAttribs.getString(XML_id, OUString()));
+            break;
     }
     // handle remaining stuff in base class
     return ShapeTypeContext::onCreateContext( nElement, rAttribs );
@@ -419,10 +424,6 @@ RectangleShapeContext::RectangleShapeContext( ContextHandler2Helper& rParent, co
 
 ContextHandlerRef RectangleShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
 {
-    if ( nElement == ( NMSP_vml + XML_textbox ) )
-        dynamic_cast< SimpleShape &>( mrShape ).setService(
-            OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame")) );
-
     // The parent class's context is fine
     return ShapeContext::onCreateContext( nElement, rAttribs );
 }
openSUSE Build Service is sponsored by