Esempio n. 1
0
        public override Collection <SymbolData> EncodeData()
        {
            Symbol = new Collection <SymbolData>();
            switch (encodingMode)
            {
            case EncodingMode.Standard:
                isGS1       = false;
                barcodeData = MessagePreProcessor.TildeParser(barcodeMessage);
                Code16K();
                break;

            case EncodingMode.GS1:
                isGS1       = true;
                barcodeData = MessagePreProcessor.AIParser(barcodeMessage);
                Code16K();
                break;
            }

            return(Symbol);
        }
Esempio n. 2
0
        public static void AddComposite(Symbology symbology, string message, Collection <SymbolData> encodedLinearData,
                                        CompositeMode compositeMode, int linearSymbolWidth)
        {
            int       dataColumns         = 0;
            int       eccLevel            = 0;
            int       compositeShiftCount = 0;
            int       linearShiftCount    = 0;
            BitVector bitStream;

            hostSymbol  = symbology;
            encodedData = encodedLinearData;
            linearWidth = linearSymbolWidth;

            compositeData = MessagePreProcessor.AIParser(message);
            int inputLength = compositeData.Length;

            if (inputLength > 2990)
            {
                throw new InvalidDataLengthException("2D Component: Input data too long.");
            }

            if ((compositeMode == CompositeMode.CCC) && (symbology != Symbology.Code128))
            {
                throw new DataEncodingException("2D Component: Invalid mode, CC-C only valid with a GS1-128 linear component.");
            }

            switch (symbology)
            {
            // Determine width of 2D component according to ISO/IEC 24723 Table 1.
            case Symbology.EAN8:
                dataColumns      = 3;
                linearShiftCount = 3;
                if (compositeMode == CompositeMode.CCB)
                {
                    linearShiftCount = 13;
                }

                break;

            case Symbology.EAN13:
                dataColumns      = 4;
                linearShiftCount = 2;
                break;

            case Symbology.UPCE:
                dataColumns      = 2;
                linearShiftCount = 2;
                break;

            case Symbology.UPCA:
                dataColumns      = 4;
                linearShiftCount = 3;
                break;

            case Symbology.Code128:
                dataColumns = 4;
                if (compositeMode == CompositeMode.CCC)
                {
                    linearShiftCount = 7;
                }

                break;

            case Symbology.DatabarOmni:
            case Symbology.DatabarTruncated:
                dataColumns      = 4;
                linearShiftCount = 4;
                break;

            case Symbology.DatabarLimited:
                dataColumns         = 3;
                compositeShiftCount = 0;
                break;

            case Symbology.DatabarExpanded:
                dataColumns         = 4;
                compositeShiftCount = 1;
                while ((encodedData[1].GetRowData()[compositeShiftCount - 1] == 0) && (encodedData[1].GetRowData()[compositeShiftCount] == 1))
                {
                    compositeShiftCount++;
                }

                break;

            case Symbology.DatabarStacked:
            case Symbology.DatabarOmniStacked:
                dataColumns         = 2;
                compositeShiftCount = 0;
                break;

            case Symbology.DatabarExpandedStacked:
                dataColumns         = 4;
                compositeShiftCount = 1;
                while ((encodedData[1].GetRowData()[compositeShiftCount - 1] == 0) && (encodedData[1].GetRowData()[compositeShiftCount] == 1))
                {
                    compositeShiftCount++;
                }

                break;
            }

            if (linearShiftCount > 0)
            {
                ShiftLinearHost(linearShiftCount);
            }

            bitStream = BitStreamEncoder.CompositeBitStream(symbology, compositeData, ref compositeMode, ref dataColumns, ref eccLevel, linearWidth);
            if (bitStream == null)
            {
                throw new InvalidDataLengthException();
            }

            switch (compositeMode)
            {
            // Note that eccLevel is only relevant to CC-C.
            case CompositeMode.CCA:
                CompositeA(bitStream, dataColumns, compositeShiftCount);
                break;

            case CompositeMode.CCB:
                CompositeB(bitStream, dataColumns, compositeShiftCount);
                break;

            case CompositeMode.CCC:
                CompositeC(bitStream, dataColumns, eccLevel);
                break;
            }
        }
        public override Collection <SymbolData> EncodeData()
        {
            Symbol = new Collection <SymbolData>();
            switch (symbolId)
            {
            case Symbology.Code128:
                switch (encodingMode)
                {
                case EncodingMode.Standard:
                    barcodeData = MessagePreProcessor.TildeParser(barcodeMessage);
                    Code128();
                    barcodeText = new String(barcodeData);
                    break;

                case EncodingMode.GS1:
                    isGS1       = true;
                    barcodeData = MessagePreProcessor.AIParser(barcodeMessage);
                    EAN128();
                    barcodeText = barcodeMessage;
                    barcodeText = barcodeText.Replace('[', '(');
                    barcodeText = barcodeText.Replace(']', ')');
                    break;

                case EncodingMode.HIBC:
                    barcodeData = MessagePreProcessor.HIBCParser(barcodeMessage);
                    Code128();
                    barcodeText = new String(barcodeData);
                    break;
                }

                break;

            case Symbology.EAN14:
                isCompositeSymbol = false;
                barcodeData       = MessagePreProcessor.MessageParser(barcodeMessage);
                EAN14();
                barcodeText = new string(barcodeData);
                break;

            case Symbology.SSCC18:
                isCompositeSymbol = false;
                barcodeData       = MessagePreProcessor.MessageParser(barcodeMessage);
                SSC18();
                barcodeText = new string(barcodeData);
                break;
            }

            // Expand the row pattern into the symbol data.
            SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f);

            // Build the symbol separator and add the 2D component (GS1-128)
            if (isGS1 && isCompositeSymbol)
            {
                byte[] rowData = new byte[Symbol[0].GetRowData().Length];
                for (int i = 0; i < rowData.Length; i++)
                {
                    if (Symbol[0].GetRowData()[i] == 0)
                    {
                        rowData[i] = 1;
                    }
                }

                // Insert the separator to the symbol (top down ).
                SymbolData symbolData = new SymbolData(rowData, 1.0f);
                Symbol.Insert(0, symbolData);
                CompositeEncoder.AddComposite(symbolId, compositeMessage, Symbol, compositeMode, rowData.Length);
            }

            return(Symbol);
        }