filters

KWEFUtil.cpp
1/*
2 This file is part of the KDE project
3 Copyright (C) 2001 Nicolas GOUTTE <goutte@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqstring.h>
22#include <tqtextcodec.h>
23
24#include <KoPageLayout.h>
25
26#include "KWEFUtil.h"
27
28TQString KWEFUtil::EscapeSgmlText(const TQTextCodec* codec,
29 const TQString& strIn,
30 const bool quot /* = false */ ,
31 const bool apos /* = false */ )
32{
33 TQString strReturn;
34 TQChar ch;
35
36 for (uint i=0; i<strIn.length(); i++)
37 {
38 ch=strIn[i];
39 switch (ch.unicode())
40 {
41 case 38: // &
42 {
43 strReturn+="&amp;";
44 break;
45 }
46 case 60: // <
47 {
48 strReturn+="&lt;";
49 break;
50 }
51 case 62: // >
52 {
53 strReturn+="&gt;";
54 break;
55 }
56 case 34: // "
57 {
58 if (quot)
59 strReturn+="&quot;";
60 else
61 strReturn+=ch;
62 break;
63 }
64 case 39: // '
65 {
66 // NOTE: HTML does not define &apos; by default (only XML/XHTML does)
67 if (apos)
68 strReturn+="&apos;";
69 else
70 strReturn+=ch;
71 break;
72 }
73 default:
74 {
75 // verify that the character ch can be expressed in the
76 // encoding in which we will write the HTML file.
77 if (codec)
78 {
79 if (!codec->canEncode(ch))
80 {
81 strReturn+=TQString("&#%1;").arg(ch.unicode());
82 break;
83 }
84 }
85 strReturn+=ch;
86 break;
87 }
88 }
89 }
90
91 return strReturn;
92}
93
94void KWEFUtil::GetNativePaperFormat(const int format,
95 TQString& width, TQString& height, TQString& units)
96// Find data for paper format, as needed for AbiWord and CSS
97{
98 switch (format)
99 {
100 // ISO A formats
101 case PG_DIN_A0: // ISO A0
102 {
103 width="84.1"; height="118.0"; units="cm";
104 break;
105 }
106 case PG_DIN_A1: // ISO A1
107 {
108 width="59.4"; height="84.1"; units="cm";
109 break;
110 }
111 case PG_DIN_A2: // ISO A2
112 {
113 width="42.0"; height="59.4"; units="cm";
114 break;
115 }
116 case PG_DIN_A3: // ISO A3
117 {
118 width="29.7"; height="42.0"; units="cm";
119 break;
120 }
121 case PG_DIN_A4: // ISO A4
122 {
123 width="21.0"; height="29.7"; units="cm";
124 break;
125 }
126 case PG_DIN_A5: // ISO A5
127 {
128 width="14.8"; height="21.0"; units="cm";
129 break;
130 }
131 case PG_DIN_A6: // ISO A6
132 {
133 width="10.5"; height="14.8"; units="cm";
134 break;
135 }
136 // ISO B formats
137 case PG_DIN_B0: // ISO B0
138 {
139 width="100.0"; height="141.0"; units="cm";
140 break;
141 }
142 case PG_DIN_B1: // ISO B1
143 {
144 width="70.7"; height="100.0"; units="cm";
145 break;
146 }
147 case PG_DIN_B2: // ISO B2
148 {
149 width="50.0"; height="70.7"; units="cm";
150 break;
151 }
152 case PG_DIN_B3: // ISO B3
153 {
154 width="35.3"; height="50.0"; units="cm";
155 break;
156 }
157 case PG_DIN_B4: // ISO B4
158 {
159 width="25.8"; height="35.3"; units="cm";
160 break;
161 }
162 case PG_DIN_B5: // ISO B5
163 {
164 width="17.6"; height="25.0"; units="cm";
165 break;
166 }
167 case PG_DIN_B6: // ISO B6
168 {
169 width="12.5"; height="17.6"; units="cm";
170 break;
171 }
172 // American formats
173 case PG_US_LETTER: // US Letter
174 {
175 width="8.5"; height="11.0"; units="inch";
176 break;
177 }
178 case PG_US_LEGAL: // US Legal
179 {
180 width="8.5"; height="14.0"; units="inch";
181 break;
182 }
183 case PG_US_EXECUTIVE: // US Executive
184 {
185 width="7.5"; height="10.0"; units="inch";
186 break;
187 }
188 // Other format not supported yet by AbiWord CVS 2001-04-25)
189 case PG_DIN_A7: // ISO A7
190 case PG_DIN_A8: // ISO A8
191 case PG_DIN_A9: // ISO A9
192 case PG_DIN_B10: // ISO B10
193 // Other formats
194 case PG_SCREEN: // Screen
195 case PG_CUSTOM: // Custom
196 default:
197 {
198 // TODO
199 width=TQString();
200 height=TQString();
201 units=TQString();
202 break;
203 }
204 }
205}