comphelper/qa/unit/test_hash.cxx | 26 +----- comphelper/source/misc/hash.cxx | 13 +++ filter/source/pdf/impdialog.cxx | 71 ----------------- filter/source/pdf/impdialog.hxx | 158 +++++++++++++++++++-------------------- include/comphelper/hash.hxx | 3 5 files changed, 104 insertions(+), 167 deletions(-)
New commits: commit d9a0beb0b4dc22cf57ccb53ea0a4ab5442c43550 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Thu Oct 31 18:27:55 2024 +0100 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Mon Nov 4 21:20:01 2024 +0100 pdf: PDF dialog set the default member var. values in header file Just a simplification and clean-up as this is easier to read. Change-Id: I8a920849d2bac7ae89d0d7b5f90421a7fac3a0c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176021 Reviewed-by: Tomaž Vajngerl <[email protected]> Tested-by: Jenkins diff --git a/filter/source/pdf/impdialog.cxx b/filter/source/pdf/impdialog.cxx index 3d86c3acabb4..fb9bab206a81 100644 --- a/filter/source/pdf/impdialog.cxx +++ b/filter/source/pdf/impdialog.cxx @@ -54,73 +54,10 @@ using namespace ::com::sun::star::uno; */ ImpPDFTabDialog::ImpPDFTabDialog(weld::Window* pParent, const Sequence< PropertyValue >& rFilterData, const Reference< XComponent >& rxDoc) - : SfxTabDialogController(pParent, u"filter/ui/pdfoptionsdialog.ui"_ustr, u"PdfOptionsDialog"_ustr), - mrDoc(rxDoc), - maConfigItem( u"Office.Common/Filter/PDF/Export/", &rFilterData ), - maConfigI18N( u"Office.Common/I18N/CTL/" ), - mbIsPresentation( false ), - mbIsSpreadsheet( false ), - mbIsWriter( false ), - - mbSelectionPresent( false ), - mbUseCTLFont( false ), - mbUseLosslessCompression( true ), - mnQuality( DefaultPDFJPEGQuality ), - mbReduceImageResolution( false ), - mnMaxImageResolution( DefaultPDFImageDPI ), - mbUseTaggedPDF( false ), - mbUseTaggedPDFUserSelection( false ), - mbExportNotes( true ), - mbExportNotesInMargin( false ), - mbViewPDF( false ), - mbUseReferenceXObject( false ), - mbExportNotesPages( false ), - mbExportOnlyNotesPages( false ), - mbUseTransitionEffects( false ), - mbIsSkipEmptyPages( true ), - mbIsExportPlaceholders( false ), - mbAddStream( false ), - mnFormsType( 0 ), - mbExportFormFields( false ), - mbAllowDuplicateFieldNames( false ), - mbExportBookmarks( true ), - mbExportHiddenSlides ( false ), - mbSinglePageSheets ( false ), - mnOpenBookmarkLevels( -1 ), - - mbHideViewerToolbar( false ), - mbHideViewerMenubar( false ), - mbHideViewerWindowControls( false ), - mbResizeWinToInit( false ), - mbCenterWindow( false ), - mbOpenInFullScreenMode( false ), - mbDisplayPDFDocumentTitle( false ), - mnMagnification( 0 ), - mnInitialView( 1 ), - mnZoom( 0 ), - mnInitialPage( 1 ), - mnPageLayout( 0 ), - mbFirstPageLeft( false ), - - mbEncrypt( false ), - mbRestrictPermissions( false ), - mnPrint( 0 ), - mnChangesAllowed( 0 ), - mbCanCopyOrExtract( false ), - mbCanExtractForAccessibility( true ), - - mbIsPageRangeChecked( false ), - msPageRange( ' ' ), - mbIsSheetRangeChecked( false ), - msSheetRange( ' ' ), - - mbSelectionIsChecked( false ), - mbExportRelativeFsysLinks( false ), - mnViewPDFMode( 0 ), - mbConvertOOoTargets( false ), - mbExportBmkToPDFDestination( false ), - - mbSignPDF( false ) + : SfxTabDialogController(pParent, u"filter/ui/pdfoptionsdialog.ui"_ustr, u"PdfOptionsDialog"_ustr) + , mrDoc(rxDoc) + , maConfigItem( u"Office.Common/Filter/PDF/Export/", &rFilterData ) + , maConfigI18N( u"Office.Common/I18N/CTL/" ) { // check for selection try diff --git a/filter/source/pdf/impdialog.hxx b/filter/source/pdf/impdialog.hxx index 95d25f99d705..0db3c4e66ed5 100644 --- a/filter/source/pdf/impdialog.hxx +++ b/filter/source/pdf/impdialog.hxx @@ -60,94 +60,94 @@ class ImpPDFTabDialog final : public SfxTabDialogController { css::uno::Reference<css::lang::XComponent> mrDoc; - FilterConfigItem maConfigItem; - FilterConfigItem maConfigI18N; + FilterConfigItem maConfigItem; + FilterConfigItem maConfigI18N; - Any maSelection; + Any maSelection; DECL_LINK(CancelHdl, weld::Button&, void); DECL_LINK(OkHdl, weld::Button&, void); // the following data are the configuration used throughout the dialog and pages - bool mbIsPresentation; - bool mbIsSpreadsheet; - bool mbIsWriter; - bool mbSelectionPresent; - bool mbUseCTLFont; - bool mbUseLosslessCompression; - sal_Int32 mnQuality; - bool mbReduceImageResolution; - sal_Int32 mnMaxImageResolution; - bool mbUseTaggedPDF; - bool mbUseTaggedPDFUserSelection; - sal_Int32 mnPDFTypeSelection; - bool mbPDFUACompliance; - bool mbExportNotes; - bool mbExportNotesInMargin; - bool mbViewPDF; - bool mbUseReferenceXObject; - bool mbUseReferenceXObjectUserSelection = false; - bool mbExportNotesPages; - bool mbExportOnlyNotesPages; - bool mbUseTransitionEffects; - bool mbIsSkipEmptyPages; - bool mbIsExportPlaceholders; - bool mbAddStream; - sal_Int32 mnFormsType; - bool mbExportFormFields; - bool mbAllowDuplicateFieldNames; - bool mbExportBookmarks; - bool mbExportBookmarksUserSelection = true; - bool mbExportHiddenSlides; - bool mbSinglePageSheets; - sal_Int32 mnOpenBookmarkLevels; - - bool mbHideViewerToolbar; - bool mbHideViewerMenubar; - bool mbHideViewerWindowControls; - bool mbResizeWinToInit; - bool mbCenterWindow; - bool mbOpenInFullScreenMode; - bool mbDisplayPDFDocumentTitle; - sal_Int32 mnMagnification; - sal_Int32 mnInitialView; - sal_Int32 mnInitialViewUserSelection; - sal_Int32 mnZoom; - sal_Int32 mnInitialPage; - - sal_Int32 mnPageLayout; - bool mbFirstPageLeft; - - bool mbEncrypt; - - bool mbRestrictPermissions; + bool mbIsPresentation = false; + bool mbIsSpreadsheet = false; + bool mbIsWriter = false; + bool mbSelectionPresent = false; + bool mbUseCTLFont = false; + bool mbUseLosslessCompression = true; + sal_Int32 mnQuality = 90; + bool mbReduceImageResolution = false; + sal_Int32 mnMaxImageResolution = 300; + bool mbUseTaggedPDF = false; + bool mbUseTaggedPDFUserSelection = false; + sal_Int32 mnPDFTypeSelection; + bool mbPDFUACompliance; + bool mbExportNotes = true; + bool mbExportNotesInMargin = false; + bool mbViewPDF = false; + bool mbUseReferenceXObject = false; + bool mbUseReferenceXObjectUserSelection = false; + bool mbExportNotesPages = false; + bool mbExportOnlyNotesPages = false; + bool mbUseTransitionEffects = false; + bool mbIsSkipEmptyPages = true; + bool mbIsExportPlaceholders = false; + bool mbAddStream = false; + sal_Int32 mnFormsType = 0; + bool mbExportFormFields = false; + bool mbAllowDuplicateFieldNames = false; + bool mbExportBookmarks = true; + bool mbExportBookmarksUserSelection = true; + bool mbExportHiddenSlides = false; + bool mbSinglePageSheets = false; + sal_Int32 mnOpenBookmarkLevels = -1; + + bool mbHideViewerToolbar = false; + bool mbHideViewerMenubar = false; + bool mbHideViewerWindowControls = false; + bool mbResizeWinToInit = false; + bool mbCenterWindow = false; + bool mbOpenInFullScreenMode = false; + bool mbDisplayPDFDocumentTitle = false; + sal_Int32 mnMagnification = 0; + sal_Int32 mnInitialView = 1; + sal_Int32 mnInitialViewUserSelection; + sal_Int32 mnZoom = 0; + sal_Int32 mnInitialPage = 1; + + sal_Int32 mnPageLayout = 0; + bool mbFirstPageLeft = false; + + bool mbEncrypt = false; + + bool mbRestrictPermissions = false; css::uno::Sequence< css::beans::NamedValue > maPreparedOwnerPassword; - sal_Int32 mnPrint; - sal_Int32 mnChangesAllowed; - bool mbCanCopyOrExtract; - bool mbCanExtractForAccessibility; + sal_Int32 mnPrint = 0; + sal_Int32 mnChangesAllowed = 0; + bool mbCanCopyOrExtract = false; + bool mbCanExtractForAccessibility = true; css::uno::Reference< css::beans::XMaterialHolder > mxPreparedPasswords; - bool mbIsPageRangeChecked; - OUString msPageRange; - bool mbIsSheetRangeChecked; - OUString msSheetRange; - bool mbSelectionIsChecked; - - bool mbExportRelativeFsysLinks; - sal_Int32 mnViewPDFMode; - bool mbConvertOOoTargets; - bool mbExportBmkToPDFDestination; - - bool mbSignPDF; - OUString msSignPassword; - OUString msSignLocation; - OUString msSignContact; - OUString msSignReason; - css::uno::Reference< css::security::XCertificate > maSignCertificate; - OUString msSignTSA; - - OUString maWatermarkText; + bool mbIsPageRangeChecked = false; + OUString msPageRange = OUString(' '); + bool mbIsSheetRangeChecked = false; + OUString msSheetRange = OUString(' '); + bool mbSelectionIsChecked = false; + + bool mbExportRelativeFsysLinks = false; + sal_Int32 mnViewPDFMode = 0; + bool mbConvertOOoTargets = false; + bool mbExportBmkToPDFDestination = false; + + bool mbSignPDF = false; + OUString msSignPassword; + OUString msSignLocation; + OUString msSignContact; + OUString msSignReason; + css::uno::Reference<css::security::XCertificate> maSignCertificate; + OUString msSignTSA; + + OUString maWatermarkText; public: commit c749c21c5abba12f7caa979e5be9d02decb26919 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Wed Oct 16 09:30:11 2024 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Mon Nov 4 21:19:51 2024 +0100 comphelper: move tostring to hash.hxx so it can be reused tostring to convert a vector of bytes into a hex string is useful in other tests and implementation, so move it into common hash.hxx Change-Id: Iebc71919c6209222eb01b78c307420afddc8caca Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176020 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/comphelper/qa/unit/test_hash.cxx b/comphelper/qa/unit/test_hash.cxx index dc96a03318ef..93933f84b9a3 100644 --- a/comphelper/qa/unit/test_hash.cxx +++ b/comphelper/qa/unit/test_hash.cxx @@ -13,7 +13,6 @@ #include <comphelper/docpasswordhelper.hxx> #include <rtl/ustring.hxx> -#include <iomanip> #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> @@ -48,21 +47,6 @@ public: CPPUNIT_TEST_SUITE_END(); }; -namespace { - -std::string tostring(const std::vector<unsigned char>& a) -{ - std::stringstream aStrm; - for (auto& i:a) - { - aStrm << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(i); - } - - return aStrm.str(); -} - -} - void TestHash::testMD5() { comphelper::Hash aHash(comphelper::HashType::MD5); @@ -70,7 +54,7 @@ void TestHash::testMD5() aHash.update(reinterpret_cast<const unsigned char*>(pInput), 0); std::vector<unsigned char> calculate_hash = aHash.finalize(); CPPUNIT_ASSERT_EQUAL(size_t(16), calculate_hash.size()); - CPPUNIT_ASSERT_EQUAL(std::string("d41d8cd98f00b204e9800998ecf8427e"), tostring(calculate_hash)); + CPPUNIT_ASSERT_EQUAL(std::string("d41d8cd98f00b204e9800998ecf8427e"), comphelper::hashToString(calculate_hash)); } void TestHash::testSHA1() @@ -80,7 +64,7 @@ void TestHash::testSHA1() aHash.update(reinterpret_cast<const unsigned char*>(pInput), 0); std::vector<unsigned char> calculate_hash = aHash.finalize(); CPPUNIT_ASSERT_EQUAL(size_t(20), calculate_hash.size()); - CPPUNIT_ASSERT_EQUAL(std::string("da39a3ee5e6b4b0d3255bfef95601890afd80709"), tostring(calculate_hash)); + CPPUNIT_ASSERT_EQUAL(std::string("da39a3ee5e6b4b0d3255bfef95601890afd80709"), comphelper::hashToString(calculate_hash)); } void TestHash::testSHA256() @@ -90,7 +74,7 @@ void TestHash::testSHA256() aHash.update(reinterpret_cast<const unsigned char*>(pInput), 0); std::vector<unsigned char> calculate_hash = aHash.finalize(); CPPUNIT_ASSERT_EQUAL(size_t(32), calculate_hash.size()); - CPPUNIT_ASSERT_EQUAL(std::string("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), tostring(calculate_hash)); + CPPUNIT_ASSERT_EQUAL(std::string("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), comphelper::hashToString(calculate_hash)); } void TestHash::testSHA512() @@ -101,7 +85,7 @@ void TestHash::testSHA512() std::vector<unsigned char> calculate_hash = aHash.finalize(); CPPUNIT_ASSERT_EQUAL(size_t(64), calculate_hash.size()); std::string aStr("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"); - CPPUNIT_ASSERT_EQUAL(aStr, tostring(calculate_hash)); + CPPUNIT_ASSERT_EQUAL(aStr, comphelper::hashToString(calculate_hash)); } // Must be identical to testSHA512() @@ -113,7 +97,7 @@ void TestHash::testSHA512_NoSaltNoSpin() nullptr, 0, 0, comphelper::Hash::IterCount::NONE, comphelper::HashType::SHA512); CPPUNIT_ASSERT_EQUAL(size_t(64), calculate_hash.size()); std::string aStr("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"); - CPPUNIT_ASSERT_EQUAL(aStr, tostring(calculate_hash)); + CPPUNIT_ASSERT_EQUAL(aStr, comphelper::hashToString(calculate_hash)); } // Password, salt, hash and spin count taken from OOXML sheetProtection of diff --git a/comphelper/source/misc/hash.cxx b/comphelper/source/misc/hash.cxx index 25b93ad87e54..96e125cac23d 100644 --- a/comphelper/source/misc/hash.cxx +++ b/comphelper/source/misc/hash.cxx @@ -15,6 +15,8 @@ #include <rtl/alloc.h> #include <osl/endian.h> #include <config_oox.h> +#include <sstream> +#include <iomanip> #if USE_TLS_NSS #include <nss.h> @@ -27,6 +29,17 @@ namespace comphelper { +std::string hashToString(const std::vector<unsigned char>& rHash) +{ + std::stringstream aStringStream; + for (auto& i: rHash) + { + aStringStream << std::setw(2) << std::setfill('0') << std::hex << int(i); + } + + return aStringStream.str(); +} + struct HashImpl { diff --git a/include/comphelper/hash.hxx b/include/comphelper/hash.hxx index a3ad468d3eb5..e148276abfb3 100644 --- a/include/comphelper/hash.hxx +++ b/include/comphelper/hash.hxx @@ -14,6 +14,7 @@ #include <rtl/digest.h> #include <memory> +#include <string> #include <vector> namespace rtl { @@ -39,6 +40,8 @@ const sal_uInt32 SHA512_HASH_LENGTH = 64; struct HashImpl; +COMPHELPER_DLLPUBLIC std::string hashToString(const std::vector<unsigned char>& rHash); + class COMPHELPER_DLLPUBLIC Hash { private:
