BarcodeCodabar.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace FastReport.Barcode
  5. {
  6. /// <summary>
  7. /// Generates the Codabar barcode.
  8. /// </summary>
  9. public class BarcodeCodabar : LinearBarcodeBase
  10. {
  11. #if READONLY_STRUCTS
  12. private readonly struct Codabar
  13. #else
  14. private struct Codabar
  15. #endif
  16. {
  17. #pragma warning disable FR0006 // Field name of struct must be longer than 2 characters.
  18. public readonly string c;
  19. #pragma warning restore FR0006 // Field name of struct must be longer than 2 characters.
  20. public readonly string data;
  21. public Codabar(string c, string data)
  22. {
  23. this.c = c;
  24. this.data = data;
  25. }
  26. }
  27. private static Codabar[] tabelle_cb = {
  28. new Codabar("1", "5050615"),
  29. new Codabar("2", "5051506"),
  30. new Codabar("3", "6150505"),
  31. new Codabar("4", "5060515"),
  32. new Codabar("5", "6050515"),
  33. new Codabar("6", "5150506"),
  34. new Codabar("7", "5150605"),
  35. new Codabar("8", "5160505"),
  36. new Codabar("9", "6051505"),
  37. new Codabar("0", "5050516"),
  38. new Codabar("-", "5051605"),
  39. new Codabar("$", "5061505"),
  40. new Codabar(":", "6050606"),
  41. new Codabar("/", "6060506"),
  42. new Codabar(".", "6060605"),
  43. new Codabar("+", "5060606"),
  44. new Codabar("A", "5061515"),
  45. new Codabar("B", "5151506"),
  46. new Codabar("C", "5051516"),
  47. new Codabar("D", "5051615") };
  48. /// <inheritdoc/>
  49. public override bool IsNumeric
  50. {
  51. get { return false; }
  52. }
  53. private int FindBarItem(string c)
  54. {
  55. for (int i = 0; i < tabelle_cb.Length; i++)
  56. {
  57. if (c == tabelle_cb[i].c)
  58. return i;
  59. }
  60. return -1;
  61. }
  62. internal override string GetPattern()
  63. {
  64. string result = "";
  65. int index = FindBarItem("A");
  66. if (index >= 0)
  67. {
  68. result = tabelle_cb[index].data + "0";
  69. }
  70. foreach (char c in text)
  71. {
  72. index = FindBarItem(c.ToString());
  73. if (index >= 0)
  74. {
  75. result += tabelle_cb[index].data + "0";
  76. }
  77. }
  78. index = FindBarItem("B");
  79. if (index >= 0)
  80. {
  81. result += tabelle_cb[index].data;
  82. }
  83. return result;
  84. }
  85. /// <summary>
  86. /// Initializes a new instance of the <see cref="BarcodeCodabar"/> class with default settings.
  87. /// </summary>
  88. public BarcodeCodabar()
  89. {
  90. ratioMin = 2;
  91. ratioMax = 3;
  92. }
  93. }
  94. }