- Fixed memory leak of pending events in wxEvtHandler
- Added wxRadioBox::IsItemEnabled/Shown()
- Added space after list item number in wxHTML.
+- Implemented <sub> and <sup> handling in wxHTML (based on patch
+ by Sandro Sigala)
wxMSW:
};
+// Superscript/subscript/normal script mode of a cell
+enum wxHtmlScriptMode
+{
+ wxHTML_SCRIPT_NORMAL,
+ wxHTML_SCRIPT_SUB,
+ wxHTML_SCRIPT_SUP
+};
// ---------------------------------------------------------------------------
int GetHeight() const {return m_Height;}
int GetDescent() const {return m_Descent;}
+ void SetScriptMode(wxHtmlScriptMode mode, long previousBase);
+ wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; }
+ long GetScriptBaseline() { return m_ScriptBaseline; }
+
// Formatting cells are not visible on the screen, they only alter
// renderer's state.
bool IsFormattingCell() const { return m_Width == 0 && m_Height == 0; }
{ return wxEmptyString; }
protected:
+ // pointer to the next cell
wxHtmlCell *m_Next;
- // pointer to the next cell
+ // pointer to parent cell
wxHtmlContainerCell *m_Parent;
- // pointer to parent cell
+
+ // dimensions of fragment (m_Descent is used to position text & images)
long m_Width, m_Height, m_Descent;
- // dimensions of fragment
- // m_Descent is used to position text&images..
+ // position where the fragment is drawn:
long m_PosX, m_PosY;
- // position where the fragment is drawn
+
+ // superscript/subscript/normal:
+ wxHtmlScriptMode m_ScriptMode;
+ long m_ScriptBaseline;
+
+ // destination address if this fragment is hypertext link, NULL otherwise
wxHtmlLinkInfo *m_Link;
- // destination address if this fragment is hypertext link, NULL otherwise
+ // true if this cell can be placed on pagebreak, false otherwise
bool m_CanLiveOnPagebreak;
- // true if this cell can be placed on pagebreak, false otherwise
+ // unique identifier of the cell, generated from "id" property of tags
wxString m_id;
- // unique identifier of the cell, generated from "id" property of tags
DECLARE_ABSTRACT_CLASS(wxHtmlCell)
DECLARE_NO_COPY_CLASS(wxHtmlCell)
#if WXWIN_COMPATIBILITY_2_4
wxDEPRECATED( wxHtmlCell* GetFirstCell() const );
#endif
+ // returns last child cell:
+ wxHtmlCell* GetLastChild() const { return m_LastCell; }
// see comment in wxHtmlCell about this method
virtual bool IsTerminalCell() const { return false; }
int GetAlign() const {return m_Align;}
void SetAlign(int a) {m_Align = a;}
+
+ wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; }
+ void SetScriptMode(wxHtmlScriptMode mode) { m_ScriptMode = mode; }
+ long GetScriptBaseline() const { return m_ScriptBaseline; }
+ void SetScriptBaseline(long base) { m_ScriptBaseline = base; }
+
const wxColour& GetLinkColor() const { return m_LinkColor; }
void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; }
const wxColour& GetActualColor() const { return m_ActualColor; }
const wxHtmlLinkInfo& GetLink() const { return m_Link; }
void SetLink(const wxHtmlLinkInfo& link);
+ // applies current parser state (link, sub/supscript, ...) to given cell
+ void ApplyStateToCell(wxHtmlCell *cell);
+
#if !wxUSE_UNICODE
void SetInputEncoding(wxFontEncoding enc);
wxFontEncoding GetInputEncoding() const { return m_InputEnc; }
// average height of normal-sized text
int m_Align;
// actual alignment
+ wxHtmlScriptMode m_ScriptMode;
+ // current script mode (sub/sup/normal)
+ long m_ScriptBaseline;
+ // current sub/supscript base
wxFont* m_FontsTable[2][2][2][2][7];
wxString m_FontsFacesTable[2][2][2][2][7];
--- /dev/null
+<html>
+<body>
+
+The quick brown fox jumps over the lazy dog H<sub>2</sub>O The quick brown fox jumps over the lazy dog
+The quick brown fox jumps over the lazy dog H<sub>2</sub>O The quick brown fox jumps over the lazy dog
+The quick brown fox jumps over the lazy dog H<sup><img src="foo.png"></img></sup>O The quick brown fox jumps over the lazy dog
+H<sub>The quick brown fox jumps over the lazy dog</sub>O The quick brown <sup>fox <sup>jumps over</sup> the</sup> lazy dog
+<br>
+The quick brown fox jumps over the lazy dog H<sub>2<sup>4<sup>5</sup></sup></sub>O The quick brown fox jumps over the lazy dog
+The quick brown fox jumps over the lazy dog H<sub>2<sup>5</sup></sub>O The quick brown fox jumps over the lazy dog
+The quick brown fox jumps over the lazy dog H<sub><img src="foo.png"></sub>O The quick brown fox jumps over the lazy dog
+The quick brown fox jumps over the lazy dog H<sub>2<sub>4</sub></sub>O The quick brown fox jumps over the lazy dog
+
+<br>
+
+<br>
+
+<img src="foo.png"><sup>tm</sup>
+
+<br>
+1<sup>2<sup>3<sup><a href="foo.html">link</a></sup></sup></sup>
+<br>
+x<sup>2</sup> + y<sup>2</sup> = r<sup>2</sup>
+<br>
+e<sup>sqrt(x<sup>2</sup> + y<sup>2</sup>)</sup>
+<br>
+log<sub>2</sub>5 = y<sup>3</sup>
+<br>
+Intel<sup>tm</sup>
+<br>
+Windows<sup>©</sup>
+<br>
+tst<sup>test</sup> me
+<br>
+<br>
+
+<font size=36>tst<sub>tst<sub>tst</sub></sub> me</font>
+
+<br>
+
+</body>
+</html>
<files>
f.html fft.html imagemap.htm imagemap.png pic.png pic2.bmp
tables.htm test.htm listtest.htm i18n.gif 8859_2.htm cp1250.htm
- regres.htm
+ regres.htm foo.png subsup.html
</files>
</wx-data>
m_Next = NULL;
m_Parent = NULL;
m_Width = m_Height = m_Descent = 0;
+ m_ScriptMode = wxHTML_SCRIPT_NORMAL; // <sub> or <sup> mode
+ m_ScriptBaseline = 0; // <sub> or <sup> baseline
m_CanLiveOnPagebreak = true;
m_Link = NULL;
}
delete m_Link;
}
+// Update the descent value when whe are in a <sub> or <sup>.
+// prevbase is the parent base
+void wxHtmlCell::SetScriptMode(wxHtmlScriptMode mode, long previousBase)
+{
+ m_ScriptMode = mode;
+
+ if (mode == wxHTML_SCRIPT_SUP)
+ m_ScriptBaseline = previousBase - (m_Height + 1) / 2;
+ else if (mode == wxHTML_SCRIPT_SUB)
+ m_ScriptBaseline = previousBase + (m_Height + 1) / 6;
+ else
+ m_ScriptBaseline = 0;
+
+ m_Descent += m_ScriptBaseline;
+}
void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y,
const wxMouseEvent& event)
str, w, h,
m_WParser->GetPixelScale(),
al, mn);
- cel->SetLink(m_WParser->GetLink());
+ m_WParser->ApplyStateToCell(cel);
cel->SetId(tag.GetParam(wxT("id"))); // may be empty
m_WParser->GetContainer()->InsertCell(cel);
if (str)
+TAG_HANDLER_BEGIN(SUBSUP, "SUB,SUP")
+
+ TAG_HANDLER_PROC(tag)
+ {
+ bool issub = (tag.GetName() == wxT("SUB"));
+ wxHtmlScriptMode oldmode = m_WParser->GetScriptMode();
+ int oldbase = m_WParser->GetScriptBaseline();
+ int oldsize = m_WParser->GetFontSize();
+
+ wxHtmlContainerCell *cont = m_WParser->GetContainer();
+ wxHtmlCell *c = cont->GetLastChild();
+
+ m_WParser->SetScriptMode(issub ? wxHTML_SCRIPT_SUB : wxHTML_SCRIPT_SUP);
+ m_WParser->SetScriptBaseline(oldbase + c->GetScriptBaseline());
+
+ // select smaller font
+ m_WParser->SetFontSize(m_WParser->GetFontSize()-2);
+ cont->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+
+ ParseInner(tag);
+
+ // restore font size
+ m_WParser->SetFontSize(oldsize);
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+
+ // restore base and alignment
+ m_WParser->SetScriptBaseline(oldbase);
+ m_WParser->SetScriptMode(oldmode);
+
+ return true;
+ }
+
+TAG_HANDLER_END(SUBSUP)
+
+
// Tag handler for tags that we have to ignore, otherwise non-text data
// would show up as text:
TAG_HANDLER_BEGIN(DoNothing, "SCRIPT")
+
+
TAGS_MODULE_BEGIN(Layout)
TAGS_MODULE_ADD(P)
TAGS_MODULE_ADD(TITLE)
TAGS_MODULE_ADD(BODY)
TAGS_MODULE_ADD(BLOCKQUOTE)
+ TAGS_MODULE_ADD(SUBSUP)
TAGS_MODULE_ADD(DoNothing)
TAGS_MODULE_END(Layout)
m_LinkColor.Set(0, 0, 0xFF);
m_ActualColor.Set(0, 0, 0);
m_Align = wxHTML_ALIGN_LEFT;
+ m_ScriptMode = wxHTML_SCRIPT_NORMAL;
+ m_ScriptBaseline = 0;
m_tmpLastWasSpace = false;
m_lastWordCell = NULL;
wxHtmlCell *c = new wxHtmlWordCell(temp, *(GetDC()));
- if (m_UseLink)
- c->SetLink(m_Link);
+ ApplyStateToCell(c);
+
m_Container->InsertCell(c);
((wxHtmlWordCell*)c)->SetPreviousWord(m_lastWordCell);
m_lastWordCell = (wxHtmlWordCell*)c;
m_UseLink = (link.GetHref() != wxEmptyString);
}
-
void wxHtmlWinParser::SetFontFace(const wxString& face)
{
if (GetFontFixed()) m_FontFaceFixed = face;
#endif
}
+void wxHtmlWinParser::ApplyStateToCell(wxHtmlCell *cell)
+{
+ // set the link:
+ if (m_UseLink)
+ cell->SetLink(GetLink());
+
+ // apply current script mode settings:
+ cell->SetScriptMode(GetScriptMode(), GetScriptBaseline());
+}
#if !wxUSE_UNICODE