From 2c48f0327582c9776c5cb43202406e3ac1aff360 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 23 Sep 2009 07:53:22 +0000 Subject: [PATCH] Fixed #10702 (encoding not used in HTML handler) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/richtext/richtexthtml.cpp | 159 ++++++++++++++++++++-------------- 1 file changed, 94 insertions(+), 65 deletions(-) diff --git a/src/richtext/richtexthtml.cpp b/src/richtext/richtexthtml.cpp index 9c0d6c2035..95f6c4754d 100644 --- a/src/richtext/richtexthtml.cpp +++ b/src/richtext/richtexthtml.cpp @@ -77,79 +77,108 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& buffer->Defragment(); - wxTextOutputStream str(stream); - - wxTextAttr currentParaStyle = buffer->GetAttributes(); - wxTextAttr currentCharStyle = buffer->GetAttributes(); - - if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0) - str << wxT("\n"); - - OutputFont(currentParaStyle, str); - - m_font = false; - m_inTable = false; - - m_indents.Clear(); - m_listTypes.Clear(); - - wxRichTextObjectList::compatibility_iterator node = buffer->GetChildren().GetFirst(); - while (node) +#if wxUSE_UNICODE + wxCSConv* customEncoding = NULL; + wxMBConv* conv = NULL; + if (!GetEncoding().IsEmpty()) { - wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph); - wxASSERT (para != NULL); - - if (para) + customEncoding = new wxCSConv(GetEncoding()); + if (!customEncoding->IsOk()) { - wxTextAttr paraStyle(para->GetCombinedAttributes()); - - BeginParagraphFormatting(currentParaStyle, paraStyle, str); + delete customEncoding; + customEncoding = NULL; + } + } + if (customEncoding) + conv = customEncoding; + else + conv = & wxConvUTF8; +#endif - wxRichTextObjectList::compatibility_iterator node2 = para->GetChildren().GetFirst(); - while (node2) + { +#if wxUSE_UNICODE + wxTextOutputStream str(stream, wxEOL_NATIVE, *conv); +#else + wxTextOutputStream str(stream, wxEOL_NATIVE); +#endif + + wxTextAttr currentParaStyle = buffer->GetAttributes(); + wxTextAttr currentCharStyle = buffer->GetAttributes(); + + if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0) + str << wxT("\n"); + + OutputFont(currentParaStyle, str); + + m_font = false; + m_inTable = false; + + m_indents.Clear(); + m_listTypes.Clear(); + + wxRichTextObjectList::compatibility_iterator node = buffer->GetChildren().GetFirst(); + while (node) + { + wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph); + wxASSERT (para != NULL); + + if (para) { - wxRichTextObject* obj = node2->GetData(); - wxRichTextPlainText* textObj = wxDynamicCast(obj, wxRichTextPlainText); - if (textObj && !textObj->IsEmpty()) + wxTextAttr paraStyle(para->GetCombinedAttributes()); + + BeginParagraphFormatting(currentParaStyle, paraStyle, str); + + wxRichTextObjectList::compatibility_iterator node2 = para->GetChildren().GetFirst(); + while (node2) { - wxTextAttr charStyle(para->GetCombinedAttributes(obj->GetAttributes())); - BeginCharacterFormatting(currentCharStyle, charStyle, paraStyle, str); - - wxString text = textObj->GetText(); - - if (charStyle.HasTextEffects() && (charStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS)) - text.MakeUpper(); - - wxString toReplace = wxRichTextLineBreakChar; - text.Replace(toReplace, wxT("
")); - - str << text; - - EndCharacterFormatting(currentCharStyle, charStyle, paraStyle, str); + wxRichTextObject* obj = node2->GetData(); + wxRichTextPlainText* textObj = wxDynamicCast(obj, wxRichTextPlainText); + if (textObj && !textObj->IsEmpty()) + { + wxTextAttr charStyle(para->GetCombinedAttributes(obj->GetAttributes())); + BeginCharacterFormatting(currentCharStyle, charStyle, paraStyle, str); + + wxString text = textObj->GetText(); + + if (charStyle.HasTextEffects() && (charStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS)) + text.MakeUpper(); + + wxString toReplace = wxRichTextLineBreakChar; + text.Replace(toReplace, wxT("
")); + + str << text; + + EndCharacterFormatting(currentCharStyle, charStyle, paraStyle, str); + } + + wxRichTextImage* image = wxDynamicCast(obj, wxRichTextImage); + if( image && (!image->IsEmpty() || image->GetImageBlock().GetData())) + WriteImage( image, stream ); + + node2 = node2->GetNext(); } - - wxRichTextImage* image = wxDynamicCast(obj, wxRichTextImage); - if( image && (!image->IsEmpty() || image->GetImageBlock().GetData())) - WriteImage( image, stream ); - - node2 = node2->GetNext(); + + EndParagraphFormatting(currentParaStyle, paraStyle, str); + + str << wxT("\n"); } - - EndParagraphFormatting(currentParaStyle, paraStyle, str); - - str << wxT("\n"); + node = node->GetNext(); } - node = node->GetNext(); + + CloseLists(-1, str); + + str << wxT(""); + + if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0) + str << wxT(""); + + str << wxT("\n"); } - CloseLists(-1, str); - - str << wxT(""); - - if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0) - str << wxT(""); - - str << wxT("\n"); +#if wxUSE_UNICODE + if (customEncoding) + delete customEncoding; +#endif m_buffer = NULL; @@ -256,7 +285,7 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxTextAttr& WXUNUSED( str << wxString::Format(wxT("

"); @@ -284,7 +313,7 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxTextAttr& WXUNUSED( str << wxString::Format(wxT("

"); } -- 2.45.2