예제 #1
0
파일: CPC.cs 프로젝트: noikiy/Barcodes
        protected override void OnBeforeDrawModule(State state, int index)
        {
            //digit 3 uses only 5 bits, so move back 3 bits
            if (index == 3)
                state.Left -= (state.Settings.NarrowWidth + state.Settings.WideWidth) * 3;

            base.OnBeforeDrawModule(state, index);
        }
예제 #2
0
		/// <summary>
		/// Test method for adding a measure along the top of the image
		/// </summary>
		/// <param name="settings">Settings to sue for calculations</param>
		/// <param name="width">width of the image in pixels</param>
		/// <param name="canvas">Canvas to draw on</param>
		protected void AddMeasure(State state)
		{
			int left = 0;
			bool alt = true;

			while (left < state.Canvas.VisibleClipBounds.Width)
			{
				if (alt)
					state.Canvas.FillRectangle(Brushes.Gainsboro, left, 0, 1, state.Settings.TopMargin);
				left++;
				alt = !alt;
			}
		}
예제 #3
0
파일: EAN.cs 프로젝트: noikiy/Barcodes
		/// <summary>
		/// Draws the required guard bar
		/// </summary>
		/// <param name="state">drawing state</param>
		/// <param name="type">type of guard bar to draw</param>
		protected void DrawGuardBar(State state, GuardType type)
		{
			Rectangle[] guardbar = DrawPattern(PatternSet[(int)type], state);
			int offset = (5 * state.Settings.NarrowWidth) / 2;
			foreach (Rectangle bar in guardbar)
			{
				bar.Inflate(0, offset);
				bar.Offset(0, offset);

				state.Canvas.FillRectangle(Brushes.Black, bar);
			}

			state.Left += PatternSet[(int)type].NarrowCount * state.Settings.NarrowWidth;
		}
예제 #4
0
파일: EAN.cs 프로젝트: noikiy/Barcodes
		protected override void PaintText(State state)
		{
			int y = state.Settings.TopMargin + state.Settings.BarHeight + TEXTPADDING;
			state.Canvas.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

			int x = state.Settings.LeftMargin;

			if (DigitGrouping[0] > 0)
				state.Canvas.DrawString(state.Text.Substring(0, DigitGrouping[0]), state.Settings.Font, Brushes.Black, x, y);

			x += (DigitGrouping[0] * 7 * state.Settings.NarrowWidth);
			x += (PatternSet[(int)GuardType.Limit].NarrowCount * state.Settings.NarrowWidth) + state.Settings.TextPadding;
			state.Canvas.DrawString(state.Text.Substring(DigitGrouping[0], DigitGrouping[1]), state.Settings.Font, Brushes.Black, x, y);

			x += (DigitGrouping[1] * 7 * state.Settings.NarrowWidth);
			x += (PatternSet[(int)GuardType.Split].NarrowCount * state.Settings.NarrowWidth);
			state.Canvas.DrawString(state.Text.Substring(DigitGrouping[0] + DigitGrouping[1], DigitGrouping[2]), state.Settings.Font, Brushes.Black, x, y);
		}
예제 #5
0
파일: UPCE.cs 프로젝트: noikiy/Barcodes
 protected override void OnAfterDrawCode(State state)
 {
     DrawGuardBar(state, (GuardType)33);
 }
예제 #6
0
파일: UPCE.cs 프로젝트: noikiy/Barcodes
 protected override void OnBeforeDrawModule(State state, int index)
 {
     //No inter-module behaviour
 }
예제 #7
0
파일: UPC5.cs 프로젝트: noikiy/Barcodes
 protected override void OnBeforeDrawCode(State state)
 {
     state.Top += Convert.ToInt32(state.Settings.Font.GetHeight()) + state.Settings.TextPadding;
 }
예제 #8
0
파일: UPC5.cs 프로젝트: noikiy/Barcodes
        protected override void OnBeforeDrawModule(State state, int index)
        {
            if (index == 1)
                state.Left -= 3 * state.Settings.NarrowWidth;

            if (index > 1 && index % 2 == 1)
                state.Left -= 5 * state.Settings.NarrowWidth;
        }
예제 #9
0
		protected void Paint(State state)
		{
			state.Canvas.ScaleTransform(state.Settings.Scale, state.Settings.Scale);
			state.Canvas.Clear(Color.White);

#if MEASURE
			AddMeasure(state);
#endif
			OnBeforeDrawCode(state);

#if MARKER
			bool isGrey = true;
#endif

			for (int i = 0; i < state.Codes.Count; i++)
			{
				state.ModuleValue = (char)state.Codes[i];
				OnBeforeDrawModule(state, i);

#if MARKER
				if (isGrey)
					state.Canvas.FillRectangle(Brushes.Gray, state.Left, 0, (PatternSet[state.Codes[i]].WideCount * state.Settings.WideWidth) + (PatternSet[state.Codes[i]].NarrowCount * state.Settings.NarrowWidth), state.Canvas.VisibleClipBounds.Height);
				isGrey = !isGrey;
#endif
				Rectangle[] r = DrawPattern(PatternSet[state.Codes[i]], state);
				if (r.Length > 0)
					state.Canvas.FillRectangles(Brushes.Black, r);


				OnAfterDrawModule(state, i);
			}

			OnAfterDrawCode(state);
			PaintText(state);
		}
예제 #10
0
파일: UPC5.cs 프로젝트: noikiy/Barcodes
 protected override void OnAfterDrawCode(State state)
 {
     //Do nothing
 }
예제 #11
0
파일: EAN.cs 프로젝트: noikiy/Barcodes
		protected override void OnAfterDrawCode(State state)
		{
			DrawGuardBar(state, GuardType.Limit);
		}
예제 #12
0
		/// <summary>
		/// If the barcode requires the text to be limited with a character(s), this adds them
		/// </summary>
		/// <param name="value">the text to pad</param>
		/// <param name="settings">the settings in use</param>
		/// <returns>the text with any padding added</returns>
		protected string PadText(State state)
		{
			if (!state.Settings.IsTextPadded)
				return state.Text;


			StringBuilder sb = new StringBuilder();
			//sb.Append(" ");
			foreach (char item in state.Text)
			{
				sb.AppendFormat("{0} ", item);
			}
			return sb.ToString();
		}
예제 #13
0
		/// <summary>
		/// Occurs after the last module drawn
		/// </summary>
		/// <param name="state">drawing state object</param>
		protected virtual void OnAfterDrawCode(State state)
		{
		}
예제 #14
0
		protected Rectangle[] DrawPattern(Pattern pattern, State state)
		{
			List<Rectangle> rects = new List<Rectangle>();

			int offset = (state.Settings.MediumHeight - state.Settings.ShortHeight);
			int left = state.Left;
			Rectangle rect;
			foreach (Elements item in pattern.Elements)
			{
				switch (item)
				{
					case Elements.WideBlack:
						rect = new Rectangle(left, state.Top, state.Settings.WideWidth, state.Settings.BarHeight);
						left += state.Settings.WideWidth;

						rects.Add(rect);
						break;
					case Elements.WideWhite:
						left += state.Settings.WideWidth;
						break;
					case Elements.NarrowBlack:
						rect = new Rectangle(left, state.Top, state.Settings.NarrowWidth, state.Settings.BarHeight);
						left += state.Settings.NarrowWidth;

						rects.Add(rect);
						break;
					case Elements.NarrowWhite:
						left += state.Settings.NarrowWidth;
						break;
					case Elements.Tracker:
						rect = new Rectangle(left, state.Top + offset, state.Settings.NarrowWidth, state.Settings.ShortHeight);
						left += state.Settings.NarrowWidth;
						rects.Add(rect);
						break;
					case Elements.Ascender:
						rect = new Rectangle(left, state.Top, state.Settings.NarrowWidth, state.Settings.MediumHeight);
						left += state.Settings.NarrowWidth;
						rects.Add(rect);
						break;
					case Elements.Descender:
						rect = new Rectangle(left, state.Top + offset, state.Settings.NarrowWidth, state.Settings.MediumHeight);
						left += state.Settings.NarrowWidth;
						rects.Add(rect);
						break;
				}
			}

			return rects.ToArray();
		}
예제 #15
0
		/// <summary>
		/// Occurs after a module has been drawn
		/// </summary>
		/// <param name="state"></param>
		/// <param name="index"></param>
		protected virtual void OnAfterDrawModule(State state, int index)
		{
			state.Left += (PatternSet[state.ModuleValue].WideCount * state.Settings.WideWidth) + (PatternSet[state.ModuleValue].NarrowCount * state.Settings.NarrowWidth) + state.Settings.ModulePadding;
		}
예제 #16
0
		/// <summary>
		/// Occurs inbetween characters. Each character is a "module"
		/// </summary>
		/// <param name="state">drawing state</param>
		/// <param name="index">module index in the text to encode</param>
		protected virtual void OnBeforeDrawModule(State state, int index)
		{
		}
예제 #17
0
		/// <summary>
		/// Occurs before the barcode is drawn
		/// </summary>
		/// <param name="state">drawing state object</param>
		protected virtual void OnBeforeDrawCode(State state)
		{
		}
예제 #18
0
파일: EAN.cs 프로젝트: noikiy/Barcodes
		protected override void OnBeforeDrawCode(State state)
		{
			state.Left += DigitGrouping[0] * 7 * state.Settings.NarrowWidth;
			DrawGuardBar(state, GuardType.Limit);

			base.OnBeforeDrawCode(state);
		}
예제 #19
0
파일: UPC5.cs 프로젝트: noikiy/Barcodes
        protected override void PaintText(State state)
        {
            if (!state.Settings.IsTextShown)
                return;

            string text = PadText(state);

            SizeF textSize = state.Canvas.MeasureString(text, state.Settings.Font);
            int x = (int)(state.Canvas.VisibleClipBounds.Width / 2) - ((int)textSize.Width / 2) - 4;
            int y = state.Settings.TopMargin;

            state.Canvas.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            state.Canvas.DrawString(text, state.Settings.Font, Brushes.Black, x, y);
        }
예제 #20
0
파일: EAN.cs 프로젝트: noikiy/Barcodes
		protected override void OnBeforeDrawModule(State state, int index)
		{
			if (index == DigitGrouping[1])
				DrawGuardBar(state, GuardType.Split);
		}
예제 #21
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;
		}
예제 #22
0
파일: Code128.cs 프로젝트: noikiy/Barcodes
 protected override void OnBeforeDrawCode(State state)
 {
     state.Left += 10 * state.Settings.NarrowWidth;
     base.OnBeforeDrawCode(state);
 }
예제 #23
0
		public AddChecksumEventArgs(State state)
		{
			Text = state.Text;
			Codes = state.Codes;
		}