Пример #1
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            //10 narrow space queit zone + 2 narrow bars for the STOP
            width += (codes.Count * 11 * settings.NarrowWidth) + (2 * 10 * settings.NarrowWidth) + (2 * settings.NarrowWidth);

            return(base.OnCalculateWidth(width, settings, codes));
        }
Пример #2
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            foreach (int item in codes)
            {
                width += (PatternSet[item].NarrowCount * settings.NarrowWidth) + (PatternSet[item].WideCount * settings.WideWidth);
            }

            return(base.OnCalculateWidth(width, settings, codes));
        }
Пример #3
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            foreach (int item in codes)
            {
                width += (PatternSet[item].WideCount * settings.WideWidth) + (PatternSet[item].NarrowCount * settings.NarrowWidth);
            }

            return base.OnCalculateWidth(width, settings, codes);
        }
Пример #4
0
        /// <summary>
        /// Modify the height
        /// </summary>
        /// <param name="height">calculated pixel height</param>
        /// <param name="codes">parsed value</param>
        /// <returns>new pixel height</returns>
        protected virtual int OnCalculateHeight(int height, BarcodeSettings settings, CodedValueCollection codes)
        {
            height = settings.TopMargin + settings.BarHeight + settings.BottomMargin;

            if (settings.IsTextShown)
            {
                height += Convert.ToInt32(settings.Font.GetHeight()) + settings.TextPadding;
            }

            return(height);
        }
Пример #5
0
		public BarcodeBase(BarcodeSettings settings)
		{
			DefaultSettings = settings;

			Init();

			if (PatternSet == null)
			{
				lock (TheLock)
				{
					if (PatternSet == null)
						CreatePatternSet();
				}
			}
		}
Пример #6
0
        public BarcodeBase(BarcodeSettings settings)
        {
            DefaultSettings = settings;

            Init();

            if (PatternSet == null)
            {
                lock (TheLock)
                {
                    if (PatternSet == null)
                    {
                        CreatePatternSet();
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Calculates the size of the barcode image &amp; sets the margins if a size is defined
        /// </summary>
        /// <param name="settings">setting in use with this barcode</param>
        /// <param name="codes">The encoded barcode data</param>
        /// <returns>size of the resultant image</returns>
        private Size GetDimensions(BarcodeSettings settings, CodedValueCollection codes)
        {
            int width  = OnCalculateWidth(0, settings, codes);
            int height = OnCalculateHeight(0, settings, codes);

            if (settings.MaxWidth > 0 && width > settings.MaxWidth)
            {
                throw new BarcodeSizeException("The barcode width exceeds the maximum allowed width");
            }
            if (settings.MaxHeight > 0 && height > settings.MaxHeight)
            {
                throw new BarcodeSizeException("The barcode height exceeds the maximum allowed height");
            }

            if (settings.Width > 0)
            {
                if (settings.Width < width)
                {
                    throw new BarcodeSizeException("The barcode width is larger than the defined width");
                }

                settings.LeftMargin  = (settings.Width - width) / 2;
                settings.RightMargin = settings.Width - width - settings.LeftMargin;
                width = settings.Width;
            }
            if (settings.Height > 0)
            {
                if (settings.Height < height)
                {
                    throw new BarcodeSizeException("The barcode height is larger than the defined height");
                }
                settings.TopMargin    = (settings.Height - height) / 2;
                settings.BottomMargin = settings.Height - height - settings.TopMargin;
                height = settings.Height;
            }

            return(new Size((int)Math.Ceiling(width * settings.Scale), (int)Math.Ceiling(height * settings.Scale)));
        }
Пример #8
0
        /// <summary>
        /// Main function to draw the barcode
        /// </summary>
        /// <param name="settings">setting in use with this barcode</param>
        /// <param name="text">text to encode</param>
        /// <returns>bitmap image of the barcode</returns>
        protected Bitmap Paint(BarcodeSettings settings, string text)
        {
            State state = new State(settings, settings.LeftMargin, settings.TopMargin);

            state.Codes = new CodedValueCollection();
            state.Text  = ParseText(text, state.Codes);

            if (settings.IsChecksumCalculated)
            {
                AddChecksumEventArgs args = new AddChecksumEventArgs(state);
                OnAddChecksum(args);
                state.Text = args.Text;
            }

            Size size = GetDimensions(settings, state.Codes);

            Bitmap b = new Bitmap(size.Width, size.Height);            //, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale);

            state.Canvas = Graphics.FromImage(b);

            Paint(state);

            return(b);
        }
Пример #9
0
 /// <summary>
 /// Main entry point for generating the barcode
 /// </summary>
 /// <param name="text">text to encode</param>
 /// <param name="settings">setting to use to overide the defaults</param>
 /// <returns>bitmap of the generated barcode</returns>
 public Bitmap Generate(string text, BarcodeSettings settings)
 {
     return(Paint(settings, text));
 }
Пример #10
0
		/// <summary>
		/// Calculates the size of the barcode image &amp; sets the margins if a size is defined
		/// </summary>
		/// <param name="settings">setting in use with this barcode</param>
		/// <param name="codes">The encoded barcode data</param>
		/// <returns>size of the resultant image</returns>
		private Size GetDimensions(BarcodeSettings settings, CodedValueCollection codes)
		{
			int width = OnCalculateWidth(0, settings, codes);
			int height = OnCalculateHeight(0, settings, codes);

			if (settings.MaxWidth > 0 && width > settings.MaxWidth)
				throw new BarcodeSizeException("The barcode width exceeds the maximum allowed width");
			if (settings.MaxHeight > 0 && height > settings.MaxHeight)
				throw new BarcodeSizeException("The barcode height exceeds the maximum allowed height");

			if (settings.Width > 0)
			{
				if (settings.Width < width)
					throw new BarcodeSizeException("The barcode width is larger than the defined width");

				settings.LeftMargin = (settings.Width - width) / 2;
				settings.RightMargin = settings.Width - width - settings.LeftMargin;
				width = settings.Width;
			}
			if (settings.Height > 0)
			{
				if (settings.Height < height)
					throw new BarcodeSizeException("The barcode height is larger than the defined height");
				settings.TopMargin = (settings.Height - height) / 2;
				settings.BottomMargin = settings.Height - height - settings.TopMargin;
				height = settings.Height;
			}

			return new Size((int)Math.Ceiling(width * settings.Scale), (int)Math.Ceiling(height * settings.Scale));
		}
Пример #11
0
		protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
		{
			width += (settings.NarrowWidth * ((codes.Count * 7) + 11)) + (DigitGrouping[0] * 7 * settings.NarrowWidth);

			return base.OnCalculateWidth(width, settings, codes);
		}
Пример #12
0
		/// <summary>
		/// Main entry point for generating the barcode
		/// </summary>
		/// <param name="text">text to encode</param>
		/// <param name="settings">setting to use to overide the defaults</param>
		/// <returns>bitmap of the generated barcode</returns>
		public Bitmap Generate(string text, BarcodeSettings settings)
		{
			return Paint(settings, text);
		}
Пример #13
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            width += (settings.NarrowWidth * ((codes.Count * 7) + 11)) + (DigitGrouping[0] * 7 * settings.NarrowWidth);

            return(base.OnCalculateWidth(width, settings, codes));
        }
Пример #14
0
		public State(BarcodeSettings settings, int left, int top)
		{
			Left = left;
			Top = top;
			Settings = settings;
		}
Пример #15
0
		/// <summary>
		/// Modify the width calculation
		/// </summary>
		/// <param name="width">calculated pixel width</param>
		/// <param name="codes">parsed value</param>
		/// <returns>new pixel width</returns>
		protected virtual int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
		{
			return width + settings.LeftMargin + settings.RightMargin + ((codes.Count - 1) * settings.ModulePadding);
		}
Пример #16
0
 public Bitmap Generate(GS1.GS1Builder value, BarcodeSettings settings)
 {
     AiMarker = value.FNC1;
     _Value   = value;
     return(Generate(value.ToString(), settings));
 }
Пример #17
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            //10 narrow space queit zone + 2 narrow bars for the STOP
            width += (codes.Count * 11 * settings.NarrowWidth) + (2 * 10 * settings.NarrowWidth) + (2 * settings.NarrowWidth);

            return base.OnCalculateWidth(width, settings, codes);
        }
Пример #18
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            width += (settings.WideWidth + settings.NarrowWidth) * 27; //1+8+5+4+8+1

            return base.OnCalculateWidth(width, settings, codes);
        }
Пример #19
0
 /// <summary>
 /// Modify the width calculation
 /// </summary>
 /// <param name="width">calculated pixel width</param>
 /// <param name="codes">parsed value</param>
 /// <returns>new pixel width</returns>
 protected virtual int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
 {
     return(width + settings.LeftMargin + settings.RightMargin + ((codes.Count - 1) * settings.ModulePadding));
 }
Пример #20
0
 protected override int OnCalculateHeight(int height, BarcodeSettings settings, CodedValueCollection codes)
 {
     height -= (settings.BarHeight - settings.MediumHeight);
     return(base.OnCalculateHeight(height, settings, codes));
 }
Пример #21
0
 public State(BarcodeSettings settings, int left, int top)
 {
     Left     = left;
     Top      = top;
     Settings = settings;
 }
Пример #22
0
		/// <summary>
		/// Modify the height
		/// </summary>
		/// <param name="height">calculated pixel height</param>
		/// <param name="codes">parsed value</param>
		/// <returns>new pixel height</returns>
		protected virtual int OnCalculateHeight(int height, BarcodeSettings settings, CodedValueCollection codes)
		{
			
			height = settings.TopMargin + settings.BarHeight + settings.BottomMargin;
			
			if (settings.IsTextShown)
				height += Convert.ToInt32(settings.Font.GetHeight()) + settings.TextPadding;

			return height;
		}
Пример #23
0
 protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
 {
     width += (codes.Count * ((7 * settings.NarrowWidth) + (2 * settings.WideWidth)));
     width += (14 * settings.NarrowWidth);
     return base.OnCalculateWidth(width, settings, codes);
 }
Пример #24
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            width += ((-23) * settings.NarrowWidth);

            return(base.OnCalculateWidth(width, settings, codes));
        }
Пример #25
0
 protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
 {
     width = settings.NarrowWidth * (codes.Count - 1);
     return(base.OnCalculateWidth(width, settings, codes));
 }
Пример #26
0
 protected override int OnCalculateHeight(int height, BarcodeSettings settings, CodedValueCollection codes)
 {
     height -= (settings.BarHeight - settings.MediumHeight);
     return base.OnCalculateHeight(height, settings, codes);
 }
Пример #27
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            width += (((4 * settings.WideWidth) + (6 * settings.NarrowWidth)) * codes.Count) + (6 * settings.NarrowWidth) + settings.WideWidth;

            return(base.OnCalculateWidth(width, settings, codes));
        }
Пример #28
0
 public Bitmap Generate(GS1.GS1Builder value, BarcodeSettings settings)
 {
     AiMarker = value.FNC1;
     _Value = value;
     return Generate(value.ToString(), settings);
 }
Пример #29
0
 protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
 {
     width += (codes.Count * ((7 * settings.NarrowWidth) + (2 * settings.WideWidth)));
     width += (14 * settings.NarrowWidth);
     return(base.OnCalculateWidth(width, settings, codes));
 }
Пример #30
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            width += ((codes.Count - 1) * 9 * settings.NarrowWidth) + settings.NarrowWidth;

            return base.OnCalculateWidth(width, settings, codes);
        }
Пример #31
0
        protected override int OnCalculateWidth(int width, BarcodeSettings settings, CodedValueCollection codes)
        {
            width += (settings.WideWidth + settings.NarrowWidth) * 27; //1+8+5+4+8+1

            return(base.OnCalculateWidth(width, settings, codes));
        }
Пример #32
0
		/// <summary>
		/// Main function to draw the barcode
		/// </summary>
		/// <param name="settings">setting in use with this barcode</param>
		/// <param name="text">text to encode</param>
		/// <returns>bitmap image of the barcode</returns>
		protected Bitmap Paint(BarcodeSettings settings, string text)
		{
			State state = new State(settings, settings.LeftMargin, settings.TopMargin);
			state.Codes = new CodedValueCollection();
			state.Text = ParseText(text, state.Codes);

			if (settings.IsChecksumCalculated)
			{
				AddChecksumEventArgs args = new AddChecksumEventArgs(state);
				OnAddChecksum(args);
				state.Text = args.Text;
			}

			Size size = GetDimensions(settings, state.Codes);

			Bitmap b = new Bitmap(size.Width, size.Height);//, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale);
			state.Canvas = Graphics.FromImage(b);

			Paint(state);

			return b;
		}