From 0df2f074ba3311fdd3aeb6036e65806965064474 Mon Sep 17 00:00:00 2001 From: Brad Barnhill Date: Sun, 23 Feb 2020 17:29:35 -0600 Subject: [PATCH] fix single digit Pharmacode --- BarcodeStandard/BarcodeStandard.csproj | 4 +-- BarcodeStandard/Release Notes.txt | 2 ++ BarcodeStandard/Symbologies/Pharmacode.cs | 30 ++++++++--------------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/BarcodeStandard/BarcodeStandard.csproj b/BarcodeStandard/BarcodeStandard.csproj index 2201496..809cd4f 100644 --- a/BarcodeStandard/BarcodeStandard.csproj +++ b/BarcodeStandard/BarcodeStandard.csproj @@ -3,13 +3,13 @@ netstandard2.0 true - 2.2.3 + 2.2.4 BarcodeLib Pnuema Productions BarcodeLib Brad Barnhill 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. - Copyright 2007-2019 Brad Barnhill + Copyright 2007-2020 Brad Barnhill https://github.com/barnhill/barcodelib https://raw.githubusercontent.com/barnhill/barcodelib/master/BarcodeStandard/examples/upca.gif diff --git a/BarcodeStandard/Release Notes.txt b/BarcodeStandard/Release Notes.txt index ad784a9..f5943d3 100644 --- a/BarcodeStandard/Release Notes.txt +++ b/BarcodeStandard/Release Notes.txt @@ -1,5 +1,7 @@ Release Notes for BarcodeLib.dll ================================ +2.2.4.0 +- Fix incorrect encoding for single digit Pharmacode 2.2.3.0 - Allow use in partially trusted assemblies for SSRS 2.2.2.0 diff --git a/BarcodeStandard/Symbologies/Pharmacode.cs b/BarcodeStandard/Symbologies/Pharmacode.cs index c8528a2..5d1fe00 100644 --- a/BarcodeStandard/Symbologies/Pharmacode.cs +++ b/BarcodeStandard/Symbologies/Pharmacode.cs @@ -58,35 +58,25 @@ private string Encode_Pharmacode() } } - double sum = Math.Pow(2, startIndex + 1) - 2; - string [] encoded = new string[startIndex + 1]; - int i = 0; - - for (int index = startIndex; index >= 0; index--) + string result = String.Empty; + do { - double power = Math.Pow(2, index); - double diff = num - sum; - if (diff > power) + if ((num & 1) == 0) { - encoded[i++] = _thickBar; - sum += power; + result = _thickBar + result; + num = (num - 2) / 2; } else { - encoded[i++] = _thinBar; + result = _thinBar + result; + num = (num - 1) / 2; } - } - string result = String.Empty; - foreach (string s in encoded) - { - if (result != String.Empty) + if (num != 0) { - result += _gap; + result = _gap + result; } - - result += s; - } + } while (num != 0); return result; }