xref: /trunk/main/sd/source/filter/cgm/sdcgmfilter.cxx (revision 79aad27f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include <osl/module.hxx>
28 #include <tools/urlobj.hxx>
29 #include <svl/itemset.hxx>
30 #include <sfx2/docfile.hxx>
31 #include <sfx2/docfilt.hxx>
32 #include <svx/xflclit.hxx>
33 #include <svx/xfillit0.hxx>
34 
35 #include "sdpage.hxx"
36 #include "drawdoc.hxx"
37 #include "sdcgmfilter.hxx"
38 
39 // -----------
40 // - Defines -
41 // -----------
42 
43 #define CGM_IMPORT_CGM		0x00000001
44 #define CGM_IMPORT_IM		0x00000002
45 
46 #define CGM_EXPORT_IMPRESS	0x00000100
47 #define CGM_EXPORT_META		0x00000200
48 #define CGM_EXPORT_COMMENT	0x00000400
49 
50 #define CGM_NO_PAD_BYTE 	0x00010000
51 #define CGM_BIG_ENDIAN		0x00020000
52 #define CGM_LITTLE_ENDIAN	0x00040000
53 
54 // --------------
55 // - Namespaces -
56 // --------------
57 
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::task;
60 using namespace ::com::sun::star::frame;
61 
62 // ------------
63 // - Typedefs -
64 // ------------
65 
66 typedef sal_uInt32 ( __LOADONCALLAPI *ImportCGM )( ::rtl::OUString&, Reference< XModel >&, sal_uInt32, Reference< XStatusIndicator >& );
67 typedef sal_Bool ( __LOADONCALLAPI *ExportCGM )( ::rtl::OUString&, Reference< XModel >&, Reference< XStatusIndicator >&, void* );
68 
69 // ---------------
70 // - SdPPTFilter -
71 // ---------------
72 
SdCGMFilter(SfxMedium & rMedium,::sd::DrawDocShell & rDocShell,sal_Bool bShowProgress)73 SdCGMFilter::SdCGMFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell, sal_Bool bShowProgress ) :
74 	SdFilter( rMedium, rDocShell, bShowProgress )
75 {
76 }
77 
78 // -----------------------------------------------------------------------------
79 
~SdCGMFilter()80 SdCGMFilter::~SdCGMFilter()
81 {
82 }
83 
84 // -----------------------------------------------------------------------------
85 
Import()86 sal_Bool SdCGMFilter::Import()
87 {
88 	::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
89 	sal_Bool		bRet = sal_False;
90 
91 	if( pLibrary && mxModel.is() )
92 	{
93 		ImportCGM		FncImportCGM = reinterpret_cast< ImportCGM >( pLibrary->getFunctionSymbol( ::rtl::OUString::createFromAscii( "ImportCGM" ) ) );
94 		::rtl::OUString	aFileURL( mrMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
95 		sal_uInt32			nRetValue;
96 
97 		if( mrDocument.GetPageCount() == 0L )
98 			mrDocument.CreateFirstPages();
99 
100 		CreateStatusIndicator();
101 		nRetValue = FncImportCGM( aFileURL, mxModel, CGM_IMPORT_CGM | CGM_BIG_ENDIAN | CGM_EXPORT_IMPRESS, mxStatusIndicator );
102 
103 		if( nRetValue )
104 		{
105 			bRet = sal_True;
106 
107 			if( ( nRetValue &~0xff000000 ) != 0xffffff )	// maybe the backgroundcolor is already white
108 			{												// so we must not set a master page
109 				mrDocument.StopWorkStartupDelay();
110                 SdPage* pSdPage = mrDocument.GetMasterSdPage(0, PK_STANDARD);
111 
112                 if(pSdPage)
113                 {
114 					// set PageFill to given color
115 				    const Color aColor((sal_uInt8)(nRetValue >> 16), (sal_uInt8)(nRetValue >> 8), (sal_uInt8)(nRetValue >> 16));
116 				    pSdPage->getSdrPageProperties().PutItem(XFillColorItem(String(), aColor));
117 				    pSdPage->getSdrPageProperties().PutItem(XFillStyleItem(XFILL_SOLID));
118                 }
119 			}
120 		}
121 	}
122 
123 	delete pLibrary;
124 
125 	return bRet;
126 }
127 
128 // -----------------------------------------------------------------------------
129 
Export()130 sal_Bool SdCGMFilter::Export()
131 {
132 	::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
133 	sal_Bool		bRet = sal_False;
134 
135 	if( pLibrary && mxModel.is() )
136 	{
137 		ExportCGM FncCGMExport = reinterpret_cast< ExportCGM >( pLibrary->getFunctionSymbol( ::rtl::OUString::createFromAscii( "ExportCGM" ) ) );
138 
139 		if( FncCGMExport )
140 		{
141 			::rtl::OUString aPhysicalName( mrMedium.GetPhysicalName() );
142 
143 			/* !!!
144 			if ( pViewShell && pViewShell->GetView() )
145 				pViewShell->GetView()->SdrEndTextEdit();
146 			*/
147 			CreateStatusIndicator();
148 			bRet = FncCGMExport( aPhysicalName, mxModel, mxStatusIndicator, NULL );
149 		}
150 	}
151 
152 	delete pLibrary;
153 
154 	return bRet;
155 }
156