Update of /cvsroot/mahogany/M/src/modules
In directory sc8-pr-cvs1:/tmp/cvs-serv3175/src/modules

Modified Files:
        HtmlViewer.cpp 
Log Message:
show bold/italic text in HTML viewer properly

Index: HtmlViewer.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/HtmlViewer.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -b -u -2 -r1.44 -r1.45
--- HtmlViewer.cpp      5 Dec 2002 23:14:59 -0000       1.44
+++ HtmlViewer.cpp      8 Dec 2002 00:42:06 -0000       1.45
@@ -205,29 +205,26 @@
 {
 public:
-   AttributeChanger(String& str) : m_str(str) { m_doChange = false; }
+   AttributeChanger(String& str) : m_str(str) { }
 
    void DoChange(const String& start, const String& end)
    {
-      m_doChange = true;
-
       m_str += start;
       m_end = end;
    }
 
-   ~AttributeChanger() { if ( m_doChange ) m_str += m_end; }
+   ~AttributeChanger() { m_str += m_end; }
 
 private:
    String& m_str;
 
+   // the end tag (or empty if none)
    String m_end;
-
-   bool m_doChange;
 };
 
 // ----------------------------------------------------------------------------
-// EncodingChanger
+// EncodingChanger: change the encoding to the given one during its lifetime
 // ----------------------------------------------------------------------------
 
-class EncodingChanger : public AttributeChanger
+class EncodingChanger : private AttributeChanger
 {
 public:
@@ -256,8 +253,8 @@
 
 // ----------------------------------------------------------------------------
-// FontColourChanger
+// FontColourChanger: change the font colour during its lifetime
 // ----------------------------------------------------------------------------
 
-class FontColourChanger : public AttributeChanger
+class FontColourChanger : private AttributeChanger
 {
 public:
@@ -276,4 +273,33 @@
 
 // ----------------------------------------------------------------------------
+// FontStyleChanger: changes bold/italic attributes during its lifetime
+// ----------------------------------------------------------------------------
+
+class FontStyleChanger
+{
+public:
+   FontStyleChanger(const wxFont& font, String& str)
+      : m_changerWeight(str),
+        m_changerSlant(str)
+   {
+      // the order is important:should be the reverse of the order of
+      // destruction of the subobjects
+      if ( font.GetStyle() == wxFONTSTYLE_ITALIC )
+      {
+         m_changerSlant.DoChange("<i>", "</i>");
+      }
+
+      if ( font.GetWeight() == wxFONTWEIGHT_BOLD )
+      {
+         m_changerWeight.DoChange("<b>", "</b>");
+      }
+   }
+
+private:
+   AttributeChanger m_changerWeight,
+                    m_changerSlant;
+};
+
+// ----------------------------------------------------------------------------
 // HtmlViewerWindow: wxLayoutWindow used by HtmlViewer
 // ----------------------------------------------------------------------------
@@ -890,4 +916,6 @@
 
    FontColourChanger colChanger(style.GetTextColour(), m_htmlText);
+
+   FontStyleChanger styleChanger(style.GetFont(), m_htmlText);
 
    m_htmlText += MakeHtmlSafe(text, HtmlSpace_Keep);



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to