Exemplo n.º 1
0
        internal EanUpcSupplement ResolveSupplement(string supplement)
        {
            EanUpcSupplement supp = null;

            if (supplement != null && supplement.Length > 0)
            {
                supp = EanUpcSupplement.GetSupplementBarCode(this, supplement);
            }
            return(supp);
        }
Exemplo n.º 2
0
        public override void Draw(IBarCodeBuilder builder, string data, string supplement)
        {
            // resolve the supplement barcode
            EanUpcSupplement supp = ResolveSupplement(supplement);

            // the data is Upca data
            data = Validate(data, 12);

            if (data[0] != '0' && data[0] != '1')
            {
                throw new BarCodeFormatException("Can't encode Upce for Upca Number System.");
            }

            // Upce data to be encoded
            string upce = FromUpca(data);

            // encode the Upce symbol using the number system and check digit of the Upca data
            BitArray[] encoded = EncodeLeft(upce, ParityEncoder.Encode(data[0].ToString() + data[11]));

            // calculate total width
            float totalWidth = TotalWidth +
                               (supp == null ? 0 : SupplementOffset + supp.TotalWidth);

            // set the canvas size
            builder.Prepare(totalWidth, TotalHeight);

            // draw the background
            builder.DrawRectangle(BackColor, 0, 0, totalWidth, TotalHeight);

            // draw the barcode
            float x = 0, y = 0;

            float[] textX = new float[3];
            x       += OffsetWidth + QuietZone;
            y       += OffsetHeight;
            textX[0] = x;
            x       += TextWidth;
            x        = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, LeftGuard);
            textX[1] = x;
            x        = DrawSymbols(builder, x, y, BarHeight, encoded);
            x        = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, RightGuard);
            textX[2] = x;

            // draw the text strings
            DrawText(builder, textX, y - TextHeight, new string[] { data[0].ToString(), upce, data[11].ToString() });

            // draw the supplement barcode, if one is present
            if (supp != null)
            {
                supp.Draw(builder, supplement, x + TextWidth + SupplementOffset, y - OffsetHeight);
            }
        }
Exemplo n.º 3
0
        public override void Draw(IBarCodeBuilder builder, string data, string supplement)
        {
            // resolve the supplement barcode
            EanUpcSupplement supp = ResolveSupplement(supplement);

            // validate Ean13 data
            data = Validate(data, 13);

            // split the data in its sub components
            string[] text = new string[] { data.Substring(0, 1), data.Substring(1, 6), data.Substring(7, 6) };

            // encode the data
            BitArray[] left  = EncodeLeft(text[1], ParityEncoder.Encode(text[0]));
            BitArray[] right = EncodeRight(text[2]);

            // calculate total width
            float totalWidth = TotalWidth +
                               (supp == null ? 0 : SupplementOffset + supp.TotalWidth);

            // set the canvas size
            builder.Prepare(totalWidth, TotalHeight);

            // draw the background
            builder.DrawRectangle(BackColor, 0, 0, totalWidth, TotalHeight);

            // draw the barcode
            float x = 0, y = 0;

            float[] textX = new float[3];
            x       += OffsetWidth + QuietZone;
            y       += OffsetHeight;
            textX[0] = x;
            x       += TextWidth;
            x        = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, LeftGuard);
            textX[1] = x;
            x        = DrawSymbols(builder, x, y, BarHeight, left);
            x        = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, CenterGuard);
            textX[2] = x;
            x        = DrawSymbols(builder, x, y, BarHeight, right);
            x        = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, RightGuard);

            // draw the text strings
            DrawText(builder, textX, y - TextHeight, text);

            // draw the supplement barcode, if one is present
            if (supp != null)
            {
                supp.Draw(builder, supplement, x + SupplementOffset, y - OffsetHeight);
            }
        }