Beispiel #1
0
        private void Generate(byte[] text, int textOffset, int textSize)
        {
            int      e, k, full;
            DmParams dm, last;

            byte[] data = new byte[2500];
            e = -1;

            if (height == 0 || width == 0)
            {
                last = dmSizes[dmSizes.Length - 1];
                e    = GetEncodation(text, textOffset, textSize, data, 0, last.dataSize, false);
                if (e < 0)
                {
                    throw new Exception("The text is too big.");
                }
                for (k = 0; k < dmSizes.Length; ++k)
                {
                    if (dmSizes[k].dataSize >= e)
                    {
                        break;
                    }
                }
                dm     = dmSizes[k];
                height = dm.height;
                width  = dm.width;
            }
            else
            {
                for (k = 0; k < dmSizes.Length; ++k)
                {
                    if (height == dmSizes[k].height && width == dmSizes[k].width)
                    {
                        break;
                    }
                }
                if (k == dmSizes.Length)
                {
                    throw new Exception("Invalid symbol size.");
                }
                dm = dmSizes[k];
                e  = GetEncodation(text, textOffset, textSize, data, 0, dm.dataSize, true);
                if (e < 0)
                {
                    throw new Exception("The text is too big.");
                }
            }

            image = new byte[((dm.width + 7) / 8) * dm.height];
            MakePadding(data, e, dm.dataSize - e);
            place = Placement.DoPlacement(dm.height - (dm.height / dm.heightSection * 2), dm.width - (dm.width / dm.widthSection * 2));
            full  = dm.dataSize + ((dm.dataSize + 2) / dm.dataBlock) * dm.errorBlock;
            ReedSolomon.GenerateECC(data, dm.dataSize, dm.dataBlock, dm.errorBlock);
            Draw(data, full, dm);
        }
Beispiel #2
0
        /// <summary>Creates a barcode.</summary>
        /// <param name="text">the text</param>
        /// <param name="textOffset">the offset to the start of the text</param>
        /// <param name="textSize">the text size</param>
        /// <returns>
        /// the status of the generation. It can be one of this values:
        /// <p/>
        /// <CODE>DM_NO_ERROR</CODE> - no error.<br />
        /// <CODE>DM_ERROR_TEXT_TOO_BIG</CODE> - the text is too big for the symbology capabilities.<br />
        /// <CODE>DM_ERROR_INVALID_SQUARE</CODE> - the dimensions given for the symbol are illegal.<br />
        /// <CODE>DM_ERROR_EXTENSION</CODE> - an error was while parsing an extension.
        /// </returns>
        public virtual int SetCode(byte[] text, int textOffset, int textSize)
        {
            int      extCount;
            int      e;
            int      k;
            int      full;
            DmParams dm;
            DmParams last;

            byte[] data = new byte[2500];
            extOut   = 0;
            extCount = ProcessExtensions(text, textOffset, textSize, data);
            if (extCount < 0)
            {
                return(DM_ERROR_EXTENSION);
            }
            e = -1;
            if (height == 0 || width == 0)
            {
                last = dmSizes[dmSizes.Length - 1];
                e    = GetEncodation(text, textOffset + extOut, textSize - extOut, data, extCount, last.dataSize - extCount,
                                     options, false);
                if (e < 0)
                {
                    return(DM_ERROR_TEXT_TOO_BIG);
                }
                e += extCount;
                for (k = 0; k < dmSizes.Length; ++k)
                {
                    if (dmSizes[k].dataSize >= e)
                    {
                        break;
                    }
                }
                dm     = dmSizes[k];
                height = dm.height;
                width  = dm.width;
            }
            else
            {
                for (k = 0; k < dmSizes.Length; ++k)
                {
                    if (height == dmSizes[k].height && width == dmSizes[k].width)
                    {
                        break;
                    }
                }
                if (k == dmSizes.Length)
                {
                    return(DM_ERROR_INVALID_SQUARE);
                }
                dm = dmSizes[k];
                e  = GetEncodation(text, textOffset + extOut, textSize - extOut, data, extCount, dm.dataSize - extCount, options
                                   , true);
                if (e < 0)
                {
                    return(DM_ERROR_TEXT_TOO_BIG);
                }
                e += extCount;
            }
            if ((options & DM_TEST) != 0)
            {
                return(DM_NO_ERROR);
            }
            image = new byte[(dm.width + 2 * ws + 7) / 8 * (dm.height + 2 * ws)];
            MakePadding(data, e, dm.dataSize - e);
            place = Placement.DoPlacement(dm.height - dm.height / dm.heightSection * 2, dm.width - dm.width / dm.widthSection
                                          * 2);
            full = dm.dataSize + (dm.dataSize + 2) / dm.dataBlock * dm.errorBlock;
            ReedSolomon.GenerateECC(data, dm.dataSize, dm.dataBlock, dm.errorBlock);
            Draw(data, full, dm);
            return(DM_NO_ERROR);
        }