1*22e87013SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*22e87013SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*22e87013SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*22e87013SAndrew Rist * distributed with this work for additional information 6*22e87013SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*22e87013SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*22e87013SAndrew Rist * "License"); you may not use this file except in compliance 9*22e87013SAndrew Rist * with the License. You may obtain a copy of the License at 10*22e87013SAndrew Rist * 11*22e87013SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*22e87013SAndrew Rist * 13*22e87013SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*22e87013SAndrew Rist * software distributed under the License is distributed on an 15*22e87013SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*22e87013SAndrew Rist * KIND, either express or implied. See the License for the 17*22e87013SAndrew Rist * specific language governing permissions and limitations 18*22e87013SAndrew Rist * under the License. 19*22e87013SAndrew Rist * 20*22e87013SAndrew Rist *************************************************************/ 21*22e87013SAndrew Rist 22*22e87013SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _T602FILTER_HXX 25cdf0e10cSrcweir #define _T602FILTER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/document/XFilter.hpp> 28cdf0e10cSrcweir #include <com/sun/star/document/XImporter.hpp> 29cdf0e10cSrcweir #include <com/sun/star/document/XExtendedFilterDetection.hpp> 30cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 31cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 32cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 33cdf0e10cSrcweir #include <com/sun/star/lang/XLocalizable.hpp> 34cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyAccess.hpp> 35cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 36cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx> 37cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx> 38cdf0e10cSrcweir #include <xmloff/attrlist.hxx> 39cdf0e10cSrcweir #include <tools/resmgr.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir namespace T602ImportFilter { 42cdf0e10cSrcweir 43cdf0e10cSrcweir typedef enum {L2,KAM,KOI} tcode; 44cdf0e10cSrcweir 45cdf0e10cSrcweir typedef enum { 46cdf0e10cSrcweir standard, // default 47cdf0e10cSrcweir fat, // bold 48cdf0e10cSrcweir cursive, // italic 49cdf0e10cSrcweir bold, // wide 50cdf0e10cSrcweir tall, // high 51cdf0e10cSrcweir big, // big 52cdf0e10cSrcweir lindex, // lower index 53cdf0e10cSrcweir hindex, // upper index 54cdf0e10cSrcweir err, // not set yet 55cdf0e10cSrcweir chngul // change underline 56cdf0e10cSrcweir } fonts; 57cdf0e10cSrcweir 58cdf0e10cSrcweir typedef enum {START,READCH,EOL,POCMD,EXPCMD,SETCMD,SETCH,WRITE,EEND,QUIT} tnode; 59cdf0e10cSrcweir 60cdf0e10cSrcweir ::rtl::OUString getImplementationName() 61cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException ); 62cdf0e10cSrcweir 63cdf0e10cSrcweir ::com::sun::star::uno::Sequence < ::rtl::OUString > getSupportedServiceNames() 64cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException ); 65cdf0e10cSrcweir 66cdf0e10cSrcweir 67cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > SAL_CALL 68cdf0e10cSrcweir CreateInstance( const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &r) 69cdf0e10cSrcweir throw ( ::com::sun::star::uno::Exception ); 70cdf0e10cSrcweir 71cdf0e10cSrcweir 72cdf0e10cSrcweir // 73cdf0e10cSrcweir // class T602ImportFilter 74cdf0e10cSrcweir // 75cdf0e10cSrcweir 76cdf0e10cSrcweir struct inistruct 77cdf0e10cSrcweir { 78cdf0e10cSrcweir bool showcomm; // true show comment lines 79cdf0e10cSrcweir bool forcecode; // false the user has changed the encoding with something else than @CT 80cdf0e10cSrcweir tcode xcode; // KAM encoding set - forced 81cdf0e10cSrcweir bool ruscode; // false Russian tables turned on 82cdf0e10cSrcweir bool reformatpars; // false Reformat paragraphs (whitespaces and line breaks) 83cdf0e10cSrcweir sal_Int16 fontsize; // font size in points 84cdf0e10cSrcweir inistructT602ImportFilter::inistruct85cdf0e10cSrcweir inistruct() 86cdf0e10cSrcweir : showcomm( true ) 87cdf0e10cSrcweir , forcecode( false ) 88cdf0e10cSrcweir , xcode ( KAM ) 89cdf0e10cSrcweir , ruscode ( false ) 90cdf0e10cSrcweir , reformatpars ( false ) 91cdf0e10cSrcweir , fontsize (10) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir }; 94cdf0e10cSrcweir }; 95cdf0e10cSrcweir 96cdf0e10cSrcweir class T602ImportFilterDialog : public cppu::WeakImplHelper4 < 97cdf0e10cSrcweir com::sun::star::ui::dialogs::XExecutableDialog, 98cdf0e10cSrcweir com::sun::star::lang::XLocalizable, 99cdf0e10cSrcweir com::sun::star::lang::XServiceInfo, 100cdf0e10cSrcweir com::sun::star::beans::XPropertyAccess 101cdf0e10cSrcweir > 102cdf0e10cSrcweir { 103cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; 104cdf0e10cSrcweir com::sun::star::lang::Locale meLocale; 105cdf0e10cSrcweir ResMgr *mpResMgr; 106cdf0e10cSrcweir sal_Bool OptionsDlg(); 107cdf0e10cSrcweir ResMgr* getResMgr(); 108cdf0e10cSrcweir rtl::OUString getResStr( sal_Int16 resid ); 109cdf0e10cSrcweir void initLocale(); 110cdf0e10cSrcweir 111cdf0e10cSrcweir ~T602ImportFilterDialog(); 112cdf0e10cSrcweir 113cdf0e10cSrcweir // XExecutableDialog 114cdf0e10cSrcweir virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) 115cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 116cdf0e10cSrcweir virtual sal_Int16 SAL_CALL execute() 117cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 118cdf0e10cSrcweir 119cdf0e10cSrcweir // XLocalizable 120cdf0e10cSrcweir virtual void SAL_CALL setLocale( const com::sun::star::lang::Locale& eLocale ) 121cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 122cdf0e10cSrcweir virtual com::sun::star::lang::Locale SAL_CALL getLocale() 123cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 124cdf0e10cSrcweir 125cdf0e10cSrcweir // XServiceInfo 126cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) 127cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 128cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 129cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 130cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) 131cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 132cdf0e10cSrcweir 133cdf0e10cSrcweir // XPropertyAccess 134cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > 135cdf0e10cSrcweir SAL_CALL getPropertyValues() throw (::com::sun::star::uno::RuntimeException); 136cdf0e10cSrcweir virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< 137cdf0e10cSrcweir ::com::sun::star::beans::PropertyValue >& aProps ) 138cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, 139cdf0e10cSrcweir ::com::sun::star::beans::PropertyVetoException, 140cdf0e10cSrcweir ::com::sun::star::lang::IllegalArgumentException, 141cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, 142cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 143cdf0e10cSrcweir 144cdf0e10cSrcweir public: 145cdf0e10cSrcweir T602ImportFilterDialog(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r ); 146cdf0e10cSrcweir 147cdf0e10cSrcweir }; 148cdf0e10cSrcweir 149cdf0e10cSrcweir 150cdf0e10cSrcweir class T602ImportFilter : public cppu::WeakImplHelper5 < 151cdf0e10cSrcweir com::sun::star::document::XFilter, 152cdf0e10cSrcweir com::sun::star::document::XImporter, 153cdf0e10cSrcweir com::sun::star::document::XExtendedFilterDetection, 154cdf0e10cSrcweir com::sun::star::lang::XInitialization, 155cdf0e10cSrcweir com::sun::star::lang::XServiceInfo 156cdf0e10cSrcweir > 157cdf0e10cSrcweir { 158cdf0e10cSrcweir private: 159cdf0e10cSrcweir // ::com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream; 160cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::xml::sax::XDocumentHandler> mxHandler; 161cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; 162cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc; 163cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > mxInputStream; 164cdf0e10cSrcweir ::rtl::OUString msFilterName; 165cdf0e10cSrcweir 166cdf0e10cSrcweir SvXMLAttributeList *mpAttrList; 167cdf0e10cSrcweir 168cdf0e10cSrcweir tnode node; // START 169cdf0e10cSrcweir 170cdf0e10cSrcweir struct { 171cdf0e10cSrcweir sal_Int16 mt; // row for header 172cdf0e10cSrcweir sal_Int16 mb; // row for footer 173cdf0e10cSrcweir sal_Int16 tb; // tabs 174cdf0e10cSrcweir sal_Int16 ct; // encoding (0-kamenik, 1-latin2, 2-koi8) 175cdf0e10cSrcweir sal_Int16 pn; // from page number 176cdf0e10cSrcweir sal_Int16 lh; // linespacing 3-2x, 4-1.5x, 6-1x 177cdf0e10cSrcweir sal_Int16 lm; // left border 178cdf0e10cSrcweir sal_Int16 rm; // right border 179cdf0e10cSrcweir sal_Int16 pl; // page length 180cdf0e10cSrcweir } format602; 181cdf0e10cSrcweir 182cdf0e10cSrcweir // Initialisation constants - they are not changed during the conversion 183cdf0e10cSrcweir 184cdf0e10cSrcweir inistruct ini; 185cdf0e10cSrcweir 186cdf0e10cSrcweir // Font state - changes based on font 187cdf0e10cSrcweir 188cdf0e10cSrcweir struct { 189cdf0e10cSrcweir fonts nowfnt; // current font 190cdf0e10cSrcweir fonts oldfnt; // previous font 191cdf0e10cSrcweir bool uline; // underlined 192cdf0e10cSrcweir bool olduline; // previous value of uline (font change) 193cdf0e10cSrcweir } fst; 194cdf0e10cSrcweir 195cdf0e10cSrcweir // Paragraph state 196cdf0e10cSrcweir 197cdf0e10cSrcweir struct { 198cdf0e10cSrcweir sal_Int16 pars; // the number of line endings times linespacing on the current page 199cdf0e10cSrcweir bool comment; // in comments 200cdf0e10cSrcweir sal_Int16 wasspace; // 0 there was a space - for reformatting 201cdf0e10cSrcweir bool wasfdash; // 0 formatting dash 202cdf0e10cSrcweir bool ccafterln; // false 203cdf0e10cSrcweir bool willbeeop; // false 204cdf0e10cSrcweir bool waspar; // false 205cdf0e10cSrcweir } pst; 206cdf0e10cSrcweir 207cdf0e10cSrcweir void Reset602(); 208cdf0e10cSrcweir unsigned char Readchar602(); 209cdf0e10cSrcweir void Read602(); 210cdf0e10cSrcweir void par602(bool endofpage); 211cdf0e10cSrcweir void inschr(unsigned char ch); 212cdf0e10cSrcweir void inschrdef(unsigned char ch); 213cdf0e10cSrcweir unsigned char Setformat602(char *cmd); 214cdf0e10cSrcweir sal_Int16 readnum(unsigned char *ch, bool show); 215cdf0e10cSrcweir tnode PointCmd602(unsigned char *ch); 216cdf0e10cSrcweir void setfnt(fonts fnt,bool mustwrite); 217cdf0e10cSrcweir void wrtfnt(); 218cdf0e10cSrcweir 219cdf0e10cSrcweir sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) 220cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 221cdf0e10cSrcweir 222cdf0e10cSrcweir public: 223cdf0e10cSrcweir T602ImportFilter(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r ); 224cdf0e10cSrcweir ~T602ImportFilter(); 225cdf0e10cSrcweir 226cdf0e10cSrcweir // XFilter 227cdf0e10cSrcweir virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) 228cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); cancel()229cdf0e10cSrcweir virtual void SAL_CALL cancel( ) 230cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) {}; 231cdf0e10cSrcweir 232cdf0e10cSrcweir // XImporter 233cdf0e10cSrcweir virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) 234cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 235cdf0e10cSrcweir 236cdf0e10cSrcweir // XExtendedTypeDetection 237cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL detect( 238cdf0e10cSrcweir com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor ) 239cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 240cdf0e10cSrcweir 241cdf0e10cSrcweir // XInitialization 242cdf0e10cSrcweir virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) 243cdf0e10cSrcweir throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 244cdf0e10cSrcweir 245cdf0e10cSrcweir // XServiceInfo 246cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) 247cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 248cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 249cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 250cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) 251cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 252cdf0e10cSrcweir }; 253cdf0e10cSrcweir 254cdf0e10cSrcweir ::rtl::OUString T602ImportFilter_getImplementationName() 255cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException ); 256cdf0e10cSrcweir 257cdf0e10cSrcweir sal_Bool SAL_CALL T602ImportFilter_supportsService( const ::rtl::OUString& ServiceName ) 258cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException ); 259cdf0e10cSrcweir 260cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilter_getSupportedServiceNames( ) 261cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException ); 262cdf0e10cSrcweir 263cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 264cdf0e10cSrcweir SAL_CALL T602ImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) 265cdf0e10cSrcweir throw ( ::com::sun::star::uno::Exception ); 266cdf0e10cSrcweir 267cdf0e10cSrcweir ::rtl::OUString T602ImportFilterDialog_getImplementationName() 268cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException ); 269cdf0e10cSrcweir 270cdf0e10cSrcweir sal_Bool SAL_CALL T602ImportFilterDialog_supportsService( const ::rtl::OUString& ServiceName ) 271cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException ); 272cdf0e10cSrcweir 273cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilterDialog_getSupportedServiceNames( ) 274cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException ); 275cdf0e10cSrcweir 276cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 277cdf0e10cSrcweir SAL_CALL T602ImportFilterDialog_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) 278cdf0e10cSrcweir throw ( ::com::sun::star::uno::Exception ); 279cdf0e10cSrcweir 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir #endif 283