summaryrefslogtreecommitdiffstats
path: root/filters/kword/libexport/KWEFUtil.cc
blob: a02a45ece9a6d0dea4cf8040ba97d1805a57ebfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
   This file is part of the KDE project
   Copyright (C) 2001 Nicolas GOUTTE <goutte@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include <tqstring.h>
#include <tqtextcodec.h>

#include <KoPageLayout.h>

#include "KWEFUtil.h"

TQString KWEFUtil::EscapeSgmlText(const TQTextCodec* codec,
                      const TQString& strIn,
                      const bool quot /* = false */ ,
                      const bool apos /* = false */ )
{
    TQString strReturn;
    TQChar ch;

    for (uint i=0; i<strIn.length(); i++)
    {
        ch=strIn[i];
        switch (ch.unicode())
        {
        case 38: // &
            {
                strReturn+="&amp;";
                break;
            }
        case 60: // <
            {
                strReturn+="&lt;";
                break;
            }
        case 62: // >
            {
                strReturn+="&gt;";
                break;
            }
        case 34: // "
            {
                if (quot)
                    strReturn+="&quot;";
                else
                    strReturn+=ch;
                break;
            }
        case 39: // '
            {
                // NOTE:  HTML does not define &apos; by default (only XML/XHTML does)
                if (apos)
                    strReturn+="&apos;";
                else
                    strReturn+=ch;
                break;
            }
        default:
            {
                // verify that the character ch can be expressed in the
                //   encoding in which we will write the HTML file.
                if (codec)
                {
                    if (!codec->canEncode(ch))
                    {
                        strReturn+=TQString("&#%1;").arg(ch.unicode());
                        break;
                    }
                }
                strReturn+=ch;
                break;
            }
        }
    }

    return strReturn;
}

void KWEFUtil::GetNativePaperFormat(const int format,
    TQString& width, TQString& height, TQString& units)
// Find data for paper format, as needed for AbiWord and CSS
{
    switch (format)
    {
        // ISO A formats
        case PG_DIN_A0: // ISO A0
        {
            width="84.1"; height="118.0"; units="cm";
            break;
        }
        case PG_DIN_A1: // ISO A1
        {
            width="59.4"; height="84.1"; units="cm";
            break;
        }
        case PG_DIN_A2: // ISO A2
        {
            width="42.0"; height="59.4"; units="cm";
            break;
        }
        case PG_DIN_A3: // ISO A3
        {
            width="29.7"; height="42.0"; units="cm";
            break;
        }
        case PG_DIN_A4: // ISO A4
        {
            width="21.0"; height="29.7"; units="cm";
            break;
        }
        case PG_DIN_A5: // ISO A5
        {
            width="14.8"; height="21.0"; units="cm";
            break;
        }
        case PG_DIN_A6: // ISO A6
        {
            width="10.5"; height="14.8"; units="cm";
            break;
        }
        // ISO B formats
        case PG_DIN_B0: // ISO B0
        {
            width="100.0"; height="141.0"; units="cm";
            break;
        }
        case PG_DIN_B1: // ISO B1
        {
            width="70.7"; height="100.0"; units="cm";
            break;
        }
        case PG_DIN_B2: // ISO B2
        {
            width="50.0"; height="70.7"; units="cm";
            break;
        }
        case PG_DIN_B3: // ISO B3
        {
            width="35.3"; height="50.0"; units="cm";
            break;
        }
        case PG_DIN_B4: // ISO B4
        {
            width="25.8"; height="35.3"; units="cm";
            break;
        }
        case PG_DIN_B5: // ISO B5
        {
            width="17.6"; height="25.0"; units="cm";
            break;
        }
        case PG_DIN_B6: // ISO B6
        {
            width="12.5"; height="17.6"; units="cm";
            break;
        }
        // American formats
        case PG_US_LETTER: // US Letter
        {
            width="8.5"; height="11.0"; units="inch";
            break;
        }
        case PG_US_LEGAL: // US Legal
        {
            width="8.5"; height="14.0"; units="inch";
            break;
        }
        case PG_US_EXECUTIVE: // US Executive
        {
            width="7.5"; height="10.0"; units="inch";
            break;
        }
        // Other format not supported yet by AbiWord CVS 2001-04-25)
        case PG_DIN_A7: // ISO A7
        case PG_DIN_A8: // ISO A8
        case PG_DIN_A9: // ISO A9
        case PG_DIN_B10: // ISO B10
        // Other formats
        case PG_SCREEN: // Screen
        case PG_CUSTOM: // Custom
        default:
        {
            // TODO
            width=TQString();
            height=TQString();
            units=TQString();
            break;
        }
    }
}