Skip to content

Commit

Permalink
Add Interleaved 2 of 5 Mod 10, Add Standard 2 of 5 Mod 10
Browse files Browse the repository at this point in the history
  • Loading branch information
barnhill committed Dec 20, 2018
1 parent 687c08d commit 2b9b875
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 131 deletions.
9 changes: 6 additions & 3 deletions BarcodeStandard/BarcodeLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace BarcodeLib
{
#region Enums
public enum TYPE : int { UNSPECIFIED, UPCA, UPCE, UPC_SUPPLEMENTAL_2DIGIT, UPC_SUPPLEMENTAL_5DIGIT, EAN13, EAN8, Interleaved2of5, Standard2of5, Industrial2of5, CODE39, CODE39Extended, CODE39_Mod43, Codabar, PostNet, BOOKLAND, ISBN, JAN13, MSI_Mod10, MSI_2Mod10, MSI_Mod11, MSI_Mod11_Mod10, Modified_Plessey, CODE11, USD8, UCC12, UCC13, LOGMARS, CODE128, CODE128A, CODE128B, CODE128C, ITF14, CODE93, TELEPEN, FIM, PHARMACODE };
public enum TYPE : int { UNSPECIFIED, UPCA, UPCE, UPC_SUPPLEMENTAL_2DIGIT, UPC_SUPPLEMENTAL_5DIGIT, EAN13, EAN8, Interleaved2of5, Interleaved2of5_Mod10, Standard2of5, Standard2of5_Mod10, Industrial2of5, Industrial2of5_Mod10, CODE39, CODE39Extended, CODE39_Mod43, Codabar, PostNet, BOOKLAND, ISBN, JAN13, MSI_Mod10, MSI_2Mod10, MSI_Mod11, MSI_Mod11_Mod10, Modified_Plessey, CODE11, USD8, UCC12, UCC13, LOGMARS, CODE128, CODE128A, CODE128B, CODE128C, ITF14, CODE93, TELEPEN, FIM, PHARMACODE };
public enum SaveTypes : int { JPG, BMP, PNG, GIF, TIFF, UNSPECIFIED };
public enum AlignmentPositions : int { CENTER, LEFT, RIGHT };
public enum LabelPositions : int { TOPLEFT, TOPCENTER, TOPRIGHT, BOTTOMLEFT, BOTTOMCENTER, BOTTOMRIGHT };
Expand Down Expand Up @@ -391,12 +391,15 @@ internal Image Encode()
case TYPE.EAN13: //Encode_EAN13();
ibarcode = new EAN13(Raw_Data);
break;
case TYPE.Interleaved2of5_Mod10:
case TYPE.Interleaved2of5: //Encode_Interleaved2of5();
ibarcode = new Interleaved2of5(Raw_Data);
ibarcode = new Interleaved2of5(Raw_Data, Encoded_Type);
break;
case TYPE.Industrial2of5_Mod10:
case TYPE.Industrial2of5:
case TYPE.Standard2of5_Mod10:
case TYPE.Standard2of5: //Encode_Standard2of5();
ibarcode = new Standard2of5(Raw_Data);
ibarcode = new Standard2of5(Raw_Data, Encoded_Type);
break;
case TYPE.LOGMARS:
case TYPE.CODE39: //Encode_Code39();
Expand Down
4 changes: 2 additions & 2 deletions BarcodeStandard/BarcodeStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.1.0</Version>
<Version>2.2.0</Version>
<PackageId>BarcodeLib</PackageId>
<Company>Pnuema Productions</Company>
<Product>BarcodeLib</Product>
<Authors>Brad Barnhill</Authors>
<Description>This library was designed to give an easy class for developers to use when they need to generate barcode images from a string of data.</Description>
<Copyright>Copyright 2007-2017 Brad Barnhill</Copyright>
<Copyright>Copyright 2007-2018 Brad Barnhill</Copyright>
<PackageLicenseUrl>https://github.com/bbarnhill/barcodelib/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/barnhill/barcodelib</PackageProjectUrl>
<PackageIconUrl>https://github.com/barnhill/barcodelib/blob/master/BarcodeStandard/examples/upca.gif</PackageIconUrl>
Expand Down
5 changes: 5 additions & 0 deletions BarcodeStandard/Release Notes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Release Notes for BarcodeLib.dll
================================
2.2.0.0
- Add Interleaved 2 of 5 Mod 10
- Add Standard 2 of 5 Mod 10
2.1.0.0
- Fix massive memory leak
2.0.0.0
- Conversion to .NET Standard 2.0
- Build nuget package on every build
Expand Down
35 changes: 25 additions & 10 deletions BarcodeStandard/Symbologies/Interleaved2of5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,34 @@ namespace BarcodeLib.Symbologies
/// </summary>
class Interleaved2of5 : BarcodeCommon, IBarcode
{
private string[] I25_Code = { "NNWWN", "WNNNW", "NWNNW", "WWNNN", "NNWNW", "WNWNN", "NWWNN", "NNNWW", "WNNWN", "NWNWN" };
private readonly string[] I25_Code = { "NNWWN", "WNNNW", "NWNNW", "WWNNN", "NNWNW", "WNWNN", "NWWNN", "NNNWW", "WNNWN", "NWNWN" };
private readonly TYPE Encoded_Type = TYPE.UNSPECIFIED;

public Interleaved2of5(string input)
public Interleaved2of5(string input, TYPE EncodedType)
{
Encoded_Type = EncodedType;
Raw_Data = input;
}
/// <summary>
/// Encode the raw data using the Interleaved 2 of 5 algorithm.
/// </summary>
private string Encode_Interleaved2of5()
{
//check length of input
if (Raw_Data.Length % 2 != 0)
//check length of input (only even if no checkdigit, else with check digit odd)
if (Raw_Data.Length % 2 != (Encoded_Type == TYPE.Interleaved2of5_Mod10 ? 1 : 0))
Error("EI25-1: Data length invalid.");

if (!CheckNumericOnly(Raw_Data))
Error("EI25-2: Numeric Data Only");

string result = "1010";
string data = Raw_Data + (Encoded_Type == TYPE.Interleaved2of5_Mod10 ? CalculateMod10CheckDigit().ToString() : "");

for (int i = 0; i < Raw_Data.Length; i += 2)
for (int i = 0; i < data.Length; i += 2)
{
bool bars = true;
string patternbars = I25_Code[Int32.Parse(Raw_Data[i].ToString())];
string patternspaces = I25_Code[Int32.Parse(Raw_Data[i + 1].ToString())];
string patternbars = I25_Code[Int32.Parse(data[i].ToString())];
string patternspaces = I25_Code[Int32.Parse(data[i + 1].ToString())];
string patternmixed = "";

//interleave
Expand Down Expand Up @@ -61,14 +64,26 @@ private string Encode_Interleaved2of5()
}//else
bars = !bars;
}//foreach

}//foreach

//add ending bars
result += "1101";
return result;
}//Encode_Interleaved2of5

private int CalculateMod10CheckDigit()
{
int sum = 0;
bool even = true;
for (int i = Raw_Data.Length - 1; i >= 0; --i)
{
sum += Raw_Data[i] * (even ? 3 : 1);
even = !even;
}

return sum % 10;
}

#region IBarcode Members

public string Encoded_Value
Expand Down
22 changes: 20 additions & 2 deletions BarcodeStandard/Symbologies/Standard2of5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ namespace BarcodeLib.Symbologies
/// </summary>
class Standard2of5 : BarcodeCommon, IBarcode
{
private string[] S25_Code = { "11101010101110", "10111010101110", "11101110101010", "10101110101110", "11101011101010", "10111011101010", "10101011101110", "10101110111010", "11101010111010", "10111010111010" };
private readonly string[] S25_Code = { "11101010101110", "10111010101110", "11101110101010", "10101110101110", "11101011101010", "10111011101010", "10101011101110", "10101110111010", "11101010111010", "10111010111010" };
private readonly TYPE Encoded_Type = TYPE.UNSPECIFIED;

public Standard2of5(string input)
public Standard2of5(string input, TYPE EncodedType)
{
Raw_Data = input;
Encoded_Type = EncodedType;
}//Standard2of5

/// <summary>
/// Encode the raw data using the Standard 2 of 5 algorithm.
/// </summary>
Expand All @@ -29,11 +32,26 @@ private string Encode_Standard2of5()
result += S25_Code[Int32.Parse(c.ToString())];
}//foreach

string checkPattern = Encoded_Type == TYPE.Standard2of5_Mod10 ? S25_Code[CalculateMod10CheckDigit()] : "";

//add ending bars
result += "1101011";
return result;
}//Encode_Standard2of5

private int CalculateMod10CheckDigit()
{
int sum = 0;
bool even = true;
for (int i = Raw_Data.Length - 1; i >= 0; --i)
{
sum += Raw_Data[i] * (even ? 3 : 1);
even = !even;
}

return sum % 10;
}

#region IBarcode Members

public string Encoded_Value
Expand Down
4 changes: 2 additions & 2 deletions BarcodeStandardExample/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
Loading

0 comments on commit 2b9b875

Please sign in to comment.