xref: /trunk/main/svtools/source/svhtml/htmlout.cxx (revision 5900e8ec)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #include <tools/urlobj.hxx>
28 #include <svl/zformat.hxx>
29 #include <svl/macitem.hxx>
30 #include <tools/cachestr.hxx>
31 #include <vcl/svapp.hxx>
32 #include <svl/zforlist.hxx>
33 
34 #include <svtools/htmlout.hxx>
35 #include <svtools/htmlkywd.hxx>
36 #include <svtools/imap.hxx>
37 #include <svtools/imaprect.hxx>
38 #include <svtools/imapcirc.hxx>
39 #include <svtools/imappoly.hxx>
40 #include "svl/urihelper.hxx"
41 
42 #ifndef RTL_CONSTASCII_STRINGPARAM
43 #define RTL_CONSTASCII_STRINGPARAM( c ) c, sizeof(c)-1
44 #endif
45 
46 #if defined(UNX)
47 const sal_Char HTMLOutFuncs::sNewLine = '\012';
48 #else
49 const sal_Char __FAR_DATA HTMLOutFuncs::sNewLine[] = "\015\012";
50 #endif
51 
52 #define TXTCONV_BUFFER_SIZE 20
53 
HTMLOutContext(rtl_TextEncoding eDestEnc)54 HTMLOutContext::HTMLOutContext( rtl_TextEncoding eDestEnc )
55 {
56 	m_eDestEnc = RTL_TEXTENCODING_DONTKNOW == eDestEnc
57 					? gsl_getSystemTextEncoding()
58 					: eDestEnc;
59 
60 	m_hConv = rtl_createUnicodeToTextConverter( eDestEnc );
61 	DBG_ASSERT( m_hConv,
62 		"HTMLOutContext::HTMLOutContext: no converter for source encoding" );
63 	m_hContext = m_hConv ? rtl_createUnicodeToTextContext( m_hConv )
64 					 : (rtl_TextToUnicodeContext)1;
65 }
66 
~HTMLOutContext()67 HTMLOutContext::~HTMLOutContext()
68 {
69 	rtl_destroyUnicodeToTextContext( m_hConv, m_hContext );
70 	rtl_destroyUnicodeToTextConverter( m_hConv );
71 }
72 
lcl_svhtml_GetEntityForChar(sal_Unicode c,rtl_TextEncoding eDestEnc)73 const sal_Char *lcl_svhtml_GetEntityForChar( sal_Unicode c,
74 											 rtl_TextEncoding eDestEnc )
75 {
76 	const sal_Char* pStr = 0;
77 
78     // Note: We currently handle special cases for ISO-8859-2 here simply because
79     // the code was already submitted.  But we should also handle other code pages
80     // as well as the code becomes available.
81 
82     if( eDestEnc == RTL_TEXTENCODING_ISO_8859_2 || eDestEnc == RTL_TEXTENCODING_MS_1250 )
83     {
84         // Don't handle the following characters for Easter European (ISO-8859-2).
85         switch ( c )
86         {
87         case 164: // curren
88         case 184: // ccedil
89         case 193: // Aacute
90         case 194: // Acirc
91         case 196: // Auml
92         case 199: // Ccedil
93         case 201: // Eacute
94         case 203: // Euml
95         case 205: // Iacute
96         case 206: // Icirc
97         case 211: // Oacute
98         case 212: // Ocirc
99         case 214: // Ouml
100         case 215: // times
101         case 218: // Uacute
102         case 220: // Uuml
103         case 221: // Yacute
104         case 225: // aacute
105         case 226: // acirc
106         case 228: // auml
107         case 233: // eacute
108         case 235: // euml
109         case 237: // iacute
110         case 238: // icirc
111         case 243: // oacute
112         case 244: // ocirc
113         case 246: // ouml
114         case 247: // divide
115         case 250: // uacute
116         case 252: // uuml
117         case 253: // yacute
118         case 352: // Scaron
119         case 353: // scaron
120             return pStr;
121         }
122     }
123 
124     // TODO: handle more special cases for other code pages.
125 
126 	switch( c )
127 	{
128 //	    case '\x0a':   return HTMLOutFuncs::Out_Tag( rStream, OOO_STRING_SVTOOLS_HTML_linebreak );
129 
130 	case '<':		pStr = OOO_STRING_SVTOOLS_HTML_C_lt;		break;
131 	case '>':		pStr = OOO_STRING_SVTOOLS_HTML_C_gt;		break;
132 	case '&':		pStr = OOO_STRING_SVTOOLS_HTML_C_amp;		break;
133 	case '"':		pStr = OOO_STRING_SVTOOLS_HTML_C_quot;	break;
134 
135 	case 161:		pStr = OOO_STRING_SVTOOLS_HTML_S_iexcl;	break;
136 	case 162:		pStr = OOO_STRING_SVTOOLS_HTML_S_cent;	break;
137 	case 163:		pStr = OOO_STRING_SVTOOLS_HTML_S_pound;	break;
138 	case 164:		pStr = OOO_STRING_SVTOOLS_HTML_S_curren;	break;
139 	case 165:		pStr = OOO_STRING_SVTOOLS_HTML_S_yen;		break;
140 	case 166:		pStr = OOO_STRING_SVTOOLS_HTML_S_brvbar;	break;
141 	case 167:		pStr = OOO_STRING_SVTOOLS_HTML_S_sect;	break;
142 	case 168:		pStr = OOO_STRING_SVTOOLS_HTML_S_uml;		break;
143 	case 169:		pStr = OOO_STRING_SVTOOLS_HTML_S_copy;	break;
144 	case 170:		pStr = OOO_STRING_SVTOOLS_HTML_S_ordf;	break;
145 	case 171:		pStr = OOO_STRING_SVTOOLS_HTML_S_laquo;	break;
146 	case 172:		pStr = OOO_STRING_SVTOOLS_HTML_S_not;		break;
147 	case 174:		pStr = OOO_STRING_SVTOOLS_HTML_S_reg;		break;
148 	case 175:		pStr = OOO_STRING_SVTOOLS_HTML_S_macr;	break;
149 	case 176:		pStr = OOO_STRING_SVTOOLS_HTML_S_deg;		break;
150 	case 177:		pStr = OOO_STRING_SVTOOLS_HTML_S_plusmn;	break;
151 	case 178:		pStr = OOO_STRING_SVTOOLS_HTML_S_sup2;	break;
152 	case 179:		pStr = OOO_STRING_SVTOOLS_HTML_S_sup3;	break;
153 	case 180:		pStr = OOO_STRING_SVTOOLS_HTML_S_acute;	break;
154 	case 181:		pStr = OOO_STRING_SVTOOLS_HTML_S_micro;	break;
155 	case 182:		pStr = OOO_STRING_SVTOOLS_HTML_S_para;	break;
156 	case 183:		pStr = OOO_STRING_SVTOOLS_HTML_S_middot;	break;
157 	case 184:		pStr = OOO_STRING_SVTOOLS_HTML_S_cedil;	break;
158 	case 185:		pStr = OOO_STRING_SVTOOLS_HTML_S_sup1;	break;
159 	case 186:		pStr = OOO_STRING_SVTOOLS_HTML_S_ordm;	break;
160 	case 187:		pStr = OOO_STRING_SVTOOLS_HTML_S_raquo;	break;
161 	case 188:		pStr = OOO_STRING_SVTOOLS_HTML_S_frac14;	break;
162 	case 189:		pStr = OOO_STRING_SVTOOLS_HTML_S_frac12;	break;
163 	case 190:		pStr = OOO_STRING_SVTOOLS_HTML_S_frac34;	break;
164 	case 191:		pStr = OOO_STRING_SVTOOLS_HTML_S_iquest;	break;
165 
166 	case 192:		pStr = OOO_STRING_SVTOOLS_HTML_C_Agrave;	break;
167 	case 193:		pStr = OOO_STRING_SVTOOLS_HTML_C_Aacute;	break;
168 	case 194:		pStr = OOO_STRING_SVTOOLS_HTML_C_Acirc;	break;
169 	case 195:		pStr = OOO_STRING_SVTOOLS_HTML_C_Atilde;	break;
170 	case 196:		pStr = OOO_STRING_SVTOOLS_HTML_C_Auml;	break;
171 	case 197:		pStr = OOO_STRING_SVTOOLS_HTML_C_Aring;	break;
172 	case 198:		pStr = OOO_STRING_SVTOOLS_HTML_C_AElig;	break;
173 	case 199:		pStr = OOO_STRING_SVTOOLS_HTML_C_Ccedil;	break;
174 	case 200:		pStr = OOO_STRING_SVTOOLS_HTML_C_Egrave;	break;
175 	case 201:		pStr = OOO_STRING_SVTOOLS_HTML_C_Eacute;	break;
176 	case 202:		pStr = OOO_STRING_SVTOOLS_HTML_C_Ecirc;	break;
177 	case 203:		pStr = OOO_STRING_SVTOOLS_HTML_C_Euml;	break;
178 	case 204:		pStr = OOO_STRING_SVTOOLS_HTML_C_Igrave;	break;
179 	case 205:		pStr = OOO_STRING_SVTOOLS_HTML_C_Iacute;	break;
180 	case 206:		pStr = OOO_STRING_SVTOOLS_HTML_C_Icirc;	break;
181 	case 207:		pStr = OOO_STRING_SVTOOLS_HTML_C_Iuml;	break;
182 	case 208:		pStr = OOO_STRING_SVTOOLS_HTML_C_ETH;		break;
183 	case 209:		pStr = OOO_STRING_SVTOOLS_HTML_C_Ntilde;	break;
184 	case 210:		pStr = OOO_STRING_SVTOOLS_HTML_C_Ograve;	break;
185 	case 211:		pStr = OOO_STRING_SVTOOLS_HTML_C_Oacute;	break;
186 	case 212:		pStr = OOO_STRING_SVTOOLS_HTML_C_Ocirc;	break;
187 	case 213:		pStr = OOO_STRING_SVTOOLS_HTML_C_Otilde;	break;
188 	case 214:		pStr = OOO_STRING_SVTOOLS_HTML_C_Ouml;	break;
189 	case 215:		pStr = OOO_STRING_SVTOOLS_HTML_S_times;	break;
190 	case 216:		pStr = OOO_STRING_SVTOOLS_HTML_C_Oslash;	break;
191 	case 217:		pStr = OOO_STRING_SVTOOLS_HTML_C_Ugrave;	break;
192 	case 218:		pStr = OOO_STRING_SVTOOLS_HTML_C_Uacute;	break;
193 	case 219:		pStr = OOO_STRING_SVTOOLS_HTML_C_Ucirc;	break;
194 	case 220:		pStr = OOO_STRING_SVTOOLS_HTML_C_Uuml;	break;
195 	case 221:		pStr = OOO_STRING_SVTOOLS_HTML_C_Yacute;	break;
196 
197 	case 222:		pStr = OOO_STRING_SVTOOLS_HTML_C_THORN;	break;
198 	case 223:		pStr = OOO_STRING_SVTOOLS_HTML_C_szlig;	break;
199 
200 	case 224:		pStr = OOO_STRING_SVTOOLS_HTML_S_agrave;	break;
201 	case 225:		pStr = OOO_STRING_SVTOOLS_HTML_S_aacute;	break;
202 	case 226:		pStr = OOO_STRING_SVTOOLS_HTML_S_acirc;	break;
203 	case 227:		pStr = OOO_STRING_SVTOOLS_HTML_S_atilde;	break;
204 	case 228:		pStr = OOO_STRING_SVTOOLS_HTML_S_auml;	break;
205 	case 229:		pStr = OOO_STRING_SVTOOLS_HTML_S_aring;	break;
206 	case 230:		pStr = OOO_STRING_SVTOOLS_HTML_S_aelig;	break;
207 	case 231:		pStr = OOO_STRING_SVTOOLS_HTML_S_ccedil;	break;
208 	case 232:		pStr = OOO_STRING_SVTOOLS_HTML_S_egrave;	break;
209 	case 233:		pStr = OOO_STRING_SVTOOLS_HTML_S_eacute;	break;
210 	case 234:		pStr = OOO_STRING_SVTOOLS_HTML_S_ecirc;	break;
211 	case 235:		pStr = OOO_STRING_SVTOOLS_HTML_S_euml;	break;
212 	case 236:		pStr = OOO_STRING_SVTOOLS_HTML_S_igrave;	break;
213 	case 237:		pStr = OOO_STRING_SVTOOLS_HTML_S_iacute;	break;
214 	case 238:		pStr = OOO_STRING_SVTOOLS_HTML_S_icirc;	break;
215 	case 239:		pStr = OOO_STRING_SVTOOLS_HTML_S_iuml;	break;
216 	case 240:		pStr = OOO_STRING_SVTOOLS_HTML_S_eth;		break;
217 	case 241:		pStr = OOO_STRING_SVTOOLS_HTML_S_ntilde;	break;
218 	case 242:		pStr = OOO_STRING_SVTOOLS_HTML_S_ograve;	break;
219 	case 243:		pStr = OOO_STRING_SVTOOLS_HTML_S_oacute;	break;
220 	case 244:		pStr = OOO_STRING_SVTOOLS_HTML_S_ocirc;	break;
221 	case 245:		pStr = OOO_STRING_SVTOOLS_HTML_S_otilde;	break;
222 	case 246:		pStr = OOO_STRING_SVTOOLS_HTML_S_ouml;	break;
223 	case 247:		pStr = OOO_STRING_SVTOOLS_HTML_S_divide;	break;
224 	case 248:		pStr = OOO_STRING_SVTOOLS_HTML_S_oslash;	break;
225 	case 249:		pStr = OOO_STRING_SVTOOLS_HTML_S_ugrave;	break;
226 	case 250:		pStr = OOO_STRING_SVTOOLS_HTML_S_uacute;	break;
227 	case 251:		pStr = OOO_STRING_SVTOOLS_HTML_S_ucirc;	break;
228 	case 252:		pStr = OOO_STRING_SVTOOLS_HTML_S_uuml;	break;
229 	case 253:		pStr = OOO_STRING_SVTOOLS_HTML_S_yacute;	break;
230 	case 254:		pStr = OOO_STRING_SVTOOLS_HTML_S_thorn;	break;
231 	case 255:     	pStr = OOO_STRING_SVTOOLS_HTML_S_yuml;	break;
232 
233 	case 338:		pStr = OOO_STRING_SVTOOLS_HTML_S_OElig;	break;
234 	case 339:		pStr = OOO_STRING_SVTOOLS_HTML_S_oelig;	break;
235 	case 352:		pStr = OOO_STRING_SVTOOLS_HTML_S_Scaron;	break;
236 	case 353:		pStr = OOO_STRING_SVTOOLS_HTML_S_scaron;	break;
237 	case 376:		pStr = OOO_STRING_SVTOOLS_HTML_S_Yuml;	break;
238 	case 402:		pStr = OOO_STRING_SVTOOLS_HTML_S_fnof;	break;
239 	case 710:		pStr = OOO_STRING_SVTOOLS_HTML_S_circ;	break;
240 	case 732:		pStr = OOO_STRING_SVTOOLS_HTML_S_tilde;	break;
241 
242 	// Greek chars are handled later,
243 	// since they should *not* be transformed to entities
244 	// when generating Greek text (== using Greek encoding)
245 
246 	case 8194:		pStr = OOO_STRING_SVTOOLS_HTML_S_ensp;	break;
247 	case 8195:		pStr = OOO_STRING_SVTOOLS_HTML_S_emsp;	break;
248 	case 8201:		pStr = OOO_STRING_SVTOOLS_HTML_S_thinsp;	break;
249 	case 8204:		pStr = OOO_STRING_SVTOOLS_HTML_S_zwnj;	break;
250 	case 8205:		pStr = OOO_STRING_SVTOOLS_HTML_S_zwj;		break;
251 	case 8206:		pStr = OOO_STRING_SVTOOLS_HTML_S_lrm;		break;
252 	case 8207:		pStr = OOO_STRING_SVTOOLS_HTML_S_rlm;		break;
253 	case 8211:		pStr = OOO_STRING_SVTOOLS_HTML_S_ndash;	break;
254 	case 8212:		pStr = OOO_STRING_SVTOOLS_HTML_S_mdash;	break;
255 	case 8216:		pStr = OOO_STRING_SVTOOLS_HTML_S_lsquo;	break;
256 	case 8217:		pStr = OOO_STRING_SVTOOLS_HTML_S_rsquo;	break;
257 	case 8218:		pStr = OOO_STRING_SVTOOLS_HTML_S_sbquo;	break;
258 	case 8220:		pStr = OOO_STRING_SVTOOLS_HTML_S_ldquo;	break;
259 	case 8221:		pStr = OOO_STRING_SVTOOLS_HTML_S_rdquo;	break;
260 	case 8222:		pStr = OOO_STRING_SVTOOLS_HTML_S_bdquo;	break;
261 	case 8224:		pStr = OOO_STRING_SVTOOLS_HTML_S_dagger;	break;
262 	case 8225:		pStr = OOO_STRING_SVTOOLS_HTML_S_Dagger;	break;
263 	case 8226:		pStr = OOO_STRING_SVTOOLS_HTML_S_bull;	break;
264 	case 8230:		pStr = OOO_STRING_SVTOOLS_HTML_S_hellip;	break;
265 	case 8240:		pStr = OOO_STRING_SVTOOLS_HTML_S_permil;	break;
266 	case 8242:		pStr = OOO_STRING_SVTOOLS_HTML_S_prime;	break;
267 	case 8243:		pStr = OOO_STRING_SVTOOLS_HTML_S_Prime;	break;
268 	case 8249:		pStr = OOO_STRING_SVTOOLS_HTML_S_lsaquo;	break;
269 	case 8250:		pStr = OOO_STRING_SVTOOLS_HTML_S_rsaquo;	break;
270 	case 8254:		pStr = OOO_STRING_SVTOOLS_HTML_S_oline;	break;
271 	case 8260:		pStr = OOO_STRING_SVTOOLS_HTML_S_frasl;	break;
272 	case 8364:		pStr = OOO_STRING_SVTOOLS_HTML_S_euro;	break;
273 	case 8465:		pStr = OOO_STRING_SVTOOLS_HTML_S_image;	break;
274 	case 8472:		pStr = OOO_STRING_SVTOOLS_HTML_S_weierp;	break;
275 	case 8476:		pStr = OOO_STRING_SVTOOLS_HTML_S_real;	break;
276 	case 8482:		pStr = OOO_STRING_SVTOOLS_HTML_S_trade;	break;
277 	case 8501:		pStr = OOO_STRING_SVTOOLS_HTML_S_alefsym;	break;
278 	case 8592:		pStr = OOO_STRING_SVTOOLS_HTML_S_larr;	break;
279 	case 8593:		pStr = OOO_STRING_SVTOOLS_HTML_S_uarr;	break;
280 	case 8594:		pStr = OOO_STRING_SVTOOLS_HTML_S_rarr;	break;
281 	case 8595:		pStr = OOO_STRING_SVTOOLS_HTML_S_darr;	break;
282 	case 8596:		pStr = OOO_STRING_SVTOOLS_HTML_S_harr;	break;
283 	case 8629:		pStr = OOO_STRING_SVTOOLS_HTML_S_crarr;	break;
284 	case 8656:		pStr = OOO_STRING_SVTOOLS_HTML_S_lArr;	break;
285 	case 8657:		pStr = OOO_STRING_SVTOOLS_HTML_S_uArr;	break;
286 	case 8658:		pStr = OOO_STRING_SVTOOLS_HTML_S_rArr;	break;
287 	case 8659:		pStr = OOO_STRING_SVTOOLS_HTML_S_dArr;	break;
288 	case 8660:		pStr = OOO_STRING_SVTOOLS_HTML_S_hArr;	break;
289 	case 8704:		pStr = OOO_STRING_SVTOOLS_HTML_S_forall;	break;
290 	case 8706:		pStr = OOO_STRING_SVTOOLS_HTML_S_part;	break;
291 	case 8707:		pStr = OOO_STRING_SVTOOLS_HTML_S_exist;	break;
292 	case 8709:		pStr = OOO_STRING_SVTOOLS_HTML_S_empty;	break;
293 	case 8711:		pStr = OOO_STRING_SVTOOLS_HTML_S_nabla;	break;
294 	case 8712:		pStr = OOO_STRING_SVTOOLS_HTML_S_isin;	break;
295 	case 8713:		pStr = OOO_STRING_SVTOOLS_HTML_S_notin;	break;
296 	case 8715:		pStr = OOO_STRING_SVTOOLS_HTML_S_ni;		break;
297 	case 8719:		pStr = OOO_STRING_SVTOOLS_HTML_S_prod;	break;
298 	case 8721:		pStr = OOO_STRING_SVTOOLS_HTML_S_sum;		break;
299 	case 8722:		pStr = OOO_STRING_SVTOOLS_HTML_S_minus;	break;
300 	case 8727:		pStr = OOO_STRING_SVTOOLS_HTML_S_lowast;	break;
301 	case 8730:		pStr = OOO_STRING_SVTOOLS_HTML_S_radic;	break;
302 	case 8733:		pStr = OOO_STRING_SVTOOLS_HTML_S_prop;	break;
303 	case 8734:		pStr = OOO_STRING_SVTOOLS_HTML_S_infin;	break;
304 	case 8736:		pStr = OOO_STRING_SVTOOLS_HTML_S_ang;		break;
305 	case 8743:		pStr = OOO_STRING_SVTOOLS_HTML_S_and;		break;
306 	case 8744:		pStr = OOO_STRING_SVTOOLS_HTML_S_or;		break;
307 	case 8745:		pStr = OOO_STRING_SVTOOLS_HTML_S_cap;		break;
308 	case 8746:		pStr = OOO_STRING_SVTOOLS_HTML_S_cup;		break;
309 	case 8747:		pStr = OOO_STRING_SVTOOLS_HTML_S_int;		break;
310 	case 8756:		pStr = OOO_STRING_SVTOOLS_HTML_S_there4;	break;
311 	case 8764:		pStr = OOO_STRING_SVTOOLS_HTML_S_sim;		break;
312 	case 8773:		pStr = OOO_STRING_SVTOOLS_HTML_S_cong;	break;
313 	case 8776:		pStr = OOO_STRING_SVTOOLS_HTML_S_asymp;	break;
314 	case 8800:		pStr = OOO_STRING_SVTOOLS_HTML_S_ne;		break;
315 	case 8801:		pStr = OOO_STRING_SVTOOLS_HTML_S_equiv;	break;
316 	case 8804:		pStr = OOO_STRING_SVTOOLS_HTML_S_le;		break;
317 	case 8805:		pStr = OOO_STRING_SVTOOLS_HTML_S_ge;		break;
318 	case 8834:		pStr = OOO_STRING_SVTOOLS_HTML_S_sub;		break;
319 	case 8835:		pStr = OOO_STRING_SVTOOLS_HTML_S_sup;		break;
320 	case 8836:		pStr = OOO_STRING_SVTOOLS_HTML_S_nsub;	break;
321 	case 8838:		pStr = OOO_STRING_SVTOOLS_HTML_S_sube;	break;
322 	case 8839:		pStr = OOO_STRING_SVTOOLS_HTML_S_supe;	break;
323 	case 8853:		pStr = OOO_STRING_SVTOOLS_HTML_S_oplus;	break;
324 	case 8855:		pStr = OOO_STRING_SVTOOLS_HTML_S_otimes;	break;
325 	case 8869:		pStr = OOO_STRING_SVTOOLS_HTML_S_perp;	break;
326 	case 8901:		pStr = OOO_STRING_SVTOOLS_HTML_S_sdot;	break;
327 	case 8968:		pStr = OOO_STRING_SVTOOLS_HTML_S_lceil;	break;
328 	case 8969:		pStr = OOO_STRING_SVTOOLS_HTML_S_rceil;	break;
329 	case 8970:		pStr = OOO_STRING_SVTOOLS_HTML_S_lfloor;	break;
330 	case 8971:		pStr = OOO_STRING_SVTOOLS_HTML_S_rfloor;	break;
331 	case 9001:		pStr = OOO_STRING_SVTOOLS_HTML_S_lang;	break;
332 	case 9002:		pStr = OOO_STRING_SVTOOLS_HTML_S_rang;	break;
333 	case 9674:		pStr = OOO_STRING_SVTOOLS_HTML_S_loz;		break;
334 	case 9824:		pStr = OOO_STRING_SVTOOLS_HTML_S_spades;	break;
335 	case 9827:		pStr = OOO_STRING_SVTOOLS_HTML_S_clubs;	break;
336 	case 9829:		pStr = OOO_STRING_SVTOOLS_HTML_S_hearts;	break;
337 	case 9830:		pStr = OOO_STRING_SVTOOLS_HTML_S_diams;	break;
338 	}
339 
340 	// Greek chars: if we do not produce a Greek encoding,
341 	// transform them into entities
342 	if( !pStr &&
343 		( eDestEnc != RTL_TEXTENCODING_ISO_8859_7 ) &&
344 	    ( eDestEnc != RTL_TEXTENCODING_MS_1253 ) )
345 	{
346 		switch( c )
347 		{
348 		case 913:		pStr = OOO_STRING_SVTOOLS_HTML_S_Alpha;	break;
349 		case 914:		pStr = OOO_STRING_SVTOOLS_HTML_S_Beta;	break;
350 		case 915:		pStr = OOO_STRING_SVTOOLS_HTML_S_Gamma;	break;
351 		case 916:		pStr = OOO_STRING_SVTOOLS_HTML_S_Delta;	break;
352 		case 917:		pStr = OOO_STRING_SVTOOLS_HTML_S_Epsilon;	break;
353 		case 918:		pStr = OOO_STRING_SVTOOLS_HTML_S_Zeta;	break;
354 		case 919:		pStr = OOO_STRING_SVTOOLS_HTML_S_Eta;		break;
355 		case 920:		pStr = OOO_STRING_SVTOOLS_HTML_S_Theta;	break;
356 		case 921:		pStr = OOO_STRING_SVTOOLS_HTML_S_Iota;	break;
357 		case 922:		pStr = OOO_STRING_SVTOOLS_HTML_S_Kappa;	break;
358 		case 923:		pStr = OOO_STRING_SVTOOLS_HTML_S_Lambda;	break;
359 		case 924:		pStr = OOO_STRING_SVTOOLS_HTML_S_Mu;		break;
360 		case 925:		pStr = OOO_STRING_SVTOOLS_HTML_S_Nu;		break;
361 		case 926:		pStr = OOO_STRING_SVTOOLS_HTML_S_Xi;		break;
362 		case 927:		pStr = OOO_STRING_SVTOOLS_HTML_S_Omicron;	break;
363 		case 928:		pStr = OOO_STRING_SVTOOLS_HTML_S_Pi;		break;
364 		case 929:		pStr = OOO_STRING_SVTOOLS_HTML_S_Rho;		break;
365 		case 931:		pStr = OOO_STRING_SVTOOLS_HTML_S_Sigma;	break;
366 		case 932:		pStr = OOO_STRING_SVTOOLS_HTML_S_Tau;		break;
367 		case 933:		pStr = OOO_STRING_SVTOOLS_HTML_S_Upsilon;	break;
368 		case 934:		pStr = OOO_STRING_SVTOOLS_HTML_S_Phi;		break;
369 		case 935:		pStr = OOO_STRING_SVTOOLS_HTML_S_Chi;		break;
370 		case 936:		pStr = OOO_STRING_SVTOOLS_HTML_S_Psi;		break;
371 		case 937:		pStr = OOO_STRING_SVTOOLS_HTML_S_Omega;	break;
372 		case 945:		pStr = OOO_STRING_SVTOOLS_HTML_S_alpha;	break;
373 		case 946:		pStr = OOO_STRING_SVTOOLS_HTML_S_beta;	break;
374 		case 947:		pStr = OOO_STRING_SVTOOLS_HTML_S_gamma;	break;
375 		case 948:		pStr = OOO_STRING_SVTOOLS_HTML_S_delta;	break;
376 		case 949:		pStr = OOO_STRING_SVTOOLS_HTML_S_epsilon;	break;
377 		case 950:		pStr = OOO_STRING_SVTOOLS_HTML_S_zeta;	break;
378 		case 951:		pStr = OOO_STRING_SVTOOLS_HTML_S_eta;		break;
379 		case 952:		pStr = OOO_STRING_SVTOOLS_HTML_S_theta;	break;
380 		case 953:		pStr = OOO_STRING_SVTOOLS_HTML_S_iota;	break;
381 		case 954:		pStr = OOO_STRING_SVTOOLS_HTML_S_kappa;	break;
382 		case 955:		pStr = OOO_STRING_SVTOOLS_HTML_S_lambda;	break;
383 		case 956:		pStr = OOO_STRING_SVTOOLS_HTML_S_mu;		break;
384 		case 957:		pStr = OOO_STRING_SVTOOLS_HTML_S_nu;		break;
385 		case 958:		pStr = OOO_STRING_SVTOOLS_HTML_S_xi;		break;
386 		case 959:		pStr = OOO_STRING_SVTOOLS_HTML_S_omicron;	break;
387 		case 960:		pStr = OOO_STRING_SVTOOLS_HTML_S_pi;		break;
388 		case 961:		pStr = OOO_STRING_SVTOOLS_HTML_S_rho;		break;
389 		case 962:		pStr = OOO_STRING_SVTOOLS_HTML_S_sigmaf;	break;
390 		case 963:		pStr = OOO_STRING_SVTOOLS_HTML_S_sigma;	break;
391 		case 964:		pStr = OOO_STRING_SVTOOLS_HTML_S_tau;		break;
392 		case 965:		pStr = OOO_STRING_SVTOOLS_HTML_S_upsilon;	break;
393 		case 966:		pStr = OOO_STRING_SVTOOLS_HTML_S_phi;		break;
394 		case 967:		pStr = OOO_STRING_SVTOOLS_HTML_S_chi;		break;
395 		case 968:		pStr = OOO_STRING_SVTOOLS_HTML_S_psi;		break;
396 		case 969:		pStr = OOO_STRING_SVTOOLS_HTML_S_omega;	break;
397 		case 977:		pStr = OOO_STRING_SVTOOLS_HTML_S_thetasym;break;
398 		case 978:		pStr = OOO_STRING_SVTOOLS_HTML_S_upsih;	break;
399 		case 982:		pStr = OOO_STRING_SVTOOLS_HTML_S_piv;		break;
400 		}
401 	}
402 
403 	return pStr;
404 }
405 
lcl_ConvertCharToHTML(sal_Unicode c,ByteString & rDest,HTMLOutContext & rContext,String * pNonConvertableChars)406 void lcl_ConvertCharToHTML( sal_Unicode c, ByteString& rDest,
407 							HTMLOutContext& rContext,
408 							String *pNonConvertableChars )
409 {
410 	DBG_ASSERT( RTL_TEXTENCODING_DONTKNOW != rContext.m_eDestEnc,
411 					"wrong destination encoding" );
412 	const sal_Char *pStr = 0;
413 	switch( c )
414 	{
415 	case 0xA0:		// is a hard blank
416 //!! the TextConverter has a problem with this character - so change it to
417 // a hard space - that's the same as our 5.2
418 	case 0x2011:	// is a hard hyphen
419 		pStr = OOO_STRING_SVTOOLS_HTML_S_nbsp;
420 		break;
421 	case 0xAD:		// is a soft hyphen
422 		pStr = OOO_STRING_SVTOOLS_HTML_S_shy;
423 		break;
424 	default:
425 		// There may be an entity for the character.
426 		// The new HTML4 entities above 255 are not used for UTF-8,
427 		// because Netscape 4 does support UTF-8 but does not support
428 		// these entities.
429 		if( c < 128 || RTL_TEXTENCODING_UTF8 != rContext.m_eDestEnc )
430 			pStr = lcl_svhtml_GetEntityForChar( c, rContext.m_eDestEnc );
431 		break;
432 	}
433 
434 	sal_Char cBuffer[TXTCONV_BUFFER_SIZE];
435 	sal_uInt32 nInfo = 0;
436 	sal_Size nSrcChars;
437 	const sal_uInt32 nFlags = RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE|
438 						RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE|
439 						RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR|
440 						RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR;
441 	if( pStr )
442 	{
443 		sal_Size nLen = rtl_convertUnicodeToText(
444 							rContext.m_hConv, rContext.m_hContext, &c, 0,
445 							cBuffer, TXTCONV_BUFFER_SIZE,
446 							nFlags|RTL_UNICODETOTEXT_FLAGS_FLUSH,
447 							&nInfo, &nSrcChars );
448 		DBG_ASSERT( (nInfo & (RTL_UNICODETOTEXT_INFO_ERROR|RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL)) == 0, "HTMLOut: error while flushing" );
449 		sal_Char *pBuffer = cBuffer;
450 		while( nLen-- )
451 			rDest += *pBuffer++;
452 		((rDest += '&') += pStr) += ';';
453 	}
454 	else
455 	{
456 		sal_Size nLen = rtl_convertUnicodeToText( rContext.m_hConv,
457 												  rContext.m_hContext, &c, 1,
458 										   		  cBuffer, TXTCONV_BUFFER_SIZE,
459 												  nFlags,
460 												  &nInfo, &nSrcChars );
461 		if( nLen > 0 && (nInfo & (RTL_UNICODETOTEXT_INFO_ERROR|RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL)) == 0 )
462 		{
463 			sal_Char *pBuffer = cBuffer;
464 			while( nLen-- )
465 				rDest += *pBuffer++;
466 		}
467 		else
468 		{
469 			// If the character could not be converted to the destination
470 			// character set, the UNICODE character is exported as character
471 			// entity.
472 			nLen = rtl_convertUnicodeToText(
473 								rContext.m_hConv, rContext.m_hContext, &c, 0,
474 								cBuffer, TXTCONV_BUFFER_SIZE,
475 								nFlags|RTL_UNICODETOTEXT_FLAGS_FLUSH,
476 								&nInfo, &nSrcChars );
477 			DBG_ASSERT( (nInfo & (RTL_UNICODETOTEXT_INFO_ERROR|RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL)) == 0, "HTMLOut: error while flushing" );
478 			sal_Char *pBuffer = cBuffer;
479 			while( nLen-- )
480 				rDest += *pBuffer++;
481 
482 			(((rDest += '&') += '#') +=
483 					ByteString::CreateFromInt64( (sal_uInt32)c )) += ';';
484 			if( pNonConvertableChars &&
485 				STRING_NOTFOUND == pNonConvertableChars->Search( c ) )
486 				pNonConvertableChars->Append( c );
487 		}
488 	}
489 }
490 
lcl_FlushToAscii(ByteString & rDest,HTMLOutContext & rContext)491 sal_Bool lcl_FlushToAscii( ByteString& rDest, HTMLOutContext& rContext )
492 {
493 	sal_Unicode c = 0;
494 	sal_Char cBuffer[TXTCONV_BUFFER_SIZE];
495 	sal_uInt32 nInfo = 0;
496 	sal_Size nSrcChars;
497 	const sal_uInt32 nFlags = RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE|
498 						RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE|
499 						RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR|
500 						RTL_UNICODETOTEXT_FLAGS_FLUSH|
501 						RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR;
502 	sal_Size nLen = rtl_convertUnicodeToText(
503 						rContext.m_hConv, rContext.m_hContext, &c, 0,
504 						cBuffer, TXTCONV_BUFFER_SIZE, nFlags,
505 						&nInfo, &nSrcChars );
506 	DBG_ASSERT( (nInfo & (RTL_UNICODETOTEXT_INFO_ERROR|RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL)) == 0, "HTMLOut: error while flushing" );
507 	sal_Bool bRet = nLen > 0;
508 	sal_Char *pBuffer = cBuffer;
509 	while( nLen-- )
510 		rDest += *pBuffer++;
511 	return bRet;
512 }
513 
ConvertStringToHTML(const String & rSrc,ByteString & rDest,rtl_TextEncoding eDestEnc,String * pNonConvertableChars)514 void HTMLOutFuncs::ConvertStringToHTML( const String& rSrc,
515 										ByteString& rDest,
516 										rtl_TextEncoding eDestEnc,
517 									 	String *pNonConvertableChars )
518 {
519 	HTMLOutContext aContext( eDestEnc );
520 	for( sal_uInt32 i=0UL, nLen = rSrc.Len(); i < nLen; i++ )
521 		lcl_ConvertCharToHTML( rSrc.GetChar( (xub_StrLen)i ), rDest, aContext,
522 							   pNonConvertableChars );
523 	lcl_FlushToAscii( rDest, aContext );
524 }
525 
Out_AsciiTag(SvStream & rStream,const sal_Char * pStr,sal_Bool bOn,rtl_TextEncoding)526 SvStream& HTMLOutFuncs::Out_AsciiTag( SvStream& rStream, const sal_Char *pStr,
527 									  sal_Bool bOn, rtl_TextEncoding )
528 {
529 	sal_Char sStt[3] = "</";
530 	if( bOn )
531 		sStt[1] = 0;
532 	return (rStream << sStt << pStr << '>');
533 }
534 
Out_Char(SvStream & rStream,sal_Unicode c,HTMLOutContext & rContext,String * pNonConvertableChars)535 SvStream& HTMLOutFuncs::Out_Char( SvStream& rStream, sal_Unicode c,
536 								  HTMLOutContext& rContext,
537 								  String *pNonConvertableChars )
538 {
539 	ByteString sOut;
540 	lcl_ConvertCharToHTML( c, sOut,  rContext, pNonConvertableChars );
541 	rStream << sOut.GetBuffer();
542 	return rStream;
543 }
544 
Out_String(SvStream & rStream,const String & rStr,rtl_TextEncoding eDestEnc,String * pNonConvertableChars)545 SvStream& HTMLOutFuncs::Out_String( SvStream& rStream, const String& rStr,
546 								    rtl_TextEncoding eDestEnc,
547 								    String *pNonConvertableChars )
548 {
549 	HTMLOutContext aContext( eDestEnc );
550 	xub_StrLen nLen = rStr.Len();
551 	for( xub_StrLen n = 0; n < nLen; n++ )
552 		HTMLOutFuncs::Out_Char( rStream, rStr.GetChar( (xub_StrLen)n ),
553 								aContext, pNonConvertableChars );
554 	HTMLOutFuncs::FlushToAscii( rStream, aContext );
555 	return rStream;
556 }
557 
FlushToAscii(SvStream & rStream,HTMLOutContext & rContext)558 SvStream& HTMLOutFuncs::FlushToAscii( SvStream& rStream,
559 		 							  HTMLOutContext& rContext )
560 {
561 	ByteString sOut;
562 	if( lcl_FlushToAscii( sOut, rContext ) )
563 		rStream << sOut.GetBuffer();
564 
565 	return rStream;
566 }
567 
Out_Hex(SvStream & rStream,sal_uLong nHex,sal_uInt8 nLen,rtl_TextEncoding)568 SvStream& HTMLOutFuncs::Out_Hex( SvStream& rStream, sal_uLong nHex, sal_uInt8 nLen,
569 							  	 rtl_TextEncoding )
570 {												   // in einen Stream aus
571 	sal_Char aNToABuf[] = "0000000000000000";
572 
573 	DBG_ASSERT( nLen < sizeof(aNToABuf), "zu viele Stellen" );
574 	if( nLen>=sizeof(aNToABuf) )
575 		nLen = (sizeof(aNToABuf)-1);
576 
577 	// Pointer an das Bufferende setzen
578 	sal_Char *pStr = aNToABuf + (sizeof(aNToABuf)-1);
579 	for( sal_uInt8 n = 0; n < nLen; ++n )
580 	{
581 		*(--pStr) = (sal_Char)(nHex & 0xf ) + 48;
582 		if( *pStr > '9' )
583 			*pStr += 39;
584 		nHex >>= 4;
585 	}
586 	return rStream << pStr;
587 }
588 
589 
Out_Color(SvStream & rStream,const Color & rColor,rtl_TextEncoding)590 SvStream& HTMLOutFuncs::Out_Color( SvStream& rStream, const Color& rColor,
591 								   rtl_TextEncoding )
592 {
593 	rStream << "\"#";
594 	if( rColor.GetColor() == COL_AUTO )
595 	{
596 		rStream << "000000";
597 	}
598 	else
599 	{
600 		Out_Hex( rStream, rColor.GetRed(), 2 );
601 		Out_Hex( rStream, rColor.GetGreen(), 2 );
602 		Out_Hex( rStream, rColor.GetBlue(), 2 );
603 	}
604 	rStream << '\"';
605 
606 	return rStream;
607 }
608 
Out_ImageMap(SvStream & rStream,const String & rBaseURL,const ImageMap & rIMap,const String & rName,const HTMLOutEvent * pEventTable,sal_Bool bOutStarBasic,const sal_Char * pDelim,const sal_Char * pIndentArea,const sal_Char * pIndentMap,rtl_TextEncoding eDestEnc,String * pNonConvertableChars)609 SvStream& HTMLOutFuncs::Out_ImageMap( SvStream& rStream,
610                                       const String& rBaseURL,
611 									  const ImageMap& rIMap,
612 									  const String& rName,
613 									  const HTMLOutEvent *pEventTable,
614 									  sal_Bool bOutStarBasic,
615 									  const sal_Char *pDelim,
616 									  const sal_Char *pIndentArea,
617 									  const sal_Char *pIndentMap,
618 								      rtl_TextEncoding eDestEnc,
619 								  	  String *pNonConvertableChars	)
620 {
621 	if( RTL_TEXTENCODING_DONTKNOW == eDestEnc )
622 		eDestEnc = gsl_getSystemTextEncoding();
623 
624 	const String& rOutName = rName.Len() ? rName : rIMap.GetName();
625 	DBG_ASSERT( rOutName.Len(), "Kein ImageMap-Name" );
626 	if( !rOutName.Len() )
627 		return rStream;
628 
629 	ByteString sOut( '<' );
630 	sOut.Append( RTL_CONSTASCII_STRINGPARAM(OOO_STRING_SVTOOLS_HTML_map ) );
631 	sOut.Append( ' ' );
632 	sOut.Append( RTL_CONSTASCII_STRINGPARAM(OOO_STRING_SVTOOLS_HTML_O_name) );
633 	sOut.Append( RTL_CONSTASCII_STRINGPARAM("=\"") );
634 	rStream << sOut.GetBuffer();
635 	sOut.Erase();
636 	Out_String( rStream, rOutName, eDestEnc, pNonConvertableChars );
637 	rStream << "\">";
638 
639 	for( sal_uInt16 i=0U; i<rIMap.GetIMapObjectCount(); i++ )
640 	{
641 		const IMapObject* pObj = rIMap.GetIMapObject( i );
642 		DBG_ASSERT( pObj, "Wo ist das ImageMap-Object?" );
643 
644 		if( pObj )
645 		{
646 			const sal_Char *pShape = 0;
647 			ByteString aCoords;
648 			switch( pObj->GetType() )
649 			{
650 			case( IMAP_OBJ_RECTANGLE ):
651 				{
652 					const IMapRectangleObject* pRectObj =
653 						(const IMapRectangleObject *)pObj;
654 					pShape = OOO_STRING_SVTOOLS_HTML_SH_rect;
655 					Rectangle aRect( pRectObj->GetRectangle() );
656 					((((((aCoords =
657 						ByteString::CreateFromInt32(aRect.Left())) += ',')
658 						+= ByteString::CreateFromInt32(aRect.Top())) += ',')
659 						+= ByteString::CreateFromInt32(aRect.Right())) += ',')
660 						+= ByteString::CreateFromInt32(aRect.Bottom());
661 				}
662 				break;
663 			case( IMAP_OBJ_CIRCLE ):
664 				{
665 					const IMapCircleObject* pCirc =
666 						(const IMapCircleObject *)pObj;
667 					pShape= OOO_STRING_SVTOOLS_HTML_SH_circ;
668 					Point aCenter( pCirc->GetCenter() );
669 					long nOff = pCirc->GetRadius();
670 					((((aCoords =
671 						ByteString::CreateFromInt32(aCenter.X())) += ',')
672 						+= ByteString::CreateFromInt32(aCenter.Y())) += ',')
673 						+= ByteString::CreateFromInt32(nOff);
674 				}
675 				break;
676 			case( IMAP_OBJ_POLYGON ):
677 				{
678 					const IMapPolygonObject* pPolyObj =
679 						(const IMapPolygonObject *)pObj;
680 					pShape= OOO_STRING_SVTOOLS_HTML_SH_poly;
681 					Polygon aPoly( pPolyObj->GetPolygon() );
682 					sal_uInt16 nCount = aPoly.GetSize();
683 					if( nCount>0 )
684 					{
685 						const Point& rPoint = aPoly[0];
686 						((aCoords =
687 							ByteString::CreateFromInt32(rPoint.X())) += ',')
688 							+= ByteString::CreateFromInt32(rPoint.Y());
689 					}
690 					for( sal_uInt16 j=1; j<nCount; j++ )
691 					{
692 						const Point& rPoint = aPoly[j];
693 						(((aCoords += ',')
694 						  	+= ByteString::CreateFromInt32(rPoint.X())) += ',')
695 							+= ByteString::CreateFromInt32(rPoint.Y());
696 					}
697 				}
698 				break;
699 			default:
700 				DBG_ASSERT( pShape, "unbekanntes IMapObject" );
701 				break;
702 			}
703 
704 			if( pShape )
705 			{
706 				if( pDelim )
707 					rStream << pDelim;
708 				if( pIndentArea )
709 					rStream << pIndentArea;
710 
711 				((((((((((sOut = '<') += OOO_STRING_SVTOOLS_HTML_area) += ' ')
712 					+= OOO_STRING_SVTOOLS_HTML_O_shape) += '=') += pShape) += ' ')
713 					+= OOO_STRING_SVTOOLS_HTML_O_coords) += "=\"") += aCoords) += "\" ";
714 				rStream << sOut.GetBuffer();
715 
716 				String aURL( pObj->GetURL() );
717 				if( aURL.Len() && pObj->IsActive() )
718 				{
719                     aURL = URIHelper::simpleNormalizedMakeRelative(
720                         rBaseURL, aURL );
721 					(sOut = OOO_STRING_SVTOOLS_HTML_O_href) += "=\"";
722 					rStream << sOut.GetBuffer();
723 					Out_String( rStream, aURL, eDestEnc, pNonConvertableChars ) << '\"';
724 				}
725 				else
726 					rStream << OOO_STRING_SVTOOLS_HTML_O_nohref;
727 
728 				const String& rObjName = pObj->GetName();
729 				if( rObjName.Len() )
730 				{
731 					((sOut = ' ') += OOO_STRING_SVTOOLS_HTML_O_name) += "=\"";
732 					rStream << sOut.GetBuffer();
733 					Out_String( rStream, rObjName, eDestEnc, pNonConvertableChars ) << '\"';
734 				}
735 
736 				const String& rTarget = pObj->GetTarget();
737 				if( rTarget.Len() && pObj->IsActive() )
738 				{
739 					((sOut = ' ') += OOO_STRING_SVTOOLS_HTML_O_target) += "=\"";
740 					rStream << sOut.GetBuffer();
741 					Out_String( rStream, rTarget, eDestEnc, pNonConvertableChars ) << '\"';
742 				}
743 
744 				String rDesc( pObj->GetAltText() );
745 				if( rDesc.Len() == 0 )
746 					rDesc = pObj->GetDesc();
747 
748 				if( rDesc.Len() )
749 				{
750 					((sOut = ' ') += OOO_STRING_SVTOOLS_HTML_O_alt) += "=\"";
751 					rStream << sOut.GetBuffer();
752 					Out_String( rStream, rDesc, eDestEnc, pNonConvertableChars ) << '\"';
753 				}
754 
755 				const SvxMacroTableDtor& rMacroTab = pObj->GetMacroTable();
756 				if( pEventTable && rMacroTab.Count() )
757 					Out_Events( rStream, rMacroTab, pEventTable,
758 								bOutStarBasic, eDestEnc, pNonConvertableChars );
759 
760 				rStream << '>';
761 			}
762 		}
763 
764 	}
765 
766 	if( pDelim )
767 		rStream << pDelim;
768 	if( pIndentMap )
769 		rStream << pIndentMap;
770 	Out_AsciiTag( rStream, OOO_STRING_SVTOOLS_HTML_map, sal_False );
771 
772 	return rStream;
773 }
774 
OutScript(SvStream & rStrm,const String & rBaseURL,const String & rSource,const String & rLanguage,ScriptType eScriptType,const String & rSrc,const String * pSBLibrary,const String * pSBModule,rtl_TextEncoding eDestEnc,String * pNonConvertableChars)775 SvStream& HTMLOutFuncs::OutScript( SvStream& rStrm,
776                                    const String& rBaseURL,
777 								   const String& rSource,
778 								   const String& rLanguage,
779 								   ScriptType eScriptType,
780 								   const String& rSrc,
781 								   const String *pSBLibrary,
782 								   const String *pSBModule,
783 								   rtl_TextEncoding eDestEnc,
784 								   String *pNonConvertableChars )
785 {
786 	if( RTL_TEXTENCODING_DONTKNOW == eDestEnc )
787 		eDestEnc = gsl_getSystemTextEncoding();
788 
789 	// Script wird komplett nicht eingerueckt!
790 	ByteString sOut( '<' );
791 	sOut.Append( RTL_CONSTASCII_STRINGPARAM(OOO_STRING_SVTOOLS_HTML_script) );
792 
793 	if( rLanguage.Len() )
794 	{
795 		sOut.Append( ' ' );
796 		sOut.Append( RTL_CONSTASCII_STRINGPARAM(OOO_STRING_SVTOOLS_HTML_O_language) );
797 		sOut.Append( RTL_CONSTASCII_STRINGPARAM("=\"") );
798 		rStrm << sOut.GetBuffer();
799 		Out_String( rStrm, rLanguage, eDestEnc, pNonConvertableChars );
800 		sOut = '\"';
801 	}
802 
803 	if( rSrc.Len() )
804 	{
805 		((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_src) += "=\"";
806 		rStrm << sOut.GetBuffer();
807         Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(rBaseURL, rSrc), eDestEnc, pNonConvertableChars );
808 		sOut = '\"';
809 	}
810 
811 	if( STARBASIC != eScriptType && pSBLibrary )
812 	{
813 		((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_sdlibrary) += "=\"";
814 		rStrm << sOut.GetBuffer();
815 		Out_String( rStrm, *pSBLibrary, eDestEnc, pNonConvertableChars );
816 		sOut = '\"';
817 	}
818 
819 	if( STARBASIC != eScriptType && pSBModule )
820 	{
821 		((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_sdmodule) += "=\"";
822 		rStrm << sOut.GetBuffer();
823 		Out_String( rStrm, *pSBModule, eDestEnc, pNonConvertableChars );
824 		sOut = '\"';
825 	}
826 
827 	sOut += '>';
828 
829 	rStrm << sOut.GetBuffer();
830 
831 	if( rSource.Len() || pSBLibrary || pSBModule )
832 	{
833 		rStrm << sNewLine;
834 
835 		if( JAVASCRIPT != eScriptType )
836 		{
837 			rStrm << "<!--"
838 				  << sNewLine;
839 		}
840 
841 		if( STARBASIC == eScriptType )
842 		{
843 			if( pSBLibrary )
844 			{
845 				sOut.Assign( RTL_CONSTASCII_STRINGPARAM("' ") );
846 				sOut.Append( RTL_CONSTASCII_STRINGPARAM(OOO_STRING_SVTOOLS_HTML_SB_library) );
847 				sOut.Append( ' ' );
848 				ByteString sTmp( *pSBLibrary, eDestEnc );
849 				sOut.Append( sTmp );
850 				rStrm << sOut.GetBuffer() << sNewLine;
851 			}
852 
853 			if( pSBModule )
854 			{
855 				sOut.Assign( RTL_CONSTASCII_STRINGPARAM("' ") );
856 				sOut.Append( RTL_CONSTASCII_STRINGPARAM(OOO_STRING_SVTOOLS_HTML_SB_module) );
857 				sOut.Append( ' ' );
858 				ByteString sTmp( *pSBModule, eDestEnc );
859 				sOut.Append( sTmp );
860 				rStrm << sOut.GetBuffer() << sNewLine;
861 			}
862 		}
863 
864 		if( rSource.Len() )
865 		{
866 			// Wir schreiben das Modul mm ANSI-Zeichensatz, aber mit
867 			// System-Zeilenumbruechen raus.
868 			ByteString sSource( rSource, eDestEnc );
869 			sSource.ConvertLineEnd( GetSystemLineEnd() );
870 			rStrm << sSource.GetBuffer();
871 		}
872 		rStrm << sNewLine;
873 
874 		if( JAVASCRIPT != eScriptType )
875 		{
876 			// MIB/MM: Wenn es kein StarBasic ist, kann ein // natuerlich
877 			// falsch sein. Da der Kommentar aber beim Einlesen wider
878 			// entfernt wird, schickt uns das nicht weiter ...
879 			rStrm << (STARBASIC == eScriptType ? "' -->" : "// -->")
880 				  << sNewLine;
881 		}
882 	}
883 
884 	HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_script, sal_False );
885 
886 	return rStrm;
887 }
888 
889 
Out_Events(SvStream & rStrm,const SvxMacroTableDtor & rMacroTable,const HTMLOutEvent * pEventTable,sal_Bool bOutStarBasic,rtl_TextEncoding eDestEnc,String * pNonConvertableChars)890 SvStream& HTMLOutFuncs::Out_Events( SvStream& rStrm,
891 									const SvxMacroTableDtor& rMacroTable,
892 									const HTMLOutEvent *pEventTable,
893 									sal_Bool bOutStarBasic,
894 								    rtl_TextEncoding eDestEnc,
895 								    String *pNonConvertableChars )
896 {
897 	sal_uInt16 i=0;
898 	while( pEventTable[i].pBasicName || pEventTable[i].pJavaName )
899 	{
900 		const SvxMacro *pMacro =
901 			rMacroTable.Get( pEventTable[i].nEvent );
902 
903 		if( pMacro && pMacro->GetMacName().Len() &&
904 			( JAVASCRIPT == pMacro->GetScriptType() || bOutStarBasic ))
905 		{
906 			const sal_Char *pStr = STARBASIC == pMacro->GetScriptType()
907 				? pEventTable[i].pBasicName
908 				: pEventTable[i].pJavaName;
909 
910 			if( pStr )
911 			{
912 				ByteString sOut( ' ' );
913 				(sOut += pStr) += "=\"";
914 				rStrm << sOut.GetBuffer();
915 
916 				Out_String( rStrm, pMacro->GetMacName(), eDestEnc, pNonConvertableChars ) << '\"';
917 			}
918 		}
919 		i++;
920 	}
921 
922 	return rStrm;
923 }
924 
CreateTableDataOptionsValNum(ByteString & aStrTD,sal_Bool bValue,double fVal,sal_uLong nFormat,SvNumberFormatter & rFormatter,rtl_TextEncoding eDestEnc,String * pNonConvertableChars)925 ByteString& HTMLOutFuncs::CreateTableDataOptionsValNum( ByteString& aStrTD,
926 			sal_Bool bValue,
927 			double fVal, sal_uLong nFormat, SvNumberFormatter& rFormatter,
928             rtl_TextEncoding eDestEnc, String* pNonConvertableChars )
929 {
930 	if ( bValue )
931 	{
932 		// printf / scanf ist zu ungenau
933 		String aValStr;
934 		rFormatter.GetInputLineString( fVal, 0, aValStr );
935 		ByteString sTmp( aValStr, eDestEnc );
936 		((((aStrTD += ' ') += OOO_STRING_SVTOOLS_HTML_O_SDval) += "=\"") += sTmp) += '\"';
937 	}
938 	if ( bValue || nFormat )
939 	{
940 		((aStrTD += ' ') += OOO_STRING_SVTOOLS_HTML_O_SDnum) += "=\"";
941 		(aStrTD += ByteString::CreateFromInt32(
942 								Application::GetSettings().GetLanguage() ))
943 			+= ';';	// Language fuer Format 0
944 		if ( nFormat )
945 		{
946 			ByteString aNumStr;
947 			LanguageType nLang;
948 			const SvNumberformat* pFormatEntry = rFormatter.GetEntry( nFormat );
949 			if ( pFormatEntry )
950 			{
951                 ConvertStringToHTML( pFormatEntry->GetFormatstring(), aNumStr,
952                     eDestEnc, pNonConvertableChars );
953 				nLang = pFormatEntry->GetLanguage();
954 			}
955 			else
956 				nLang = LANGUAGE_SYSTEM;
957 			((aStrTD += ByteString::CreateFromInt32(nLang)) += ';') += aNumStr;
958 		}
959 		aStrTD += '\"';
960 	}
961 	return aStrTD;
962 }
963 
PrivateURLToInternalImg(String & rURL)964 sal_Bool HTMLOutFuncs::PrivateURLToInternalImg( String& rURL )
965 {
966 	if( rURL.Len() > 14UL &&
967 		rURL.CompareToAscii( OOO_STRING_SVTOOLS_HTML_private_image, 14UL ) == COMPARE_EQUAL )
968 	{
969 		rURL.Erase( 0UL, 14UL );
970 		return sal_True;
971 	}
972 
973 	return sal_False;
974 }
975 
976 
977