コード例 #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
ファイル: BarcodeBase.cs プロジェクト: newlysoft/Barcodes
        /// <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
ファイル: BarcodeBase.cs プロジェクト: noikiy/Barcodes
		public BarcodeBase(BarcodeSettings settings)
		{
			DefaultSettings = settings;

			Init();

			if (PatternSet == null)
			{
				lock (TheLock)
				{
					if (PatternSet == null)
						CreatePatternSet();
				}
			}
		}
コード例 #6
0
ファイル: BarcodeBase.cs プロジェクト: newlysoft/Barcodes
        public BarcodeBase(BarcodeSettings settings)
        {
            DefaultSettings = settings;

            Init();

            if (PatternSet == null)
            {
                lock (TheLock)
                {
                    if (PatternSet == null)
                    {
                        CreatePatternSet();
                    }
                }
            }
        }
コード例 #7
0
ファイル: BarcodeBase.cs プロジェクト: newlysoft/Barcodes
        /// <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
ファイル: BarcodeBase.cs プロジェクト: newlysoft/Barcodes
        /// <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
ファイル: BarcodeBase.cs プロジェクト: newlysoft/Barcodes
 /// <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
ファイル: BarcodeBase.cs プロジェクト: noikiy/Barcodes
		/// <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
ファイル: BarcodeBase.cs プロジェクト: noikiy/Barcodes
		/// <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
ファイル: BarcodeBase.cs プロジェクト: noikiy/Barcodes
		/// <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
ファイル: EAN128.cs プロジェクト: newlysoft/Barcodes
 public Bitmap Generate(GS1.GS1Builder value, BarcodeSettings settings)
 {
     AiMarker = value.FNC1;
     _Value   = value;
     return(Generate(value.ToString(), settings));
 }
コード例 #17
0
ファイル: Code128.cs プロジェクト: noikiy/Barcodes
        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
ファイル: BarcodeBase.cs プロジェクト: newlysoft/Barcodes
 /// <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
ファイル: State.cs プロジェクト: newlysoft/Barcodes
 public State(BarcodeSettings settings, int left, int top)
 {
     Left     = left;
     Top      = top;
     Settings = settings;
 }
コード例 #22
0
ファイル: BarcodeBase.cs プロジェクト: noikiy/Barcodes
		/// <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
ファイル: Code2of5.cs プロジェクト: noikiy/Barcodes
 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
ファイル: UPC5.cs プロジェクト: newlysoft/Barcodes
        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
ファイル: Postnet.cs プロジェクト: noikiy/Barcodes
 protected override int OnCalculateHeight(int height, BarcodeSettings settings, CodedValueCollection codes)
 {
     height -= (settings.BarHeight - settings.MediumHeight);
     return base.OnCalculateHeight(height, settings, codes);
 }
コード例 #27
0
ファイル: Interleaved2of5.cs プロジェクト: newlysoft/Barcodes
        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
ファイル: BarcodeBase.cs プロジェクト: noikiy/Barcodes
		/// <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;
		}