bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / filter / cgm / sdcgmfilter.cxx
blob80b11519d45aba9beb5cb86f674b9012c8c56763
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <memory>
21 #include <tools/urlobj.hxx>
22 #include <unotools/ucbstreamhelper.hxx>
23 #include <sfx2/docfile.hxx>
24 #include <svx/xflclit.hxx>
25 #include <svx/xfillit0.hxx>
27 #include <sddll.hxx>
28 #include <sdpage.hxx>
29 #include <drawdoc.hxx>
30 #include <sdcgmfilter.hxx>
32 #include <DrawDocShell.hxx>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::task;
37 using namespace ::com::sun::star::frame;
39 typedef sal_uInt32 ( *ImportCGMPointer )(SvStream&, Reference< XModel > const &, Reference< XStatusIndicator > const &);
41 #ifdef DISABLE_DYNLOADING
43 extern "C" sal_uInt32 ImportCGM(SvStream&, Reference< XModel > const &, Reference< XStatusIndicator > const &);
45 #endif
47 SdCGMFilter::SdCGMFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell ) :
48 SdFilter( rMedium, rDocShell )
52 SdCGMFilter::~SdCGMFilter()
56 namespace
58 class CGMPointer
60 ImportCGMPointer m_pPointer;
61 public:
62 CGMPointer()
64 #ifdef DISABLE_DYNLOADING
65 m_pPointer = ImportCGM;
66 #else
67 m_pPointer = reinterpret_cast<ImportCGMPointer>(
68 SdFilter::GetLibrarySymbol("icg", "ImportCGM"));
69 #endif
71 ImportCGMPointer get() { return m_pPointer; }
75 bool SdCGMFilter::Import()
77 bool bRet = false;
79 CGMPointer aPointer;
80 ImportCGMPointer FncImportCGM = aPointer.get();
81 if (FncImportCGM && mxModel.is())
83 OUString aFileURL( mrMedium.GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
84 sal_uInt32 nRetValue;
86 if( mrDocument.GetPageCount() == 0 )
87 mrDocument.CreateFirstPages();
89 CreateStatusIndicator();
90 std::unique_ptr<SvStream> xIn(::utl::UcbStreamHelper::CreateStream(aFileURL, StreamMode::READ));
91 nRetValue = xIn ? FncImportCGM(*xIn, mxModel, mxStatusIndicator) : 0;
93 if( nRetValue )
95 bRet = true;
97 if( ( nRetValue &~0xff000000 ) != 0xffffff ) // maybe the backgroundcolor is already white
98 { // so we must not set a master page
99 mrDocument.StopWorkStartupDelay();
100 SdPage* pSdPage = mrDocument.GetMasterSdPage(0, PageKind::Standard);
102 if(pSdPage)
104 // set PageFill to given color
105 const Color aColor(static_cast<sal_uInt8>(nRetValue >> 16), static_cast<sal_uInt8>(nRetValue >> 8), static_cast<sal_uInt8>(nRetValue >> 16));
106 pSdPage->getSdrPageProperties().PutItem(XFillColorItem(OUString(), aColor));
107 pSdPage->getSdrPageProperties().PutItem(XFillStyleItem(drawing::FillStyle_SOLID));
112 return bRet;
115 bool SdCGMFilter::Export()
117 // No ExportCGM function exists(!)
118 return false;
121 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportCGM(SvStream &rStream)
123 SdDLL::Init();
125 ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false, DocumentType::Impress);
127 CGMPointer aPointer;
129 xDocShRef->GetDoc()->EnableUndo(false);
130 bool bRet = aPointer.get()(rStream, xDocShRef->GetModel(), css::uno::Reference<css::task::XStatusIndicator>()) == 0;
132 xDocShRef->DoClose();
134 return bRet;
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */