2007-08-17 Jeffrey Stedfast <fejj@novell.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
31 #if RTF_LIB
32         public
33 #else
34         internal
35 #endif
36         class Font {
37                 #region Local Variables
38                 private string          name;
39                 private string          alt_name;
40                 private int             num;
41                 private int             family;
42                 private CharsetType     charset;
43                 private int             pitch;
44                 private int             type;
45                 private int             codepage;
46                 private Font            next;
47                 private RTF             rtf;
48                 #endregion      // Local Variables
49
50                 #region Constructors
51                 public Font(RTF rtf) {
52                         this.rtf = rtf;
53                         num = -1;
54                         name = String.Empty;
55
56                         lock (rtf) {
57                                 if (rtf.Fonts == null)
58                                         rtf.Fonts = this;
59                                 else {
60                                         Font f = rtf.Fonts;
61                                         while (f.next != null)
62                                                 f = f.next;
63                                         f.next = this;
64                                 }
65                         }
66                 }
67                 #endregion      // Constructors
68
69                 #region Properties
70                 public string Name {
71                         get {
72                                 return name;
73                         }
74
75                         set {
76                                 name = value;
77                         }
78                 }
79
80                 public string AltName {
81                         get {
82                                 return alt_name;
83                         }
84
85                         set {
86                                 alt_name = value;
87                         }
88                 }
89
90                 public int Num {
91                         get {
92                                 return num;
93                         }
94
95                         set {
96                                 // Whack any previous font with the same number
97                                 DeleteFont(rtf, value);
98                                 num = value;
99                         }
100                 }
101
102                 public int Family {
103                         get {
104                                 return family;
105                         }
106
107                         set {
108                                 family = value;
109                         }
110                 }
111
112                 public CharsetType Charset {
113                         get {
114                                 return charset;
115                         }
116
117                         set {
118                                 charset = value;
119                         }
120                 }
121
122
123                 public int Pitch {
124                         get {
125                                 return pitch;
126                         }
127
128                         set {
129                                 pitch = value;
130                         }
131                 }
132
133                 public int Type {
134                         get {
135                                 return type;
136                         }
137
138                         set {
139                                 type = value;
140                         }
141                 }
142
143                 public int Codepage {
144                         get {
145                                 return codepage;
146                         }
147
148                         set {
149                                 codepage = value;
150                         }
151                 }
152                 #endregion      // Properties
153
154                 #region Methods
155                 static public bool DeleteFont(RTF rtf, int font_number) {
156                         Font    f;
157                         Font    prev;
158
159                         lock (rtf) {
160                                 f = rtf.Fonts;
161                                 prev = null;
162                                 while ((f != null) && (f.num != font_number)) {
163                                         prev = f;
164                                         f = f.next;
165                                 }
166
167                                 if (f != null) {
168                                         if (f == rtf.Fonts) {
169                                                 rtf.Fonts = f.next;
170                                         } else {
171                                                 if (prev != null) {
172                                                         prev.next = f.next;
173                                                 } else {
174                                                         rtf.Fonts = f.next;
175                                                 }
176                                         }
177                                         return true;
178                                 }
179                         }
180                         return false;
181                 }
182
183                 static public Font GetFont(RTF rtf, int font_number) {
184                         Font    f;
185
186                         lock (rtf) {
187                                 f = GetFont(rtf.Fonts, font_number);
188                         }
189                         return f;
190                 }
191
192                 static public Font GetFont(Font start, int font_number) {
193                         Font    f;
194
195                         if (font_number == -1) {
196                                 return start;
197                         }
198
199                         f = start;
200
201                         while ((f != null) && (f.num != font_number)) {
202                                 f = f.next;
203                         }
204                         return f;
205                 }
206                 #endregion      // Methods
207         }
208 }