示例#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
文件: Code11.cs 项目: noikiy/Barcodes
        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
文件: EAN.cs 项目: noikiy/Barcodes
		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
文件: EAN.cs 项目: newlysoft/Barcodes
        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
文件: State.cs 项目: noikiy/Barcodes
		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
文件: CPC.cs 项目: noikiy/Barcodes
        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
文件: EAN128.cs 项目: noikiy/Barcodes
 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
文件: Code93.cs 项目: noikiy/Barcodes
        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;
		}