IndexToLocationClass.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. namespace FastReport.Fonts
  3. {
  4. /// <summary>
  5. /// IndexToLocation table
  6. /// </summary>
  7. public class IndexToLocationClass : TrueTypeTable
  8. {
  9. private ushort[] shortIndexToLocation = null;
  10. private uint[] longIndexToLocation = null;
  11. internal ushort[] Short { get { return shortIndexToLocation; } }
  12. internal uint[] Long { get { return longIndexToLocation; } }
  13. internal void LoadIndexToLocation(FontStream stream, FontHeaderClass font_header)
  14. {
  15. int count;
  16. stream.Seek(this.Offset, System.IO.SeekOrigin.Begin);
  17. switch (font_header.indexToLocFormat)
  18. {
  19. case FontHeaderClass.IndexToLoc.ShortType:
  20. count = (int)this.Length / 2;
  21. shortIndexToLocation = new ushort[count];
  22. for (int i = 0; i < count; i++)
  23. {
  24. shortIndexToLocation[i] = stream.ReadUInt16();
  25. }
  26. break;
  27. case FontHeaderClass.IndexToLoc.LongType:
  28. count = (int)this.Length / 4;
  29. longIndexToLocation = new uint[count];
  30. for (int j = 0; j < count; j++)
  31. {
  32. longIndexToLocation[j] = stream.ReadUInt32();
  33. }
  34. break;
  35. default:
  36. throw new Exception("Unsupported Index to Location format");
  37. }
  38. }
  39. public ushort GetGlyph(ushort i2l_idx, FontHeaderClass font_header, out uint location)
  40. {
  41. location = 0;
  42. ushort length = 0;
  43. switch (font_header.indexToLocFormat)
  44. {
  45. case FontHeaderClass.IndexToLoc.ShortType:
  46. if (i2l_idx >= shortIndexToLocation.Length)
  47. {
  48. location = 0;
  49. break;
  50. }
  51. location = (uint)(2 * shortIndexToLocation[i2l_idx]);
  52. length = (ushort)(2 * (shortIndexToLocation[i2l_idx + 1] - shortIndexToLocation[i2l_idx]));
  53. break;
  54. case FontHeaderClass.IndexToLoc.LongType:
  55. if (i2l_idx >= longIndexToLocation.Length - 1)
  56. {
  57. break;
  58. }
  59. location = longIndexToLocation[i2l_idx];
  60. length = (ushort)(longIndexToLocation[i2l_idx + 1] - longIndexToLocation[i2l_idx]);
  61. break;
  62. }
  63. return length;
  64. }
  65. //internal override uint Save(FontStream font, uint offset)
  66. //// internal override uint Save(IntPtr src, IntPtr dst, uint offset)
  67. //{
  68. // this.Offset = offset;
  69. // return base.Save(font, offset);
  70. //}
  71. public IndexToLocationClass(TrueTypeTable src) : base(src) { }
  72. }
  73. }