Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <osl/module.hxx>
22 : #include <tools/urlobj.hxx>
23 : #include <svl/itemset.hxx>
24 : #include <sfx2/docfile.hxx>
25 : #include <sfx2/docfilt.hxx>
26 : #include <svx/xflclit.hxx>
27 : #include <svx/xfillit0.hxx>
28 :
29 : #include "sdpage.hxx"
30 : #include "drawdoc.hxx"
31 : #include "sdcgmfilter.hxx"
32 :
33 : #define CGM_IMPORT_CGM 0x00000001
34 :
35 : #define CGM_EXPORT_IMPRESS 0x00000100
36 :
37 : #define CGM_BIG_ENDIAN 0x00020000
38 :
39 : using namespace ::com::sun::star::uno;
40 : using namespace ::com::sun::star::task;
41 : using namespace ::com::sun::star::frame;
42 :
43 : typedef sal_uInt32 ( SAL_CALL *ImportCGMPointer )( OUString&, Reference< XModel >&, sal_uInt32, Reference< XStatusIndicator >& );
44 : typedef sal_Bool ( SAL_CALL *ExportCGMPointer )( OUString&, Reference< XModel >&, Reference< XStatusIndicator >&, void* );
45 :
46 : #ifdef DISABLE_DYNLOADING
47 :
48 : extern "C" sal_uInt32 ImportCGM( OUString&, Reference< XModel >&, sal_uInt32, Reference< XStatusIndicator >& );
49 :
50 : #endif
51 :
52 0 : SdCGMFilter::SdCGMFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell, sal_Bool bShowProgress ) :
53 0 : SdFilter( rMedium, rDocShell, bShowProgress )
54 : {
55 0 : }
56 :
57 0 : SdCGMFilter::~SdCGMFilter()
58 : {
59 0 : }
60 :
61 0 : sal_Bool SdCGMFilter::Import()
62 : {
63 : #ifndef DISABLE_DYNLOADING
64 0 : ::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
65 : #endif
66 0 : sal_Bool bRet = sal_False;
67 :
68 0 : if(
69 : #ifndef DISABLE_DYNLOADING
70 0 : pLibrary &&
71 : #endif
72 0 : mxModel.is() )
73 : {
74 : #ifndef DISABLE_DYNLOADING
75 0 : ImportCGMPointer FncImportCGM = reinterpret_cast< ImportCGMPointer >( pLibrary->getFunctionSymbol( "ImportCGM" ) );
76 : #else
77 : ImportCGMPointer FncImportCGM = ImportCGM;
78 : #endif
79 0 : OUString aFileURL( mrMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
80 : sal_uInt32 nRetValue;
81 :
82 0 : if( mrDocument.GetPageCount() == 0L )
83 0 : mrDocument.CreateFirstPages();
84 :
85 0 : CreateStatusIndicator();
86 0 : nRetValue = FncImportCGM( aFileURL, mxModel, CGM_IMPORT_CGM | CGM_BIG_ENDIAN | CGM_EXPORT_IMPRESS, mxStatusIndicator );
87 :
88 0 : if( nRetValue )
89 : {
90 0 : bRet = sal_True;
91 :
92 0 : if( ( nRetValue &~0xff000000 ) != 0xffffff ) // maybe the backgroundcolor is already white
93 : { // so we must not set a master page
94 0 : mrDocument.StopWorkStartupDelay();
95 0 : SdPage* pSdPage = mrDocument.GetMasterSdPage(0, PK_STANDARD);
96 :
97 0 : if(pSdPage)
98 : {
99 : // set PageFill to given color
100 0 : const Color aColor((sal_uInt8)(nRetValue >> 16), (sal_uInt8)(nRetValue >> 8), (sal_uInt8)(nRetValue >> 16));
101 0 : pSdPage->getSdrPageProperties().PutItem(XFillColorItem(OUString(), aColor));
102 0 : pSdPage->getSdrPageProperties().PutItem(XFillStyleItem(XFILL_SOLID));
103 : }
104 : }
105 0 : }
106 : }
107 : #ifndef DISABLE_DYNLOADING
108 0 : delete pLibrary;
109 : #endif
110 0 : return bRet;
111 : }
112 :
113 0 : sal_Bool SdCGMFilter::Export()
114 : {
115 : #ifdef DISABLE_DYNLOADING
116 : // No ExportCGM function exists(!)
117 : return sal_False;
118 : #else
119 0 : ::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
120 0 : sal_Bool bRet = sal_False;
121 :
122 0 : if( pLibrary && mxModel.is() )
123 : {
124 0 : ExportCGMPointer FncCGMExport = reinterpret_cast< ExportCGMPointer >( pLibrary->getFunctionSymbol( "ExportCGM" ) );
125 :
126 0 : if( FncCGMExport )
127 : {
128 0 : OUString aPhysicalName( mrMedium.GetPhysicalName() );
129 :
130 0 : CreateStatusIndicator();
131 0 : bRet = FncCGMExport( aPhysicalName, mxModel, mxStatusIndicator, NULL );
132 : }
133 : }
134 :
135 0 : delete pLibrary;
136 0 : return bRet;
137 : #endif
138 : }
139 :
140 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|