Font.cs 3.6 KB

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