コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            Enums.Barcodes barcodeType = (Enums.Barcodes) int.Parse(context.Request.QueryString["barcodeType"]);
            string         message     = context.Request.QueryString["message"];
            IBarcode       barcoder    = BarcodeBuilder.CreateBarcode(barcodeType);

            Bitmap bitmap;

            if (barcodeType == Enums.Barcodes.MSI)
            {
                Enums.Modulo       modulo    = (Enums.Modulo) int.Parse(context.Request.QueryString["modulo"]);
                Enums.MSIWeighting weighting = (Enums.MSIWeighting) int.Parse(context.Request.QueryString["msiWeighting"]);
                bitmap = ((BarcodeMSI)barcoder).EncodeToBitmap(message, modulo, weighting);
            }
            else
            {
                bitmap = barcoder.EncodeToBitmap(message);
            }

            MemoryStream mem = new MemoryStream();

            bitmap.Save(mem, ImageFormat.Png);

            byte[] buffer = mem.ToArray();

            context.Response.ContentType = "image/png";
            context.Response.BinaryWrite(buffer);
            context.Response.Flush();
        }
コード例 #2
0
        public void Encode_Barcoder_ShouldEncodePdf417CodeCorrectly()
        {
            // Arrange
            var content          = "Barcoder";
            var expectedDataBits = ImageStringToBools(@"
                ++++++++.+.+.+...+++.+.+.+++......+++.+.+...+++....+++.+..++...++++.++++.+.++..+++++.+++++.+.+.+++++..+++++++.+...+.+..+
                ++++++++.+.+.+...+++.+.+.+++......+++.+.+...+++....+++.+..++...++++.++++.+.++..+++++.+++++.+.+.+++++..+++++++.+...+.+..+
                ++++++++.+.+.+...++++++.+.+...+++.++++.+..+....+...+++.+..+++..++...+..++.+++++..+...++++++.+.+.+++...+++++++.+...+.+..+
                ++++++++.+.+.+...++++++.+.+...+++.++++.+..+....+...+++.+..+++..++...+..++.+++++..+...++++++.+.+.+++...+++++++.+...+.+..+
                ++++++++.+.+.+...+.+.+..++++......++...+++++..+..+.+...++..+....+++.+....++..++.++++.+++.+.+...++++++.+++++++.+...+.+..+
                ++++++++.+.+.+...+.+.+..++++......++...+++++..+..+.+...++..+....+++.+....++..++.++++.+++.+.+...++++++.+++++++.+...+.+..+
                ++++++++.+.+.+...++.+.++++.+++++..+.++....+++...++.+++.+..+..+++....++....++....+..+.++.+.++++..+++++.+++++++.+...+.+..+
                ++++++++.+.+.+...++.+.++++.+++++..+.++....+++...++.+++.+..+..+++....++....++....+..+.++.+.++++..+++++.+++++++.+...+.+..+
                ++++++++.+.+.+...+++.+.+++....++..+++..+.++..+.....+++.+...++.....+.+.++++++..+.++...+++.+.+++..++....+++++++.+...+.+..+
                ++++++++.+.+.+...+++.+.+++....++..+++..+.++..+.....+++.+...++.....+.+.++++++..+.++...+++.+.+++..++....+++++++.+...+.+..+
            ");

            // Act
            IBarcode pdf417 = Pdf417Encoder.Encode(content, 2);

            // Assert
            pdf417.Should().NotBeNull();
            expectedDataBits.Length.Should().Be(pdf417.Bounds.X * pdf417.Bounds.Y);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % pdf417.Bounds.X;
                int y = i / pdf417.Bounds.X;
                pdf417.At(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
コード例 #3
0
        private void Render1D(IBarcode barcode, Stream outputStream)
        {
            int width  = (barcode.Bounds.X + 2 * barcode.Margin) * _pixelSize;
            int height = (_barHeightFor1DBarcode + 2 * barcode.Margin) * _pixelSize;

            using (var image = new Image <Gray8>(width, height))
            {
                image.Mutate(ctx =>
                {
                    ctx.Fill(NamedColors <Gray8> .White);
                    for (var x = 0; x < barcode.Bounds.X; x++)
                    {
                        if (!barcode.At(x, 0))
                        {
                            continue;
                        }
                        ctx.FillPolygon(
                            NamedColors <Gray8> .Black,
                            new Vector2((barcode.Margin + x) * _pixelSize, barcode.Margin * _pixelSize),
                            new Vector2((barcode.Margin + x + 1) * _pixelSize, barcode.Margin * _pixelSize),
                            new Vector2((barcode.Margin + x + 1) * _pixelSize, (_barHeightFor1DBarcode + barcode.Margin) * _pixelSize),
                            new Vector2((barcode.Margin + x) * _pixelSize, (_barHeightFor1DBarcode + barcode.Margin) * _pixelSize));
                    }
                });

                if (_includeEanContentAsText && barcode.IsEanBarcode())
                {
                    EanContentRenderer.Render(image, barcode, fontFamily: _eanFontFamily, scale: _pixelSize);
                }

                image.Save(outputStream, _imageEncoder);
            }
        }
コード例 #4
0
        public static T InitEntity <T>(this T _entity, IBarcode data)
            where T : IBarcode
        {
            if (_entity == null)
            {
                throw new StackOverflowException("初始化对象entity不能为空!");
            }
            if (data == null)
            {
                throw new StackOverflowException("初始化对象data不能为空!");
            }

            var type           = typeof(T);
            var dataType       = data.GetType();
            var properties     = type.GetProperties();
            var dataProperties = dataType.GetProperties().ToList();

            foreach (var item in properties)
            {
                var dataProperty = dataProperties.FirstOrDefault(o => o.Name == item.Name && o.CanRead);
                if (item.CanWrite && dataProperty != null)
                {
                    item.SetValue(_entity, dataProperty.GetValue(data, null), null);
                }
            }
            return(_entity);
        }
コード例 #5
0
        public void Encode_Barcode_ShouldEncodeKixCorrectly()
        {
            // Arrange
            var content          = "123ABC789XYZ"; // checksum character == 'K'
            var expectedDataBits = ImageStringToBools(@"
                ....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+....
                ....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+....
                ....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+....
                +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
                +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
                ..+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+....
                ..+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+....
                ..+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+....
            ");

            // Act
            IBarcode kixCode = KixEncoder.Encode(content);

            // Assert
            kixCode.Should().NotBeNull();
            kixCode.Metadata.CodeKind.Should().Be(BarcodeType.KixCode);
            expectedDataBits.Length.Should().Be(kixCode.Bounds.X * kixCode.Bounds.Y);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % kixCode.Bounds.X;
                int y = i / kixCode.Bounds.X;
                kixCode.At(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
コード例 #6
0
        private void Render2D(IBarcode barcode, Stream outputStream)
        {
            int width  = (barcode.Bounds.X + 2 * barcode.Margin) * _pixelSize;
            int height = (barcode.Bounds.Y + 2 * barcode.Margin) * _pixelSize;

            using (var image = new Image <Gray8>(width, height))
            {
                image.Mutate(ctx =>
                {
                    ctx.Fill(NamedColors <Gray8> .White);
                    for (var y = 0; y < barcode.Bounds.Y; y++)
                    {
                        for (var x = 0; x < barcode.Bounds.X; x++)
                        {
                            if (!barcode.At(x, y))
                            {
                                continue;
                            }
                            ctx.FillPolygon(
                                NamedColors <Gray8> .Black,
                                new Vector2((barcode.Margin + x) * _pixelSize, (barcode.Margin + y) * _pixelSize),
                                new Vector2((barcode.Margin + x + 1) * _pixelSize, (barcode.Margin + y) * _pixelSize),
                                new Vector2((barcode.Margin + x + 1) * _pixelSize, (barcode.Margin + y + 1) * _pixelSize),
                                new Vector2((barcode.Margin + x) * _pixelSize, (barcode.Margin + y + 1) * _pixelSize));
                        }
                    }
                });

                image.Save(outputStream, _imageEncoder);
            }
        }
コード例 #7
0
ファイル: ImageRenderer.cs プロジェクト: vmanthena/barcoder
        private void Render1D(IBarcode barcode, Stream outputStream)
        {
            int width  = (barcode.Bounds.X + 2 * barcode.Margin) * _pixelSize;
            int height = (_barHeightFor1DBarcode + 2 * barcode.Margin) * _pixelSize;

            using (var image = new ImageSharp.Image <Gray8>(width, height))
            {
                image.Mutate(ctx =>
                {
                    var black = new Gray8(0);
                    ctx.Fill(new Gray8(255));
                    for (var x = 0; x < barcode.Bounds.X; x++)
                    {
                        if (!barcode.At(x, 0))
                        {
                            continue;
                        }
                        ctx.FillPolygon(
                            black,
                            new Vector2((barcode.Margin + x) * _pixelSize, barcode.Margin * _pixelSize),
                            new Vector2((barcode.Margin + x + 1) * _pixelSize, barcode.Margin * _pixelSize),
                            new Vector2((barcode.Margin + x + 1) * _pixelSize, (_barHeightFor1DBarcode + barcode.Margin) * _pixelSize),
                            new Vector2((barcode.Margin + x) * _pixelSize, (_barHeightFor1DBarcode + barcode.Margin) * _pixelSize));
                    }
                });

                image.Save(outputStream, _pngEncoder);
            }
        }
コード例 #8
0
        public void Encode_Barcode_ShouldEncodeRm4ScCorrectly()
        {
            // Arrange
            var content          = "123ABC789XYZ"; // checksum character == 'K'
            var expectedDataBits = ImageStringToBools(@"
                +.....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+.....+.....+.+
                +.....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+.....+.....+.+
                +.....+.+.....+.+.....+.+...+...+...+...+...+.+.....+...+...+...+...+...+.+.+.....+.+.....+.+.....+.....+.+
                +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
                +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
                ....+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+.......+.+...+
                ....+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+.......+.+...+
                ....+...+...+.+...+.....+.+...+...+.+.........+.+...+...+...+.+...+.....+.+.....+.+...+...+.+.......+.+...+
            ");

            // Act
            IBarcode royalMailCode = RoyalMailFourStateCodeEncoder.Encode(content);

            // Assert
            royalMailCode.Should().NotBeNull();
            royalMailCode.Metadata.CodeKind.Should().Be(BarcodeType.RM4SC);
            expectedDataBits.Length.Should().Be(royalMailCode.Bounds.X * royalMailCode.Bounds.Y);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % royalMailCode.Bounds.X;
                int y = i / royalMailCode.Bounds.X;
                royalMailCode.At(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
コード例 #9
0
 private static byte[] RenderBarcodeToByteArray(IRenderer renderer, IBarcode barcode)
 {
     using (var stream = new MemoryStream())
     {
         renderer.Render(barcode, stream);
         return(stream.ToArray());
     }
 }
コード例 #10
0
        public void Render_Ean8_IncludeContentAsText()
        {
            var      renderer = new SvgRenderer(includeEanContentAsText: true);
            IBarcode barcode  = EanEncoder.Encode("1234567");

            using Stream stream = File.OpenWrite(@"d:\temp\ean-test.svg");
            renderer.Render(barcode, stream);
        }
コード例 #11
0
        public void Render_Ean13_IncludeContentAsText()
        {
            var      renderer = new ImageRenderer(imageFormat: ImageFormat.Png, includeEanContentAsText: true);
            IBarcode barcode  = EanEncoder.Encode("978020137962");

            using Stream stream = File.OpenWrite(@"d:\temp\ean-test.png");
            renderer.Render(barcode, stream);
        }
コード例 #12
0
ファイル: DrawBarcodes.cs プロジェクト: wwkkww1983/WMS
 internal void CreateBarcodeInterFace(BarcodeType be)
 {
     if (barcodefactory == null)
     {
         barcodefactory = new BarcodeFactory();
     }
     Ibarcodes             = barcodefactory.CreateBarcode("CIT.MES.BarCode." + Enum.GetName(typeof(BarcodeType), be) + ",CIT.MES");
     Ibarcodes.BarcodeRect = barcodeRectangle;
 }
コード例 #13
0
 public BarcodeBase(uint id, string name, string description, uint folderId, BarcodeType barcodeType, IBarcode barcode, long created, long updated, long deleted, long viewed)
     : base(id, name, description, created, updated, deleted)
 {
     // this.code = code;
     this.folderId    = folderId;
     this.barcodeType = barcodeType;
     this.barcode     = barcode;
     this.viewed      = viewed;
 }
コード例 #14
0
        /// <summary>
        /// Build and send provided barcode. If this is too limiting,
        /// feel free to follow the docs and build your own payload that
        /// can be sent with the #SendRaw method.
        /// </summary>
        /// <param name="barcode">Barcode object</param>
        public void PrintBarcode(IBarcode barcode)
        {
            var payload = barcode.Build();

            if (payload.Length > 0)
            {
                internalSend(payload);
            }
        }
コード例 #15
0
 private static string RenderBarcodeToString(IRenderer renderer, IBarcode barcode)
 {
     using (var stream = new MemoryStream())
         using (var reader = new StreamReader(stream))
         {
             renderer.Render(barcode, stream);
             stream.Position = 0;
             return(reader.ReadToEnd().Replace("\r", "").Replace("\n", ""));
         }
 }
コード例 #16
0
        public void Render_Barcode1D()
        {
            // Arrange
            var      renderer = new ImageRenderer();
            IBarcode barcode  = Code128Encoder.Encode("Wikipedia");

            // Act
            byte[] data = RenderBarcodeToByteArray(renderer, barcode);

            // Assert
            data.Should().NotBeNull();
        }
コード例 #17
0
        public void Render_Barcode2D()
        {
            // Arrange
            var      renderer = new ImageRenderer();
            IBarcode barcode  = QrEncoder.Encode("Hello Unicode\nHave a nice day!", ErrorCorrectionLevel.L, Encoding.Unicode);

            // Act
            byte[] data = RenderBarcodeToByteArray(renderer, barcode);

            // Assert
            data.Should().NotBeNull();
        }
コード例 #18
0
        internal void ResetProduct(SaleStatus status)
        {
            //重置订单历史小计
            EditTotal = -1;

            //重置促销赠品

            //重置促销信息
            foreach (var item in OrderList)
            {
                if (item.ProductType == ProductType.Bundling && item is BundlingBarcode && (item.Details.SaleStatus == SaleStatus.Normal))
                {
                    item.Details.SaleStatus = SaleStatus.Promotion;
                }
                else if (item.Details.SaleStatus == SaleStatus.Promotion)
                {
                    item.Details.SaleStatus = SaleStatus.Normal;
                }
                else if (item.Details.SaleStatus == SaleStatus.ActivityGifts)
                {
                    item.Details.IsActivityGiftsTimeOut = true;
                }
                item.MarketingMarks = new List <ActiveMarketingRule>();
                item.MarketingPrice = item.SalePrice;
                item.Details.Total  = item.SalePrice * item.SaleNumber;
                item.Details.CollectionMarketingPrice = item.MarketingPrice;
            }

            //重置促销造成的同商品分条目显示(合并促销的同商品条目)
            var groupOrders = OrderList.Where(o => !o.HasEditPrice && o.ProductType != ProductType.Weigh)
                              .GroupBy(o => new { o.MainBarcode, o.Details.SaleStatus }).ToList();

            //合并商品
            foreach (var item in groupOrders)
            {
                if (item.Count() > 1)
                {
                    IBarcode barcode = item.FirstOrDefault();
                    var      list    = item.ToList();

                    if (list.Count > 1)
                    {
                        barcode.SaleNumber = list.Sum(o => o.SaleNumber);
                        list.Remove(barcode);
                        OrderList.RemoveAll(o => list.Exists(p => p == o));
                        barcode.MarketingPrice = barcode.SalePrice;
                        barcode.Details.Total  = barcode.SalePrice * barcode.SaleNumber;
                        barcode.Details.CollectionMarketingPrice = barcode.MarketingPrice;
                    }
                }
            }
        }
コード例 #19
0
        public void Render_Barcode2D()
        {
            // Arrange
            var      renderer = new SvgRenderer();
            IBarcode barcode  = QrEncoder.Encode("Hello Unicode\nHave a nice day!", ErrorCorrectionLevel.L, Encoding.Unicode);
            string   expected = GetExpectedSvgOutput("QrCode.ExpectedSvgOutput.txt");

            // Act
            string svg = RenderBarcodeToString(renderer, barcode);

            // Assert
            svg.Length.Should().BeGreaterOrEqualTo(0);
            svg.Should().Be(expected);
        }
コード例 #20
0
 public CustomBarcode(IBarcode barcode)
 {
     Count         = barcode.Count;
     CurrentString = barcode.CurrentString;
     ProductType   = barcode.ProductType;
     SalePrice     = barcode.SalePrice;
     SaleNumber    = barcode.SaleNumber;
     ProductCode   = barcode.ProductCode;
     Details       = barcode.Details;
     IsMultiCode   = barcode.IsMultiCode;
     MultiCode     = barcode.MultiCode;
     AveragePrice  = barcode.AveragePrice;
     MainBarcode   = barcode.MainBarcode;
 }
コード例 #21
0
        }//Encode()

        /// <summary>
        /// Encodes the raw data into binary form representing bars and spaces.
        /// </summary>
        internal Image Encode()
        {
            ibarcode.Errors.Clear();

            DateTime dtStartTime = DateTime.Now;

            //make sure there is something to encode
            if (Raw_Data.Trim() == "")
            {
                throw new Exception("EENCODE-1: Input data not allowed to be blank.");
            }

            if (this.EncodedType == TYPE.UNSPECIFIED)
            {
                throw new Exception("EENCODE-2: Symbology type not allowed to be unspecified.");
            }

            this.Encoded_Value = "";
            this._Country_Assigning_Manufacturer_Code = "N/A";

            switch (this.Encoded_Type)
            {
            case TYPE.EAN13:     //Encode_EAN13();
                ibarcode = new EAN13(Raw_Data);
                break;

            case TYPE.CODE39:     //Encode_Code39();
                ibarcode = new Code39(Raw_Data);
                break;

            case TYPE.CODE39Extended:
                ibarcode = new Code39(Raw_Data, true);
                break;

            default: throw new Exception("EENCODE-2: Unsupported encoding type specified.");
            }//switch

            this.Encoded_Value = ibarcode.Encoded_Value;
            this.Raw_Data      = ibarcode.RawData;

            _Encoded_Image = (Image)Generate_Image();

            this.EncodedImage.RotateFlip(this.RotateFlipType);

            //_XML = GetXML();

            this._EncodingTime = ((TimeSpan)(DateTime.Now - dtStartTime)).TotalMilliseconds;

            return(EncodedImage);
        }//Encode
コード例 #22
0
        public void Render_Barcode1D()
        {
            // Arrange
            var      renderer = new SvgRenderer();
            IBarcode barcode  = Code128Encoder.Encode("Wikipedia");
            string   expected = GetExpectedSvgOutput("Code128.ExpectedSvgOutput.txt");

            // Act
            string svg = RenderBarcodeToString(renderer, barcode);

            // Assert
            svg.Length.Should().BeGreaterOrEqualTo(0);
            svg.Should().Be(expected);
        }
コード例 #23
0
        public IBarcode CreateBarcode(string Name, params object[] args)
        {
            IBarcode MyBarcode = null;

            try
            {
                Type btype = Type.GetType(Name, true);
                MyBarcode = (IBarcode)Activator.CreateInstance(btype, args);
            }
            catch (TypeLoadException)
            {
                System.Windows.Forms.MessageBox.Show("条码加载失败!" + Name, "WormSoft Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            return(MyBarcode);
        }
コード例 #24
0
 public void Render(IBarcode barcode, Stream outputStream)
 {
     if (barcode.Bounds.Y == 1)
     {
         Render1D(barcode, outputStream);
     }
     else if (barcode.Bounds.Y > 1)
     {
         Render2D(barcode, outputStream);
     }
     else
     {
         throw new NotSupportedException($"Y value of {barcode.Bounds.Y} is invalid");
     }
 }
コード例 #25
0
        public static void Render(Image <Gray8> image, IBarcode barcode, string fontFamily, int scale)
        {
            Font font = SystemFonts.CreateFont(fontFamily, UnscaledFontSize * scale, FontStyle.Regular);

            switch (barcode.Metadata.CodeKind)
            {
            case BarcodeType.EAN8:
                RenderContentForEan8(image, barcode.Content, font, barcode.Margin, scale);
                break;

            case BarcodeType.EAN13:
                RenderContentForEan13(image, barcode.Content, font, barcode.Margin, scale);
                break;
            }
        }
コード例 #26
0
ファイル: SvgRenderer.cs プロジェクト: vmanthena/barcoder
        private static void Render1D(IBarcode barcode, Stream outputStream)
        {
            var document = SvgDocument.Create();

            document.ViewBox = new SvgViewBox
            {
                Left   = 0,
                Top    = 0,
                Width  = barcode.Bounds.X + 2 * barcode.Margin,
                Height = 50
            };
            document.Fill          = "#FFFFFF";
            document.Stroke        = "#000000";
            document.StrokeWidth   = 1;
            document.StrokeLineCap = SvgStrokeLineCap.Butt;

            var prevBar = false;

            for (var x = 0; x < barcode.Bounds.X; x++)
            {
                if (!barcode.At(x, 0))
                {
                    prevBar = false;
                    continue;
                }

                SvgLine line;
                if (prevBar)
                {
                    line             = document.AddLine();
                    line.StrokeWidth = 1.5;
                    line.X1          = line.X2 = x + barcode.Margin - 0.25;
                    line.Y1          = 0;
                    line.Y2          = 50;
                }
                else
                {
                    line    = document.AddLine();
                    line.X1 = line.X2 = x + barcode.Margin;
                    line.Y1 = 0;
                    line.Y2 = 50;
                }

                prevBar = true;
            }

            document.Save(outputStream);
        }
コード例 #27
0
        public void Render_ImageFormatGif_ShouldRenderGif()
        {
            // Arrange
            var      renderer = new ImageRenderer(imageFormat: ImageFormat.Gif);
            IBarcode barcode  = QrEncoder.Encode("Hello", ErrorCorrectionLevel.L, Encoding.Unicode);

            using var stream = new MemoryStream();

            // Act
            renderer.Render(barcode, stream);

            // Assert
            stream.Position = 0;
            using var image = ImageSharp.Image.Load(stream, out IImageFormat imageFormat);
            imageFormat.Name.Should().Be("GIF");
        }
コード例 #28
0
ファイル: SvgRenderer.cs プロジェクト: vmanthena/barcoder
 public void Render(IBarcode barcode, Stream outputStream)
 {
     barcode      = barcode ?? throw new ArgumentNullException(nameof(barcode));
     outputStream = outputStream ?? throw new ArgumentNullException(nameof(outputStream));
     if (barcode.Bounds.Y == 1)
     {
         Render1D(barcode, outputStream);
     }
     else if (barcode.Bounds.Y > 1)
     {
         Render2D(barcode, outputStream);
     }
     else
     {
         throw new NotSupportedException($"Y value of {barcode.Bounds.Y} is invalid");
     }
 }
コード例 #29
0
ファイル: QrEncoderTests.cs プロジェクト: orion6dev/barcoder
        public void Encode_ValidUnicodeContent_ShouldEncodeQrCodeCorrectly()
        {
            // Arrange
            var content          = "hello world";
            var expectedDataBits = ImageStringToBools(@"
                +++++++.+.+.+...+.+++++++
                +.....+.++...+++..+.....+
                +.+++.+.+.+.++.++.+.+++.+
                +.+++.+....++.++..+.+++.+
                +.+++.+..+...++.+.+.+++.+
                +.....+.+..+..+++.+.....+
                +++++++.+.+.+.+.+.+++++++
                ........++..+..+.........
                ..+++.+.+++.+.++++++..+++
                +++..+..+...++.+...+..+..
                +...+.++++....++.+..++.++
                ++.+.+.++...+...+.+....++
                ..+..+++.+.+++++.++++++++
                +.+++...+..++..++..+..+..
                +.....+..+.+.....+++++.++
                +.+++.....+...+.+.+++...+
                +.+..+++...++.+.+++++++..
                ........+....++.+...+.+..
                +++++++......++++.+.+.+++
                +.....+....+...++...++.+.
                +.+++.+.+.+...+++++++++..
                +.+++.+.++...++...+.++..+
                +.+++.+.++.+++++..++.+..+
                +.....+..+++..++.+.++...+
                +++++++....+..+.+..+..+++
            ");

            // Act
            IBarcode qr = QrEncoder.Encode(content, ErrorCorrectionLevel.H, Encoding.Unicode);

            // Assert
            qr.Should().NotBeNull();
            expectedDataBits.Length.Should().Be(qr.Bounds.X * qr.Bounds.Y);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % qr.Bounds.X;
                int y = i / qr.Bounds.X;
                qr.At(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
コード例 #30
0
        public void Encode(string txt, string testResult)
        {
            IBarcode code = Codabar.Encode(txt);

            code.Should().NotBeNull();
            code.Bounds.X.Should().Be(testResult.Length);
            code.Bounds.Y.Should().Be(1);
            code.Metadata.CodeKind.Should().Be(BarcodeType.Codabar);
            code.Metadata.Dimensions.Should().Be(1);
            string encoded = string.Empty;
            int    i       = 0;

            foreach (var r in testResult)
            {
                encoded += code.At(i++, 0) ? "1" : "0";
            }
            encoded.Should().Be(testResult);
        }
コード例 #31
0
ファイル: Options.cs プロジェクト: jshor/zint-csharp
        public void ChangeSymbology(BarcodeTypes symbol)
        {
            // remove all tabs except the "appearance" tab
            for (int i = 0; i < generalTab.TabPages.Count; i++ )
            {
                if (generalTab.TabPages[i] != appearanceTab && generalTab.TabPages[i] != dataTab)
                {
                    generalTab.TabPages.Remove(generalTab.TabPages[i]);
                }
            }

            switch (symbol)
            {
                case BarcodeTypes.AZTEC:
                    symbologyOptions = new Aztec(symbology);
                    break;
                case BarcodeTypes.CHANNEL:
                    symbologyOptions = new ChannelCode(symbology);
                    break;
                case BarcodeTypes.CODE128:
                    symbologyOptions = new Code128(symbology);
                    break;
                case BarcodeTypes.CODE16K:
                    symbologyOptions = new Code16k(symbology);
                    break;
                case BarcodeTypes.CODE39:
                    symbologyOptions = new Code39(symbology);
                    break;
                case BarcodeTypes.EXCODE39:
                    symbologyOptions = new Code39Ext(symbology);
                    break;
                case BarcodeTypes.CODE49:
                    symbologyOptions = new Code49(symbology);
                    break;
                case BarcodeTypes.CODEONE:
                    symbologyOptions = new CodeOne(symbology);
                    break;
                case BarcodeTypes.DATAMATRIX:
                    symbologyOptions = new DataMatrix(symbology);
                    break;
                case BarcodeTypes.GRIDMATRIX:
                    symbologyOptions = new GridMatrix(symbology);
                    break;
                case BarcodeTypes.MAXICODE:
                    symbologyOptions = new MaxiCode(symbology);
                    break;
                case BarcodeTypes.MICROPDF417:
                    symbologyOptions = new MicroPDF(symbology);
                    break;
                case BarcodeTypes.MICROQR:
                    symbologyOptions = new MicroQR(symbology);
                    break;
                case BarcodeTypes.MSI_PLESSEY:
                    symbologyOptions = new MSIPlessey(symbology);
                    break;
                case BarcodeTypes.PDF417:
                    symbologyOptions = new PDF417(symbology);
                    break;
                case BarcodeTypes.QRCODE:
                    symbologyOptions = new QRCode(symbology);
                    break;
                default:
                    symbologyOptions = null;
                    break;
            }

            if(symbologyOptions != null)
            {
                // add the "options" tab if it's set and add event listener
                TabPage optionsTab = new TabPage("Options");
                optionsTab.Controls.Add(symbologyOptions.GetControl());
                generalTab.TabPages.Add(optionsTab);
                symbologyOptions.OptionsChanged += symbologyOptions_OptionsChanged;
            }

            // show the 2D composite options group box, if applies
            if (Allows2DComponent(symbol))
            {
                add2DComponentGroup.Visible = true;
            }
            else
            {
                add2DComponent.Checked = false;
                add2DComponentGroup.Visible = false;
                componentType.SelectedIndex = 0;
                secondaryData.Text = "";
            }

            symbology.Symbol = symbol;
        }
コード例 #32
0
ファイル: BarcodeLib.cs プロジェクト: AAGJKPRT/LMT
        /// <summary>
        /// Encodes the raw data into binary form representing bars and spaces.
        /// </summary>
        internal Image Encode()
        {
            ibarcode.Errors.Clear();

            DateTime dtStartTime = DateTime.Now;

            //make sure there is something to encode
            if (Raw_Data.Trim() == "")
                throw new Exception("EENCODE-1: Input data not allowed to be blank.");

            if (this.EncodedType == TYPE.UNSPECIFIED)
                throw new Exception("EENCODE-2: Symbology type not allowed to be unspecified.");

            this.Encoded_Value = "";
            this._Country_Assigning_Manufacturer_Code = "N/A";
            //ibarcode = new Code93(Raw_Data);
            ibarcode=new Code128(Raw_Data);
            //ibarcode = new (Raw_Data,true);
            this.Encoded_Value = ibarcode.Encoded_Value;
            this.Raw_Data = ibarcode.RawData;

            _Encoded_Image = (Image)Generate_Image();

            this.EncodedImage.RotateFlip(this.RotateFlipType);

            _XML = GetXML();

            this.EncodingTime = ((TimeSpan)(DateTime.Now - dtStartTime)).TotalMilliseconds;

            return EncodedImage;
        }
コード例 #33
0
        /// <summary>
        /// Encodes the raw data into binary form representing bars and spaces.
        /// </summary>
        internal Image Encode()
        {
            ibarcode.Errors.Clear();

            DateTime dtStartTime = DateTime.Now;

            //make sure there is something to encode
            if (Raw_Data.Trim() == "")
                throw new Exception("EENCODE-1: Input data not allowed to be blank.");

            if (this.EncodedType == TYPE.UNSPECIFIED)
                throw new Exception("EENCODE-2: Symbology type not allowed to be unspecified.");

            this.Encoded_Value = "";
            this._Country_Assigning_Manufacturer_Code = "N/A";

            switch (this.Encoded_Type)
            {
                case TYPE.UCC12:
                case TYPE.UPCA: //Encode_UPCA();
                    ibarcode = new UPCA(Raw_Data);
                    break;
                case TYPE.UCC13:
                case TYPE.EAN13: //Encode_EAN13();
                    ibarcode = new EAN13(Raw_Data);
                    break;
                case TYPE.Interleaved2of5: //Encode_Interleaved2of5();
                    ibarcode = new Interleaved2of5(Raw_Data);
                    break;
                case TYPE.Industrial2of5:
                case TYPE.Standard2of5: //Encode_Standard2of5();
                    ibarcode = new Standard2of5(Raw_Data);
                    break;
                case TYPE.LOGMARS:
                case TYPE.CODE39: //Encode_Code39();
                    ibarcode = new Code39(Raw_Data);
                    break;
                case TYPE.CODE39Extended:
                    ibarcode = new Code39(Raw_Data, true);
                    break;
                case TYPE.CODE39_Mod43:
                    ibarcode = new Code39(Raw_Data, false, true);
                    break;
                case TYPE.Codabar: //Encode_Codabar();
                    ibarcode = new Codabar(Raw_Data);
                    break;
                case TYPE.PostNet: //Encode_PostNet();
                    ibarcode = new Postnet(Raw_Data);
                    break;
                case TYPE.ISBN:
                case TYPE.BOOKLAND: //Encode_ISBN_Bookland();
                    ibarcode = new ISBN(Raw_Data);
                    break;
                case TYPE.JAN13: //Encode_JAN13();
                    ibarcode = new JAN13(Raw_Data);
                    break;
                case TYPE.UPC_SUPPLEMENTAL_2DIGIT: //Encode_UPCSupplemental_2();
                    ibarcode = new UPCSupplement2(Raw_Data);
                    break;
                case TYPE.MSI_Mod10:
                case TYPE.MSI_2Mod10:
                case TYPE.MSI_Mod11:
                case TYPE.MSI_Mod11_Mod10:
                case TYPE.Modified_Plessey: //Encode_MSI();
                    ibarcode = new MSI(Raw_Data, Encoded_Type);
                    break;
                case TYPE.UPC_SUPPLEMENTAL_5DIGIT: //Encode_UPCSupplemental_5();
                    ibarcode = new UPCSupplement5(Raw_Data);
                    break;
                case TYPE.UPCE: //Encode_UPCE();
                    ibarcode = new UPCE(Raw_Data);
                    break;
                case TYPE.EAN8: //Encode_EAN8();
                    ibarcode = new EAN8(Raw_Data);
                    break;
                case TYPE.USD8:
                case TYPE.CODE11: //Encode_Code11();
                    ibarcode = new Code11(Raw_Data);
                    break;
                case TYPE.CODE128: //Encode_Code128();
                    ibarcode = new Code128(Raw_Data);
                    break;
                case TYPE.CODE128A:
                    ibarcode = new Code128(Raw_Data, Code128.TYPES.A);
                    break;
                case TYPE.CODE128B:
                    ibarcode = new Code128(Raw_Data, Code128.TYPES.B);
                    break;
                case TYPE.CODE128C:
                    ibarcode = new Code128(Raw_Data, Code128.TYPES.C);
                    break;
                case TYPE.ITF14:
                    ibarcode = new ITF14(Raw_Data);
                    break;
                case TYPE.CODE93:
                    ibarcode = new Code93(Raw_Data);
                    break;
                case TYPE.TELEPEN:
                    ibarcode = new Telepen(Raw_Data);
                    break;
                case TYPE.FIM:
                    ibarcode = new FIM(Raw_Data);
                    break;
                case TYPE.PHARMACODE:
                    ibarcode = new Pharmacode(Raw_Data);
                    break;

                default: throw new Exception("EENCODE-2: Unsupported encoding type specified.");
            }//switch

            this.Encoded_Value = ibarcode.Encoded_Value;
            this.Raw_Data = ibarcode.RawData;

            _Encoded_Image = (Image)Generate_Image();

            this.EncodedImage.RotateFlip(this.RotateFlipType);

            _XML = GetXML();

            this.EncodingTime = ((TimeSpan)(DateTime.Now - dtStartTime)).TotalMilliseconds;

            return EncodedImage;
        }
コード例 #34
0
ファイル: BarcodeLib.cs プロジェクト: njmube/RetailPOS
        /// <summary>
        /// Encodes the raw data into binary form representing bars and spaces.
        /// </summary>
        internal Image Encode()
        {
            ibarcode.Errors.Clear();

            DateTime dtStartTime = DateTime.Now;

            //make sure there is something to encode
            if (Raw_Data.Trim() == "")
                throw new Exception("EENCODE-1: Input data not allowed to be blank.");

            if (this.EncodedType == TYPE.UNSPECIFIED)
                throw new Exception("EENCODE-2: Symbology type not allowed to be unspecified.");

            this.Encoded_Value = "";
            this._Country_Assigning_Manufacturer_Code = "N/A";

            switch (this.Encoded_Type)
            {
                case TYPE.EAN13: //Encode_EAN13();
                    ibarcode = new EAN13(Raw_Data);
                    break;
                case TYPE.CODE39: //Encode_Code39();
                    ibarcode = new Code39(Raw_Data);
                    break;
                case TYPE.CODE39Extended:
                    ibarcode = new Code39(Raw_Data, true);
                    break;
                default: throw new Exception("EENCODE-2: Unsupported encoding type specified.");
            }//switch

            this.Encoded_Value = ibarcode.Encoded_Value;
            this.Raw_Data = ibarcode.RawData;

            _Encoded_Image = (Image)Generate_Image();

            this.EncodedImage.RotateFlip(this.RotateFlipType);

            //_XML = GetXML();

            this._EncodingTime = ((TimeSpan)(DateTime.Now - dtStartTime)).TotalMilliseconds;

            return EncodedImage;
        }
コード例 #35
0
ファイル: LabelRenderer.cs プロジェクト: konne88/MyInventory
        private void RenderBarcode(IBarcode bc, Cairo.Context cr, double x, double y, double width, double height)
        {
            // throws an exception if no stop was added
            double barWidth = width/(double)bc.BarcodeWidth;

            cr.Save();

            cr.LineWidth = barWidth;
            cr.Color = new Cairo.Color(0, 0, 0);

            x += bc.Silence*barWidth;
            foreach(bool b in bc.Bars){
                if(b){
                    cr.MoveTo(x,y);
                    cr.RelLineTo(0,height);
                }
                x+=barWidth;
            }

            cr.Stroke();
            cr.Restore();
        }