From 8932702b0c03086ce8f5e75f191701ed303bad3b Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 23 Sep 2009 11:06:30 +0000 Subject: [PATCH] Added wxRICHTEXT_HANDLER_USE_CSS flag for HTML handler to use CSS where possible. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@62033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 9 +- docs/latex/wx/richtexthtmlhandler.tex | 2 + include/wx/richtext/richtexthtml.h | 3 + src/richtext/richtexthtml.cpp | 115 ++++++++++++++++++-------- 4 files changed, 95 insertions(+), 34 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index bbd33ef8f2..d9c12ce964 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -116,11 +116,14 @@ All (GUI): - Add wxBU_EXACTFIT support to wxToggleButton XRC handler (Ronny Krueger). - wxRTC: fixed AltGr+key input and numeric keypad Delete on Windows. +- wxRTC: added background colour setting to font dialog. +- wxRTC: added wxRICHTEXT_HANDLER_USE_CSS flag for HTML handler to use CSS + where possible. +- wxRTC: corrected centring and right-justification spacing. - Paper size conversion from dimensions to id now uses definition ordering in order to use common types where there are duplications, fixing problems where invalid sizes caused incorrect second invocation of page setup dialog. -- Added background colour setting to wxRichTextCtrl font dialog. - Corrected writing direction for Farsi. wxMSW: @@ -133,6 +136,10 @@ wxMSW: You now need to set wxUSE_HIGH_QUALITY_PREVIEW_IN_WXMSW in src/common/prntbase.cpp and wxUSE_ENH_METAFILE_FROM_DC in include/wx/msw/enhmeta.h. +- Worked around child window and caret positioning bug (in Windows) when using + wxBORDER_THEME in a container window. +- Suppressed spurious character event for decimal key in numeric keypad. + wxMac: diff --git a/docs/latex/wx/richtexthtmlhandler.tex b/docs/latex/wx/richtexthtmlhandler.tex index f0808f8a72..c4a30a62c2 100644 --- a/docs/latex/wx/richtexthtmlhandler.tex +++ b/docs/latex/wx/richtexthtmlhandler.tex @@ -30,6 +30,8 @@ SetHandlerFlags function: \twocolitem{\windowstyle{wxRICHTEXT\_HANDLER\_SAVE\_IMAGES\_TO\_FILES}}{Images are saved to temporary files: suitable for showing in wxHTML windows.} \twocolitem{\windowstyle{wxRICHTEXT\_HANDLER\_SAVE\_IMAGES\_TO\_BASE64}}{Images are written with the HTML files in Base 64 format: suitable for showing in web browsers.} \twocolitem{\windowstyle{wxRICHTEXT\_HANDLER\_NO\_HEADER\_FOOTER}}{Don't include header and footer tags (HTML, HEAD, BODY), so that the HTML can be used as part of a larger document.} +\twocolitem{\windowstyle{wxRICHTEXT\_HANDLER\_USE\_CSS}}{Use CSS where possible, otherwise use workarounds that will show in wxHtmlWindow.} + \end{twocollist} \wxheading{Derived from} diff --git a/include/wx/richtext/richtexthtml.h b/include/wx/richtext/richtexthtml.h index f71ed68d9d..34e9479339 100644 --- a/include/wx/richtext/richtexthtml.h +++ b/include/wx/richtext/richtexthtml.h @@ -18,6 +18,9 @@ #include "wx/richtext/richtextbuffer.h" +// Use CSS styles where applicable, otherwise use non-CSS workarounds +#define wxRICHTEXT_HANDLER_USE_CSS 0x1000 + /*! * wxRichTextHTMLHandler */ diff --git a/src/richtext/richtexthtml.cpp b/src/richtext/richtexthtml.cpp index 6e610bef71..1e3f47d6d2 100644 --- a/src/richtext/richtexthtml.cpp +++ b/src/richtext/richtexthtml.cpp @@ -101,33 +101,33 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& #else wxTextOutputStream str(stream, wxEOL_NATIVE); #endif - + wxTextAttrEx currentParaStyle = buffer->GetAttributes(); wxTextAttrEx 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) { wxTextAttrEx paraStyle(para->GetCombinedAttributes()); - + BeginParagraphFormatting(currentParaStyle, paraStyle, str); - + wxRichTextObjectList::compatibility_iterator node2 = para->GetChildren().GetFirst(); while (node2) { @@ -137,41 +137,41 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& { wxTextAttrEx 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(); } - + EndParagraphFormatting(currentParaStyle, paraStyle, str); - + str << wxT("\n"); } node = node->GetNext(); } - + CloseLists(-1, str); - + str << wxT(""); - + if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0) str << wxT(""); - + str << wxT("\n"); } @@ -284,25 +284,59 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxTextAttrEx& WXUNUSE wxString align = GetAlignment(thisStyle); str << wxString::Format(wxT("

0.0)) + { + styleStr += wxString::Format(wxT("margin-left: %.2fmm; "), indentLeftMM); + } + float indentRightMM = thisStyle.GetRightIndent()/10.0; + if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasRightIndent() && (indentRightMM > 0.0)) + { + styleStr += wxString::Format(wxT("margin-right: %.2fmm; "), indentRightMM); + } + // First line indentation + float firstLineIndentMM = - thisStyle.GetLeftSubIndent() / 10.0; + if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && (firstLineIndentMM > 0.0)) + { + styleStr += wxString::Format(wxT("text-indent: %.2fmm; "), firstLineIndentMM); + } + + if (!styleStr.IsEmpty()) + str << wxT(" style=\"") << styleStr << wxT("\""); str << wxT(">"); - // Use a table - int indentTenthsMM = thisStyle.GetLeftIndent() + thisStyle.GetLeftSubIndent(); // TODO: convert to pixels - int indentPixels = indentTenthsMM/4; - str << wxString::Format(wxT("
"), indentPixels); + int indentPixels = indentLeftMM*10/4; + + if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) == 0) + { + // Use a table to do indenting if we don't have CSS + str << wxString::Format(wxT("
"), indentPixels); + m_inTable = true; + } OutputFont(thisStyle, str); - if (thisStyle.GetLeftSubIndent() < 0) + if (((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) == 0) && (thisStyle.GetLeftSubIndent() < 0)) { str << SymbolicIndent( - thisStyle.GetLeftSubIndent()); } - - m_inTable = true; } } else @@ -312,8 +346,23 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxTextAttrEx& WXUNUSE wxString align = GetAlignment(thisStyle); str << wxString::Format(wxT("

"); }