]> git.saurik.com Git - wxWidgets.git/blame - src/richtext/richtexthtml.cpp
Adding support for item font/style/color customization, unfortunately, it does not...
[wxWidgets.git] / src / richtext / richtexthtml.cpp
CommitLineData
b71e9aa4 1/////////////////////////////////////////////////////////////////////////////
40989e46 2// Name: src/richtext/richtexthtml.cpp
b71e9aa4
JS
3// Purpose: HTML I/O for wxRichTextCtrl
4// Author: Julian Smart
5// Modified by:
6// Created: 2005-09-30
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
40989e46 16 #pragma hdrstop
b71e9aa4
JS
17#endif
18
19#if wxUSE_RICHTEXT
20
21#include "wx/richtext/richtexthtml.h"
22
23#ifndef WX_PRECOMP
b71e9aa4
JS
24#endif
25
26#include "wx/filename.h"
27#include "wx/wfstream.h"
28#include "wx/txtstrm.h"
29
30IMPLEMENT_DYNAMIC_CLASS(wxRichTextHTMLHandler, wxRichTextFileHandler)
31
32/// Can we handle this filename (if using files)? By default, checks the extension.
33bool wxRichTextHTMLHandler::CanHandle(const wxString& filename) const
34{
35 wxString path, file, ext;
36 wxSplitPath(filename, & path, & file, & ext);
37
38 return (ext.Lower() == wxT("html") || ext.Lower() == wxT("htm"));
39}
40
41
42#if wxUSE_STREAMS
43bool wxRichTextHTMLHandler::DoLoadFile(wxRichTextBuffer *WXUNUSED(buffer), wxInputStream& WXUNUSED(stream))
44{
45 return false;
46}
47
48/*
49 * We need to output only _changes_ in character formatting.
50 */
51
52bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
53{
54 buffer->Defragment();
40989e46 55
b71e9aa4 56 wxTextOutputStream str(stream);
40989e46 57
b71e9aa4
JS
58 wxTextAttrEx currentParaStyle = buffer->GetAttributes();
59 wxTextAttrEx currentCharStyle = buffer->GetAttributes();
40989e46 60
b71e9aa4 61 str << wxT("<html><head></head><body>\n");
40989e46 62
2dec6761
JS
63 /*
64 wxRichText may be support paper formats like a1/a2/a3/a4
65 when this widget grown enough, i should turn back and support its new features
66 but not yet
40989e46 67
2dec6761 68 str << wxT("<table border=0 cellpadding=0 cellspacing=0><tr><td>");
40989e46 69
2dec6761
JS
70 wxString left_indent = SymbolicIndent(currentParaStyle.GetLeftIndent());
71 wxString right_indent = SymbolicIndent(currentParaStyle.GetRightIndent());
40989e46 72
2dec6761
JS
73 str << wxString::Format(wxT("%s</td><td></td><td>%s</td></tr><tr>"),
74 left_indent.c_str(), //Document-Wide Left Indent
75 right_indent.c_str()); //Document-Wide Right Indent
40989e46 76
2dec6761
JS
77 str << wxT("<td></td><td width=\"100%\">");
78 */
40989e46 79
2dec6761 80 str << wxT("<table border=0 cellpadding=0 cellspacing=0><tr><td width=\"100%\">");
40989e46
WS
81
82 str << wxString::Format(wxT("<font face=\"%s\" size=\"%ld\" color=\"%s\" >"),
83 currentParaStyle.GetFont().GetFaceName().c_str(), Pt_To_Size( currentParaStyle.GetFont().GetPointSize() ),
84 currentParaStyle.GetTextColour().GetAsString(wxC2S_HTML_SYNTAX).c_str());
85
2dec6761
JS
86 //wxString align = GetAlignment( currentParaStyle.GetAlignment() );
87 //str << wxString::Format(wxT("<p align=\"%s\">"), align );
40989e46 88
2dec6761
JS
89 m_font = false;
90 m_indent = 0;
91 m_list = false;
40989e46 92
b71e9aa4
JS
93 wxRichTextObjectList::compatibility_iterator node = buffer->GetChildren().GetFirst();
94 while (node)
95 {
96 wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
97 wxASSERT (para != NULL);
40989e46 98
b71e9aa4
JS
99 if (para)
100 {
27507b61
JS
101 wxTextAttrEx paraStyle(para->GetCombinedAttributes());
102
103 OutputParagraphFormatting(currentParaStyle, paraStyle, stream);
40989e46 104
b71e9aa4
JS
105 wxRichTextObjectList::compatibility_iterator node2 = para->GetChildren().GetFirst();
106 while (node2)
107 {
108 wxRichTextObject* obj = node2->GetData();
109 wxRichTextPlainText* textObj = wxDynamicCast(obj, wxRichTextPlainText);
110 if (textObj && !textObj->IsEmpty())
111 {
27507b61
JS
112 wxTextAttrEx charStyle(para->GetCombinedAttributes(obj->GetAttributes()));
113 BeginCharacterFormatting(currentCharStyle, charStyle, paraStyle, stream);
40989e46 114
b71e9aa4 115 str << textObj->GetText();
40989e46 116
27507b61 117 EndCharacterFormatting(currentCharStyle, charStyle, paraStyle, stream);
b71e9aa4 118 }
40989e46 119
2dec6761
JS
120 wxRichTextImage* image = wxDynamicCast(obj, wxRichTextImage);
121 if( image && !image->IsEmpty())
122 Image_to_Base64( image, stream );
40989e46 123
b71e9aa4
JS
124 node2 = node2->GetNext();
125 }
d5363f57 126 str << wxT("\n");
2dec6761 127 //OutputParagraphFormatting(currentParaStyle, para->GetAttributes(), stream, false);
b71e9aa4 128 }
b71e9aa4
JS
129 node = node->GetNext();
130 }
40989e46 131
2dec6761 132 str << wxT("</font></td></tr></table></body></html>\n");
40989e46 133
b71e9aa4
JS
134 return true;
135}
136
27507b61 137void wxRichTextHTMLHandler::BeginCharacterFormatting(const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, const wxTextAttrEx& paraStyle, wxOutputStream& stream)
b71e9aa4
JS
138{
139 wxTextOutputStream str(stream);
40989e46 140
2dec6761 141 //Is the item bulleted one?
27507b61 142 if( paraStyle.GetBulletStyle() != wxTEXT_ATTR_BULLET_STYLE_NONE )
b71e9aa4 143 {
2dec6761
JS
144 //Is there any opened list?
145 if( m_list )
146 {
147 //Yes there is
40989e46 148
2dec6761
JS
149 //Is the item among the previous ones
150 //Is the item one of the previous list tag's child items
27507b61 151 if( (paraStyle.GetLeftIndent() == (m_indent + 100)) || (paraStyle.GetLeftIndent() < 100) )
2dec6761
JS
152 str << wxT("<li>");//Yes it is
153 else
154 {
155 //No it isn't
40989e46 156
2dec6761
JS
157 //So we should close the list tag
158 str << (m_is_ul ? wxT("</ul>") : wxT("</ol>"));
40989e46 159
2dec6761 160 //And renavigate to new list's horizontal position
27507b61 161 NavigateToListPosition(paraStyle, str);
2dec6761 162 //Ok it's done
40989e46 163
2dec6761
JS
164 //Get the appropriate tag, an ol for numerical values, an ul for dot, square etc.
165 wxString tag;
27507b61 166 TypeOfList(paraStyle, tag);
21e354f1 167 str << tag << wxT("<li>");
2dec6761
JS
168 }
169 }
170 else
171 {
172 //No there isn't a list
40989e46 173
2dec6761 174 //navigate to new list's horizontal position(indent)
27507b61 175 NavigateToListPosition(paraStyle, str);
40989e46 176
2dec6761
JS
177 //Get the appropriate tag, an ol for numerical values, an ul for dot, square etc.
178 wxString tag;
27507b61 179 TypeOfList(paraStyle, tag);
21e354f1 180 str << tag << wxT("<li>");
40989e46 181
2dec6761
JS
182 //Now we have a list, mark it.
183 m_list = true;
40989e46 184 }
b71e9aa4 185 }
2dec6761
JS
186 else if( m_list )
187 {
40989e46 188 //The item is not bulleted and there is a list what should be closed now.
2dec6761 189 //So close the list
b71e9aa4 190
2dec6761
JS
191 str << (m_is_ul ? wxT("</ul>") : wxT("</ol>"));
192 //And mark as there is no an opened list
193 m_list = false;
194 }
40989e46 195
2dec6761 196 // does the item have an indentation ?
27507b61 197 if( paraStyle.GetLeftIndent() )
b71e9aa4 198 {
27507b61 199 if( paraStyle.GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_NONE )
2dec6761
JS
200 {
201 if( m_indent )
202 {
27507b61 203 if( (paraStyle.GetLeftIndent() + paraStyle.GetLeftSubIndent()) == m_indent )
2dec6761 204 {
27507b61 205 if( paraStyle.GetLeftSubIndent() < 0 )
2dec6761 206 {
27507b61 207 str << SymbolicIndent(~paraStyle.GetLeftSubIndent());
2dec6761
JS
208 }
209 }
210 else
211 {
27507b61 212 if( paraStyle.GetLeftIndent() + paraStyle.GetLeftSubIndent() > m_indent )
2dec6761 213 {
27507b61
JS
214 Indent(paraStyle, str);
215 m_indent = paraStyle.GetLeftIndent() + paraStyle.GetLeftSubIndent();
2dec6761
JS
216 m_indents.Add( m_indent );
217 }
218 else
219 {
220 int i = m_indents.size() - 1;
221 for(; i > -1; i--)
222 {
27507b61 223 if( m_indent < (paraStyle.GetLeftIndent() + paraStyle.GetLeftSubIndent()) )
2dec6761 224 {
27507b61
JS
225 Indent(paraStyle, str);
226 m_indent = paraStyle.GetLeftIndent() + paraStyle.GetLeftSubIndent();
2dec6761 227 m_indents.Add( m_indent );
40989e46 228
2dec6761
JS
229 break;
230 }
27507b61 231 else if( m_indent == (paraStyle.GetLeftIndent() + paraStyle.GetLeftSubIndent()) )
2dec6761 232 {
27507b61 233 if( paraStyle.GetLeftSubIndent() < 0 )
2dec6761 234 {
27507b61 235 str << SymbolicIndent(~paraStyle.GetLeftSubIndent());
2dec6761
JS
236 }
237 break;
238 }
239 else
240 {
241 str << wxT("</td></tr></table>");
40989e46 242
2dec6761 243 m_indents.RemoveAt(i);
40989e46 244
2dec6761
JS
245 if( i < 1 ){m_indent=0; break;}
246 m_indent = m_indents[i-1];
247 }
248 }
249 }
250 }
251 }
252 else
253 {
27507b61
JS
254 Indent(paraStyle, str);
255 m_indent = paraStyle.GetLeftIndent() + paraStyle.GetLeftSubIndent();
2dec6761
JS
256 m_indents.Add( m_indent );
257 }
258 }
b71e9aa4 259 }
2dec6761 260 else if( m_indent )
b71e9aa4 261 {
2dec6761 262 //The item is not indented and there is a table(s) what should be closed now.
40989e46 263
2dec6761
JS
264 //So close them
265 for(unsigned int i = 0; i < m_indents.size(); i++ )
266 str << wxT("</td></tr></table>");
40989e46 267
2dec6761
JS
268 m_indent = 0;
269 m_indents.Clear();
b71e9aa4 270 }
40989e46
WS
271
272
2dec6761 273 wxString style;
40989e46 274
2dec6761
JS
275 //Is there any change on the font properties of the item
276 if( thisStyle.GetFont().GetFaceName() != currentStyle.GetFont().GetFaceName() )
21e354f1 277 style += wxString::Format(wxT(" face=\"%s\""), thisStyle.GetFont().GetFaceName().c_str());
2dec6761 278 if( thisStyle.GetFont().GetPointSize() != currentStyle.GetFont().GetPointSize() )
d0c3476b 279 style += wxString::Format(wxT(" size=\"%ld\""), Pt_To_Size(thisStyle.GetFont().GetPointSize()) );
2dec6761 280 if( thisStyle.GetTextColour() != currentStyle.GetTextColour() )
40989e46
WS
281 style += wxString::Format(wxT(" color=\"%s\""), thisStyle.GetTextColour().GetAsString(wxC2S_HTML_SYNTAX).c_str());
282
21e354f1
JS
283 if( style.size() )
284 {
285 str << wxString::Format(wxT("<font %s >"), style.c_str());
286 m_font = true;
287 }
40989e46 288
2dec6761
JS
289 if( thisStyle.GetFont().GetWeight() == wxBOLD )
290 str << wxT("<b>");
291 if( thisStyle.GetFont().GetStyle() == wxITALIC )
292 str << wxT("<i>");
293 if( thisStyle.GetFont().GetUnderlined() )
294 str << wxT("<u>");
b71e9aa4
JS
295}
296
27507b61 297void wxRichTextHTMLHandler::EndCharacterFormatting(const wxTextAttrEx& WXUNUSED(currentStyle), const wxTextAttrEx& thisStyle, const wxTextAttrEx& WXUNUSED(paraStyle), wxOutputStream& stream)
b71e9aa4 298{
b71e9aa4 299 wxTextOutputStream str(stream);
40989e46 300
2dec6761
JS
301 if( thisStyle.GetFont().GetUnderlined() )
302 str << wxT("</u>");
303 if( thisStyle.GetFont().GetStyle() == wxITALIC )
304 str << wxT("</i>");
305 if( thisStyle.GetFont().GetWeight() == wxBOLD )
306 str << wxT("</b>");
40989e46 307
2dec6761
JS
308 if( m_font )
309 {
310 m_font = false;
311 str << wxT("</font>");
312 }
313}
b71e9aa4 314
2dec6761
JS
315/// Output paragraph formatting
316void wxRichTextHTMLHandler::OutputParagraphFormatting(const wxTextAttrEx& WXUNUSED(currentStyle), const wxTextAttrEx& thisStyle, wxOutputStream& stream)
317{
318 //If there is no opened list currently, insert a <p> after every paragraph
319 if(!m_list)
b71e9aa4 320 {
2dec6761
JS
321 wxTextOutputStream str(stream);
322 wxString align = GetAlignment( thisStyle );
21e354f1 323 str << wxString::Format(wxT("<p align=\"%s\">"), align.c_str());
b71e9aa4 324 }
2dec6761 325}
b71e9aa4 326
2dec6761
JS
327void wxRichTextHTMLHandler::NavigateToListPosition(const wxTextAttrEx& thisStyle, wxTextOutputStream& str)
328{
329 //indenting an item using an ul/ol tag is equal to inserting 5 x &nbsp; on its left side.
330 //so we should start from 100 point left
40989e46
WS
331
332 //Is the second td's left wall of the current indentaion table at the 100+ point-left-side
2dec6761
JS
333 //of the item, horizontally?
334 if( m_indent + 100 < thisStyle.GetLeftIndent() )
b71e9aa4 335 {
2dec6761
JS
336 //yes it is
337 LIndent(thisStyle, str);
338 m_indent = thisStyle.GetLeftIndent() - 100;
339 m_indents.Add( m_indent );
340 return;
b71e9aa4 341 }
2dec6761 342 //No it isn't
40989e46 343
2dec6761
JS
344 int i = m_indents.size() - 1;
345 for(; i > -1; i--)
346 {
40989e46 347 //Is the second td's left wall of the current indentaion table at the 100+ point-left-side
2dec6761
JS
348 //of the item ?
349 if( m_indent + 100 < thisStyle.GetLeftIndent() )
350 {
351 //Yes it is
352 LIndent(thisStyle, str);
353 m_indent = thisStyle.GetLeftIndent() - 100;
354 m_indents.Add( m_indent );
355 break;
356 }
357 else if( m_indent + 100 == thisStyle.GetLeftIndent() )
358 break;//exact match
359 else
360 {
361 //No it is not, the second td's left wall of the current indentaion table is at the
362 //right side of the current item horizontally, so close it.
363 str << wxT("</td></tr></table>");
40989e46 364
2dec6761 365 m_indents.RemoveAt(i);
40989e46 366
2dec6761
JS
367 if( i < 1 ){m_indent=0; break;}
368 m_indent = m_indents[i-1];
369 }
370 }
371}
372void wxRichTextHTMLHandler::Indent( const wxTextAttrEx& thisStyle, wxTextOutputStream& str )
373{
374 //As a five year experienced web developer i assure you there is no way to indent an item
375 //in html way, but we can use tables.
40989e46
WS
376
377
378
2dec6761
JS
379 //Item -> "Hello world"
380 //Its Left Indentation -> 100
381 //Its Left Sub-Indentation ->40
382 //A typical indentation-table for the item will be construct as the following
40989e46 383
2dec6761
JS
384 //3 x nbsp = 60
385 //2 x nbsp = 40
386 //LSI = Left Sub Indent
387 //LI = Left Indent - LSI
388 //
389 //-------------------------------------------
390 //|&nbsp;&nbsp;nbsp;|nbsp;nbsp;Hello World |
40989e46 391 //| | | | |
2dec6761
JS
392 //| V | V |
393 //| --LI-- | --LSI-- |
394 //-------------------------------------------
40989e46 395
2dec6761 396 str << wxT("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
40989e46 397
2dec6761 398 wxString symbolic_indent = SymbolicIndent( (thisStyle.GetLeftIndent() + thisStyle.GetLeftSubIndent()) - m_indent );
21e354f1 399 str << wxString::Format( wxT("<td>%s</td>"), symbolic_indent.c_str() );
2dec6761 400 str << wxT("<td width=\"100%\">");
40989e46 401
2dec6761
JS
402 if( thisStyle.GetLeftSubIndent() < 0 )
403 {
21e354f1 404 str << SymbolicIndent(~thisStyle.GetLeftSubIndent());
2dec6761
JS
405 }
406}
407
408void wxRichTextHTMLHandler::LIndent( const wxTextAttrEx& thisStyle, wxTextOutputStream& str )
409{
410 //Code:
411 //r.BeginNumberedBullet(1, 200, 60);
412 //r.Newline();
413 //r.WriteText(wxT("first item"));
414 //r.EndNumberedBullet();
415 //r.BeginNumberedBullet(2, 200, 60);
416 //r.Newline();
417 //r.WriteText(wxT("second item."));
418 //r.EndNumberedBullet();
419 //
420 //A typical indentation-table for the item will be construct as the following
40989e46 421
2dec6761
JS
422 //1 x nbsp = 20 point
423 //ULI -> 100pt (UL/OL tag indents its sub element by 100 point)
424 //<--------- 100 pt ---------->|
425 //------------------------------------------------------
426 //|&nbsp;&nbsp;nbsp;&nbsp;nbsp;|<ul> |
40989e46 427 //| |<-ULI-><li>first item |
2dec6761
JS
428 //| |<-ULI-><li>second item |
429 //| |</ul> |
430 //------------------------------------------------------
40989e46
WS
431 // |<-100->|
432
433
2dec6761 434 str << wxT("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
40989e46 435
2dec6761 436 wxString symbolic_indent = SymbolicIndent( (thisStyle.GetLeftIndent() - m_indent) - 100);
21e354f1 437 str << wxString::Format( wxT("<td>%s</td>"), symbolic_indent.c_str() );
2dec6761
JS
438 str << wxT("<td width=\"100%\">");
439}
440
441void wxRichTextHTMLHandler::TypeOfList( const wxTextAttrEx& thisStyle, wxString& tag )
442{
40989e46 443 //We can use number attribute of li tag but not all the browsers support it.
2dec6761 444 //also wxHtmlWindow doesn't support type attribute.
40989e46 445
2dec6761
JS
446 m_is_ul = false;
447 if( thisStyle.GetBulletStyle() == (wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD))
448 tag = wxT("<ol type=\"1\">");
449 else if( thisStyle.GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER )
450 tag = wxT("<ol type=\"A\">");
451 else if( thisStyle.GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER )
452 tag = wxT("<ol type=\"a\">");
453 else if( thisStyle.GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER )
454 tag = wxT("<ol type=\"I\">");
455 else if( thisStyle.GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER )
456 tag = wxT("<ol type=\"i\">");
b71e9aa4
JS
457 else
458 {
2dec6761
JS
459 tag = wxT("<ul>");
460 m_is_ul = true;
b71e9aa4
JS
461 }
462}
463
2dec6761
JS
464wxString wxRichTextHTMLHandler::GetAlignment( const wxTextAttrEx& thisStyle )
465{
466 switch( thisStyle.GetAlignment() )
467 {
468 case wxTEXT_ALIGNMENT_LEFT:
469 return wxT("left");
470 case wxTEXT_ALIGNMENT_RIGHT:
471 return wxT("right");
472 case wxTEXT_ALIGNMENT_CENTER:
473 return wxT("center");
474 case wxTEXT_ALIGNMENT_JUSTIFIED:
475 return wxT("justify");
476 default:
477 return wxT("left");
478 }
479}
480
481void wxRichTextHTMLHandler::Image_to_Base64(wxRichTextImage* image, wxOutputStream& stream)
482{
483 wxTextOutputStream str(stream);
40989e46 484
2dec6761
JS
485 str << wxT("<img src=\"");
486 str << wxT("data:");
487 str << GetMimeType(image->GetImageBlock().GetImageType());
488 str << wxT(";base64,");
40989e46 489
d5363f57
JS
490 if (image->GetImage().Ok() && !image->GetImageBlock().GetData())
491 image->MakeBlock();
40989e46 492
2dec6761
JS
493 wxChar* data = b64enc( image->GetImageBlock().GetData(), image->GetImageBlock().GetDataSize() );
494 str << data;
40989e46 495
2dec6761 496 delete[] data;
40989e46 497
2dec6761
JS
498 str << wxT("\" />");
499}
500
501long wxRichTextHTMLHandler::Pt_To_Size(long size)
502{
503 //return most approximate size
504 if(size < 9 ) return 1;
505 else if( size < 11 ) return 2;
506 else if( size < 14 ) return 3;
507 else if( size < 18 ) return 4;
508 else if( size < 23 ) return 5;
509 else if( size < 30 ) return 6;
510 else return 7;
511}
512
513wxString wxRichTextHTMLHandler::SymbolicIndent(long indent)
514{
515 wxString in;
516 for(;indent > 0; indent -= 20)
517 in.Append( wxT("&nbsp;") );
518 return in;
519}
520
21e354f1 521const wxChar* wxRichTextHTMLHandler::GetMimeType(int imageType)
2dec6761
JS
522{
523 switch(imageType)
524 {
525 case wxBITMAP_TYPE_BMP:
526 return wxT("image/bmp");
527 case wxBITMAP_TYPE_TIF:
528 return wxT("image/tiff");
529 case wxBITMAP_TYPE_GIF:
530 return wxT("image/gif");
531 case wxBITMAP_TYPE_PNG:
532 return wxT("image/png");
533 case wxBITMAP_TYPE_JPEG:
534 return wxT("image/jpeg");
535 default:
536 return wxT("image/unknown");
537 }
538}
539
540//exim-style base64 encoder
541wxChar* wxRichTextHTMLHandler::b64enc( unsigned char* input, size_t in_len )
542{
543 //elements of enc64 array must be 8 bit values
544 //otherwise encoder will fail
545 //hmmm.. Does wxT macro define a char as 16 bit value
40989e46 546 //when compiling with UNICODE option?
21e354f1 547 static const wxChar enc64[] = wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
2dec6761
JS
548 wxChar* output = new wxChar[4*((in_len+2)/3)+1];
549 wxChar* p = output;
40989e46 550
2dec6761
JS
551 while( in_len-- > 0 )
552 {
553 register wxChar a, b;
40989e46 554
2dec6761 555 a = *input++;
40989e46 556
2dec6761 557 *p++ = enc64[ (a >> 2) & 0x3f ];
40989e46 558
07854e5e 559 if( in_len-- == 0 )
2dec6761
JS
560 {
561 *p++ = enc64[ (a << 4 ) & 0x30 ];
562 *p++ = '=';
563 *p++ = '=';
564 break;
565 }
40989e46 566
2dec6761 567 b = *input++;
40989e46 568
2dec6761 569 *p++ = enc64[(( a << 4 ) | ((b >> 4) &0xf )) & 0x3f];
40989e46 570
07854e5e 571 if( in_len-- == 0 )
2dec6761
JS
572 {
573 *p++ = enc64[ (b << 2) & 0x3f ];
574 *p++ = '=';
575 break;
576 }
40989e46 577
2dec6761 578 a = *input++;
40989e46 579
2dec6761 580 *p++ = enc64[ ((( b << 2 ) & 0x3f ) | ((a >> 6)& 0x3)) & 0x3f ];
40989e46 581
2dec6761
JS
582 *p++ = enc64[ a & 0x3f ];
583 }
584 *p = 0;
40989e46 585
2dec6761
JS
586 return output;
587}
b71e9aa4 588#endif
2dec6761 589// wxUSE_STREAMS
b71e9aa4
JS
590
591#endif
2dec6761 592// wxUSE_RICHTEXT