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
This commit is contained in:
@@ -116,11 +116,14 @@ All (GUI):
|
|||||||
|
|
||||||
- Add wxBU_EXACTFIT support to wxToggleButton XRC handler (Ronny Krueger).
|
- Add wxBU_EXACTFIT support to wxToggleButton XRC handler (Ronny Krueger).
|
||||||
- wxRTC: fixed AltGr+key input and numeric keypad Delete on Windows.
|
- 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
|
- Paper size conversion from dimensions to id now uses definition ordering
|
||||||
in order to use common types where there are duplications, fixing problems
|
in order to use common types where there are duplications, fixing problems
|
||||||
where invalid sizes caused incorrect second invocation of page setup
|
where invalid sizes caused incorrect second invocation of page setup
|
||||||
dialog.
|
dialog.
|
||||||
- Added background colour setting to wxRichTextCtrl font dialog.
|
|
||||||
- Corrected writing direction for Farsi.
|
- Corrected writing direction for Farsi.
|
||||||
|
|
||||||
wxMSW:
|
wxMSW:
|
||||||
@@ -133,6 +136,10 @@ wxMSW:
|
|||||||
You now need to set wxUSE_HIGH_QUALITY_PREVIEW_IN_WXMSW in
|
You now need to set wxUSE_HIGH_QUALITY_PREVIEW_IN_WXMSW in
|
||||||
src/common/prntbase.cpp and wxUSE_ENH_METAFILE_FROM_DC in
|
src/common/prntbase.cpp and wxUSE_ENH_METAFILE_FROM_DC in
|
||||||
include/wx/msw/enhmeta.h.
|
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:
|
wxMac:
|
||||||
|
|
||||||
|
@@ -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\_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\_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\_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}
|
\end{twocollist}
|
||||||
|
|
||||||
\wxheading{Derived from}
|
\wxheading{Derived from}
|
||||||
|
@@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
#include "wx/richtext/richtextbuffer.h"
|
#include "wx/richtext/richtextbuffer.h"
|
||||||
|
|
||||||
|
// Use CSS styles where applicable, otherwise use non-CSS workarounds
|
||||||
|
#define wxRICHTEXT_HANDLER_USE_CSS 0x1000
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* wxRichTextHTMLHandler
|
* wxRichTextHTMLHandler
|
||||||
*/
|
*/
|
||||||
|
@@ -101,33 +101,33 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream&
|
|||||||
#else
|
#else
|
||||||
wxTextOutputStream str(stream, wxEOL_NATIVE);
|
wxTextOutputStream str(stream, wxEOL_NATIVE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxTextAttrEx currentParaStyle = buffer->GetAttributes();
|
wxTextAttrEx currentParaStyle = buffer->GetAttributes();
|
||||||
wxTextAttrEx currentCharStyle = buffer->GetAttributes();
|
wxTextAttrEx currentCharStyle = buffer->GetAttributes();
|
||||||
|
|
||||||
if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0)
|
if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0)
|
||||||
str << wxT("<html><head></head><body>\n");
|
str << wxT("<html><head></head><body>\n");
|
||||||
|
|
||||||
OutputFont(currentParaStyle, str);
|
OutputFont(currentParaStyle, str);
|
||||||
|
|
||||||
m_font = false;
|
m_font = false;
|
||||||
m_inTable = false;
|
m_inTable = false;
|
||||||
|
|
||||||
m_indents.Clear();
|
m_indents.Clear();
|
||||||
m_listTypes.Clear();
|
m_listTypes.Clear();
|
||||||
|
|
||||||
wxRichTextObjectList::compatibility_iterator node = buffer->GetChildren().GetFirst();
|
wxRichTextObjectList::compatibility_iterator node = buffer->GetChildren().GetFirst();
|
||||||
while (node)
|
while (node)
|
||||||
{
|
{
|
||||||
wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
|
wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
|
||||||
wxASSERT (para != NULL);
|
wxASSERT (para != NULL);
|
||||||
|
|
||||||
if (para)
|
if (para)
|
||||||
{
|
{
|
||||||
wxTextAttrEx paraStyle(para->GetCombinedAttributes());
|
wxTextAttrEx paraStyle(para->GetCombinedAttributes());
|
||||||
|
|
||||||
BeginParagraphFormatting(currentParaStyle, paraStyle, str);
|
BeginParagraphFormatting(currentParaStyle, paraStyle, str);
|
||||||
|
|
||||||
wxRichTextObjectList::compatibility_iterator node2 = para->GetChildren().GetFirst();
|
wxRichTextObjectList::compatibility_iterator node2 = para->GetChildren().GetFirst();
|
||||||
while (node2)
|
while (node2)
|
||||||
{
|
{
|
||||||
@@ -137,41 +137,41 @@ bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream&
|
|||||||
{
|
{
|
||||||
wxTextAttrEx charStyle(para->GetCombinedAttributes(obj->GetAttributes()));
|
wxTextAttrEx charStyle(para->GetCombinedAttributes(obj->GetAttributes()));
|
||||||
BeginCharacterFormatting(currentCharStyle, charStyle, paraStyle, str);
|
BeginCharacterFormatting(currentCharStyle, charStyle, paraStyle, str);
|
||||||
|
|
||||||
wxString text = textObj->GetText();
|
wxString text = textObj->GetText();
|
||||||
|
|
||||||
if (charStyle.HasTextEffects() && (charStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS))
|
if (charStyle.HasTextEffects() && (charStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS))
|
||||||
text.MakeUpper();
|
text.MakeUpper();
|
||||||
|
|
||||||
wxString toReplace = wxRichTextLineBreakChar;
|
wxString toReplace = wxRichTextLineBreakChar;
|
||||||
text.Replace(toReplace, wxT("<br>"));
|
text.Replace(toReplace, wxT("<br>"));
|
||||||
|
|
||||||
str << text;
|
str << text;
|
||||||
|
|
||||||
EndCharacterFormatting(currentCharStyle, charStyle, paraStyle, str);
|
EndCharacterFormatting(currentCharStyle, charStyle, paraStyle, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxRichTextImage* image = wxDynamicCast(obj, wxRichTextImage);
|
wxRichTextImage* image = wxDynamicCast(obj, wxRichTextImage);
|
||||||
if( image && (!image->IsEmpty() || image->GetImageBlock().GetData()))
|
if( image && (!image->IsEmpty() || image->GetImageBlock().GetData()))
|
||||||
WriteImage( image, stream );
|
WriteImage( image, stream );
|
||||||
|
|
||||||
node2 = node2->GetNext();
|
node2 = node2->GetNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
EndParagraphFormatting(currentParaStyle, paraStyle, str);
|
EndParagraphFormatting(currentParaStyle, paraStyle, str);
|
||||||
|
|
||||||
str << wxT("\n");
|
str << wxT("\n");
|
||||||
}
|
}
|
||||||
node = node->GetNext();
|
node = node->GetNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseLists(-1, str);
|
CloseLists(-1, str);
|
||||||
|
|
||||||
str << wxT("</font>");
|
str << wxT("</font>");
|
||||||
|
|
||||||
if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0)
|
if ((GetFlags() & wxRICHTEXT_HANDLER_NO_HEADER_FOOTER) == 0)
|
||||||
str << wxT("</body></html>");
|
str << wxT("</body></html>");
|
||||||
|
|
||||||
str << wxT("\n");
|
str << wxT("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,25 +284,59 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxTextAttrEx& WXUNUSE
|
|||||||
wxString align = GetAlignment(thisStyle);
|
wxString align = GetAlignment(thisStyle);
|
||||||
str << wxString::Format(wxT("<p align=\"%s\""), align.c_str());
|
str << wxString::Format(wxT("<p align=\"%s\""), align.c_str());
|
||||||
|
|
||||||
if (thisStyle.HasParagraphSpacingAfter() && thisStyle.GetParagraphSpacingAfter() == 0)
|
wxString styleStr;
|
||||||
str << wxT(" style=\"margin: 0px;\"");
|
|
||||||
|
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingBefore())
|
||||||
|
{
|
||||||
|
float spacingBeforeMM = thisStyle.GetParagraphSpacingBefore() / 10.0;
|
||||||
|
|
||||||
|
styleStr += wxString::Format(wxT("margin-top: %.2fmm; "), spacingBeforeMM);
|
||||||
|
}
|
||||||
|
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingAfter())
|
||||||
|
{
|
||||||
|
float spacingAfterMM = thisStyle.GetParagraphSpacingAfter() / 10.0;
|
||||||
|
|
||||||
|
styleStr += wxString::Format(wxT("margin-bottom: %.2fmm; "), spacingAfterMM);
|
||||||
|
}
|
||||||
|
|
||||||
|
float indentLeftMM = (thisStyle.GetLeftIndent() + thisStyle.GetLeftSubIndent())/10.0;
|
||||||
|
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && (indentLeftMM > 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(">");
|
str << wxT(">");
|
||||||
|
|
||||||
// Use a table
|
|
||||||
int indentTenthsMM = thisStyle.GetLeftIndent() + thisStyle.GetLeftSubIndent();
|
|
||||||
// TODO: convert to pixels
|
// TODO: convert to pixels
|
||||||
int indentPixels = indentTenthsMM/4;
|
int indentPixels = indentLeftMM*10/4;
|
||||||
str << wxString::Format(wxT("<table border=0 cellpadding=0 cellspacing=0><tr><td width=\"%d\"></td><td>"), indentPixels);
|
|
||||||
|
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) == 0)
|
||||||
|
{
|
||||||
|
// Use a table to do indenting if we don't have CSS
|
||||||
|
str << wxString::Format(wxT("<table border=0 cellpadding=0 cellspacing=0><tr><td width=\"%d\"></td><td>"), indentPixels);
|
||||||
|
m_inTable = true;
|
||||||
|
}
|
||||||
|
|
||||||
OutputFont(thisStyle, str);
|
OutputFont(thisStyle, str);
|
||||||
|
|
||||||
if (thisStyle.GetLeftSubIndent() < 0)
|
if (((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) == 0) && (thisStyle.GetLeftSubIndent() < 0))
|
||||||
{
|
{
|
||||||
str << SymbolicIndent( - thisStyle.GetLeftSubIndent());
|
str << SymbolicIndent( - thisStyle.GetLeftSubIndent());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_inTable = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -312,8 +346,23 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxTextAttrEx& WXUNUSE
|
|||||||
wxString align = GetAlignment(thisStyle);
|
wxString align = GetAlignment(thisStyle);
|
||||||
str << wxString::Format(wxT("<p align=\"%s\""), align.c_str());
|
str << wxString::Format(wxT("<p align=\"%s\""), align.c_str());
|
||||||
|
|
||||||
if (thisStyle.HasParagraphSpacingAfter() && thisStyle.GetParagraphSpacingAfter() == 0)
|
wxString styleStr;
|
||||||
str << wxT(" style=\"margin: 0px;\"");
|
|
||||||
|
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingBefore())
|
||||||
|
{
|
||||||
|
float spacingBeforeMM = thisStyle.GetParagraphSpacingBefore() / 10.0;
|
||||||
|
|
||||||
|
styleStr += wxString::Format(wxT("margin-top: %.2fmm; "), spacingBeforeMM);
|
||||||
|
}
|
||||||
|
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingAfter())
|
||||||
|
{
|
||||||
|
float spacingAfterMM = thisStyle.GetParagraphSpacingAfter() / 10.0;
|
||||||
|
|
||||||
|
styleStr += wxString::Format(wxT("margin-bottom: %.2fmm; "), spacingAfterMM);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!styleStr.IsEmpty())
|
||||||
|
str << wxT(" style=\"") << styleStr << wxT("\"");
|
||||||
|
|
||||||
str << wxT(">");
|
str << wxT(">");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user