1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <com/sun/star/document/XFilter.hpp>
23 #include <com/sun/star/document/XImporter.hpp>
24 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
25 #include <com/sun/star/io/XInputStream.hpp>
26 #include <com/sun/star/lang/XInitialization.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/beans/XPropertyAccess.hpp>
29 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
30 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <comphelper/attributelist.hxx>
33 #include <cppuhelper/implbase.hxx>
34 #include <rtl/ref.hxx>
36 namespace T602ImportFilter
{
38 typedef enum {L2
,KAM
,KOI
} tcode
;
47 lindex
, // lower index
48 hindex
, // upper index
50 chngul
// change underline
53 enum class tnode
{START
,READCH
,EOL
,POCMD
,EXPCMD
,SETCMD
,SETCH
,WRITE
,EEND
,QUIT
};
59 bool showcomm
; // true show comment lines
60 bool forcecode
; // false the user has changed the encoding with something else than @CT
61 tcode xcode
; // KAM encoding set - forced
62 bool ruscode
; // false Russian tables turned on
63 bool reformatpars
; // false Reformat paragraphs (whitespaces and line breaks)
64 static const sal_Int16 fontsize
= 10; // font size in points
71 , reformatpars ( false )
76 class T602ImportFilterDialog
: public cppu::WeakImplHelper
<
77 css::ui::dialogs::XExecutableDialog
,
78 css::lang::XServiceInfo
,
79 css::beans::XPropertyAccess
82 static bool OptionsDlg();
84 virtual ~T602ImportFilterDialog() override
;
87 virtual void SAL_CALL
setTitle( const OUString
& aTitle
) override
;
88 virtual sal_Int16 SAL_CALL
execute() override
;
91 virtual OUString SAL_CALL
getImplementationName( ) override
;
92 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
93 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
96 virtual css::uno::Sequence
< css::beans::PropertyValue
>
97 SAL_CALL
getPropertyValues() override
;
98 virtual void SAL_CALL
setPropertyValues( const css::uno::Sequence
<
99 css::beans::PropertyValue
>& aProps
) override
;
102 explicit T602ImportFilterDialog();
107 class T602ImportFilter
: public cppu::WeakImplHelper
<
108 css::document::XFilter
,
109 css::document::XImporter
,
110 css::document::XExtendedFilterDetection
,
111 css::lang::XInitialization
,
112 css::lang::XServiceInfo
116 css::uno::Reference
<css::xml::sax::XDocumentHandler
> mxHandler
;
117 css::uno::Reference
< css::uno::XComponentContext
> mxContext
;
118 css::uno::Reference
< css::lang::XComponent
> mxDoc
;
119 css::uno::Reference
< css::io::XInputStream
> mxInputStream
;
121 rtl::Reference
<comphelper::AttributeList
> mpAttrList
;
125 struct format602struct
127 sal_Int16 mt
; // row for header
128 sal_Int16 mb
; // row for footer
129 sal_Int16 tb
; // tabs
130 sal_Int16 ct
; // encoding (0-kamenik, 1-latin2, 2-koi8)
131 sal_Int16 pn
; // from page number
132 sal_Int16 lh
; // linespacing 3-2x, 4-1.5x, 6-1x
133 sal_Int16 lm
; // left border
134 sal_Int16 rm
; // right border
135 sal_Int16 pl
; // page length
150 format602struct format602
;
152 // Initialisation constants - they are not changed during the conversion
156 // Font state - changes based on font
160 fonts nowfnt
; // current font
161 fonts oldfnt
; // previous font
162 bool uline
; // underlined
163 bool olduline
; // previous value of uline (font change)
179 sal_Int16 pars
; // the number of line endings times linespacing on the current page
180 bool comment
; // in comments
181 sal_Int16 wasspace
; // 0 there was a space - for reformatting
182 bool wasfdash
; // 0 formatting dash
183 bool ccafterln
; // false
184 bool willbeeop
; // false
185 bool waspar
; // false
201 unsigned char Readchar602();
203 void par602(bool endofpage
);
204 void inschr(unsigned char ch
);
205 void inschrdef(unsigned char ch
);
206 unsigned char Setformat602(const char *cmd
);
207 sal_Int16
readnum(unsigned char *ch
, bool show
);
208 tnode
PointCmd602(unsigned char *ch
);
209 void setfnt(fonts fnt
,bool mustwrite
);
212 /// @throws css::uno::RuntimeException
213 bool importImpl( const css::uno::Sequence
< css::beans::PropertyValue
>& aDescriptor
);
216 explicit T602ImportFilter(css::uno::Reference
<css::uno::XComponentContext
> x
);
217 explicit T602ImportFilter(css::uno::Reference
<css::io::XInputStream
> xInputStream
);
218 virtual ~T602ImportFilter() override
;
221 virtual sal_Bool SAL_CALL
filter( const css::uno::Sequence
< css::beans::PropertyValue
>& aDescriptor
) override
;
222 virtual void SAL_CALL
cancel( ) override
{};
225 virtual void SAL_CALL
setTargetDocument( const css::uno::Reference
< css::lang::XComponent
>& xDoc
) override
;
227 // XExtendedTypeDetection
228 virtual OUString SAL_CALL
detect(
229 css::uno::Sequence
< css::beans::PropertyValue
>& Descriptor
) override
;
232 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
235 virtual OUString SAL_CALL
getImplementationName( ) override
;
236 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
237 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */