From 3c115835b39194fd6c6852c96f5a9cccd2cc9aaa Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 27 Dec 2005 00:00:39 +0000 Subject: [PATCH] added support for and to wxHTML (based on patch #1263152) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36572 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 ++ include/wx/html/htmlcell.h | 34 ++++++++++++++++++++------- include/wx/html/winpars.h | 13 +++++++++++ samples/html/test/foo.png | Bin 0 -> 410 bytes samples/html/test/subsup.html | 42 ++++++++++++++++++++++++++++++++++ samples/html/test/test.bkl | 2 +- src/html/htmlcell.cpp | 17 ++++++++++++++ src/html/m_image.cpp | 2 +- src/html/m_layout.cpp | 39 +++++++++++++++++++++++++++++++ src/html/winpars.cpp | 16 ++++++++++--- 10 files changed, 154 insertions(+), 13 deletions(-) create mode 100644 samples/html/test/foo.png create mode 100644 samples/html/test/subsup.html diff --git a/docs/changes.txt b/docs/changes.txt index 22546af7c1..d6104490b3 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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 and handling in wxHTML (based on patch + by Sandro Sigala) wxMSW: diff --git a/include/wx/html/htmlcell.h b/include/wx/html/htmlcell.h index f06788d65b..62afdebae4 100644 --- a/include/wx/html/htmlcell.h +++ b/include/wx/html/htmlcell.h @@ -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; } diff --git a/include/wx/html/winpars.h b/include/wx/html/winpars.h index 2d188ace3a..12893b888b 100644 --- a/include/wx/html/winpars.h +++ b/include/wx/html/winpars.h @@ -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]; diff --git a/samples/html/test/foo.png b/samples/html/test/foo.png new file mode 100644 index 0000000000000000000000000000000000000000..e09f103beb695b06e86851681ab388f9d04029ee GIT binary patch literal 410 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VTavfC3&Vd9T(EcfWS|IVfk$L9 z0|U1(2s1Lwnj--eWH0gbb!ETGBPAlH;Z~UK4iu6tag8W(&d<$F%`0JWE=o--Nlj5G z&n(GM2+2rQaQE~Lc%P!02UPga)5S5w;`G@o2en)SMUH)(?_J`pDZKOvYtK6mBSVuw zHMdg-0t`PewZ%QU*O;`-=Lw@tgU{4mOC>zZRhA@gy815Veet={$?Lx*tiSr}edzsL z-S!ubtY~CDlm4lAM-G$CA>&(}@9sP8+ZGn^Ky32TJBcUWnlYYhS;TZb@Q+2;_Sp>4 zfr*WLVT*q!NF;w#a**%8xYv5k?bn^jk@9SXYI@h88Qam)3jDJykS{sTjT!PC{xWt~$(698cn Bs + + +The quick brown fox jumps over the lazy dog H2O The quick brown fox jumps over the lazy dog +The quick brown fox jumps over the lazy dog H2O The quick brown fox jumps over the lazy dog +The quick brown fox jumps over the lazy dog HO The quick brown fox jumps over the lazy dog +HThe quick brown fox jumps over the lazy dogO The quick brown fox jumps over the lazy dog +
+The quick brown fox jumps over the lazy dog H245O The quick brown fox jumps over the lazy dog +The quick brown fox jumps over the lazy dog H25O The quick brown fox jumps over the lazy dog +The quick brown fox jumps over the lazy dog HO The quick brown fox jumps over the lazy dog +The quick brown fox jumps over the lazy dog H24O The quick brown fox jumps over the lazy dog + +
+ +
+ +tm + +
+123link +
+x2 + y2 = r2 +
+esqrt(x2 + y2) +
+log25 = y3 +
+Inteltm +
+Windows© +
+tsttest me +
+
+ +tsttsttst me + +
+ + + diff --git a/samples/html/test/test.bkl b/samples/html/test/test.bkl index 0cea07bf90..ed18859f74 100644 --- a/samples/html/test/test.bkl +++ b/samples/html/test/test.bkl @@ -18,7 +18,7 @@ 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 diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index b4538e4fa0..114097e2fa 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -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; // or mode + m_ScriptBaseline = 0; // or 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 or . +// 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) diff --git a/src/html/m_image.cpp b/src/html/m_image.cpp index c4e902cb96..595ba007b6 100644 --- a/src/html/m_image.cpp +++ b/src/html/m_image.cpp @@ -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) diff --git a/src/html/m_layout.cpp b/src/html/m_layout.cpp index bc2150ec69..91b88f6190 100644 --- a/src/html/m_layout.cpp +++ b/src/html/m_layout.cpp @@ -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) diff --git a/src/html/winpars.cpp b/src/html/winpars.cpp index 52578cc0ee..265572a844 100644 --- a/src/html/winpars.cpp +++ b/src/html/winpars.cpp @@ -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 -- 2.45.2