1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
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 &);
47 SdCGMFilter::SdCGMFilter( SfxMedium
& rMedium
, ::sd::DrawDocShell
& rDocShell
) :
48 SdFilter( rMedium
, rDocShell
)
52 SdCGMFilter::~SdCGMFilter()
60 ImportCGMPointer m_pPointer
;
64 #ifdef DISABLE_DYNLOADING
65 m_pPointer
= ImportCGM
;
67 m_pPointer
= reinterpret_cast<ImportCGMPointer
>(
68 SdFilter::GetLibrarySymbol("icg", "ImportCGM"));
71 ImportCGMPointer
get() { return m_pPointer
; }
75 bool SdCGMFilter::Import()
80 ImportCGMPointer FncImportCGM
= aPointer
.get();
81 if (FncImportCGM
&& mxModel
.is())
83 OUString
aFileURL( mrMedium
.GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
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;
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
);
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
));
115 bool SdCGMFilter::Export()
117 // No ExportCGM function exists(!)
121 extern "C" SAL_DLLPUBLIC_EXPORT
bool TestImportCGM(SvStream
&rStream
)
125 ::sd::DrawDocShellRef xDocShRef
= new ::sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED
, false, DocumentType::Impress
);
129 xDocShRef
->GetDoc()->EnableUndo(false);
130 bool bRet
= aPointer
.get()(rStream
, xDocShRef
->GetModel(), css::uno::Reference
<css::task::XStatusIndicator
>()) == 0;
132 xDocShRef
->DoClose();
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */