Skip to content

Commit

Permalink
EAN-13 - restored standarized barcode with check digit on the left si…
Browse files Browse the repository at this point in the history
…de of lines
  • Loading branch information
Marcin Wiercioch committed May 28, 2020
1 parent bbd961b commit 9a0886d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
1 change: 1 addition & 0 deletions BarcodeStandard/BarcodeLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ private Bitmap Generate_Image()
LabelFont = labFont;

ILHeight -= (labFont.Height / 2);
shiftAdjustment = (Width % Encoded_Value.Length);
}
else
{
Expand Down
23 changes: 5 additions & 18 deletions BarcodeStandard/Labels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,7 @@ public static Image Label_EAN13(Barcode Barcode, Bitmap img)

using (Font labFont = new Font("Arial", getFontsize(Barcode.Width - Barcode.Width % Barcode.EncodedValue.Length, img.Height, defTxt), FontStyle.Regular))
{
int shiftAdjustment;
switch (Barcode.Alignment)
{
case AlignmentPositions.LEFT:
shiftAdjustment = 0;
break;
case AlignmentPositions.RIGHT:
shiftAdjustment = (Barcode.Width % Barcode.EncodedValue.Length);
break;
case AlignmentPositions.CENTER:
default:
shiftAdjustment = (Barcode.Width % Barcode.EncodedValue.Length) / 2;
break;
}//switch
int shiftAdjustment = (Barcode.Width % Barcode.EncodedValue.Length);

using (Graphics g = Graphics.FromImage(img))
{
Expand All @@ -196,25 +183,25 @@ public static Image Label_EAN13(Barcode Barcode, Bitmap img)
float w2 = iBarWidth * 42; //Width of second block
float w3 = iBarWidth * 42; //Width of third block

float s1 = shiftAdjustment - iBarWidth;
float s2 = s1 + (iBarWidth * 4); //Start position of block 2
float s2 = Barcode.Width - (Barcode.EncodedValue.Length * iBarWidth) + (iBarWidth * 3); //Start position of block 2
float s1 = s2 - (iBarWidth * 5) - w1;
float s3 = s2 + w2 + (iBarWidth * 5); //Start position of block 3

//Draw the background rectangles for each block
using (SolidBrush backBrush = new SolidBrush(Barcode.BackColor))
{
g.FillRectangle(backBrush, new RectangleF(s2, (float)LabelY, w2, (float)labFont.Height));
g.FillRectangle(backBrush, new RectangleF(s3, (float)LabelY, w3, (float)labFont.Height));

}

//draw datastring under the barcode image
using (SolidBrush foreBrush = new SolidBrush(Barcode.ForeColor))
{
using (Font smallFont = new Font(labFont.FontFamily, labFont.SizeInPoints * 0.5f, labFont.Style))
{
g.DrawString(defTxt.Substring(0, 1), smallFont, foreBrush, new RectangleF(s1, (float)img.Height - (float)(smallFont.Height * 0.9), (float)img.Width, (float)labFont.Height), f);
g.DrawString(defTxt.Substring(0, 1), smallFont, foreBrush, new RectangleF(s1, (float)LabelY, (float)img.Width, (float)labFont.Height), f);
}

g.DrawString(defTxt.Substring(1, 6), labFont, foreBrush, new RectangleF(s2, (float)LabelY, (float)img.Width, (float)labFont.Height), f);
g.DrawString(defTxt.Substring(7), labFont, foreBrush, new RectangleF(s3 - iBarWidth, (float)LabelY, (float)img.Width, (float)labFont.Height), f);
}
Expand Down

0 comments on commit 9a0886d

Please sign in to comment.