BMGlyph.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. [Serializable]
  4. public class BMGlyph
  5. {
  6. public int GetKerning(int previousChar)
  7. {
  8. if (this.kerning != null && previousChar != 0)
  9. {
  10. int i = 0;
  11. int count = this.kerning.Count;
  12. while (i < count)
  13. {
  14. if (this.kerning[i] == previousChar)
  15. {
  16. return this.kerning[i + 1];
  17. }
  18. i += 2;
  19. }
  20. }
  21. return 0;
  22. }
  23. public void SetKerning(int previousChar, int amount)
  24. {
  25. if (this.kerning == null)
  26. {
  27. this.kerning = new List<int>();
  28. }
  29. for (int i = 0; i < this.kerning.Count; i += 2)
  30. {
  31. if (this.kerning[i] == previousChar)
  32. {
  33. this.kerning[i + 1] = amount;
  34. return;
  35. }
  36. }
  37. this.kerning.Add(previousChar);
  38. this.kerning.Add(amount);
  39. }
  40. public void Trim(int xMin, int yMin, int xMax, int yMax)
  41. {
  42. int num = this.x + this.width;
  43. int num2 = this.y + this.height;
  44. if (this.x < xMin)
  45. {
  46. int num3 = xMin - this.x;
  47. this.x += num3;
  48. this.width -= num3;
  49. this.offsetX += num3;
  50. }
  51. if (this.y < yMin)
  52. {
  53. int num4 = yMin - this.y;
  54. this.y += num4;
  55. this.height -= num4;
  56. this.offsetY += num4;
  57. }
  58. if (num > xMax)
  59. {
  60. this.width -= num - xMax;
  61. }
  62. if (num2 > yMax)
  63. {
  64. this.height -= num2 - yMax;
  65. }
  66. }
  67. public int index;
  68. public int x;
  69. public int y;
  70. public int width;
  71. public int height;
  72. public int offsetX;
  73. public int offsetY;
  74. public int advance;
  75. public int channel;
  76. public List<int> kerning;
  77. }