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