Exemplo n.º 1
0
        /// <summary>
        /// Gets the index of this glyph.
        /// </summary>
        /// <param name="glyph">
        /// The <see cref="T:Zen.Barcode.BarGlyph"/> to be located.
        /// </param>
        /// <returns>
        /// The ordinal index of the glyph or -1 if not found.
        /// </returns>
        public virtual int GetRawGlyphIndex(BarGlyph glyph)
        {
            int foundIndex = -1;

            BarGlyph[] glyphs = GetGlyphs();
            for (int index = 0; index < glyphs.Length; ++index)
            {
                if (glyphs[index] == glyph)
                {
                    foundIndex = index;
                    break;
                }
            }
            return(foundIndex);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders the barcode bars.
        /// </summary>
        /// <param name="barcode">A collection of <see cref="T:Zen.Barcode.Glyph"/> objects representing the
        /// barcode to be rendered.</param>
        /// <param name="dc">A <see cref="T:System.Drawing.Graphics"/> representing the draw context.</param>
        /// <param name="bounds">The bounding rectangle.</param>
        /// <param name="interGlyphSpace">The inter glyph space in pixels.</param>
        /// <param name="barMinHeight">Minimum bar height in pixels.</param>
        /// <param name="barMinWidth">Small bar width in pixels.</param>
        /// <param name="barMaxWidth">Large bar width in pixels.</param>
        /// <remarks>
        /// By default this method renders each glyph by calling the
        /// <see cref="M:RenderBar"/> method, applying the specified
        /// inter-glyph spacing as necessary.
        /// </remarks>
        protected virtual void RenderBars(Glyph[] barcode, Graphics dc,
                                          Rectangle bounds, int interGlyphSpace, int barMinHeight,
                                          int barMinWidth, int barMaxWidth)
        {
            int barOffset = 0;

            for (int index = 0; index < barcode.Length; ++index)
            {
                BarGlyph glyph = (BarGlyph)barcode[index];

                RenderBar(index, glyph, dc, bounds, ref barOffset, barMinHeight,
                          barMinWidth, barMaxWidth);

                // Account for inter glyph spacing
                barOffset += interGlyphSpace;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Renders the barcode bars.
        /// </summary>
        /// <param name="barcode">A collection of <see cref="T:Zen.Barcode.Glyph"/> objects representing the
        /// barcode to be rendered.</param>
        /// <param name="dc">A <see cref="T:System.Drawing.Graphics"/> representing the draw context.</param>
        /// <param name="bounds">The bounding rectangle.</param>
        /// <param name="interGlyphSpace">The inter glyph space in pixels.</param>
        /// <param name="barMinHeight">Minimum bar height in pixels.</param>
        /// <param name="barMinWidth">Small bar width in pixels.</param>
        /// <param name="barMaxWidth">Large bar width in pixels.</param>
        /// <remarks>
        /// By default this method renders each glyph by calling the
        /// <see cref="M:RenderBar"/> method, applying the specified
        /// inter-glyph spacing as necessary.
        /// </remarks>
        protected virtual void RenderBars(
            Glyph[] barcode,
            DrawingContext dc,
            Rect bounds,
            double interGlyphSpace,
            double barMinHeight,
            double barMinWidth,
            double barMaxWidth)
        {
            double barOffset = 0;

            for (int index = 0; index < barcode.Length; ++index)
            {
                BarGlyph glyph = (BarGlyph)barcode[index];

                RenderBar(index, glyph, dc, bounds, ref barOffset, barMinHeight,
                          barMinWidth, barMaxWidth);

                // Account for inter glyph spacing
                barOffset += interGlyphSpace;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the index of this glyph.
 /// </summary>
 /// <param name="glyph">
 /// The <see cref="T:Zen.Barcode.BarGlyph"/> to be located.
 /// </param>
 /// <returns>
 /// The ordinal index of the glyph or -1 if not found.
 /// </returns>
 public virtual int GetRawGlyphIndex(BarGlyph glyph)
 {
     int foundIndex = -1;
     BarGlyph[] glyphs = GetGlyphs();
     for (int index = 0; index < glyphs.Length; ++index)
     {
         if (glyphs[index] == glyph)
         {
             foundIndex = index;
             break;
         }
     }
     return foundIndex;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Zen.Barcode.CompositeGlyph"/>
 /// class.
 /// </summary>
 /// <param name="character">The character.</param>
 /// <param name="first">The first.</param>
 /// <param name="second">The second.</param>
 public CompositeGlyph(char character, BarGlyph first, BarGlyph second)
     : base(character)
 {
     _first  = first;
     _second = second;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Zen.Barcode.CompositeGlyph"/>
 /// class.
 /// </summary>
 /// <param name="character">The character.</param>
 /// <param name="first">The first.</param>
 /// <param name="second">The second.</param>
 public CompositeGlyph(char character, BarGlyph first, BarGlyph second)
     : base(character)
 {
     _first = first;
     _second = second;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the glyph encoding.
 /// </summary>
 /// <param name="glyphIndex">Index of the glyph.</param>
 /// <param name="glyph">The glyph.</param>
 /// <returns></returns>
 /// <remarks>
 /// By default this method simply returns the glyph bit encoding
 /// however some algorithms may chose to modify the encoding
 /// based on positional information.
 /// </remarks>
 protected virtual int GetGlyphEncoding(int glyphIndex, BarGlyph glyph)
 {
     return(glyph.BitEncoding);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Renders the bar-code glyph.
        /// </summary>
        /// <param name="glyphIndex">Index of the glyph.</param>
        /// <param name="glyph">A <see cref="T:Zen.Barcode.Glyph"/> object to be rendered.</param>
        /// <param name="dc">A <see cref="T:System.Drawing.Graphics"/> representing the draw context.</param>
        /// <param name="bounds">The bounding rectangle.</param>
        /// <param name="barOffset">The bar offset.</param>
        /// <param name="barMinHeight">Minimum bar height in pixels.</param>
        /// <param name="barMinWidth">Small bar width in pixels.</param>
        /// <param name="barMaxWidth">Large bar width in pixels.</param>
        /// <exception cref="T:System.InvalidOperationException">
        /// Thrown if the encoding bit count is zero or variable-pitch
        /// bar rendering is attempted.
        /// </exception>
        protected virtual void RenderBar(int glyphIndex, BarGlyph glyph, Graphics dc,
                                         Rectangle bounds, ref int barOffset, int barMinHeight,
                                         int barMinWidth, int barMaxWidth)
        {
            // Sanity check
            int encodingBitCount = GetEncodingBitCount(glyph);

            if (encodingBitCount == 0)
            {
                throw new InvalidOperationException(
                          "Encoding bit width must be greater than zero.");
            }

            // Allow derived classes to modify the glyph bits
            int glyphBits = GetGlyphEncoding(glyphIndex, glyph);

            // Get glyph height
            int height = GetGlyphHeight(glyph, barMinHeight, bounds.Height);

            if (glyph is IBinaryPitchGlyph)
            {
                IBinaryPitchGlyph binGlyph = (IBinaryPitchGlyph)glyph;

                // Render glyph
                int  widthIndex   = WidthBitCount - 1;
                bool lastBitState = false;
                for (int bitIndex = encodingBitCount - 1; bitIndex >= 0; --bitIndex)
                {
                    int bitMask  = 1 << bitIndex;
                    int barWidth = barMinWidth;

                    bool currentBitState = false;
                    if ((bitMask & glyphBits) != 0)
                    {
                        currentBitState = true;
                    }

                    // Adjust the width bit checker
                    if (bitIndex < (encodingBitCount - 1) &&
                        lastBitState != currentBitState)
                    {
                        --widthIndex;
                    }
                    lastBitState = currentBitState;

                    // Determine width encoding bit mask
                    int widthMask = (1 << widthIndex);
                    if ((widthMask & binGlyph.WidthEncoding) != 0)
                    {
                        barWidth = barMaxWidth;
                    }

                    if ((binGlyph.BitEncoding & bitMask) != 0)
                    {
                        dc.FillRectangle(Brushes.Black, barOffset, bounds.Top,
                                         barWidth, height);
                    }

                    // Update offset
                    barOffset += barWidth;
                }
            }
            else
            {
                for (int bitIndex = encodingBitCount - 1; bitIndex >= 0; --bitIndex)
                {
                    int bitMask = (1 << bitIndex);
                    if ((glyphBits & bitMask) != 0)
                    {
                        dc.FillRectangle(Brushes.Black, barOffset, bounds.Top,
                                         barMinWidth, height);
                    }

                    // Update offset
                    barOffset += barMinWidth;
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Overridden. Renders the specified glyph.
        /// </summary>
        /// <param name="glyphIndex">Index of the glyph.</param>
        /// <param name="glyph">A <see cref="T:Glyph"/> to be rendered.</param>
        /// <param name="dc">A <see cref="T:Graphics"/> representing the device context.</param>
        /// <param name="bounds">The bounding rectangle.</param>
        /// <param name="barOffset">The bar offset in pixels.</param>
        /// <param name="barMinHeight">Minimum bar height in pixels.</param>
        /// <param name="barMinWidth">Minimum bar width.</param>
        /// <param name="barMaxWidth">Maximum bar width.</param>
        /// <exception cref="T:InvalidOperationException">
        /// Thrown if the encoding bit count is zero or variable-pitch
        /// bar rendering is attempted.
        /// </exception>
        protected override void RenderBar(int glyphIndex, BarGlyph glyph, DrawingContext dc,
                                          Rect bounds, ref int barOffset, int barMinHeight,
                                          int barMinWidth, int barMaxWidth)
        {
            // Sanity check
            BinaryPitchGlyph binGlyph = glyph as BinaryPitchGlyph;

            if (binGlyph == null)
            {
                throw new InvalidOperationException("Glyph must be derived from BinaryPitchGlyph.");
            }
            if (barMinWidth == barMaxWidth)
            {
                throw new InvalidOperationException("Only variable-pitch drawing supported.");
            }
            if (WidthBitCount == 0)
            {
                throw new InvalidOperationException("Must have width bit information.");
            }

            // Get glyph encoding width
            int encodingBitCount = GetGlyphEncodingBitCount(glyph);

            // Render glyph
            int  widthIndex   = WidthBitCount - 1;
            bool lastBitState = false;

            for (int bitIndex = encodingBitCount - 1; bitIndex >= 0; --bitIndex)
            {
                int bitMask  = 1 << bitIndex;
                int barWidth = barMinWidth;

                bool currentBitState = false;
                if ((bitMask & binGlyph.BitEncoding) != 0)
                {
                    currentBitState = true;
                }

                // Adjust the width bit checker
                if (bitIndex < (encodingBitCount - 1) &&
                    lastBitState != currentBitState)
                {
                    --widthIndex;
                }
                lastBitState = currentBitState;

                // Determine width encoding bit mask
                int widthMask = (1 << widthIndex);
                if ((widthMask & binGlyph.WidthEncoding) != 0)
                {
                    barWidth = barMaxWidth;
                }

                if ((binGlyph.BitEncoding & bitMask) != 0)
                {
                    dc.DrawRectangle(Foreground, null, new Rect(barOffset, bounds.Top, barWidth, bounds.Height));
                }

                // Update offset
                barOffset += barWidth;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Renders the barcode bars.
        /// </summary>
        /// <param name="barcode">A collection of <see cref="T:Zen.Barcode.Glyph"/> objects representing the
        /// barcode to be rendered.</param>
        /// <param name="dc">A <see cref="T:System.Drawing.Graphics"/> representing the draw context.</param>
        /// <param name="bounds">The bounding rectangle.</param>
        /// <param name="interGlyphSpace">The inter glyph space in pixels.</param>
        /// <param name="barMinHeight">Minimum bar height in pixels.</param>
        /// <param name="barMinWidth">Small bar width in pixels.</param>
        /// <param name="barMaxWidth">Large bar width in pixels.</param>
        /// <remarks>
        /// By default this method renders each glyph by calling the
        /// <see cref="M:RenderBar"/> method, applying the specified
        /// inter-glyph spacing as necessary.
        /// </remarks>
        protected override void RenderBars(Glyph[] barcode, Graphics dc, Rectangle bounds, int interGlyphSpace, int barMinHeight, int barMinWidth, int barMaxWidth)
        {
            // Standard Code 2 of 5 can be rendered via base class
            if (!(Factory is Code25InterleavedGlyphFactory))
            {
                base.RenderBars(barcode, dc, bounds, interGlyphSpace, barMinHeight, barMinWidth, barMaxWidth);
                return;
            }

            // Interleaved version needs custom rendering support

            int barOffset = 0;

            for (int index = 0; index < barcode.Length;)
            {
                BarGlyph glyph  = (BarGlyph)barcode[index];
                int      height = GetGlyphHeight(glyph, barMinHeight, bounds.Height);

                if (index == 0 || index == (barcode.Length - 1))
                {
                    RenderBar(index, glyph, dc, bounds, ref barOffset, barMinHeight,
                              barMinWidth, barMaxWidth);
                    ++index;
                }
                else
                {
                    // We need to render two glyphs at the same time
                    int      encodingBitCount = 5;
                    BarGlyph firstGlyph       = (BarGlyph)barcode[index];
                    BarGlyph secondGlyph      = (BarGlyph)barcode[index + 1];

                    // Get the bit encoding for each glyph

                    for (int bitIndex = encodingBitCount - 1; bitIndex >= 0; --bitIndex)
                    {
                        int bitMask = (1 << bitIndex);
                        if ((firstGlyph.BitEncoding & bitMask) != 0)
                        {
                            dc.FillRectangle(Brushes.Black, barOffset, bounds.Top,
                                             barMinWidth * 2, height);
                            barOffset += barMinWidth * 2;
                        }
                        else
                        {
                            dc.FillRectangle(Brushes.Black, barOffset, bounds.Top,
                                             barMinWidth, height);
                            barOffset += barMinWidth;
                        }

                        if ((secondGlyph.BitEncoding & bitMask) != 0)
                        {
                            barOffset += barMinWidth * 2;
                        }
                        else
                        {
                            barOffset += barMinWidth;
                        }
                    }

                    // Advance to next pair
                    index += 2;
                }

                // Account for inter glyph spacing
                barOffset += interGlyphSpace;
            }
        }