1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* MWAWDrawImportFilter: Sets up the filter, and calls DocumentCollector
3 * to do the actual filtering
5 * This file is part of the LibreOffice project.
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include <com/sun/star/uno/Reference.h>
13 #include <cppuhelper/supportsservice.hxx>
15 #include <libmwaw/libmwaw.hxx>
16 #include <libodfgen/libodfgen.hxx>
18 #include "MWAWDrawImportFilter.hxx"
20 using com::sun::star::uno::Sequence
;
21 using com::sun::star::uno::Reference
;
22 using com::sun::star::uno::Any
;
23 using com::sun::star::uno::XInterface
;
24 using com::sun::star::uno::Exception
;
25 using com::sun::star::uno::RuntimeException
;
26 using com::sun::star::uno::XComponentContext
;
28 static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData
&data
, OdfDocumentHandler
*pHandler
, const OdfStreamType streamType
)
30 OdgGenerator exporter
;
31 exporter
.addDocumentHandler(pHandler
, streamType
);
32 return MWAWDocument::decodeGraphic(data
, &exporter
);
35 static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData
&data
, OdfDocumentHandler
*pHandler
, const OdfStreamType streamType
)
37 OdsGenerator exporter
;
38 exporter
.addDocumentHandler(pHandler
, streamType
);
39 return MWAWDocument::decodeSpreadsheet(data
, &exporter
);
42 bool MWAWDrawImportFilter::doImportDocument(librevenge::RVNGInputStream
&rInput
, OdgGenerator
&rGenerator
, utl::MediaDescriptor
&)
44 return MWAWDocument::MWAW_R_OK
== MWAWDocument::parse(&rInput
, &rGenerator
);
47 bool MWAWDrawImportFilter::doDetectFormat(librevenge::RVNGInputStream
&rInput
, OUString
&rTypeName
)
51 MWAWDocument::Type docType
= MWAWDocument::MWAW_T_UNKNOWN
;
52 MWAWDocument::Kind docKind
= MWAWDocument::MWAW_K_UNKNOWN
;
53 const MWAWDocument::Confidence confidence
= MWAWDocument::isFileFormatSupported(&rInput
, docType
, docKind
);
55 if (confidence
== MWAWDocument::MWAW_C_EXCELLENT
)
57 if (docKind
== MWAWDocument::MWAW_K_DRAW
|| docKind
== MWAWDocument::MWAW_K_PAINT
)
61 case MWAWDocument::MWAW_T_BEAGLEWORKS
:
62 rTypeName
= "draw_Beagle_Works";
64 case MWAWDocument::MWAW_T_CLARISWORKS
:
65 rTypeName
= "draw_ClarisWorks";
67 case MWAWDocument::MWAW_T_GREATWORKS
:
68 rTypeName
= "draw_Great_Works";
70 case MWAWDocument::MWAW_T_MACDRAFT
:
71 rTypeName
= "draw_MacDraft";
73 case MWAWDocument::MWAW_T_MACDRAW
:
74 rTypeName
= "draw_MacDraw";
76 case MWAWDocument::MWAW_T_MACDRAWPRO
:
77 rTypeName
= "draw_MacDrawPro";
79 case MWAWDocument::MWAW_T_MACPAINT
:
80 rTypeName
= "draw_MacPaint";
82 case MWAWDocument::MWAW_T_MICROSOFTWORKS
:
83 rTypeName
= "draw_Mac_Works";
85 case MWAWDocument::MWAW_T_SUPERPAINT
:
86 rTypeName
= "draw_SuperPaint";
88 case MWAWDocument::MWAW_T_RESERVED1
:
89 rTypeName
= "draw_ClarisDraw";
92 case MWAWDocument::MWAW_T_ACTA
:
93 case MWAWDocument::MWAW_T_ADOBEILLUSTRATOR
:
94 case MWAWDocument::MWAW_T_CLARISRESOLVE
:
95 case MWAWDocument::MWAW_T_DBASE
:
96 case MWAWDocument::MWAW_T_DOCMAKER
:
97 case MWAWDocument::MWAW_T_EDOC
:
98 case MWAWDocument::MWAW_T_FAMILYTREEMAKER
:
99 case MWAWDocument::MWAW_T_FILEMAKER
:
100 case MWAWDocument::MWAW_T_FOXBASE
:
101 case MWAWDocument::MWAW_T_FRAMEMAKER
:
102 case MWAWDocument::MWAW_T_FULLIMPACT
:
103 case MWAWDocument::MWAW_T_FULLPAINT
:
104 case MWAWDocument::MWAW_T_FULLWRITE
:
105 case MWAWDocument::MWAW_T_INFOGENIE
:
106 case MWAWDocument::MWAW_T_KALEIDAGRAPH
:
107 case MWAWDocument::MWAW_T_HANMACWORDJ
:
108 case MWAWDocument::MWAW_T_HANMACWORDK
:
109 case MWAWDocument::MWAW_T_LIGHTWAYTEXT
:
110 case MWAWDocument::MWAW_T_MACDOC
:
111 case MWAWDocument::MWAW_T_MACWRITE
:
112 case MWAWDocument::MWAW_T_MACWRITEPRO
:
113 case MWAWDocument::MWAW_T_MARINERWRITE
:
114 case MWAWDocument::MWAW_T_MINDWRITE
:
115 case MWAWDocument::MWAW_T_MICROSOFTFILE
:
116 case MWAWDocument::MWAW_T_MICROSOFTMULTIPLAN
:
117 case MWAWDocument::MWAW_T_MICROSOFTWORD
:
118 case MWAWDocument::MWAW_T_MORE
:
119 case MWAWDocument::MWAW_T_NISUSWRITER
:
120 case MWAWDocument::MWAW_T_OVERVUE
:
121 case MWAWDocument::MWAW_T_PAGEMAKER
:
122 case MWAWDocument::MWAW_T_PIXELPAINT
:
123 case MWAWDocument::MWAW_T_RAGTIME
:
124 case MWAWDocument::MWAW_T_READYSETGO
:
125 case MWAWDocument::MWAW_T_SYMPOSIUM
:
126 case MWAWDocument::MWAW_T_TEACHTEXT
:
127 case MWAWDocument::MWAW_T_TEXEDIT
:
128 case MWAWDocument::MWAW_T_TRAPEZE
:
129 case MWAWDocument::MWAW_T_WINGZ
:
130 case MWAWDocument::MWAW_T_WRITENOW
:
131 case MWAWDocument::MWAW_T_WRITERPLUS
:
132 case MWAWDocument::MWAW_T_XPRESS
:
133 case MWAWDocument::MWAW_T_ZWRITE
:
134 case MWAWDocument::MWAW_T_4DIMENSION
:
136 case MWAWDocument::MWAW_T_RESERVED2
:
137 case MWAWDocument::MWAW_T_RESERVED3
:
138 case MWAWDocument::MWAW_T_RESERVED4
:
139 case MWAWDocument::MWAW_T_RESERVED5
:
140 case MWAWDocument::MWAW_T_RESERVED6
:
141 case MWAWDocument::MWAW_T_RESERVED7
:
142 case MWAWDocument::MWAW_T_RESERVED8
:
143 case MWAWDocument::MWAW_T_RESERVED9
:
144 case MWAWDocument::MWAW_T_UNKNOWN
:
151 return !rTypeName
.isEmpty();
154 void MWAWDrawImportFilter::doRegisterHandlers(OdgGenerator
&rGenerator
)
156 rGenerator
.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject
);
157 rGenerator
.registerEmbeddedObjectHandler("image/mwaw-ods", &handleEmbeddedMWAWSpreadsheetObject
);
160 OUString
MWAWDrawImportFilter_getImplementationName()
161 throw (RuntimeException
)
163 return OUString("com.sun.star.comp.Draw.MWAWDrawImportFilter");
166 Sequence
< OUString
> SAL_CALL
MWAWDrawImportFilter_getSupportedServiceNames()
167 throw (RuntimeException
)
169 Sequence
< OUString
> aRet(2);
170 OUString
*pArray
= aRet
.getArray();
171 pArray
[0] = "com.sun.star.document.ImportFilter";
172 pArray
[1] = "com.sun.star.document.ExtendedTypeDetection";
176 Reference
< XInterface
> SAL_CALL
MWAWDrawImportFilter_createInstance(const Reference
< XComponentContext
> &rContext
)
179 return (cppu::OWeakObject
*) new MWAWDrawImportFilter(rContext
);
183 OUString SAL_CALL
MWAWDrawImportFilter::getImplementationName()
184 throw (RuntimeException
, std::exception
)
186 return MWAWDrawImportFilter_getImplementationName();
188 sal_Bool SAL_CALL
MWAWDrawImportFilter::supportsService(const OUString
&rServiceName
)
189 throw (RuntimeException
, std::exception
)
191 return cppu::supportsService(this, rServiceName
);
193 Sequence
< OUString
> SAL_CALL
MWAWDrawImportFilter::getSupportedServiceNames()
194 throw (RuntimeException
, std::exception
)
196 return MWAWDrawImportFilter_getSupportedServiceNames();
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */