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).
|
||||
- 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:
|
||||
|
||||
|
@@ -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}
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -284,25 +284,59 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxTextAttrEx& WXUNUSE
|
||||
wxString align = GetAlignment(thisStyle);
|
||||
str << wxString::Format(wxT("<p align=\"%s\""), align.c_str());
|
||||
|
||||
if (thisStyle.HasParagraphSpacingAfter() && thisStyle.GetParagraphSpacingAfter() == 0)
|
||||
str << wxT(" style=\"margin: 0px;\"");
|
||||
wxString styleStr;
|
||||
|
||||
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(">");
|
||||
|
||||
// Use a table
|
||||
int indentTenthsMM = thisStyle.GetLeftIndent() + thisStyle.GetLeftSubIndent();
|
||||
// TODO: convert to pixels
|
||||
int indentPixels = indentTenthsMM/4;
|
||||
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("<table border=0 cellpadding=0 cellspacing=0><tr><td width=\"%d\"></td><td>"), 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("<p align=\"%s\""), align.c_str());
|
||||
|
||||
if (thisStyle.HasParagraphSpacingAfter() && thisStyle.GetParagraphSpacingAfter() == 0)
|
||||
str << wxT(" style=\"margin: 0px;\"");
|
||||
wxString styleStr;
|
||||
|
||||
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(">");
|
||||
}
|
||||
|
Reference in New Issue
Block a user