コード例 #1
0
ファイル: GlyphFactory.cs プロジェクト: franknew/SOAFramework
        /// <summary>
        /// Gets the array of <see cref="T:Zen.Barcode.Glyph"/> objects that
        /// correspond to the specified character.
        /// </summary>
        /// <param name="character">The character to be translated.</param>
        /// <param name="allowComposite">if set to <c>true</c> to allow
        /// composite glyphs to be returned.</param>
        /// <returns>
        /// A collection of <see cref="T:Zen.Barcode.Glyph"/> objects.
        /// </returns>
        /// <remarks>
        /// This method may return more than one glyph depending on the
        /// underlying encoding mechanism being used.
        /// </remarks>
        public virtual Glyph[] GetGlyphs(char character, bool allowComposite)
        {
            EnsureFullLookup();
            Glyph          glyph     = _lookup[character];
            CompositeGlyph compGlyph = glyph as CompositeGlyph;

            if (compGlyph != null && !allowComposite)
            {
                return(new Glyph[] { compGlyph.First, compGlyph.Second });
            }
            else
            {
                return(new Glyph[] { glyph });
            }
        }
コード例 #2
0
        /// <summary>
        /// Overridden. Gets the glyphs needed to render a full barcode.
        /// </summary>
        /// <param name="text">Text to convert into bar-code.</param>
        /// <returns>A collection of <see cref="T:Glyph"/> objects.</returns>
        protected override Glyph[] GetFullBarcode(string text)
        {
            // Run proposed barcode through validator
            Match m = Regex.Match(text, @"^\s*(?<barcode>[0-9]{7})\s*$");

            if (!m.Success)
            {
                throw new ArgumentException("Invalid barcode.");
            }
            string barcodeText = m.Groups["barcode"].Value;

            // Determine parity value for remaining encoding then strip
            //	after calculating the checksum
            if (Checksum != null)
            {
                barcodeText += Checksum.GetChecksumChar(barcodeText);
            }

            // Build result with composite glyphs
            List <Glyph> result = new List <Glyph>();

            result.AddRange(Factory.GetGlyphs(barcodeText, true));

            for (int index = 0; index < result.Count; ++index)
            {
                // Fetch next glyph
                if (result[index] is CompositeGlyph)
                {
                    // Determine effective parity arrangement
                    CompositeGlyph composite = (CompositeGlyph)result[index];
                    if (index < 4)
                    {
                        result[index] = composite.First;
                    }
                    else
                    {
                        result[index] = composite.Second;
                    }
                }
            }

            // Add start/stop and seperator glyphs
            result.Insert(4, Factory.GetRawGlyph('|'));
            result.Insert(0, Factory.GetRawGlyph('*'));
            result.Add(Factory.GetRawGlyph('*'));
            return(result.ToArray());
        }
コード例 #3
0
ファイル: CodeEan13.cs プロジェクト: franknew/SOAFramework
        /// <summary>
        /// Overridden. Gets the glyphs needed to render a full barcode.
        /// </summary>
        /// <param name="text">Text to convert into bar-code.</param>
        /// <returns>A collection of <see cref="T:Glyph"/> objects.</returns>
        protected override Glyph[] GetFullBarcode(string text)
        {
            // Run proposed barcode through validator
            Match m = Regex.Match(text, @"^\s*(?<barcode>[0-9]{12})\s*$");

            if (!m.Success)
            {
                throw new ArgumentException("Invalid barcode.");
            }
            string barcodeText = m.Groups["barcode"].Value;

            // Determine parity to use
            byte[] parityTable = new byte[]
            {
                0x00,                 // OOOOOO
                0x0B,                 // OOEOEE
                0x0D,                 // OOEEOE
                0x0E,                 // OOEEEO
                0x13,                 // OEOOEE
                0x19,                 // OEEOOE
                0x1D,                 // OEEEOE
                0x15,                 // OEOEOE
                0x16,                 // OEOEEO
                0x1A,                 // OEEOEO
            };

            // Determine parity value for remaining encoding then strip
            //	after calculating the checksum
            char parityDigit = barcodeText[0];
            byte parity      = parityTable[parityDigit - '0'];

            if (Checksum != null)
            {
                barcodeText += Checksum.GetChecksumChar(barcodeText);
            }
            barcodeText = barcodeText.Substring(1);

            // Build result with composite glyphs
            List <Glyph> result = new List <Glyph>();

            result.AddRange(Factory.GetGlyphs(barcodeText, true));

            // Now translate each composite glyph using the parity
            //	in the second digit.
            // The first two digits are encoded without parity.
            int parityIndex = 32;

            for (int index = 0; index < result.Count; ++index)
            {
                // Fetch next glyph
                if (result[index] is CompositeGlyph)
                {
                    // Determine effective parity arrangement
                    byte effectiveParity = (index < 6) ? parity : (byte)0;

                    CompositeGlyph composite = (CompositeGlyph)result[index];
                    if ((parityIndex & effectiveParity) == 0)
                    {
                        result[index] = composite.First;
                    }
                    else
                    {
                        result[index] = composite.Second;
                    }
                    if (parityIndex > 1)
                    {
                        parityIndex /= 2;
                    }
                }
            }

            // Add start/stop and seperator glyphs
            result.Insert(6, Factory.GetRawGlyph('|'));
            result.Insert(0, Factory.GetRawGlyph('*'));
            result.Add(Factory.GetRawGlyph('*'));
            return(result.ToArray());
        }