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); }
/// <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; } }
/// <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; }
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); }
protected override void OnAfterDrawCode(State state) { DrawGuardBar(state, (GuardType)33); }
protected override void OnBeforeDrawModule(State state, int index) { //No inter-module behaviour }
protected override void OnBeforeDrawCode(State state) { state.Top += Convert.ToInt32(state.Settings.Font.GetHeight()) + state.Settings.TextPadding; }
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; }
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); }
protected override void OnAfterDrawCode(State state) { //Do nothing }
protected override void OnAfterDrawCode(State state) { DrawGuardBar(state, GuardType.Limit); }
/// <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(); }
/// <summary> /// Occurs after the last module drawn /// </summary> /// <param name="state">drawing state object</param> protected virtual void OnAfterDrawCode(State state) { }
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(); }
/// <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; }
/// <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) { }
/// <summary> /// Occurs before the barcode is drawn /// </summary> /// <param name="state">drawing state object</param> protected virtual void OnBeforeDrawCode(State state) { }
protected override void OnBeforeDrawCode(State state) { state.Left += DigitGrouping[0] * 7 * state.Settings.NarrowWidth; DrawGuardBar(state, GuardType.Limit); base.OnBeforeDrawCode(state); }
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); }
protected override void OnBeforeDrawModule(State state, int index) { if (index == DigitGrouping[1]) DrawGuardBar(state, GuardType.Split); }
/// <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; }
protected override void OnBeforeDrawCode(State state) { state.Left += 10 * state.Settings.NarrowWidth; base.OnBeforeDrawCode(state); }
public AddChecksumEventArgs(State state) { Text = state.Text; Codes = state.Codes; }