X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4fdc2c5f2a4dd7f1394e374095b1cd3a34dfaa1b..eea4d01c65f9b29baa1193db762b4c6b8144af24:/src/richtext/richtexthtml.cpp diff --git a/src/richtext/richtexthtml.cpp b/src/richtext/richtexthtml.cpp index 6079da35c5..06670cb486 100644 --- a/src/richtext/richtexthtml.cpp +++ b/src/richtext/richtexthtml.cpp @@ -85,8 +85,7 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& customEncoding = new wxCSConv(GetEncoding()); if (!customEncoding->IsOk()) { - delete customEncoding; - customEncoding = NULL; + wxDELETE(customEncoding); } } if (customEncoding) @@ -102,8 +101,8 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& wxTextOutputStream str(stream, wxEOL_NATIVE); #endif - wxTextAttr currentParaStyle = buffer->GetAttributes(); - wxTextAttr currentCharStyle = buffer->GetAttributes(); + wxRichTextAttr currentParaStyle = buffer->GetAttributes(); + wxRichTextAttr currentCharStyle = buffer->GetAttributes(); if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0) str << wxT("
\n"); @@ -124,7 +123,7 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& if (para) { - wxTextAttr paraStyle(para->GetCombinedAttributes()); + wxRichTextAttr paraStyle(para->GetCombinedAttributes()); BeginParagraphFormatting(currentParaStyle, paraStyle, str); @@ -135,7 +134,7 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& wxRichTextPlainText* textObj = wxDynamicCast(obj, wxRichTextPlainText); if (textObj && !textObj->IsEmpty()) { - wxTextAttr charStyle(para->GetCombinedAttributes(obj->GetAttributes())); + wxRichTextAttr charStyle(para->GetCombinedAttributes(obj->GetAttributes())); BeginCharacterFormatting(currentCharStyle, charStyle, paraStyle, str); wxString text = textObj->GetText(); @@ -185,7 +184,7 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& return true; } -void wxRichTextHTMLHandler::BeginCharacterFormatting(const wxTextAttr& currentStyle, const wxTextAttr& thisStyle, const wxTextAttr& WXUNUSED(paraStyle), wxTextOutputStream& str) +void wxRichTextHTMLHandler::BeginCharacterFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, const wxRichTextAttr& WXUNUSED(paraStyle), wxTextOutputStream& str) { wxString style; @@ -197,10 +196,27 @@ void wxRichTextHTMLHandler::BeginCharacterFormatting(const wxTextAttr& currentSt } if (thisStyle.GetFontSize() != currentStyle.GetFontSize()) style += wxString::Format(wxT(" size=\"%ld\""), PtToSize(thisStyle.GetFontSize())); - if (thisStyle.GetTextColour() != currentStyle.GetTextColour() ) + + bool bTextColourChanged = (thisStyle.GetTextColour() != currentStyle.GetTextColour()); + bool bBackgroundColourChanged = (thisStyle.GetBackgroundColour() != currentStyle.GetBackgroundColour()); + if (bTextColourChanged || bBackgroundColourChanged) { - wxString color(thisStyle.GetTextColour().GetAsString(wxC2S_HTML_SYNTAX)); - style += wxString::Format(wxT(" color=\"%s\""), color.c_str()); + style += wxT(" style=\""); + + if (bTextColourChanged) + { + wxString color(thisStyle.GetTextColour().GetAsString(wxC2S_HTML_SYNTAX)); + style += wxString::Format(wxT("color: %s"), color.c_str()); + } + if (bTextColourChanged && bBackgroundColourChanged) + style += wxT(";"); + if (bBackgroundColourChanged) + { + wxString color(thisStyle.GetBackgroundColour().GetAsString(wxC2S_HTML_SYNTAX)); + style += wxString::Format(wxT("background-color: %s"), color.c_str()); + } + + style += wxT("\""); } if (style.size()) @@ -220,7 +236,7 @@ void wxRichTextHTMLHandler::BeginCharacterFormatting(const wxTextAttr& currentSt str << wxT(""); } -void wxRichTextHTMLHandler::EndCharacterFormatting(const wxTextAttr& WXUNUSED(currentStyle), const wxTextAttr& thisStyle, const wxTextAttr& WXUNUSED(paraStyle), wxTextOutputStream& stream) +void wxRichTextHTMLHandler::EndCharacterFormatting(const wxRichTextAttr& WXUNUSED(currentStyle), const wxRichTextAttr& thisStyle, const wxRichTextAttr& WXUNUSED(paraStyle), wxTextOutputStream& stream) { if (thisStyle.HasURL()) stream << wxT(""); @@ -240,7 +256,7 @@ void wxRichTextHTMLHandler::EndCharacterFormatting(const wxTextAttr& WXUNUSED(cu } /// Begin paragraph formatting -void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxTextAttr& WXUNUSED(currentStyle), const wxTextAttr& thisStyle, wxTextOutputStream& str) +void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxRichTextAttr& WXUNUSED(currentStyle), const wxRichTextAttr& thisStyle, wxTextOutputStream& str) { if (thisStyle.HasPageBreak()) { @@ -322,7 +338,7 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxTextAttr& WXUNUSED( str << wxT(">"); // TODO: convert to pixels - int indentPixels = indentLeftMM*10/4; + int indentPixels = static_cast