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 _T602FILTER_HXX
21 : #define _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 : ::rtl::OUString getImplementationName()
57 : throw ( ::com::sun::star::uno::RuntimeException );
58 :
59 : ::com::sun::star::uno::Sequence < ::rtl::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 : sal_Bool OptionsDlg();
103 : ResMgr* getResMgr();
104 : rtl::OUString getResStr( sal_Int16 resid );
105 : void initLocale();
106 :
107 : ~T602ImportFilterDialog();
108 :
109 : // XExecutableDialog
110 : virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
111 : throw (::com::sun::star::uno::RuntimeException);
112 : virtual sal_Int16 SAL_CALL execute()
113 : throw (::com::sun::star::uno::RuntimeException);
114 :
115 : // XLocalizable
116 : virtual void SAL_CALL setLocale( const com::sun::star::lang::Locale& eLocale )
117 : throw(::com::sun::star::uno::RuntimeException);
118 : virtual com::sun::star::lang::Locale SAL_CALL getLocale()
119 : throw(::com::sun::star::uno::RuntimeException);
120 :
121 : // XServiceInfo
122 : virtual ::rtl::OUString SAL_CALL getImplementationName( )
123 : throw (::com::sun::star::uno::RuntimeException);
124 : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
125 : throw (::com::sun::star::uno::RuntimeException);
126 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
127 : throw (::com::sun::star::uno::RuntimeException);
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);
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);
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 : ::rtl::OUString msFilterName;
161 :
162 : SvXMLAttributeList *mpAttrList;
163 :
164 : tnode node; // START
165 :
166 : struct {
167 : sal_Int16 mt; // row for header
168 : sal_Int16 mb; // row for footer
169 : sal_Int16 tb; // tabs
170 : sal_Int16 ct; // encoding (0-kamenik, 1-latin2, 2-koi8)
171 : sal_Int16 pn; // from page number
172 : sal_Int16 lh; // linespacing 3-2x, 4-1.5x, 6-1x
173 : sal_Int16 lm; // left border
174 : sal_Int16 rm; // right border
175 : sal_Int16 pl; // page length
176 : } format602;
177 :
178 : // Initialisation constants - they are not changed during the conversion
179 :
180 : inistruct ini;
181 :
182 : // Font state - changes based on font
183 :
184 : struct {
185 : fonts nowfnt; // current font
186 : fonts oldfnt; // previous font
187 : bool uline; // underlined
188 : bool olduline; // previous value of uline (font change)
189 : } fst;
190 :
191 : // Paragraph state
192 :
193 : struct {
194 : sal_Int16 pars; // the number of line endings times linespacing on the current page
195 : bool comment; // in comments
196 : sal_Int16 wasspace; // 0 there was a space - for reformatting
197 : bool wasfdash; // 0 formatting dash
198 : bool ccafterln; // false
199 : bool willbeeop; // false
200 : bool waspar; // false
201 : } pst;
202 :
203 : void Reset602();
204 : unsigned char Readchar602();
205 : void Read602();
206 : void par602(bool endofpage);
207 : void inschr(unsigned char ch);
208 : void inschrdef(unsigned char ch);
209 : unsigned char Setformat602(char *cmd);
210 : sal_Int16 readnum(unsigned char *ch, bool show);
211 : tnode PointCmd602(unsigned char *ch);
212 : void setfnt(fonts fnt,bool mustwrite);
213 : void wrtfnt();
214 :
215 : sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
216 : throw (::com::sun::star::uno::RuntimeException);
217 :
218 : public:
219 : T602ImportFilter(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r );
220 : ~T602ImportFilter();
221 :
222 : // XFilter
223 : virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
224 : throw (::com::sun::star::uno::RuntimeException);
225 0 : virtual void SAL_CALL cancel( )
226 0 : throw (::com::sun::star::uno::RuntimeException) {};
227 :
228 : // XImporter
229 : virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
230 : throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
231 :
232 : // XExtendedTypeDetection
233 : virtual ::rtl::OUString SAL_CALL detect(
234 : com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor )
235 : throw( com::sun::star::uno::RuntimeException );
236 :
237 : // XInitialization
238 : virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
239 : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
240 :
241 : // XServiceInfo
242 : virtual ::rtl::OUString SAL_CALL getImplementationName( )
243 : throw (::com::sun::star::uno::RuntimeException);
244 : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
245 : throw (::com::sun::star::uno::RuntimeException);
246 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
247 : throw (::com::sun::star::uno::RuntimeException);
248 : };
249 :
250 : ::rtl::OUString T602ImportFilter_getImplementationName()
251 : throw ( ::com::sun::star::uno::RuntimeException );
252 :
253 : sal_Bool SAL_CALL T602ImportFilter_supportsService( const ::rtl::OUString& ServiceName )
254 : throw ( ::com::sun::star::uno::RuntimeException );
255 :
256 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilter_getSupportedServiceNames( )
257 : throw ( ::com::sun::star::uno::RuntimeException );
258 :
259 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
260 : SAL_CALL T602ImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
261 : throw ( ::com::sun::star::uno::Exception );
262 :
263 : ::rtl::OUString T602ImportFilterDialog_getImplementationName()
264 : throw ( ::com::sun::star::uno::RuntimeException );
265 :
266 : sal_Bool SAL_CALL T602ImportFilterDialog_supportsService( const ::rtl::OUString& ServiceName )
267 : throw ( ::com::sun::star::uno::RuntimeException );
268 :
269 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilterDialog_getSupportedServiceNames( )
270 : throw ( ::com::sun::star::uno::RuntimeException );
271 :
272 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
273 : SAL_CALL T602ImportFilterDialog_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
274 : throw ( ::com::sun::star::uno::Exception );
275 :
276 : }
277 :
278 : #endif
279 :
280 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|