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