diff options
Diffstat (limited to 'sd')
-rw-r--r-- | sd/Library_sd.mk | 1 | ||||
-rw-r--r-- | sd/inc/sdpdffilter.hxx | 40 | ||||
-rw-r--r-- | sd/source/filter/pdf/sdpdffilter.cxx | 171 | ||||
-rw-r--r-- | sd/source/ui/docshell/docshel4.cxx | 9 |
4 files changed, 220 insertions, 1 deletions
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk index ae4592e340f3..7e165c3ec7a6 100644 --- a/sd/Library_sd.mk +++ b/sd/Library_sd.mk @@ -154,6 +154,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\ sd/source/filter/html/buttonset \ sd/source/filter/html/htmlex \ sd/source/filter/html/sdhtmlfilter \ + sd/source/filter/pdf/sdpdffilter \ sd/source/filter/sdfilter \ sd/source/filter/sdpptwrp \ sd/source/filter/xml/sdtransform \ diff --git a/sd/inc/sdpdffilter.hxx b/sd/inc/sdpdffilter.hxx new file mode 100644 index 000000000000..8971eb745179 --- /dev/null +++ b/sd/inc/sdpdffilter.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 . + */ + +#ifndef INCLUDED_SD_INC_SDPDFIUMFILTER_HXX +#define INCLUDED_SD_INC_SDPDFIUMFILTER_HXX + +#include <com/sun/star/drawing/XShape.hpp> + +#include "sdfilter.hxx" + +class SdPdfFilter : public SdFilter +{ +public: + SdPdfFilter(SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell); + + virtual ~SdPdfFilter() override; + + bool Import(); + bool Export() override; +}; + +#endif // INCLUDED_SD_INC_SDGRFFILTER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx new file mode 100644 index 000000000000..ede9f1aaf836 --- /dev/null +++ b/sd/source/filter/pdf/sdpdffilter.cxx @@ -0,0 +1,171 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 . + */ + +#include <com/sun/star/drawing/GraphicExportFilter.hpp> +#include <com/sun/star/graphic/GraphicProvider.hpp> +#include <com/sun/star/graphic/XGraphicProvider.hpp> +#include <com/sun/star/graphic/GraphicType.hpp> +#include <com/sun/star/ucb/SimpleFileAccess.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess2.hpp> + +#include <unotools/localfilehelper.hxx> +#include <vcl/errinf.hxx> +#include <vcl/weld.hxx> +#include <vcl/metaact.hxx> +#include <vcl/virdev.hxx> +#include <sfx2/sfxsids.hrc> +#include <sfx2/docfile.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/frame.hxx> +#include <svx/svdograf.hxx> +#include <svx/svdpagv.hxx> + +#include <strings.hrc> +#include <DrawViewShell.hxx> +#include <DrawDocShell.hxx> +#include <ClientView.hxx> +#include <FrameView.hxx> + +#include <comphelper/anytostring.hxx> +#include <cppuhelper/exc_hlp.hxx> + +#include <comphelper/processfactory.hxx> +#include <unotools/pathoptions.hxx> +#include <sfx2/filedlghelper.hxx> +#include <vcl/graphicfilter.hxx> +#include <svx/xoutbmp.hxx> + +#include <sdpage.hxx> +#include <drawdoc.hxx> +#include <sdresid.hxx> +#include <sdpdffilter.hxx> +#include <ViewShellBase.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/PropertyValues.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XExporter.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/drawing/XDrawView.hpp> +#include <DrawController.hxx> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/task/XInteractionHandler.hpp> +#include <com/sun/star/task/XInteractionRequest.hpp> +#include <com/sun/star/drawing/GraphicFilterRequest.hpp> + +#include <vcl/bitmap.hxx> +#include <vcl/graph.hxx> +#include <vcl/pdfread.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::graphic; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::ucb; +using namespace com::sun::star::ui::dialogs; +using namespace ::sfx2; + +SdPdfFilter::SdPdfFilter(SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell) + : SdFilter(rMedium, rDocShell) +{ +} + +SdPdfFilter::~SdPdfFilter() {} + +bool SdPdfFilter::Import() +{ + //FIXME: Replace with parsing the PDF elements to allow editing. + //FIXME: For now we import as images for simplicity. + + const OUString aFileName( + mrMedium.GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE)); + + uno::Sequence<sal_Int8> aPdfData; + std::vector<Bitmap> aBitmaps; + if (vcl::ImportPDF(aFileName, aBitmaps, aPdfData) == 0) + return false; + + // Prepare the link with the PDF stream. + const size_t nGraphicContentSize = aPdfData.getLength(); + std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]); + memcpy(pGraphicContent.get(), aPdfData.get(), nGraphicContentSize); + GfxLink aGfxLink(std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf); + + mrDocument.CreateFirstPages(); + for (int i = 0; i < aBitmaps.size() - 1; ++i) + { + mrDocument.DuplicatePage(0); + } + + size_t nPageNumber = 0; + for (Bitmap& aBitmap : aBitmaps) + { + // Create the Graphic and link the original PDF stream. + Graphic aGraphic(aBitmap); + aGraphic.setPdfData(std::make_shared<uno::Sequence<sal_Int8>>(aPdfData)); + aGraphic.SetLink(aGfxLink); + + // Create the page and insert the Graphic. + SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard); + Point aPos; + Size aPagSize(pPage->GetSize()); + Size aGrfSize(OutputDevice::LogicToLogic(aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(), + MapMode(MapUnit::Map100thMM))); + + aPagSize.AdjustWidth(-(pPage->GetLeftBorder() + pPage->GetRightBorder())); + aPagSize.AdjustHeight(-(pPage->GetUpperBorder() + pPage->GetLowerBorder())); + + // scale to fit page + if (((aGrfSize.Height() > aPagSize.Height()) || (aGrfSize.Width() > aPagSize.Width())) + && aGrfSize.Height() && aPagSize.Height()) + { + double fGrfWH = static_cast<double>(aGrfSize.Width()) / aGrfSize.Height(); + double fWinWH = static_cast<double>(aPagSize.Width()) / aPagSize.Height(); + + // adjust graphic to page size (scales) + if (fGrfWH < fWinWH) + { + aGrfSize.setWidth(static_cast<long>(aPagSize.Height() * fGrfWH)); + aGrfSize.setHeight(aPagSize.Height()); + } + else if (fGrfWH > 0.F) + { + aGrfSize.setWidth(aPagSize.Width()); + aGrfSize.setHeight(static_cast<long>(aPagSize.Width() / fGrfWH)); + } + } + + // set output rectangle for graphic + aPos.setX(((aPagSize.Width() - aGrfSize.Width()) >> 1) + pPage->GetLeftBorder()); + aPos.setY(((aPagSize.Height() - aGrfSize.Height()) >> 1) + pPage->GetUpperBorder()); + + pPage->InsertObject(new SdrGrafObj(pPage->getSdrModelFromSdrPage(), aGraphic, + ::tools::Rectangle(aPos, aGrfSize))); + } + + return true; +} + +bool SdPdfFilter::Export() { return false; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/docshell/docshel4.cxx b/sd/source/ui/docshell/docshel4.cxx index fb979fbfafa9..975b9af9dd56 100644 --- a/sd/source/ui/docshell/docshel4.cxx +++ b/sd/source/ui/docshell/docshel4.cxx @@ -79,6 +79,7 @@ #include <sdcgmfilter.hxx> #include <sdgrffilter.hxx> #include <sdhtmlfilter.hxx> +#include <sdpdffilter.hxx> #include <framework/FrameworkHelper.hxx> #include <SdUnoDrawView.hxx> @@ -489,12 +490,18 @@ bool DrawDocShell::ConvertFrom( SfxMedium& rMedium ) ErrCode nError = ERRCODE_NONE; bRet = SdXMLFilter( rMedium, *this, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 ).Import( nError ); } - else if( aFilterName == "CGM - Computer Graphics Metafile" ) + else if (aFilterName == "CGM - Computer Graphics Metafile") { mpDoc->CreateFirstPages(); mpDoc->StopWorkStartupDelay(); bRet = SdCGMFilter( rMedium, *this ).Import(); } + else if (aFilterName == "draw_pdf_import") + { + mpDoc->CreateFirstPages(); + mpDoc->StopWorkStartupDelay(); + bRet = SdPdfFilter(rMedium, *this).Import(); + } else { mpDoc->CreateFirstPages(); |