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 : #ifndef INCLUDED_FILTER_SOURCE_T602_T602FILTER_HXX
21 : #define INCLUDED_FILTER_SOURCE_T602_T602FILTER_HXX
22 :
23 : #include <com/sun/star/document/XFilter.hpp>
24 : #include <com/sun/star/document/XImporter.hpp>
25 : #include <com/sun/star/document/XExtendedFilterDetection.hpp>
26 : #include <com/sun/star/io/XInputStream.hpp>
27 : #include <com/sun/star/lang/XInitialization.hpp>
28 : #include <com/sun/star/lang/XServiceInfo.hpp>
29 : #include <com/sun/star/lang/XLocalizable.hpp>
30 : #include <com/sun/star/beans/XPropertyAccess.hpp>
31 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
32 : #include <cppuhelper/implbase5.hxx>
33 : #include <cppuhelper/implbase4.hxx>
34 : #include <xmloff/attrlist.hxx>
35 : #include <tools/resmgr.hxx>
36 :
37 : namespace T602ImportFilter {
38 :
39 : typedef enum {L2,KAM,KOI} tcode;
40 :
41 : typedef enum {
42 : standard, // default
43 : fat, // bold
44 : cursive, // italic
45 : bold, // wide
46 : tall, // high
47 : big, // big
48 : lindex, // lower index
49 : hindex, // upper index
50 : err, // not set yet
51 : chngul // change underline
52 : } fonts;
53 :
54 : typedef enum {START,READCH,EOL,POCMD,EXPCMD,SETCMD,SETCH,WRITE,EEND,QUIT} tnode;
55 :
56 : OUString getImplementationName()
57 : throw ( ::com::sun::star::uno::RuntimeException );
58 :
59 : ::com::sun::star::uno::Sequence < OUString > getSupportedServiceNames()
60 : throw ( ::com::sun::star::uno::RuntimeException );
61 :
62 :
63 : ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > SAL_CALL
64 : CreateInstance( const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &r)
65 : throw ( ::com::sun::star::uno::Exception );
66 :
67 :
68 :
69 : // class T602ImportFilter
70 :
71 :
72 : struct inistruct
73 : {
74 : bool showcomm; // true show comment lines
75 : bool forcecode; // false the user has changed the encoding with something else than @CT
76 : tcode xcode; // KAM encoding set - forced
77 : bool ruscode; // false Russian tables turned on
78 : bool reformatpars; // false Reformat paragraphs (whitespaces and line breaks)
79 : sal_Int16 fontsize; // font size in points
80 :
81 0 : inistruct()
82 : : showcomm( true )
83 : , forcecode( false )
84 : , xcode ( KAM )
85 : , ruscode ( false )
86 : , reformatpars ( false )
87 0 : , fontsize (10)
88 : {
89 0 : };
90 : };
91 :
92 : class T602ImportFilterDialog : public cppu::WeakImplHelper4 <
93 : com::sun::star::ui::dialogs::XExecutableDialog,
94 : com::sun::star::lang::XLocalizable,
95 : com::sun::star::lang::XServiceInfo,
96 : com::sun::star::beans::XPropertyAccess
97 : >
98 : {
99 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
100 : com::sun::star::lang::Locale meLocale;
101 : ResMgr *mpResMgr;
102 : bool OptionsDlg();
103 : ResMgr* getResMgr();
104 : OUString getResStr( sal_Int16 resid );
105 : void initLocale();
106 :
107 : virtual ~T602ImportFilterDialog();
108 :
109 : // XExecutableDialog
110 : virtual void SAL_CALL setTitle( const OUString& aTitle )
111 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
112 : virtual sal_Int16 SAL_CALL execute()
113 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
114 :
115 : // XLocalizable
116 : virtual void SAL_CALL setLocale( const com::sun::star::lang::Locale& eLocale )
117 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
118 : virtual com::sun::star::lang::Locale SAL_CALL getLocale()
119 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
120 :
121 : // XServiceInfo
122 : virtual OUString SAL_CALL getImplementationName( )
123 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
124 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
125 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
126 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( )
127 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
128 :
129 : // XPropertyAccess
130 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
131 : SAL_CALL getPropertyValues() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
132 : virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence<
133 : ::com::sun::star::beans::PropertyValue >& aProps )
134 : throw (::com::sun::star::beans::UnknownPropertyException,
135 : ::com::sun::star::beans::PropertyVetoException,
136 : ::com::sun::star::lang::IllegalArgumentException,
137 : ::com::sun::star::lang::WrappedTargetException,
138 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 :
140 : public:
141 : T602ImportFilterDialog(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r );
142 :
143 : };
144 :
145 :
146 : class T602ImportFilter : public cppu::WeakImplHelper5 <
147 : com::sun::star::document::XFilter,
148 : com::sun::star::document::XImporter,
149 : com::sun::star::document::XExtendedFilterDetection,
150 : com::sun::star::lang::XInitialization,
151 : com::sun::star::lang::XServiceInfo
152 : >
153 : {
154 : private:
155 : // ::com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream;
156 : ::com::sun::star::uno::Reference<com::sun::star::xml::sax::XDocumentHandler> mxHandler;
157 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
158 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc;
159 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > mxInputStream;
160 : OUString msFilterName;
161 :
162 : SvXMLAttributeList *mpAttrList;
163 :
164 : tnode node; // START
165 :
166 : struct format602struct
167 : {
168 : sal_Int16 mt; // row for header
169 : sal_Int16 mb; // row for footer
170 : sal_Int16 tb; // tabs
171 : sal_Int16 ct; // encoding (0-kamenik, 1-latin2, 2-koi8)
172 : sal_Int16 pn; // from page number
173 : sal_Int16 lh; // linespacing 3-2x, 4-1.5x, 6-1x
174 : sal_Int16 lm; // left border
175 : sal_Int16 rm; // right border
176 : sal_Int16 pl; // page length
177 0 : format602struct()
178 : : mt(0)
179 : , mb(0)
180 : , tb(0)
181 : , ct(0)
182 : , pn(0)
183 : , lh(0)
184 : , lm(0)
185 : , rm(0)
186 0 : , pl(0)
187 : {
188 0 : }
189 : };
190 :
191 : format602struct format602;
192 :
193 : // Initialisation constants - they are not changed during the conversion
194 :
195 : inistruct ini;
196 :
197 : // Font state - changes based on font
198 :
199 : struct fststruct
200 : {
201 : fonts nowfnt; // current font
202 : fonts oldfnt; // previous font
203 : bool uline; // underlined
204 : bool olduline; // previous value of uline (font change)
205 0 : fststruct()
206 : : nowfnt(standard)
207 : , oldfnt(standard)
208 : , uline(false)
209 0 : , olduline(false)
210 : {
211 0 : }
212 : };
213 :
214 : fststruct fst;
215 :
216 : // Paragraph state
217 :
218 : struct pststruct
219 : {
220 : sal_Int16 pars; // the number of line endings times linespacing on the current page
221 : bool comment; // in comments
222 : sal_Int16 wasspace; // 0 there was a space - for reformatting
223 : bool wasfdash; // 0 formatting dash
224 : bool ccafterln; // false
225 : bool willbeeop; // false
226 : bool waspar; // false
227 0 : pststruct()
228 : : pars(0)
229 : , comment(false)
230 : , wasspace(0)
231 : , wasfdash(false)
232 : , ccafterln(false)
233 : , willbeeop(false)
234 0 : , waspar(false)
235 : {
236 0 : }
237 : };
238 :
239 : pststruct pst;
240 :
241 : void Reset602();
242 : unsigned char Readchar602();
243 : void Read602();
244 : void par602(bool endofpage);
245 : void inschr(unsigned char ch);
246 : void inschrdef(unsigned char ch);
247 : unsigned char Setformat602(char *cmd);
248 : sal_Int16 readnum(unsigned char *ch, bool show);
249 : tnode PointCmd602(unsigned char *ch);
250 : void setfnt(fonts fnt,bool mustwrite);
251 : void wrtfnt();
252 :
253 : bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
254 : throw (::com::sun::star::uno::RuntimeException);
255 :
256 : public:
257 : T602ImportFilter(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r );
258 : virtual ~T602ImportFilter();
259 :
260 : // XFilter
261 : virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
262 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
263 0 : virtual void SAL_CALL cancel( )
264 0 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE {};
265 :
266 : // XImporter
267 : virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
268 : throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
269 :
270 : // XExtendedTypeDetection
271 : virtual OUString SAL_CALL detect(
272 : com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor )
273 : throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
274 :
275 : // XInitialization
276 : virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
277 : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
278 :
279 : // XServiceInfo
280 : virtual OUString SAL_CALL getImplementationName( )
281 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
282 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
283 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
284 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( )
285 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
286 : };
287 :
288 : OUString T602ImportFilter_getImplementationName()
289 : throw ( ::com::sun::star::uno::RuntimeException );
290 :
291 : bool SAL_CALL T602ImportFilter_supportsService( const OUString& ServiceName )
292 : throw ( ::com::sun::star::uno::RuntimeException );
293 :
294 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL T602ImportFilter_getSupportedServiceNames( )
295 : throw ( ::com::sun::star::uno::RuntimeException );
296 :
297 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
298 : SAL_CALL T602ImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
299 : throw ( ::com::sun::star::uno::Exception );
300 :
301 : OUString T602ImportFilterDialog_getImplementationName()
302 : throw ( ::com::sun::star::uno::RuntimeException );
303 :
304 : bool SAL_CALL T602ImportFilterDialog_supportsService( const OUString& ServiceName )
305 : throw ( ::com::sun::star::uno::RuntimeException );
306 :
307 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL T602ImportFilterDialog_getSupportedServiceNames( )
308 : throw ( ::com::sun::star::uno::RuntimeException );
309 :
310 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
311 : SAL_CALL T602ImportFilterDialog_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
312 : throw ( ::com::sun::star::uno::Exception );
313 :
314 : }
315 :
316 : #endif
317 :
318 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|