fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / hwpfilter / source / hwpreader.hxx
blobbb4e0d283101a17a8ce6e9d16bdc38738562a438
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX
21 #define INCLUDED_HWPFILTER_SOURCE_HWPREADER_HXX
22 #include <errno.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <sal/alloca.h>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/lang/XComponent.hpp>
29 #include <com/sun/star/io/XInputStream.hpp>
30 #include <com/sun/star/document/XFilter.hpp>
31 #include <com/sun/star/document/XImporter.hpp>
32 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
34 #include <com/sun/star/io/XActiveDataSink.hpp>
35 #include <com/sun/star/io/XActiveDataControl.hpp>
36 #include <com/sun/star/io/XStreamListener.hpp>
37 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
39 #include <cppuhelper/factory.hxx>
40 #include <cppuhelper/implbase1.hxx>
41 #include <cppuhelper/implbase2.hxx>
42 #include <cppuhelper/implbase4.hxx>
43 #include <cppuhelper/supportsservice.hxx>
44 #include <cppuhelper/weak.hxx>
46 using namespace ::cppu;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::io;
50 using namespace ::com::sun::star::registry;
51 using namespace ::com::sun::star::document;
52 using namespace ::com::sun::star::beans;
53 using namespace ::com::sun::star::xml::sax;
55 #include <assert.h>
57 #include <unotools/mediadescriptor.hxx>
59 #include "hwpfile.h"
60 #include "hcode.h"
61 #include "hbox.h"
62 #include "htags.h"
63 #include "hstream.hxx"
64 #include "drawdef.h"
65 #include "attributes.hxx"
67 #define IMPLEMENTATION_NAME "com.sun.comp.hwpimport.HwpImportFilter"
68 #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
69 #define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
70 #define WRITER_IMPORTER_NAME "com.sun.star.comp.Writer.XMLImporter"
72 struct HwpReaderPrivate;
73 /**
74 * This class implements the external Parser interface
76 class HwpReader : public WeakImplHelper1<XFilter>
79 public:
80 HwpReader();
81 virtual ~HwpReader();
83 public:
84 /**
85 * parseStream does Parser-startup initializations
87 virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue >& aDescriptor) throw (RuntimeException, std::exception) SAL_OVERRIDE;
88 virtual void SAL_CALL cancel() throw(RuntimeException, std::exception) SAL_OVERRIDE {}
89 void SAL_CALL setDocumentHandler(Reference< XDocumentHandler > xHandler)
91 m_rxDocumentHandler = xHandler;
93 private:
94 Reference< XDocumentHandler > m_rxDocumentHandler;
95 Reference< XAttributeList > rList;
96 AttributeListImpl *pList;
97 HWPFile hwpfile;
98 HwpReaderPrivate *d;
99 private:
100 /* -------- Document Parsing --------- */
101 void makeMeta();
102 void makeStyles();
103 void makeDrawMiscStyle(HWPDrawingObject *);
104 void makeAutoStyles();
105 void makeMasterStyles();
106 void makeBody();
108 void makeTextDecls();
110 /* -------- Paragraph Parsing --------- */
111 void parsePara(HWPPara *para, bool bParaStart = false);
112 void make_text_p0(HWPPara *para, bool bParaStart = false);
113 void make_text_p1(HWPPara *para, bool bParaStart = false);
114 void make_text_p3(HWPPara *para, bool bParaStart = false);
116 /* -------- rDocument->characters(x) --------- */
117 void makeChars(hchar_string & rStr);
119 /* -------- Special Char Parsing --------- */
120 void makeFieldCode(hchar_string & rStr, FieldCode *hbox); //6
121 void makeBookmark(Bookmark *hbox); //6
122 void makeDateFormat(DateCode *hbox); //7
123 void makeDateCode(DateCode *hbox); //8
124 void makeTab(Tab *hbox); //9
125 void makeTable(TxtBox *hbox);
126 void makeTextBox(TxtBox *hbox);
127 void makeFormula(TxtBox *hbox);
128 void makeHyperText(TxtBox *hbox);
129 void makePicture(Picture *hbox);
130 void makePictureDRAW(HWPDrawingObject *drawobj, Picture *hbox);
131 void makeLine(Line *hbox);
132 void makeHidden(Hidden *hbox);
133 void makeFootnote(Footnote *hbox);
134 void makeAutoNum(AutoNum *hbox);
135 void makeShowPageNum();
136 void makeMailMerge(MailMerge *hbox);
137 void makeOutline(Outline *hbox);
139 /* --------- Styles Parsing ------------ */
140 void makePageStyle();
141 void makeColumns(ColumnDef *);
142 void makeTStyle(CharShape *);
143 void makePStyle(ParaShape *);
144 void makeFStyle(FBoxStyle *);
145 void makeCaptionStyle(FBoxStyle *);
146 void makeDrawStyle(HWPDrawingObject *,FBoxStyle *);
147 void makeTableStyle(Table *);
148 void parseCharShape(CharShape *);
149 void parseParaShape(ParaShape *);
150 static char* getTStyleName(int, char *);
151 static char* getPStyleName(int, char *);
154 class HwpImportFilter : public WeakImplHelper4< XFilter, XImporter, XServiceInfo, XExtendedFilterDetection >
156 public:
157 HwpImportFilter(const Reference< XMultiServiceFactory >& rFact);
158 virtual ~HwpImportFilter();
160 public:
161 static Sequence< OUString > getSupportedServiceNames_Static() throw();
162 static OUString getImplementationName_Static() throw();
164 public:
165 // XFilter
166 virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor )
167 throw( RuntimeException, std::exception ) SAL_OVERRIDE;
168 virtual void SAL_CALL cancel() throw(RuntimeException, std::exception) SAL_OVERRIDE;
170 // XImporter
171 virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc)
172 throw( IllegalArgumentException, RuntimeException, std::exception ) SAL_OVERRIDE;
174 // XServiceInfo
175 OUString SAL_CALL getImplementationName() throw (RuntimeException, std::exception) SAL_OVERRIDE;
176 Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
177 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
179 //XExtendedFilterDetection
180 virtual OUString SAL_CALL detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rDescriptor ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
182 public:
183 Reference< XFilter > rFilter;
184 Reference< XImporter > rImporter;
187 Reference< XInterface > HwpImportFilter_CreateInstance(
188 const Reference< XMultiServiceFactory >& rSMgr ) throw( Exception )
190 HwpImportFilter *p = new HwpImportFilter( rSMgr );
192 return Reference< XInterface > ( (OWeakObject* )p );
195 Sequence< OUString > HwpImportFilter::getSupportedServiceNames_Static() throw ()
197 Sequence< OUString > aRet(1);
198 aRet.getArray()[0] = HwpImportFilter::getImplementationName_Static();
199 return aRet;
202 HwpImportFilter::HwpImportFilter(const Reference< XMultiServiceFactory >& rFact)
204 OUString sService( WRITER_IMPORTER_NAME );
205 try {
206 Reference< XDocumentHandler >
207 xHandler( rFact->createInstance( sService ), UNO_QUERY );
209 HwpReader *p = new HwpReader;
210 p->setDocumentHandler( xHandler );
212 Reference< XImporter > xImporter = Reference< XImporter >( xHandler, UNO_QUERY );
213 rImporter = xImporter;
214 Reference< XFilter > xFilter = Reference< XFilter >( p );
215 rFilter = xFilter;
217 catch( Exception & )
219 printf(" fail to instanciate %s\n", WRITER_IMPORTER_NAME );
220 exit( 1 );
224 HwpImportFilter::~HwpImportFilter()
228 sal_Bool HwpImportFilter::filter( const Sequence< PropertyValue >& aDescriptor )
229 throw( RuntimeException, std::exception )
231 // delegate to IchitaroImpoter
232 return rFilter->filter( aDescriptor );
235 void HwpImportFilter::cancel() throw(::com::sun::star::uno::RuntimeException, std::exception)
237 rFilter->cancel();
240 void HwpImportFilter::setTargetDocument( const Reference< XComponent >& xDoc )
241 throw( IllegalArgumentException, RuntimeException, std::exception )
243 // delegate
244 rImporter->setTargetDocument( xDoc );
247 OUString HwpImportFilter::getImplementationName_Static() throw()
249 return OUString( IMPLEMENTATION_NAME );
252 OUString HwpImportFilter::getImplementationName() throw(::com::sun::star::uno::RuntimeException, std::exception)
254 return OUString( IMPLEMENTATION_NAME );
257 sal_Bool HwpImportFilter::supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
259 return cppu::supportsService(this, ServiceName);
262 //XExtendedFilterDetection
263 OUString HwpImportFilter::detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rDescriptor ) throw (::com::sun::star::uno::RuntimeException, std::exception)
265 OUString sTypeName;
267 utl::MediaDescriptor aDescriptor(rDescriptor);
268 aDescriptor.addInputStream();
270 Reference< XInputStream > xInputStream(
271 aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY);
273 if (xInputStream.is())
275 Sequence< sal_Int8 > aData;
276 sal_Int32 nLen = HWPIDLen;
277 if (
278 nLen == xInputStream->readBytes(aData, nLen) &&
279 detect_hwp_version(reinterpret_cast<const char*>(aData.getConstArray()))
282 sTypeName = "writer_MIZI_Hwp_97";
286 return sTypeName;
289 Sequence< OUString> HwpImportFilter::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception)
291 Sequence < OUString > aRet(2);
292 OUString* pArray = aRet.getArray();
293 pArray[0] = SERVICE_NAME1;
294 pArray[1] = SERVICE_NAME2;
295 return aRet;
298 extern "C"
300 SAL_DLLPUBLIC_EXPORT void * SAL_CALL hwp_component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * )
302 void * pRet = 0;
304 if (pServiceManager )
306 Reference< XSingleServiceFactory > xRet;
307 Reference< XMultiServiceFactory > xSMgr = static_cast< XMultiServiceFactory * > ( pServiceManager );
309 OUString aImplementationName = OUString::createFromAscii( pImplName );
311 if (aImplementationName == IMPLEMENTATION_NAME )
313 xRet = createSingleFactory( xSMgr, aImplementationName,
314 HwpImportFilter_CreateInstance,
315 HwpImportFilter::getSupportedServiceNames_Static() );
317 if (xRet.is())
319 xRet->acquire();
320 pRet = xRet.get();
324 return pRet;
328 #endif
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */