Property.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #region MIT License
  2. /*Copyright (c) 2012 Robert Rouhani <robert.rouhani@gmail.com>
  3. SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
  4. Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. this software and associated documentation files (the "Software"), to deal in
  6. the Software without restriction, including without limitation the rights to
  7. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8. of the Software, and to permit persons to whom the Software is furnished to do
  9. so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.*/
  19. #endregion
  20. using System;
  21. using System.Runtime.InteropServices;
  22. using SharpFont.Bdf.Internal;
  23. namespace SharpFont.Bdf
  24. {
  25. /// <summary>
  26. /// This structure models a given BDF/PCF property.
  27. /// </summary>
  28. public class Property
  29. {
  30. #region Fields
  31. private IntPtr reference;
  32. private PropertyRec rec;
  33. #endregion
  34. #region Constructors
  35. internal Property(IntPtr reference)
  36. {
  37. Reference = reference;
  38. }
  39. #endregion
  40. #region Properties
  41. /// <summary>
  42. /// Gets the property type.
  43. /// </summary>
  44. public PropertyType Type
  45. {
  46. get
  47. {
  48. return rec.type;
  49. }
  50. }
  51. /// <summary>
  52. /// Gets the atom string, if type is <see cref="PropertyType.Atom"/>.
  53. /// </summary>
  54. public string Atom
  55. {
  56. get
  57. {
  58. // only this property throws an exception because the pointer could be to unmanaged memory not owned by
  59. // the process.
  60. if (rec.type != PropertyType.Atom)
  61. throw new InvalidOperationException("The property type is not Atom.");
  62. return Marshal.PtrToStringAnsi(rec.atom);
  63. }
  64. }
  65. /// <summary>
  66. /// Gets a signed integer, if type is <see cref="PropertyType.Integer"/>.
  67. /// </summary>
  68. public int Integer
  69. {
  70. get
  71. {
  72. return rec.integer;
  73. }
  74. }
  75. /// <summary>
  76. /// Gets an unsigned integer, if type is <see cref="PropertyType.Cardinal"/>.
  77. /// </summary>
  78. [CLSCompliant(false)]
  79. public uint Cardinal
  80. {
  81. get
  82. {
  83. return rec.cardinal;
  84. }
  85. }
  86. internal IntPtr Reference
  87. {
  88. get
  89. {
  90. return reference;
  91. }
  92. set
  93. {
  94. reference = value;
  95. rec = PInvokeHelper.PtrToStructure<PropertyRec>(reference);
  96. }
  97. }
  98. #endregion
  99. }
  100. }