2005-12-22 Peter Dennis Bartok <pbartok@novell.com>
authorPeter Dennis Bartok <pbartok@mono-cvs.ximian.com>
Fri, 23 Dec 2005 00:15:38 +0000 (00:15 -0000)
committerPeter Dennis Bartok <pbartok@mono-cvs.ximian.com>
Fri, 23 Dec 2005 00:15:38 +0000 (00:15 -0000)
* RTF.cs: Added method to allow setting the default font for the RTF
  document. This font will be used if the document does not contain
  a font table.
* Font.cs: Added method to delete font with a given number;
  changed set_Num to call this method (to allow replacing fonts
  with the same number, particulary the default font)

svn path=/trunk/mcs/; revision=54761

mcs/class/Managed.Windows.Forms/System.Windows.Forms.RTF/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms.RTF/Font.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms.RTF/RTF.cs

index bc8404d5fcdd72c47d25a1bcdd607c523f52b7e1..8ded44833a4b75754f43811c67e69f98df27a136 100644 (file)
@@ -1,3 +1,12 @@
+2005-12-22  Peter Dennis Bartok  <pbartok@novell.com>
+
+       * RTF.cs: Added method to allow setting the default font for the RTF
+         document. This font will be used if the document does not contain
+         a font table.
+       * Font.cs: Added method to delete font with a given number; 
+         changed set_Num to call this method (to allow replacing fonts
+         with the same number, particulary the default font)
+
 2005-09-04  Peter Dennis Bartok  <pbartok@novell.com>
 
        * Charcode.cs: Created; provides StandardCharCode <-> character 
index 65610a751518941fcc99f4bd65bf1b3fed43490e..b0af7c7e5347d03b957b8ae53bb27617ae6b179d 100644 (file)
@@ -38,10 +38,12 @@ namespace System.Windows.Forms.RTF {
                private int             type;
                private int             codepage;
                private Font            next;
+               private RTF             rtf;
                #endregion      // Local Variables
 
                #region Constructors
                public Font(RTF rtf) {
+                       this.rtf = rtf;
                        num = -1;
 
                        lock (rtf) {
@@ -84,6 +86,8 @@ namespace System.Windows.Forms.RTF {
                        }
 
                        set {
+                               // Whack any previous font with the same number
+                               DeleteFont(rtf, value);
                                num = value;
                        }
                }
@@ -141,6 +145,34 @@ namespace System.Windows.Forms.RTF {
                #endregion      // Properties
 
                #region Methods
+               static public bool DeleteFont(RTF rtf, int font_number) {
+                       Font    f;
+                       Font    prev;
+
+                       lock (rtf) {
+                               f = rtf.Fonts;
+                               prev = null;
+                               while ((f != null) && (f.num != font_number)) {
+                                       prev = f;
+                                       f = f.next;
+                               }
+
+                               if (f != null) {
+                                       if (f == rtf.Fonts) {
+                                               rtf.Fonts = f.next;
+                                       } else {
+                                               if (prev != null) {
+                                                       prev.next = f.next;
+                                               } else {
+                                                       rtf.Fonts = f.next;
+                                               }
+                                       }
+                                       return true;
+                               }
+                       }
+                       return false;
+               }
+
                static public Font GetFont(RTF rtf, int font_number) {
                        Font    f;
 
index e4250ffea4b1821292f266e60d74fc1066fd2838..689deafa8a48f48450636446cb9413e731614dc6 100644 (file)
@@ -233,6 +233,15 @@ namespace System.Windows.Forms.RTF {
                #endregion      // Properties
 
                #region Methods
+               /// <summary>Set the default font for documents without font table</summary>
+               public void DefaultFont(string name) {
+                       Font font;
+
+                       font = new Font(this);
+                       font.Num = 0;
+                       font.Name = name;
+               }
+
                /// <summary>Read the next character from the input</summary>
                private char GetChar() {
                        char    c;