added support for <sub> and <sup> to wxHTML (based on patch #1263152)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36572 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
43056e6ed5
commit
3c115835b3
@ -40,6 +40,8 @@ All (GUI):
|
||||
- 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:
|
||||
|
||||
|
@ -145,6 +145,13 @@ enum
|
||||
};
|
||||
|
||||
|
||||
// Superscript/subscript/normal script mode of a cell
|
||||
enum wxHtmlScriptMode
|
||||
{
|
||||
wxHTML_SCRIPT_NORMAL,
|
||||
wxHTML_SCRIPT_SUB,
|
||||
wxHTML_SCRIPT_SUP
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -176,6 +183,10 @@ public:
|
||||
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; }
|
||||
@ -297,21 +308,26 @@ public:
|
||||
{ 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)
|
||||
@ -414,6 +430,8 @@ public:
|
||||
#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; }
|
||||
|
@ -112,6 +112,12 @@ public:
|
||||
|
||||
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; }
|
||||
@ -119,6 +125,9 @@ public:
|
||||
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; }
|
||||
@ -164,6 +173,10 @@ private:
|
||||
// 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];
|
||||
|
BIN
samples/html/test/foo.png
Normal file
BIN
samples/html/test/foo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 410 B |
42
samples/html/test/subsup.html
Normal file
42
samples/html/test/subsup.html
Normal file
@ -0,0 +1,42 @@
|
||||
<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>
|
@ -18,7 +18,7 @@
|
||||
<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>
|
||||
|
||||
|
@ -90,6 +90,8 @@ wxHtmlCell::wxHtmlCell() : wxObject()
|
||||
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;
|
||||
}
|
||||
@ -99,6 +101,21 @@ wxHtmlCell::~wxHtmlCell()
|
||||
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)
|
||||
|
@ -645,7 +645,7 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
|
||||
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)
|
||||
|
@ -392,6 +392,42 @@ TAG_HANDLER_END(BLOCKQUOTE)
|
||||
|
||||
|
||||
|
||||
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")
|
||||
@ -405,6 +441,8 @@ TAG_HANDLER_END(DoNothing)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TAGS_MODULE_BEGIN(Layout)
|
||||
|
||||
TAGS_MODULE_ADD(P)
|
||||
@ -414,6 +452,7 @@ TAGS_MODULE_BEGIN(Layout)
|
||||
TAGS_MODULE_ADD(TITLE)
|
||||
TAGS_MODULE_ADD(BODY)
|
||||
TAGS_MODULE_ADD(BLOCKQUOTE)
|
||||
TAGS_MODULE_ADD(SUBSUP)
|
||||
TAGS_MODULE_ADD(DoNothing)
|
||||
|
||||
TAGS_MODULE_END(Layout)
|
||||
|
@ -192,6 +192,8 @@ void wxHtmlWinParser::InitParser(const wxString& source)
|
||||
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;
|
||||
|
||||
@ -366,8 +368,8 @@ void wxHtmlWinParser::DoAddText(wxChar *temp, int& templen, wxChar nbsp)
|
||||
|
||||
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;
|
||||
@ -464,7 +466,6 @@ void wxHtmlWinParser::SetLink(const wxHtmlLinkInfo& link)
|
||||
m_UseLink = (link.GetHref() != wxEmptyString);
|
||||
}
|
||||
|
||||
|
||||
void wxHtmlWinParser::SetFontFace(const wxString& face)
|
||||
{
|
||||
if (GetFontFixed()) m_FontFaceFixed = face;
|
||||
@ -476,6 +477,15 @@ void wxHtmlWinParser::SetFontFace(const wxString& 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
|
||||
|
Loading…
Reference in New Issue
Block a user