2006-10-10 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.RTF / Font.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Peter Bartok    (pbartok@novell.com)
24 //
25 //
26
27 // COMPLETE
28
29 namespace System.Windows.Forms.RTF {
30         internal class Font {
31                 #region Local Variables
32                 private string          name;
33                 private string          alt_name;
34                 private int             num;
35                 private int             family;
36                 private CharsetType     charset;
37                 private int             pitch;
38                 private int             type;
39                 private int             codepage;
40                 private Font            next;
41                 private RTF             rtf;
42                 #endregion      // Local Variables
43
44                 #region Constructors
45                 public Font(RTF rtf) {
46                         this.rtf = rtf;
47                         num = -1;
48                         name = String.Empty;
49
50                         lock (rtf) {
51                                 if (rtf.Fonts == null)
52                                         rtf.Fonts = this;
53                                 else {
54                                         Font f = rtf.Fonts;
55                                         while (f.next != null)
56                                                 f = f.next;
57                                         f.next = this;
58                                 }
59                         }
60                 }
61                 #endregion      // Constructors
62
63                 #region Properties
64                 public string Name {
65                         get {
66                                 return name;
67                         }
68
69                         set {
70                                 name = value;
71                         }
72                 }
73
74                 public string AltName {
75                         get {
76                                 return alt_name;
77                         }
78
79                         set {
80                                 alt_name = value;
81                         }
82                 }
83
84                 public int Num {
85                         get {
86                                 return num;
87                         }
88
89                         set {
90                                 // Whack any previous font with the same number
91                                 DeleteFont(rtf, value);
92                                 num = value;
93                         }
94                 }
95
96                 public int Family {
97                         get {
98                                 return family;
99                         }
100
101                         set {
102                                 family = value;
103                         }
104                 }
105
106                 public CharsetType Charset {
107                         get {
108                                 return charset;
109                         }
110
111                         set {
112                                 charset = value;
113                         }
114                 }
115
116
117                 public int Pitch {
118                         get {
119                                 return pitch;
120                         }
121
122                         set {
123                                 pitch = value;
124                         }
125                 }
126
127                 public int Type {
128                         get {
129                                 return type;
130                         }
131
132                         set {
133                                 type = value;
134                         }
135                 }
136
137                 public int Codepage {
138                         get {
139                                 return codepage;
140                         }
141
142                         set {
143                                 codepage = value;
144                         }
145                 }
146                 #endregion      // Properties
147
148                 #region Methods
149                 static public bool DeleteFont(RTF rtf, int font_number) {
150                         Font    f;
151                         Font    prev;
152
153                         lock (rtf) {
154                                 f = rtf.Fonts;
155                                 prev = null;
156                                 while ((f != null) && (f.num != font_number)) {
157                                         prev = f;
158                                         f = f.next;
159                                 }
160
161                                 if (f != null) {
162                                         if (f == rtf.Fonts) {
163                                                 rtf.Fonts = f.next;
164                                         } else {
165                                                 if (prev != null) {
166                                                         prev.next = f.next;
167                                                 } else {
168                                                         rtf.Fonts = f.next;
169                                                 }
170                                         }
171                                         return true;
172                                 }
173                         }
174                         return false;
175                 }
176
177                 static public Font GetFont(RTF rtf, int font_number) {
178                         Font    f;
179
180                         lock (rtf) {
181                                 f = GetFont(rtf.Fonts, font_number);
182                         }
183                         return f;
184                 }
185
186                 static public Font GetFont(Font start, int font_number) {
187                         Font    f;
188
189                         if (font_number == -1) {
190                                 return start;
191                         }
192
193                         f = start;
194
195                         while ((f != null) && (f.num != font_number)) {
196                                 f = f.next;
197                         }
198                         return f;
199                 }
200                 #endregion      // Methods
201         }
202 }