avmedia/source/framework/modeltools.cxx | 2 sd/qa/unit/data/media_embedding.odp |binary sd/qa/unit/import-tests.cxx | 4 - xmloff/source/draw/shapeexport.cxx | 70 +++++++++++++++++++++++++++----- xmloff/source/draw/ximpshap.cxx | 32 +++++++------- xmloff/source/draw/ximpshap.hxx | 2 6 files changed, 82 insertions(+), 28 deletions(-)
New commits: commit cca5aec27f0f147e33b639bac2dad887bba356f9 Author: Zolnai Tamás <tamas.zol...@collabora.com> Date: Mon Jun 16 14:00:26 2014 +0200 glTF import/export: fallback must be the second one inside the frame The previous solution was good because older LO versions import the fallback image without changing their code, but it came out it does not fit to ODF standard so export fallback image as the second object after the glTF model. (cherry picked from commit 4d8c4e7fe3e9b0ec6e14b5475a29d119e2023065) Change-Id: Ib9b2044b1f36b32d980cb79f6dac8dcf94d6209b diff --git a/sd/qa/unit/data/media_embedding.odp b/sd/qa/unit/data/media_embedding.odp index d8af1ec..8a9fefe 100644 Binary files a/sd/qa/unit/data/media_embedding.odp and b/sd/qa/unit/data/media_embedding.odp differ diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx index 049c4b0..c4bb166 100644 --- a/xmloff/source/draw/shapeexport.cxx +++ b/xmloff/source/draw/shapeexport.cxx @@ -3160,9 +3160,8 @@ lcl_StoreMediaAndGetURL(SvXMLExport & rExport, } #if HAVE_FEATURE_GLTF -static void lcl_StoreJsonExternalsAndFallback( +static void lcl_StoreGltfExternals( SvXMLExport& rExport, - const uno::Reference<beans::XPropertySet> xPropSet, const OUString& rURL ) { OUString sUrlPath; @@ -3198,16 +3197,60 @@ static void lcl_StoreJsonExternalsAndFallback( xModelStorage->copyToStorage(xModelTarget); - /* Save the fallback image under the 'Model/Fallback/' folder - Place fallback image before the plugin tag otherwise older LO versions will parse an empty - plugin shape instead of the image. In current version this image will be ingored during import.*/ + const uno::Reference<embed::XTransactedObject> xModelsTransaction(xModelsTarget, uno::UNO_QUERY); + if (xModelsTransaction.is()) + { + xModelsTransaction->commit(); + } + } + catch (uno::Exception const& e) + { + SAL_INFO("xmloff", "exception while saving embedded model: '" << e.Message << "'"); + } + } +} + +static void lcl_StoreGltfFallback( + SvXMLExport& rExport, + const uno::Reference<beans::XPropertySet> xPropSet, + const OUString& rURL ) +{ + OUString sUrlPath; + if (rURL.startsWithIgnoreAsciiCase("vnd.sun.star.Package:", &sUrlPath)) + { + sUrlPath = sUrlPath.copy(0,sUrlPath.lastIndexOf("/")); + try + { + // Base storage + uno::Reference<document::XStorageBasedDocument> const xSBD( + rExport.GetModel(), uno::UNO_QUERY_THROW); + const uno::Reference<embed::XStorage> xStorage( + xSBD->getDocumentStorage(), uno::UNO_QUERY_THROW); + + // Model source + ::comphelper::LifecycleProxy proxy; + const uno::Reference<embed::XStorage> xModelStorage( + ::comphelper::OStorageHelper::GetStorageAtPath(xStorage, sUrlPath, + embed::ElementModes::READ, proxy)); + + // Target storage + uno::Reference<embed::XStorage> const xTarget( + rExport.GetTargetStorage(), uno::UNO_QUERY_THROW); + + // Target of all models + const uno::Reference<embed::XStorage> xModelsTarget( + xTarget->openStorageElement(sUrlPath.copy(0,sUrlPath.lastIndexOf("/")), embed::ElementModes::WRITE)); + + /// Save the fallback image under the 'Models/Fallbacks/' folder uno::Reference< graphic::XGraphic > xGraphic( xPropSet->getPropertyValue("FallbackGraphic"), uno::UNO_QUERY ); if( xGraphic.is() ) { // Fallback storage + const OUString sFallbackFolder("Fallbacks"); const uno::Reference<embed::XStorage> xFallbackTarget( - xModelsTarget->openStorageElement(OUString("Fallbacks"), embed::ElementModes::WRITE)); + xModelsTarget->openStorageElement(sFallbackFolder, embed::ElementModes::WRITE)); + const OUString sModelName = sUrlPath.copy(sUrlPath.lastIndexOf("/")+1); uno::Reference< io::XStream > xPictureStream( xFallbackTarget->openStreamElement( sModelName + ".png", embed::ElementModes::WRITE ), uno::UNO_QUERY_THROW ); @@ -3225,7 +3268,7 @@ static void lcl_StoreJsonExternalsAndFallback( xFallbackTransaction->commit(); } - const OUString sFallbackURL( sUrlPath.copy(0,sUrlPath.lastIndexOf("/")) + "/Fallbacks/" + sModelName + ".png"); + const OUString sFallbackURL( sUrlPath.copy(0,sUrlPath.lastIndexOf("/")) + "/" + sFallbackFolder + "/" + sModelName + ".png"); rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sFallbackURL ); rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED ); @@ -3242,10 +3285,11 @@ static void lcl_StoreJsonExternalsAndFallback( } catch (uno::Exception const& e) { - SAL_INFO("xmloff", "exception while saving embedded model: '" << e.Message << "'"); + SAL_INFO("xmloff", "exception while saving fallback image of glTF model: '" << e.Message << "'"); } } } + #endif void XMLShapeExport::ImpExportMediaShape( @@ -3276,7 +3320,7 @@ void XMLShapeExport::ImpExportMediaShape( lcl_StoreMediaAndGetURL(GetExport(), xPropSet, aMediaURL, sMimeType); #if HAVE_FEATURE_GLTF if( sMimeType == "model/vnd.gltf+json" ) - lcl_StoreJsonExternalsAndFallback(GetExport(), xPropSet, aMediaURL); + lcl_StoreGltfExternals(GetExport(), aMediaURL); #endif mrExport.AddAttribute ( XML_NAMESPACE_XLINK, XML_HREF, persistentURL ); @@ -3288,7 +3332,7 @@ void XMLShapeExport::ImpExportMediaShape( mrExport.AddAttribute( XML_NAMESPACE_DRAW, XML_MIME_TYPE, sMimeType ); // write plugin - SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DRAW, XML_PLUGIN, !( nFeatures & SEF_EXPORT_NO_WS ), true); + SvXMLElementExport* pPluginOBJ = new SvXMLElementExport(mrExport, XML_NAMESPACE_DRAW, XML_PLUGIN, !( nFeatures & SEF_EXPORT_NO_WS ), true); // export parameters const OUString aFalseStr( "false" ), aTrueStr( "true" ); @@ -3339,6 +3383,12 @@ void XMLShapeExport::ImpExportMediaShape( mrExport.AddAttribute( XML_NAMESPACE_DRAW, XML_VALUE, aZoomValue ); delete( new SvXMLElementExport( mrExport, XML_NAMESPACE_DRAW, XML_PARAM, false, true ) ); } + + delete pPluginOBJ; +#if HAVE_FEATURE_GLTF + if( sMimeType == "model/vnd.gltf+json" ) + lcl_StoreGltfFallback(GetExport(), xPropSet, aMediaURL); +#endif } } diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx index cdcb170..ccb95f9 100644 --- a/xmloff/source/draw/ximpshap.cxx +++ b/xmloff/source/draw/ximpshap.cxx @@ -3515,7 +3515,6 @@ SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPref if( !mxImplContext.Is() ) { - SvXMLShapeContext* pShapeContext= GetImport().GetShapeImport()->CreateFrameChildContext( GetImport(), nPrefix, rLocalName, xAttrList, mxShapes, mxAttrList ); @@ -3525,6 +3524,23 @@ SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPref if ( !msHyperlink.isEmpty() ) pShapeContext->setHyperlink( msHyperlink ); + // Ignore gltf model if necessary and so the fallback image will be imported + bool bIngoreGltf; +#if !HAVE_FEATURE_GLTF + bIngoreGltf = true; +#else + bIngoreGltf = !SvtMiscOptions().IsExperimentalMode(); +#endif + if( bIngoreGltf && IsXMLToken(rLocalName, XML_PLUGIN ) ) + { + SdXMLPluginShapeContext* pPluginContext = dynamic_cast<SdXMLPluginShapeContext*>(pShapeContext); + if( pPluginContext && pPluginContext->getMimeType() == "model/vnd.gltf+json" ) + { + mxImplContext = 0; + return this; + } + } + mxImplContext = pContext; mbSupportsReplacement = IsXMLToken(rLocalName, XML_OBJECT ) || IsXMLToken(rLocalName, XML_OBJECT_OLE); setSupportsMultipleContents(IsXMLToken(rLocalName, XML_IMAGE)); @@ -3589,20 +3605,6 @@ SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPref } } } -#if HAVE_FEATURE_GLTF - // For glTF models the fallback image is placed before the real shape. - // So we need to remove the fallback image after real shape is detected. - else if ( mxImplContext.Is() && IsXMLToken(mxImplContext->GetLocalName(), XML_IMAGE) && - IsXMLToken( rLocalName, XML_PLUGIN ) && SvtMiscOptions().IsExperimentalMode() ) - { - SvXMLShapeContext* pShapeContext= GetImport().GetShapeImport()->CreateFrameChildContext( - GetImport(), nPrefix, rLocalName, xAttrList, mxShapes, mxAttrList ); - - pContext = pShapeContext; - if( pContext ) - removeGraphicFromImportContext(*mxImplContext); - } -#endif // call parent for content if(!pContext) pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList ); diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx index f3d4f90..109628b 100644 --- a/xmloff/source/draw/ximpshap.hxx +++ b/xmloff/source/draw/ximpshap.hxx @@ -529,6 +529,8 @@ public: // this is called from the parent group for each unparsed attribute in the attribute list virtual void processAttribute( sal_uInt16 nPrefix, const OUString& rLocalName, const OUString& rValue ) SAL_OVERRIDE; + + const OUString& getMimeType() const { return maMimeType; } }; // draw:floating-frame commit 1fa8ae83323320967a56f92766aca4a3925b6514 Author: Zolnai Tamás <tamas.zol...@collabora.com> Date: Mon Jun 16 12:24:48 2014 +0200 glTF export: Use plural folder names Change-Id: If17628395ede512c00b666efc5511d9711edfb5a (cherry picked from commit 9ee69cbd6f1143160aa96001462b933770cc6b76) diff --git a/avmedia/source/framework/modeltools.cxx b/avmedia/source/framework/modeltools.cxx index 00eab46..6119cb7 100644 --- a/avmedia/source/framework/modeltools.cxx +++ b/avmedia/source/framework/modeltools.cxx @@ -260,7 +260,7 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel, xSBD->getDocumentStorage(), uno::UNO_QUERY_THROW); // Model storage - const OUString sModel("Model"); + const OUString sModel("Models"); uno::Reference<embed::XStorage> const xModelStorage( xStorage->openStorageElement(sModel, embed::ElementModes::WRITE)); diff --git a/sd/qa/unit/data/media_embedding.odp b/sd/qa/unit/data/media_embedding.odp index b27bbae..d8af1ec 100644 Binary files a/sd/qa/unit/data/media_embedding.odp and b/sd/qa/unit/data/media_embedding.odp differ diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index 04af625..0f813a9 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -727,7 +727,7 @@ void SdFiltersTest::testMediaEmbedding() // First object is a glTF model SdrMediaObj *pModelObj = dynamic_cast<SdrMediaObj*>( pPage->GetObj( 2 )); CPPUNIT_ASSERT_MESSAGE( "missing model", pModelObj != NULL); - CPPUNIT_ASSERT_EQUAL( OUString( "vnd.sun.star.Package:Model/jeep/jeep.json" ), pModelObj->getMediaProperties().getURL()); + CPPUNIT_ASSERT_EQUAL( OUString( "vnd.sun.star.Package:Models/jeep/jeep.json" ), pModelObj->getMediaProperties().getURL()); CPPUNIT_ASSERT_EQUAL( OUString( "model/vnd.gltf+json" ), pModelObj->getMediaProperties().getMimeType()); // Check the case when experimental mode is disabled @@ -743,7 +743,7 @@ void SdFiltersTest::testMediaEmbedding() // If glTF is not supported, then the fallback image is imported SdrGrafObj *pGrafic = dynamic_cast<SdrGrafObj*>( pPage->GetObj( 2 )); CPPUNIT_ASSERT_MESSAGE( "Could not load glTF fallback image", pGrafic != NULL); - CPPUNIT_ASSERT_EQUAL( OUString( "vnd.sun.star.Package:Model/Fallback/jeep.png" ), pGrafic->GetGrafStreamURL()); + CPPUNIT_ASSERT_EQUAL( OUString( "vnd.sun.star.Package:Models/Fallbacks/jeep.png" ), pGrafic->GetGrafStreamURL()); // Second object is a sound SdrMediaObj *pMediaObj = dynamic_cast<SdrMediaObj*>( pPage->GetObj( 3 )); diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx index acccb67..049c4b0 100644 --- a/xmloff/source/draw/shapeexport.cxx +++ b/xmloff/source/draw/shapeexport.cxx @@ -3206,7 +3206,7 @@ static void lcl_StoreJsonExternalsAndFallback( { // Fallback storage const uno::Reference<embed::XStorage> xFallbackTarget( - xModelsTarget->openStorageElement(OUString("Fallback"), embed::ElementModes::WRITE)); + xModelsTarget->openStorageElement(OUString("Fallbacks"), embed::ElementModes::WRITE)); uno::Reference< io::XStream > xPictureStream( xFallbackTarget->openStreamElement( sModelName + ".png", embed::ElementModes::WRITE ), uno::UNO_QUERY_THROW ); @@ -3225,7 +3225,7 @@ static void lcl_StoreJsonExternalsAndFallback( xFallbackTransaction->commit(); } - const OUString sFallbackURL( sUrlPath.copy(0,sUrlPath.lastIndexOf("/")) + "/Fallback/" + sModelName + ".png"); + const OUString sFallbackURL( sUrlPath.copy(0,sUrlPath.lastIndexOf("/")) + "/Fallbacks/" + sModelName + ".png"); rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sFallbackURL ); rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits