filter/Configuration_filter.mk | 7 + filter/source/config/fragments/filters/SVGZ___Compressed_Scalable_Vector_Graphics.xcu | 30 +++++++ filter/source/config/fragments/filters/draw_svgz_Export.xcu | 30 +++++++ filter/source/config/fragments/internalgraphicfilters/svgz_Export.xcu | 27 ++++++ filter/source/config/fragments/internalgraphicfilters/svgz_Import.xcu | 27 ++++++ filter/source/config/fragments/types/svg_Scalable_Vector_Graphics.xcu | 2 filter/source/config/fragments/types/svgz_Compressed_Scalable_Vector_Graphics.xcu | 29 +++++++ filter/source/svg/svgexport.cxx | 40 +++++++++- filter/source/svg/svgfilter.cxx | 5 + filter/source/svg/svgfilter.hxx | 1 10 files changed, 196 insertions(+), 2 deletions(-)
New commits: commit 9a5d46070e70e8cf42bea0dad37063d9ed71e375 Author: offtkp <parisop...@gmail.com> AuthorDate: Thu Jun 9 16:22:32 2022 +0300 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Jun 22 14:11:14 2022 +0200 tdf#100522 Add support for exporting SVGZ in Draw Detect draw_svgz_Export and compress the SVG before exporting if needed Change-Id: I7c8463292ee845a3ce2f2a3c5aa876b25dcedb2e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135556 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/filter/Configuration_filter.mk b/filter/Configuration_filter.mk index 5c451319e95f..939234b1dc15 100644 --- a/filter/Configuration_filter.mk +++ b/filter/Configuration_filter.mk @@ -714,6 +714,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_drawgraphics_typ ras_Sun_Rasterfile \ svg_Scalable_Vector_Graphics_Draw \ svg_Scalable_Vector_Graphics \ + svgz_Compressed_Scalable_Vector_Graphics \ svm_StarView_Metafile \ tga_Truevision_TARGA \ tif_Tag_Image_File \ @@ -744,6 +745,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_drawgraphics_f RAS___Sun_Rasterfile \ SVG___Scalable_Vector_Graphics_Draw \ SVG___Scalable_Vector_Graphics \ + SVGZ___Compressed_Scalable_Vector_Graphics \ SVM___StarView_Metafile \ TGA___Truevision_TARGA \ TIF___Tag_Image_File \ @@ -764,6 +766,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_drawgraphics_f draw_jpg_Export \ draw_png_Export \ draw_svg_Export \ + draw_svgz_Export \ draw_tif_Export \ draw_webp_Export \ draw_wmf_Export \ @@ -789,6 +792,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_impressgraphics_ ras_Sun_Rasterfile \ svg_Scalable_Vector_Graphics_Draw \ svg_Scalable_Vector_Graphics \ + svgz_Compressed_Scalable_Vector_Graphics \ svm_StarView_Metafile \ tif_Tag_Image_File \ wmf_MS_Windows_Metafile \ @@ -862,6 +866,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_internalgraphics psd_Adobe_Photoshop \ ras_Sun_Rasterfile \ svg_Scalable_Vector_Graphics \ + svgz_Compressed_Scalable_Vector_Graphics \ svm_StarView_Metafile \ tga_Truevision_TARGA \ tif_Tag_Image_File \ @@ -903,6 +908,8 @@ $(eval $(call filter_Configuration_add_internal_filters,fcfg_langpack,fcfg_inter ras_Import \ svg_Export \ svg_Import \ + svgz_Export \ + svgz_Import \ svm_Export \ svm_Import \ tga_Import \ diff --git a/filter/source/config/fragments/filters/SVGZ___Compressed_Scalable_Vector_Graphics.xcu b/filter/source/config/fragments/filters/SVGZ___Compressed_Scalable_Vector_Graphics.xcu new file mode 100644 index 000000000000..35753a1f1a8b --- /dev/null +++ b/filter/source/config/fragments/filters/SVGZ___Compressed_Scalable_Vector_Graphics.xcu @@ -0,0 +1,30 @@ +<!-- + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> + <node oor:name="SVGZ - Compressed Scalable Vector Graphics" oor:op="replace"> + <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="FilterService"><value>com.sun.star.comp.Draw.SVGFilter</value></prop> + <prop oor:name="UserData"><value></value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">SVGZ - Compressed Scalable Vector Graphics</value> + </prop> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>svgz_Compressed_Scalable_Vector_Graphics</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="DocumentService"><value>com.sun.star.presentation.PresentationDocument</value></prop> + </node> diff --git a/filter/source/config/fragments/filters/draw_svgz_Export.xcu b/filter/source/config/fragments/filters/draw_svgz_Export.xcu new file mode 100644 index 000000000000..59af9fa1d5d4 --- /dev/null +++ b/filter/source/config/fragments/filters/draw_svgz_Export.xcu @@ -0,0 +1,30 @@ +<!-- + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> + <node oor:name="draw_svgz_Export" oor:op="replace"> + <prop oor:name="Flags"><value>EXPORT ALIEN 3RDPARTYFILTER</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="FilterService"><value>com.sun.star.comp.Draw.SVGFilter</value></prop> + <prop oor:name="UserData"><value></value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">SVGZ - Compressed Scalable Vector Graphics</value> + </prop> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>svgz_Compressed_Scalable_Vector_Graphics</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="DocumentService"><value>com.sun.star.drawing.DrawingDocument</value></prop> + </node> diff --git a/filter/source/config/fragments/internalgraphicfilters/svgz_Export.xcu b/filter/source/config/fragments/internalgraphicfilters/svgz_Export.xcu new file mode 100644 index 000000000000..8231ca965ff1 --- /dev/null +++ b/filter/source/config/fragments/internalgraphicfilters/svgz_Export.xcu @@ -0,0 +1,27 @@ +<!-- + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> + <node oor:name="svgz_Export" oor:op="replace" > + <prop oor:name="Type"><value>svgz_Compressed_Scalable_Vector_Graphics</value></prop> + <prop oor:name="FormatName"><value>SVESVGZ</value></prop> + <prop oor:name="RealFilterName"/> + <prop oor:name="UIComponent"><value>com.sun.star.svtools.SvFilterOptionsDialog</value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">SVGZ - Compressed Scalable Vector Graphics</value> + </prop> + <prop oor:name="Flags"><value>EXPORT</value></prop> + </node> diff --git a/filter/source/config/fragments/internalgraphicfilters/svgz_Import.xcu b/filter/source/config/fragments/internalgraphicfilters/svgz_Import.xcu new file mode 100644 index 000000000000..fe0d2deaac2a --- /dev/null +++ b/filter/source/config/fragments/internalgraphicfilters/svgz_Import.xcu @@ -0,0 +1,27 @@ +<!-- + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> + <node oor:name="svgz_Import" oor:op="replace" > + <prop oor:name="Type"><value>svgz_Compressed_Scalable_Vector_Graphics</value></prop> + <prop oor:name="FormatName"><value>SVISVGZ</value></prop> + <prop oor:name="RealFilterName"><value>SVGZ - Compressed Scalable Vector Graphics</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UIName"> + <value xml:lang="en-US">SVGZ - Compressed Scalable Vector Graphics</value> + </prop> + <prop oor:name="Flags"><value>IMPORT</value></prop> + </node> diff --git a/filter/source/config/fragments/types/svg_Scalable_Vector_Graphics.xcu b/filter/source/config/fragments/types/svg_Scalable_Vector_Graphics.xcu index a2015a536873..04b08c08b664 100644 --- a/filter/source/config/fragments/types/svg_Scalable_Vector_Graphics.xcu +++ b/filter/source/config/fragments/types/svg_Scalable_Vector_Graphics.xcu @@ -18,7 +18,7 @@ <node oor:name="svg_Scalable_Vector_Graphics" oor:op="replace" > <prop oor:name="DetectService"><value>com.sun.star.comp.Draw.SVGFilter</value></prop> <prop oor:name="URLPattern"/> - <prop oor:name="Extensions"><value>svg svgz</value></prop> + <prop oor:name="Extensions"><value>svg</value></prop> <prop oor:name="MediaType"><value>image/svg+xml</value></prop> <prop oor:name="Preferred"><value>false</value></prop> <prop oor:name="PreferredFilter"><value>SVG - Scalable Vector Graphics</value></prop> diff --git a/filter/source/config/fragments/types/svgz_Compressed_Scalable_Vector_Graphics.xcu b/filter/source/config/fragments/types/svgz_Compressed_Scalable_Vector_Graphics.xcu new file mode 100644 index 000000000000..7ba66f15f092 --- /dev/null +++ b/filter/source/config/fragments/types/svgz_Compressed_Scalable_Vector_Graphics.xcu @@ -0,0 +1,29 @@ +<!-- + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> + <node oor:name="svgz_Compressed_Scalable_Vector_Graphics" oor:op="replace" > + <prop oor:name="DetectService"><value>com.sun.star.comp.Draw.SVGFilter</value></prop> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>svgz</value></prop> + <prop oor:name="MediaType"><value>image/svg+xml</value></prop> + <prop oor:name="Preferred"><value>false</value></prop> + <prop oor:name="PreferredFilter"><value>SVGZ - Compressed Scalable Vector Graphics</value></prop> + <prop oor:name="UIName"> + <value>SVGZ - Compressed Scalable Vector Graphics</value> + </prop> + <prop oor:name="ClipboardFormat"/> + </node> diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx index 525c540020f7..09ea90a71ccb 100644 --- a/filter/source/svg/svgexport.cxx +++ b/filter/source/svg/svgexport.cxx @@ -63,6 +63,8 @@ #include <svx/svdxcgv.hxx> #include <sal/log.hxx> #include <tools/diagnose_ex.h> +#include <tools/zcodec.hxx> +#include <rtl/crc.h> #include <memory> #include <string_view> @@ -662,12 +664,16 @@ bool SVGFilter::implExportImpressOrDraw( const Reference< XOutputStream >& rxOSt { Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ) ; bool bRet = false; + // Instead of writing to rxOStm directly, we write here in case we need + // to compress the output later + SvMemoryStream aTempStm; if( rxOStm.is() ) { if( !mSelectedPages.empty() && !mMasterPageTargets.empty() ) { - Reference< XDocumentHandler > xDocHandler = implCreateExportDocumentHandler( rxOStm ); + ::rtl::Reference< ::utl::OStreamWrapper > aTempStmWrapper = new ::utl::OStreamWrapper( aTempStm ); + Reference< XDocumentHandler > xDocHandler = implCreateExportDocumentHandler( aTempStmWrapper ); if( xDocHandler.is() ) { @@ -742,6 +748,38 @@ bool SVGFilter::implExportImpressOrDraw( const Reference< XOutputStream >& rxOSt } } } + if ( bRet ) + { + const sal_Int8* aDataPtr = static_cast< const sal_Int8* >( aTempStm.GetData() ); + sal_uInt32 aDataSize = aTempStm.GetSize(); + SvMemoryStream aCompressedStm; + if ( mbShouldCompress ) + { + sal_uInt32 nUncompressedCRC32 + = rtl_crc32( 0, aTempStm.GetData(), aTempStm.GetSize() ); + ZCodec aCodec; + aTempStm.Seek( 0 ); + aCodec.BeginCompression( ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/true ); + // the inner modify time/filename doesn't really matter in this context because + // compressed graphic formats are meant to be opened as is - not to be extracted + aCodec.SetCompressionMetadata( "inner", 0, nUncompressedCRC32 ); + aCodec.Compress( aTempStm, aCompressedStm ); + sal_uInt32 nTotalIn = static_cast< sal_uInt32 >( aCodec.EndCompression() ); + if ( aCompressedStm.GetError() || nTotalIn != aDataSize ) + { + bRet = false; + return bRet; + } + else + { + aDataPtr = static_cast< const sal_Int8* >( aCompressedStm.GetData() ); + aDataSize = aCompressedStm.GetSize(); + } + } + + Sequence< sal_Int8 > aTempSeq( aDataPtr, aDataSize ); + rxOStm->writeBytes( aTempSeq ); + } return bRet; } diff --git a/filter/source/svg/svgfilter.cxx b/filter/source/svg/svgfilter.cxx index 4538e50213fc..ff822e0037b0 100644 --- a/filter/source/svg/svgfilter.cxx +++ b/filter/source/svg/svgfilter.cxx @@ -100,6 +100,7 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto mbWriterFilter = false; mbCalcFilter = false; mbImpressFilter = false; + mbShouldCompress = false; if(mxDstDoc.is()) // Import works for Impress / draw only return filterImpressOrDraw(rDescriptor); @@ -137,6 +138,10 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto mbCalcFilter = true; return filterWriterOrCalc(rDescriptor); } + else if(sFilterName == "draw_svgz_Export") + { + mbShouldCompress = true; + } break; } } diff --git a/filter/source/svg/svgfilter.hxx b/filter/source/svg/svgfilter.hxx index 93e14ec41671..5b7573a1be98 100644 --- a/filter/source/svg/svgfilter.hxx +++ b/filter/source/svg/svgfilter.hxx @@ -210,6 +210,7 @@ private: Reference< css::drawing::XDrawPage > mxDefaultPage; std::vector< Reference< css::drawing::XDrawPage > > mSelectedPages; bool mbIsPreview; + bool mbShouldCompress; bool mbWriterFilter; bool mbCalcFilter;