Line data Source code
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
4 : *
5 : * This file is part of the LibreOffice project.
6 : *
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/.
10 : */
11 :
12 : #include <com/sun/star/uno/Reference.h>
13 : #include <cppuhelper/supportsservice.hxx>
14 :
15 : #include <libmwaw/libmwaw.hxx>
16 : #include <libodfgen/libodfgen.hxx>
17 :
18 : #include "MWAWDrawImportFilter.hxx"
19 :
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;
27 :
28 0 : static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
29 : {
30 0 : OdgGenerator exporter;
31 0 : exporter.addDocumentHandler(pHandler, streamType);
32 0 : return MWAWDocument::decodeGraphic(data, &exporter);
33 : }
34 :
35 0 : static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
36 : {
37 0 : OdsGenerator exporter;
38 0 : exporter.addDocumentHandler(pHandler, streamType);
39 0 : return MWAWDocument::decodeSpreadsheet(data, &exporter);
40 : }
41 :
42 23 : bool MWAWDrawImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdgGenerator &rGenerator, utl::MediaDescriptor &)
43 : {
44 23 : return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator);
45 : }
46 :
47 893 : bool MWAWDrawImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
48 : {
49 893 : rTypeName.clear();
50 :
51 893 : MWAWDocument::Type docType = MWAWDocument::MWAW_T_UNKNOWN;
52 893 : MWAWDocument::Kind docKind = MWAWDocument::MWAW_K_UNKNOWN;
53 893 : const MWAWDocument::Confidence confidence = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind);
54 :
55 893 : if (confidence == MWAWDocument::MWAW_C_EXCELLENT)
56 : {
57 23 : if (docKind == MWAWDocument::MWAW_K_DRAW || docKind == MWAWDocument::MWAW_K_PAINT)
58 : {
59 23 : switch (docType)
60 : {
61 : case MWAWDocument::MWAW_T_BEAGLEWORKS:
62 4 : rTypeName = "draw_Beagle_Works";
63 4 : break;
64 : case MWAWDocument::MWAW_T_CLARISWORKS:
65 4 : rTypeName = "draw_ClarisWorks";
66 4 : break;
67 : case MWAWDocument::MWAW_T_GREATWORKS:
68 2 : rTypeName = "draw_Great_Works";
69 2 : break;
70 : case MWAWDocument::MWAW_T_MACDRAFT:
71 1 : rTypeName = "draw_MacDraft";
72 1 : break;
73 : case MWAWDocument::MWAW_T_MACDRAW:
74 2 : rTypeName = "draw_MacDraw";
75 2 : break;
76 : case MWAWDocument::MWAW_T_MACDRAWPRO:
77 2 : rTypeName = "draw_MacDrawPro";
78 2 : break;
79 : case MWAWDocument::MWAW_T_MACPAINT:
80 3 : rTypeName = "draw_MacPaint";
81 3 : break;
82 : case MWAWDocument::MWAW_T_MICROSOFTWORKS:
83 2 : rTypeName = "draw_Mac_Works";
84 2 : break;
85 : case MWAWDocument::MWAW_T_SUPERPAINT:
86 2 : rTypeName = "draw_SuperPaint";
87 2 : break;
88 : case MWAWDocument::MWAW_T_RESERVED1:
89 1 : rTypeName = "draw_ClarisDraw";
90 1 : break;
91 :
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:
135 :
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:
145 : default:
146 0 : break;
147 : }
148 : }
149 : }
150 :
151 893 : return !rTypeName.isEmpty();
152 : }
153 :
154 23 : void MWAWDrawImportFilter::doRegisterHandlers(OdgGenerator &rGenerator)
155 : {
156 23 : rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
157 23 : rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods", &handleEmbeddedMWAWSpreadsheetObject);
158 23 : }
159 :
160 38 : OUString MWAWDrawImportFilter_getImplementationName()
161 : throw (RuntimeException)
162 : {
163 38 : return OUString("com.sun.star.comp.Draw.MWAWDrawImportFilter");
164 : }
165 :
166 7 : Sequence< OUString > SAL_CALL MWAWDrawImportFilter_getSupportedServiceNames()
167 : throw (RuntimeException)
168 : {
169 7 : Sequence < OUString > aRet(2);
170 7 : OUString *pArray = aRet.getArray();
171 7 : pArray[0] = "com.sun.star.document.ImportFilter";
172 7 : pArray[1] = "com.sun.star.document.ExtendedTypeDetection";
173 7 : return aRet;
174 : }
175 :
176 872 : Reference< XInterface > SAL_CALL MWAWDrawImportFilter_createInstance(const Reference< XComponentContext > &rContext)
177 : throw(Exception)
178 : {
179 872 : return static_cast<cppu::OWeakObject *>(new MWAWDrawImportFilter(rContext));
180 : }
181 :
182 : // XServiceInfo
183 1 : OUString SAL_CALL MWAWDrawImportFilter::getImplementationName()
184 : throw (RuntimeException, std::exception)
185 : {
186 1 : return MWAWDrawImportFilter_getImplementationName();
187 : }
188 0 : sal_Bool SAL_CALL MWAWDrawImportFilter::supportsService(const OUString &rServiceName)
189 : throw (RuntimeException, std::exception)
190 : {
191 0 : return cppu::supportsService(this, rServiceName);
192 : }
193 1 : Sequence< OUString > SAL_CALL MWAWDrawImportFilter::getSupportedServiceNames()
194 : throw (RuntimeException, std::exception)
195 : {
196 1 : return MWAWDrawImportFilter_getSupportedServiceNames();
197 : }
198 :
199 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|