/// <summary> /// Calculate parity for given list of codes /// </summary> /// <param name="codes">list of values</param> protected virtual void CalculateParity(CodedValueCollection codes) { if (Parity == null) { CreateParity(); } bool[] parity = Parity[codes[0]]; for (int i = 1; i < codes.Count; i++) { if (i < 1 + DigitGrouping[1]) { if (parity[i - 1]) { codes[i] += 10; } } else { codes[i] += 20; } } codes.RemoveAt(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)); }
protected override void CalculateParity(CodedValueCollection codes) { for (int i = 4; i < codes.Count; i++) { codes[i] += 20; } }
public override CodedValueCollection GetCodes(string value) { var codes = new CodedValueCollection(); value = value.Replace(" ", "").ToUpper(); var index = ToBinary(ParsePair(value.Substring(0, 2)), 0, 8, codes); index = ToBinary(_Lookup[value.Substring(2, 1)], index, 5, codes); index = ToBinary(_Lookup[value.Substring(3, 1)], index, 4, codes); ToBinary(ParsePair(value.Substring(4, 2)), index, 8, codes); int p = codes.Sum() + 1; codes.Add(ALIGNMENTBAR); if (p % 2 == 0) { codes.Insert(0, ALIGNMENTBAR); } else { codes.Insert(0, ODDCOUNT); } return(codes); }
public override string AddChecksum(string value, CodedValueCollection codes) { var parsed = value.Replace(" ", ""); if (!System.Text.RegularExpressions.Regex.IsMatch(parsed, "^\\d+$")) { throw new ArgumentException("Only numeric values can have a check digit"); } int total = 0; for (int i = 0; i < parsed.Length; i++) { if (i % 2 == 0) { total += int.Parse(parsed.Substring(i, 1)); } else { int tmp = int.Parse(parsed.Substring(i, 1)) * 2; total += (tmp % 9); } } total = total % 10; codes.Insert(codes.Count - 1, total.ToString()[0]); return(value + total.ToString()); }
public override string AddChecksum(string value, CodedValueCollection codes) { var values = PatternSet.Keys; int rowTotal = 0, colTotal = 0, tmp; for (int i = 1; i < codes.Count - 1; i++) { int index = values.First(x => x == codes[i]); tmp = (index / 6) + 1; rowTotal += (tmp == 6 ? 0 : tmp); tmp = (index % 6) + 1; colTotal += (tmp == 6 ? 0 : tmp); } rowTotal = rowTotal % 6; rowTotal = rowTotal == 0 ? 6 : rowTotal - 1; colTotal = colTotal % 6; colTotal = colTotal == 0 ? 5 : colTotal - 1; codes.Insert(codes.Count - 1, values.First(x => x == (rowTotal * 6) + colTotal)); return value; }
protected static string DoChecksumCalculation(string value, int factor, CodedValueCollection codes) { int tmp = 0; int weight = 0; for (int i = 0; i < value.Length; i++) { weight = ((value.Length - i) % factor); if (weight == 0) { weight = factor; } tmp += ((value[i] == '-' ? 10 : int.Parse(value.Substring(i, 1))) * weight); } tmp = tmp % 11; value += tmp > 9 ? "-" : tmp.ToString(); if (codes != null) { if (codes.Last() == LIMIT) { codes.Insert(codes.Count - 1, tmp > 9 ? '-' : tmp + '0'); } else { codes.Add(tmp > 9 ? '-' : tmp + '0'); } } return(value); }
public override string AddChecksum(string value, CodedValueCollection codes) { var values = PatternSet.Keys; int rowTotal = 0, colTotal = 0, tmp; for (int i = 1; i < codes.Count - 1; i++) { int index = values.First(x => x == codes[i]); tmp = (index / 6) + 1; rowTotal += (tmp == 6 ? 0 : tmp); tmp = (index % 6) + 1; colTotal += (tmp == 6 ? 0 : tmp); } rowTotal = rowTotal % 6; rowTotal = rowTotal == 0 ? 6 : rowTotal - 1; colTotal = colTotal % 6; colTotal = colTotal == 0 ? 5 : colTotal - 1; codes.Insert(codes.Count - 1, values.First(x => x == (rowTotal * 6) + colTotal)); return(value); }
public override string AddChecksum(string value, CodedValueCollection codes) { if (codes.Count == 13) { return(value); } int total = 0; for (int i = 0; i < codes.Count; i++) { if (i % 2 == 0) { total += (codes[i] % 10); } else { total += 3 * (codes[i] % 10); } } total = total % 10; codes.Add(total == 0 ? 20 : 30 - total); return(value + (total == 0 ? 0 : 10 - total).ToString()); }
protected override string ParseText(string value, CodedValueCollection codes) { value = value.Replace(" ", "").ToUpper(); if (!IsValidData(value)) throw new ApplicationException("The data was not valid."); int tmp = ParsePair(value.Substring(0, 2)); codes.Add(tmp / 0x10); codes.Add(tmp % 0x10); tmp = _Lookup[value.Substring(2, 1)]; codes.Add(tmp / 0x10); codes.Add(tmp % 0x10); codes.Add(_Lookup[value.Substring(3, 1)]); tmp = ParsePair(value.Substring(4, 2)); codes.Add(tmp / 0x10); codes.Add(tmp % 0x10); int p = 1; foreach (int item in codes) { p += PatternSet[item].BlackCount; } codes.Add(ALIGNMENTBAR); if (p % 2 == 0) codes.Insert(0, ALIGNMENTBAR); else codes.Insert(0, ODDCOUNT); return null; }
public override string AddChecksum(string value, CodedValueCollection codes) { AddCheckDigit(20, codes); AddCheckDigit(15, codes); return(value); }
public override string AddChecksum(string value, CodedValueCollection codes) { AddCheckDigit(20, codes); AddCheckDigit(15, codes); return value; }
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)); }
protected override string ParseText(string value, CodedValueCollection codes) { if (value.Length > 7) { value = FromUpcA(value); } return(base.ParseText(value, codes).Substring(1, 6)); }
public virtual CodedValueCollection GetCodes(string value) { var result = new CodedValueCollection(); foreach (var item in value) { result.Add(item); } return result; }
/// <summary> /// Parses the text into encodable characters /// </summary> /// <param name="value">the text to encode</param> /// <param name="codes">the code set to sue for encoding</param> /// <returns>the text after any clean-up</returns> protected virtual string ParseText(string value, CodedValueCollection codes) { if (!IsValidData(value)) { throw new ApplicationException(); } return(value); }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); codes.Insert(0, 33); codes.Insert(2, 34); return(value); }
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); }
private int ToBinary(int value, int index, int count, CodedValueCollection codes) { for (int i = 0; i < count; i++) { codes.Insert(index, value % 2); value >>= 1; } return(index + count); }
public virtual CodedValueCollection GetCodes(string value) { var result = new CodedValueCollection(); foreach (var item in value) { result.Add(item); } return(result); }
public override CodedValueCollection GetCodes(string value) { var codes = new CodedValueCollection(); foreach (char item in value.ToCharArray()) { if (item == ' ') codes.Add(38); else if (item == '$') codes.Add(39); else if (item == '/') codes.Add(40); else if (item == '+') codes.Add(41); else if (item == '%') codes.Add(42); else if (item >= '0' && item <= '9') codes.Add(item - 48); else { var tmp = AsciiEncoder.Lookup(item); switch (tmp[0]) { case '$': codes.Add(SHIFT1); codes.Add(tmp[1] - 55); break; case '%': codes.Add(SHIFT2); codes.Add(tmp[1] - 55); break; case '/': codes.Add(SHIFT3); codes.Add(tmp[1] - 55); break; case '+': codes.Add(SHIFT4); codes.Add(tmp[1] - 55); break; default: codes.Add(tmp[0] - 55); break; } } } codes.Insert(0, LIMIT); codes.Add(LIMIT); codes.Add(TERMINATOR); return codes; }
/// <summary> /// If the barcode supports a check digit, add it to the string /// </summary> /// <param name="value">barcode value to use for calculation</param> /// <returns>check digit to return</returns> public virtual string AddCheckDigit(string value) { CodedValueCollection codes = new CodedValueCollection(); value = ParseText(value, codes); AddChecksumEventArgs e = new AddChecksumEventArgs(value, codes); OnAddChecksum(e); return(e.Text); }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); if (_Value != null) { value = _Value.ToDisplayString(); _Value = null; } return(value); }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); if (_Value != null) { value = _Value.ToDisplayString(); _Value = null; } return value; }
protected override string ParseText(string value, CodedValueCollection codes) { StringBuilder v = new StringBuilder(); foreach (char item in value.ToCharArray()) { v.Append(AsciiEncoder.Lookup(item)); } base.ParseText(v.ToString(), codes); return value; }
protected override string ParseText(string value, CodedValueCollection codes) { StringBuilder v = new StringBuilder(); foreach (char item in value.ToCharArray()) { v.Append(AsciiEncoder.Lookup(item)); } base.ParseText(v.ToString(), codes); return(value); }
public override string AddChecksum(string value, CodedValueCollection codes) { codes.RemoveAt(codes.Count - 1); value = DoChecksumCalculation(value, 10, codes); if (value.Length >= 10) value = DoChecksumCalculation(value, 9,codes); codes.Add(LIMIT); return value; }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); for (int i = 0; i < value.Length; i++) { codes.Add(int.Parse(value.Substring(i, 1))); } CalculateParity(codes); return(value); }
public virtual CodedValueCollection GetCodes(string value) { var codes = new CodedValueCollection(); for (int i = 0; i < value.Length; i++) { codes.Add(int.Parse(value.Substring(i, 1))); } CalculateParity(codes); return(codes); }
public override CodedValueCollection GetCodes(string value) { var result = new CodedValueCollection(); for (int i = 0; i < value.Length; i++) { result.Add(int.Parse(value.Substring(i, 1))); } result.Insert(0, START); result.Add(STOP); return(result); }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); for (int i = 0; i < value.Length; i++) { codes.Add(int.Parse(value.Substring(i, 1))); } codes.Insert(0, START); codes.Add(STOP); return value; }
protected override string ParseText(string value, CodedValueCollection codes) { value = value.ToLower(); string tmp = value.Replace(" ", ""); tmp = base.ParseText(tmp, codes); foreach (char item in tmp.ToCharArray()) { codes.Add(item); } return(value.Substring(1, value.Length - 2)); }
public override string AddChecksum(string value, CodedValueCollection codes) { int total = 0; for (int i = 1; i < codes.Count - 1; i++) { total += codes[i]; } total = total % 10; codes.Insert(codes.Count - 1, total == 0 ? 0 : 10 - total); return value; }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); for (int i = 0; i < value.Length; i++) { codes.Add(int.Parse(value.Substring(i, 1))); } codes.Insert(0, START); codes.Add(STOP); return(value); }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); foreach (var item in value.ToCharArray()) { codes.Add(item); } codes.Insert(0, START); codes.Add(STOP); return value; }
public override CodedValueCollection GetCodes(string value) { var codes = new CodedValueCollection(); codes.Add(STARTMARKER); for (int i = 0; i < value.Length; i += 2) { codes.Add(int.Parse(value.Substring(i, 2))); } codes.Add(ENDMARKER); return(codes); }
public override CodedValueCollection GetCodes(string value) { var codes = new CodedValueCollection(); codes.Add(STARTMARKER); for (int i = 0; i < value.Length; i += 2) { codes.Add(int.Parse(value.Substring(i, 2))); } codes.Add(ENDMARKER); return codes; }
public virtual CodedValueCollection GetCodes(string value) { var codes = new CodedValueCollection(); for (int i = 0; i < value.Length; i++) { codes.Add(int.Parse(value.Substring(i, 1))); } CalculateParity(codes); return codes; }
protected override void CalculateParity(CodedValueCollection codes) { int total = (codes[0] + codes[2] + codes[4]) * 3; total += (codes[1] + codes[3]) * 9; total = (total % 10); bool[] parity = Parity[total]; for (int i = 0; i < codes.Count; i++) { if (parity[i]) codes[i] += 10; } }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); foreach (var item in value.ToCharArray()) { codes.Add(item); } codes.Insert(0, START); codes.Add(STOP); return(value); }
public override CodedValueCollection GetCodes(string value) { var result = new CodedValueCollection(); for (int i = 0; i < value.Length; i++) { result.Add(int.Parse(value.Substring(i, 1))); } result.Insert(0, START); result.Add(STOP); return result; }
protected override void CalculateParity(CodedValueCollection codes) { int m = ((codes[0] * 10) + codes[1]) % 4; if (m > 1) { codes[0] += 10; } if (m == 1 || m == 3) { codes[1] += 10; } }
public override string AddChecksum(string value, CodedValueCollection codes) { codes.RemoveAt(codes.Count - 1); value = DoChecksumCalculation(value, 10, codes); if (value.Length >= 10) { value = DoChecksumCalculation(value, 9, codes); } codes.Add(LIMIT); return(value); }
public object Render(CodedValueCollection codes, string displayText) { Codes = codes; DisplayText = displayText; var size = GetDimensions(); var b = new Bitmap(size.Width, size.Height); Canvas = Graphics.FromImage(b); var start = new Point(Settings.LeftMargin, Settings.TopMargin); Paint(start); return b; }
protected override string ParseText(string value, CodedValueCollection codes) { value = value.Trim('*'); if (!IsValidData(value)) throw new ApplicationException("Invalid data for this barcode."); value = "*" + value.ToUpper() + "*"; foreach (char item in value.ToCharArray()) { codes.Add(item); } return value; }
public override string AddChecksum(string value, CodedValueCollection codes) { int total = 0; for (int i = 1; i < codes.Count - 1; i++) { total += codes[i]; } total = total % 10; codes.Insert(codes.Count - 1, total == 0 ? 0 : 10 - total); return(value); }
public override string AddChecksum(string value, CodedValueCollection codes) { int total = 0; bool isEven = true; for (int i = codes.Count - 2; i < 0; i--) { total += isEven ? 3 * codes[i] : codes[i]; } total = total % 10; total = total == 0 ? 0 : 10 - total; codes.Insert(codes.Count - 1, total); return value + total.ToString(); }
public override string AddChecksum(string value, CodedValueCollection codes) { int total = 0; bool isEven = true; for (int i = codes.Count - 2; i < 0; i--) { total += isEven ? 3 * codes[i] : codes[i]; } total = total % 10; total = total == 0 ? 0 : 10 - total; codes.Insert(codes.Count - 1, total); return(value + total.ToString()); }
public object Render(CodedValueCollection codes, string displayText) { Codes = codes; DisplayText = displayText; var size = GetDimensions(); var b = new Bitmap(size.Width, size.Height); Canvas = Graphics.FromImage(b); var start = new Point(Settings.LeftMargin, Settings.TopMargin); Paint(start); return(b); }
protected override string ParseText(string value, CodedValueCollection codes) { if (!IsValidData(value)) throw new ApplicationException(); codes.Add(STARTMARKER); for (int i = 0; i < value.Length; i+=2) { codes.Add(int.Parse(value.Substring(i, 2))); } codes.Add(ENDMARKER); return value; }
public override CodedValueCollection GetCodes(string value) { var codes = new CodedValueCollection(); value = value.Replace(" ", "").Replace("-", ""); for (int i = 0; i < value.Length; i++) { codes.Add(int.Parse(value.Substring(i, 1))); } codes.Insert(0, STARTSTOP); codes.Add(STARTSTOP); return codes; }
public int CheckDigitCalculate(CodedValueCollection codes) { int total = 0; bool flip = true; for (int i = codes.Count-1; i > 0; i--) { if (flip) total += codes[i] * 3; else total += codes[i]; flip = !flip; } total = total % 10; return total == 0 ? 0 : 10 - total; }
public override string AddChecksum(string value, CodedValueCollection codes) { if (codes.Count == 13) return value; int total = 0; for (int i = 0; i < codes.Count; i++) { if (i % 2 == 0) total += (codes[i] % 10); else total += 3 * (codes[i] % 10); } total = total % 10; codes.Add(total == 0 ? 20 : 30 - total); return value + (total == 0 ? 0 : 10 - total).ToString(); }
public override CodedValueCollection GetCodes(string value) { var codes = new CodedValueCollection(); value = value.Replace(" ", "").ToUpper(); var index = ToBinary(ParsePair(value.Substring(0, 2)), 0, 8, codes); index = ToBinary(_Lookup[value.Substring(2, 1)], index, 5, codes); index = ToBinary(_Lookup[value.Substring(3, 1)], index, 4, codes); ToBinary(ParsePair(value.Substring(4, 2)), index, 8, codes); int p = codes.Sum() + 1; codes.Add(ALIGNMENTBAR); if (p % 2 == 0) codes.Insert(0, ALIGNMENTBAR); else codes.Insert(0, ODDCOUNT); return codes; }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); value = Regex.Replace(value, "[-\\s]", ""); byte[] data1 = IntelligentMailHelper.Instance.ConvertToBytes(IntelligentMailHelper.Instance.ConvertRoutingCode(value.Substring(20)), value.Substring(0,20)); int fcs = IntelligentMailHelper.Instance.CRC11(data1); short[] data2 = IntelligentMailHelper.Instance.ConvertToCodewords(data1); if (IntelligentMailHelper.Instance.CheckFcs(fcs)) data2[0] += 659; IntelligentMailHelper.Instance.ConvertToCharacters(data2); IntelligentMailHelper.Instance.IncludeFcs(data2, fcs); codes.AddRange(IntelligentMailHelper.Instance.ConvertToBars(data2)); return null; }
protected static string DoChecksumCalculation(string value, int factor, CodedValueCollection codes) { int tmp = 0; int weight = 0; for (int i = 0; i < value.Length; i++) { weight = ((value.Length - i) % factor); if (weight == 0) weight = factor; tmp += ((value[i] == '-' ? 10 : int.Parse(value.Substring(i, 1))) * weight); } tmp = tmp % 11; value += tmp > 9 ? "-" : tmp.ToString(); if (codes != null) { if (codes.Last() == LIMIT) codes.Insert(codes.Count - 1, tmp > 9 ? '-' : tmp + '0'); else codes.Add(tmp > 9 ? '-' : tmp + '0'); } return value; }
public override string AddChecksum(string value, CodedValueCollection codes) { var parsed = value.Replace(" ", ""); if (!System.Text.RegularExpressions.Regex.IsMatch(parsed, "^\\d+$")) throw new ArgumentException("Only numeric values can have a check digit"); int total = 0; for (int i = 0; i < parsed.Length; i++) { if (i % 2 == 0) total += int.Parse(parsed.Substring(i, 1)); else { int tmp = int.Parse(parsed.Substring(i, 1)) * 2; total += (tmp % 9); } } total = total % 10; codes.Insert(codes.Count - 1, total.ToString()[0]); return value + total.ToString(); }
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); }
protected override string ParseText(string value, CodedValueCollection codes) { value = base.ParseText(value, codes); for (int i = 0; i < value.Length; i++) { codes.Add(int.Parse(value.Substring(i, 1))); } CalculateParity(codes); return value; }