+
+ if (image->GetImageBlock().IsOk())
+ {
+ wxString tempDir(GetTempDir());
+ if (tempDir.IsEmpty())
+ tempDir = wxFileName::GetTempDir();
+
+ wxString ext(image->GetImageBlock().GetExtension());
+ wxString tempFilename(wxString::Format(wxT("%s/image%d.%s"), tempDir, sm_fileCounter, ext));
+ image->GetImageBlock().Write(tempFilename);
+
+ m_imageLocations.Add(tempFilename);
+
+ str << wxFileSystem::FileNameToURL(tempFilename);
+ }
+ else
+ str << wxT("file:?");
+
+ sm_fileCounter ++;
+ }
+ else // if (GetFlags() & wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64) // this is implied
+#endif
+ {
+ str << wxT("data:");
+ str << GetMimeType(image->GetImageBlock().GetImageType());
+ str << wxT(";base64,");
+#if 0
+ if (image->GetImage().IsOk() && !image->GetImageBlock().GetData())
+ image->MakeBlock();
+#endif
+ if (image->GetImageBlock().IsOk())
+ {
+ wxChar* data = b64enc( image->GetImageBlock().GetData(), image->GetImageBlock().GetDataSize() );
+ str << data;
+
+ delete[] data;
+ }
+ }
+
+ str << wxT("\" />");
+}
+
+long wxRichTextHTMLHandler::PtToSize(long size)
+{
+ int i;
+ int len = m_fontSizeMapping.GetCount();
+ for (i = 0; i < len; i++)
+ if (size <= m_fontSizeMapping[i])
+ return i+1;
+ return 7;
+}
+
+wxString wxRichTextHTMLHandler::SymbolicIndent(long indent)
+{
+ wxString in;
+ for(;indent > 0; indent -= 20)
+ in.Append( wxT(" ") );
+ return in;
+}
+
+const wxChar* wxRichTextHTMLHandler::GetMimeType(int imageType)
+{
+ switch(imageType)
+ {
+ case wxBITMAP_TYPE_BMP:
+ return wxT("image/bmp");
+ case wxBITMAP_TYPE_TIFF:
+ return wxT("image/tiff");
+ case wxBITMAP_TYPE_GIF:
+ return wxT("image/gif");
+ case wxBITMAP_TYPE_PNG:
+ return wxT("image/png");
+ case wxBITMAP_TYPE_JPEG:
+ return wxT("image/jpeg");
+ default:
+ return wxT("image/unknown");
+ }
+}
+
+// exim-style base64 encoder
+wxChar* wxRichTextHTMLHandler::b64enc( unsigned char* input, size_t in_len )
+{
+ // elements of enc64 array must be 8 bit values
+ // otherwise encoder will fail
+ // hmmm.. Does wxT macro define a char as 16 bit value
+ // when compiling with UNICODE option?
+ static const wxChar enc64[] = wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
+ wxChar* output = new wxChar[4*((in_len+2)/3)+1];
+ wxChar* p = output;
+
+ while( in_len-- > 0 )
+ {
+ register wxChar a, b;
+
+ a = *input++;
+
+ *p++ = enc64[ (a >> 2) & 0x3f ];
+
+ if( in_len-- == 0 )
+ {
+ *p++ = enc64[ (a << 4 ) & 0x30 ];
+ *p++ = '=';
+ *p++ = '=';
+ break;
+ }
+
+ b = *input++;
+
+ *p++ = enc64[(( a << 4 ) | ((b >> 4) &0xf )) & 0x3f];
+
+ if( in_len-- == 0 )
+ {
+ *p++ = enc64[ (b << 2) & 0x3f ];
+ *p++ = '=';
+ break;
+ }
+
+ a = *input++;
+
+ *p++ = enc64[ ((( b << 2 ) & 0x3f ) | ((a >> 6)& 0x3)) & 0x3f ];
+
+ *p++ = enc64[ a & 0x3f ];
+ }
+ *p = 0;
+
+ return output;
+}
+#endif
+// wxUSE_STREAMS
+
+/// Delete the in-memory or temporary files generated by the last operation
+bool wxRichTextHTMLHandler::DeleteTemporaryImages()
+{
+ return DeleteTemporaryImages(GetFlags(), m_imageLocations);
+}
+
+/// Delete the in-memory or temporary files generated by the last operation
+bool wxRichTextHTMLHandler::DeleteTemporaryImages(int flags, const wxArrayString& imageLocations)
+{
+ size_t i;
+ for (i = 0; i < imageLocations.GetCount(); i++)
+ {
+ wxString location = imageLocations[i];
+
+ if (flags & wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY)
+ {
+#if wxUSE_FILESYSTEM
+ wxMemoryFSHandler::RemoveFile(location);
+#endif
+ }
+ else if (flags & wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES)
+ {
+ if (wxFileExists(location))
+ wxRemoveFile(location);
+ }
+ }
+
+ return true;
+}
+
+
+#endif
+// wxUSE_RICHTEXT
+