msword/conversion.h
1/* This file is part of the KOffice project
2 Copyright (C) 2002 Werner Trobin <trobin@kde.org>
3 Copyright (C) 2002 David Faure <faure@kde.org>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef CONVERSION_H
21#define CONVERSION_H
22
23#include <wv2/ustring.h>
24#include <tqstring.h>
25#include <tqcolor.h>
26
27class TQDomElement;
28namespace wvWare {
29 namespace Word97 {
30 class LSPD;
31 class BRC;
32 }
33 class FLD;
34}
35
36// Static methods for simple MSWord->KWord conversions
37// (enums etc.)
38
39namespace Conversion
40{
41 // UString -> TQConstString conversion. Use .string() to get the TQString.
42 // Always store the TQConstString into a variable first, to avoid a deep copy.
43 inline TQConstString string( const wvWare::UString& str ) {
44 // Let's hope there's no copying of the TQConstString happening...
45 return TQConstString( reinterpret_cast<const TQChar*>( str.data() ), str.length() );
46 }
47
48 // Prepare text for inclusion in XML
49 void encodeText(TQString &text);
50
51 // Convert color code (ico) to TQColor
52 TQColor color(int number, int defaultcolor, bool defaultWhite = false);
53
54 // Convert pattern style (ipat) to TQBrush::BrushStyle
55 int fillPatternStyle( int ipat );
56
57 // Hackery for gray levels
58 int ditheringToGray( int ipat, bool* ok );
59
60 // Convert alignment code to string
61 TQString alignment( int jc );
62
63 // Convert linespacing struct to string
64 TQString lineSpacing( const wvWare::Word97::LSPD& lspd );
65
66 // Convert number format code to KWord's COUNTER.type code
67 int numberFormatCode( int nfc );
68
69 // Set the 3 color attributes in the XML element, from a color code (ico)
70 // prefix: if empty, the attribute names will be red/blue/green
71 // if not empty, they will be xRed/xBlue/xGreen
72 void setColorAttributes( TQDomElement& element, int ico, const TQString& prefix = TQString(), bool defaultWhite = false );
73
74 // Set all border attributes in the XML element, from a BRC structure
75 // prefix: if empty, the attribute names will be red/blue/green/width/style
76 // if not empty, they will be xRed/xBlue/xGreen/xWidth/xStyle
77 void setBorderAttributes( TQDomElement& borderElement, const wvWare::Word97::BRC& brc, const TQString& prefix = TQString() );
78
79 // Convert wv2's Header Type to a KWord frameInfo value
80 int headerTypeToFrameInfo( unsigned char type );
81
82 // Convert wv2's Header Type to a KWord frameset name
83 TQString headerTypeToFramesetName( unsigned char type );
84
85 // Convert a mask of Header Types to the hType value for KWord
86 int headerMaskToHType( unsigned char mask );
87
88 // Convert a mask of Header Types to the fType value for KWord
89 int headerMaskToFType( unsigned char mask );
90
91 // Convert wv2's FLD to KWord FIELD.subtype (or -1 if can't be handled)
92 int fldToFieldType( const wvWare::FLD* fld );
93
94 bool isHeader( unsigned char type );
95}
96
97#endif