TextExtents

  1. //
  2. // Mono.Cairo.TextExtents.cs
  3. //
  4. // Authors:
  5. // Duncan Mak (duncan@ximian.com)
  6. // Hisham Mardam Bey (hisham.mardambey@gmail.com)
  7. //
  8. // (C) Ximian, Inc. 2003
  9. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30.  
  31. using System;
  32. using System.Runtime.InteropServices;
  33.  
  34. namespace Cairo
  35. {
  36. [StructLayout (LayoutKind.Sequential)]
  37. public struct TextExtents
  38. {
  39. double xbearing;
  40. double ybearing;
  41. double width;
  42. double height;
  43. double xadvance;
  44. double yadvance;
  45.  
  46. public double XBearing {
  47. get { return xbearing; }
  48. set { xbearing = value; }
  49. }
  50.  
  51. public double YBearing {
  52. get { return ybearing; }
  53. set { ybearing = value; }
  54. }
  55.  
  56. public double Width {
  57. get { return width; }
  58. set { width = value; }
  59. }
  60.  
  61. public double Height {
  62. get { return height; }
  63. set { height = value; }
  64. }
  65.  
  66. public double XAdvance {
  67. get { return xadvance; }
  68. set { xadvance = value; }
  69. }
  70.  
  71. public double YAdvance {
  72. get { return yadvance; }
  73. set { yadvance = value; }
  74. }
  75.  
  76. public override bool Equals (object obj)
  77. {
  78. if (obj is TextExtents)
  79. return this == (TextExtents)obj;
  80. return false;
  81. }
  82.  
  83. public override int GetHashCode ()
  84. {
  85. return (int)XBearing ^ (int)YBearing ^ (int)Width ^ (int)Height ^ (int)XAdvance ^ (int)YAdvance;
  86. }
  87.  
  88. public static bool operator == (TextExtents extents, TextExtents other)
  89. {
  90. return extents.XBearing == other.XBearing && extents.YBearing == other.YBearing && extents.Width == other.Width && extents.Height == other.Height && extents.XAdvance == other.XAdvance && extents.YAdvance == other.YAdvance;
  91. }
  92.  
  93. public static bool operator != (TextExtents extents, TextExtents other)
  94. {
  95. return !(extents == other);
  96. }
  97. }
  98. }
  99.  
Programming language: 
C#