public void Test_MeasureBarcodeUnit(MeasureBarcodeType heightType, float heightValue, string caseName)
        {
            MeasureBarcodeUnit height = new MeasureBarcodeUnit(0);

            if (heightType == MeasureBarcodeType.Percent)
            {
                height = MeasureBarcodeUnit.FromPercent(heightValue);
            }
            else if (heightType == MeasureBarcodeType.Pixel)
            {
                height = MeasureBarcodeUnit.FromPixel(heightValue);
            }
            height.Type.Should().Be(heightType);
            height.Value.Should().Be(heightValue);
        }
        public void Test_ValidationOfInputParameters(MeasureBarcodeType heightToCutType, float heightToCutValue, bool shouldFail, string because)
        {
            void Validate()
            {
                MeasureBarcodeUnit heightToCut = new MeasureBarcodeUnit(heightToCutValue, heightToCutType);

                BarcodesUtils.ValidateInputParameters(heightToCut, 4);
            }

            if (shouldFail)
            {
                ((Action)Validate).Should().ThrowExactly <InvalidOperationException>();
            }
            else
            {
                Validate();
            }
        }
        public void Test_Renderer_EAN_UPC(BarcodeType type, MeasureBarcodeType heightToCutType, float heightToCutValue, int scaleMultiplier, bool hasQuiteZones, bool rotate90, string caseName)
        {
            MeasureBarcodeUnit heightToCut = new MeasureBarcodeUnit(heightToCutValue, heightToCutType);
            BarcodeRotation    rotation    = BarcodeRotation.Clockwise_0;

            if (rotate90)
            {
                rotation = BarcodeRotation.Clockwise_90;
            }
            switch (type)
            {
            case BarcodeType.EAN_13:
                int widthShould  = EANData.default_barcode_width_EAN_13 * scaleMultiplier;
                int heightShould = BarcodesUtils.GetBarcodeHeightInt(widthShould, type);
                heightShould = heightShould - (int)(heightShould * BarcodesUtils.GetPercentToCut(heightShould, heightToCut, scaleMultiplier) / 100);
                Bitmap bitmap = BarcodesRenderer.DrawBitmapEAN_UPC(
                    BarcodesTestData.encodedTestDataEAN_13,
                    BarcodesTestData.inputTestStringEAN_13,
                    type, heightToCut, true, scaleMultiplier, null, null, hasQuiteZones, rotation);
                if (!hasQuiteZones)
                {
                    widthShould = widthShould - (EANData.left_quite_zone_count_EAN_13 + EANData.right_quite_zone_count) * scaleMultiplier;
                }
                if (rotate90)
                {
                    bitmap.Width.Should().Be(heightShould);
                    bitmap.Height.Should().Be(widthShould);
                }
                else
                {
                    bitmap.Width.Should().Be(widthShould);
                    bitmap.Height.Should().Be(heightShould);
                }
                break;

            case BarcodeType.EAN_8:
                widthShould  = EANData.default_barcode_width_EAN_8 * scaleMultiplier;
                heightShould = BarcodesUtils.GetBarcodeHeightInt(widthShould, type);
                heightShould = heightShould - (int)(heightShould * BarcodesUtils.GetPercentToCut(heightShould, heightToCut, scaleMultiplier) / 100);
                bitmap       = BarcodesRenderer.DrawBitmapEAN_UPC(
                    BarcodesTestData.encodedTestDataEAN_8,
                    BarcodesTestData.inputTestStringEAN_8,
                    type, heightToCut, true, scaleMultiplier, null, null, hasQuiteZones, rotation);
                if (!hasQuiteZones)
                {
                    widthShould = widthShould - (EANData.left_quite_zone_count_EAN_8 + EANData.right_quite_zone_count) * scaleMultiplier;
                }
                if (rotate90)
                {
                    bitmap.Width.Should().Be(heightShould);
                    bitmap.Height.Should().Be(widthShould);
                }
                else
                {
                    bitmap.Width.Should().Be(widthShould);
                    bitmap.Height.Should().Be(heightShould);
                }
                break;

            case BarcodeType.UPC_A:
                widthShould  = EANData.default_barcode_width_EAN_13 * scaleMultiplier;
                heightShould = BarcodesUtils.GetBarcodeHeightInt(widthShould, type);
                heightShould = heightShould - (int)(heightShould * BarcodesUtils.GetPercentToCut(heightShould, heightToCut, scaleMultiplier) / 100);
                bitmap       = BarcodesRenderer.DrawBitmapEAN_UPC(
                    BarcodesTestData.encodedTestDataUPC_A,
                    BarcodesTestData.inputTestStringUPC_A,
                    type, heightToCut, true, scaleMultiplier, null, null, hasQuiteZones, rotation);
                if (!hasQuiteZones)
                {
                    widthShould = widthShould - (EANData.left_quite_zone_count_EAN_13 + EANData.right_quite_zone_count) * scaleMultiplier;
                }
                if (rotate90)
                {
                    bitmap.Width.Should().Be(heightShould);
                    bitmap.Height.Should().Be(widthShould);
                }
                else
                {
                    bitmap.Width.Should().Be(widthShould);
                    bitmap.Height.Should().Be(heightShould);
                }
                break;
            }

            Assert.True(true, caseName);
        }
        public void Test_Renderer_GS1_128(BarcodeType type, MeasureBarcodeType heightToCutType, float heightToCutValue, int scaleMultiplier, bool hasQuiteZones, bool rotate270, string caseName)
        {
            MeasureBarcodeUnit heightToCut = new MeasureBarcodeUnit(heightToCutValue, heightToCutType);
            float labelHeight = scaleMultiplier * 2;
            int   widthShould;
            Font  labelFont = new Font(GS1_128Data.font_family_name, GS1_128Data.default_font_size * scaleMultiplier);

            labelHeight += labelFont.Size;
            BarcodeRotation rotation = BarcodeRotation.Clockwise_0;

            if (rotate270)
            {
                rotation = BarcodeRotation.Clockwise_270;
            }
            switch (type)
            {
            case BarcodeType.GS1_128A:
                if (hasQuiteZones)
                {
                    widthShould = (GS1_128Data.QuietZoneMinimumWidth * 2 + BarcodesTestData.encodedTestDataGS1_128A.Length) * scaleMultiplier;
                }
                else
                {
                    widthShould = BarcodesTestData.encodedTestDataGS1_128A.Length * scaleMultiplier;
                }
                int heightShould = (int)(widthShould * 0.15f);
                heightShould = heightShould - (int)(heightShould * BarcodesUtils.GetPercentToCut(heightShould, heightToCut, scaleMultiplier) / 100);
                heightShould = heightShould + (int)labelHeight;
                Bitmap bitmap = BarcodesRenderer.DrawBitmapGS1_128(
                    BarcodesTestData.encodedTestDataGS1_128A,
                    BarcodesTestData.inputTestStringGS1_128A,
                    heightToCut,
                    true, scaleMultiplier, null, null, hasQuiteZones, rotation);
                if (rotate270)
                {
                    bitmap.Width.Should().Be(heightShould);
                    bitmap.Height.Should().Be(widthShould);
                }
                else
                {
                    bitmap.Width.Should().Be(widthShould);
                    bitmap.Height.Should().Be(heightShould);
                }
                break;

            case BarcodeType.GS1_128B:
                if (hasQuiteZones)
                {
                    widthShould = (GS1_128Data.QuietZoneMinimumWidth * 2 + BarcodesTestData.encodedTestDataGS1_128B.Length) * scaleMultiplier;
                }
                else
                {
                    widthShould = BarcodesTestData.encodedTestDataGS1_128B.Length * scaleMultiplier;
                }
                heightShould = (int)(widthShould * 0.15f);
                heightShould = heightShould - (int)(heightShould * BarcodesUtils.GetPercentToCut(heightShould, heightToCut, scaleMultiplier) / 100);
                heightShould = heightShould + (int)labelHeight;
                bitmap       = BarcodesRenderer.DrawBitmapGS1_128(
                    BarcodesTestData.encodedTestDataGS1_128B,
                    BarcodesTestData.inputTestStringGS1_128B,
                    heightToCut,
                    true, scaleMultiplier, null, null, hasQuiteZones, rotation);
                if (rotate270)
                {
                    bitmap.Width.Should().Be(heightShould);
                    bitmap.Height.Should().Be(widthShould);
                }
                else
                {
                    bitmap.Width.Should().Be(widthShould);
                    bitmap.Height.Should().Be(heightShould);
                }
                break;

            case BarcodeType.GS1_128C:
                if (hasQuiteZones)
                {
                    widthShould = (GS1_128Data.QuietZoneMinimumWidth * 2 + BarcodesTestData.encodedTestDataGS1_128C.Length) * scaleMultiplier;
                }
                else
                {
                    widthShould = BarcodesTestData.encodedTestDataGS1_128C.Length * scaleMultiplier;
                }
                heightShould = (int)(widthShould * 0.15f);
                heightShould = heightShould - (int)(heightShould * BarcodesUtils.GetPercentToCut(heightShould, heightToCut, scaleMultiplier) / 100);
                heightShould = heightShould + (int)labelHeight;
                bitmap       = BarcodesRenderer.DrawBitmapGS1_128(
                    BarcodesTestData.encodedTestDataGS1_128C,
                    BarcodesTestData.inputTestStringGS1_128C,
                    heightToCut,
                    true, scaleMultiplier, null, null, hasQuiteZones, rotation);
                if (rotate270)
                {
                    bitmap.Width.Should().Be(heightShould);
                    bitmap.Height.Should().Be(widthShould);
                }
                else
                {
                    bitmap.Width.Should().Be(widthShould);
                    bitmap.Height.Should().Be(heightShould);
                }
                break;
            }
            Assert.True(true, caseName);
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MeasureBarcodeUnit"/> class.
 /// </summary>
 /// <param name="value">The measurement unit value to set.</param>
 /// <param name="type">The measurement unit type to set.</param>
 public MeasureBarcodeUnit(float value, MeasureBarcodeType type = MeasureBarcodeType.Pixel)
 {
     Value = value;
     Type  = type;
 }