using System; namespace DataMatrix4Net { public enum SymbolSize { RectAuto = -3, SquareAuto = -2, ShapeAuto = -1, Sq10x10 = 0, Sq12x12, Sq14x14, Sq16x16, Sq18x18, Sq20x20, Sq22x22, Sq24x24, Sq26x26, Sq32x32, Sq36x36, Sq40x40, Sq44x44, Sq48x48, Sq52x52, Sq64x64, Sq72x72, Sq80x80, Sq88x88, Sq96x96, Sq104x104, Sq120x120, Sq132x132, Sq144x144, Rect8x18, Rect8x32, Rect12x26, Rect12x36, Rect16x36, Rect16x48, Count } public enum SymbolAttribute { SymbolRows, SymbolCols, DataRegionRows, DataRegionCols, HorizDataRegions, VertDataRegions, MappingMatrixRows, MappingMatrixCols, InterleavedBlocks, BlockErrorWords, BlockMaxCorrectable, SymbolDataWords, SymbolErrorWords, SymbolMaxCorrectable, } public static class Symbol { public const SymbolSize SymbolSquareCount = SymbolSize.Rect8x18; /// (---------------------------------------------- square ------------------------------------------------------) (--- rectangular ---) static readonly int[] symbolRows = new int[] { 10, 12, 14, 16, 18, 20, 22, 24, 26, 32, 36, 40, 44, 48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144, 8, 8, 12, 12, 16, 16 }; static readonly int[] symbolCols = new int[] { 10, 12, 14, 16, 18, 20, 22, 24, 26, 32, 36, 40, 44, 48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144, 18, 32, 26, 36, 36, 48 }; static readonly int[] dataRegionRows = new int[] { 8, 10, 12, 14, 16, 18, 20, 22, 24, 14, 16, 18, 20, 22, 24, 14, 16, 18, 20, 22, 24, 18, 20, 22, 6, 6, 10, 10, 14, 14 }; static readonly int[] dataRegionCols = new int[] { 8, 10, 12, 14, 16, 18, 20, 22, 24, 14, 16, 18, 20, 22, 24, 14, 16, 18, 20, 22, 24, 18, 20, 22, 16, 14, 24, 16, 16, 22 }; static readonly int[] horizDataRegions = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 6, 6, 6, 1, 2, 1, 2, 2, 2 }; static readonly int[] interleavedBlocks = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 4, 4, 4, 4, 6, 6, 8, 10, 1, 1, 1, 1, 1, 1 }; static readonly int[] symbolDataWords = new int[] { 3, 5, 8, 12, 18, 22, 30, 36, 44, 62, 86, 114, 144, 174, 204, 280, 368, 456, 576, 696, 816, 1050, 1304, 1558, 5, 10, 16, 22, 32, 49 }; static readonly int[] blockErrorWords = new int[] { 5, 7, 10, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 68, 42, 56, 36, 48, 56, 68, 56, 68, 62, 62, 7, 11, 14, 18, 24, 28 }; static readonly int[] blockMaxCorrectable = new int[] { 2, 3, 5, 6, 7, 9, 10, 12, 14, 18, 21, 24, 28, 34, 21, 28, 18, 24, 28, 34, 28, 34, 31, 31, 3, 5, 7, 9, 12, 14 }; /// /// Return a symbol attribute /// /// Symbol attribute /// Size ID (or index) /// Sybol attribute value, -1 when undefined public static int GetSymbolAttribute(SymbolAttribute attribute, SymbolSize sizeId) { if (sizeId < 0 || sizeId >= SymbolSize.Count) return -1; switch (attribute) { case SymbolAttribute.SymbolRows: return symbolRows[(int)sizeId]; case SymbolAttribute.SymbolCols: return symbolCols[(int)sizeId]; case SymbolAttribute.DataRegionRows: return dataRegionRows[(int)sizeId]; case SymbolAttribute.DataRegionCols: return dataRegionCols[(int)sizeId]; case SymbolAttribute.HorizDataRegions: return horizDataRegions[(int)sizeId]; case SymbolAttribute.VertDataRegions: return (sizeId < SymbolSquareCount) ? horizDataRegions[(int)sizeId] : 1; case SymbolAttribute.MappingMatrixRows: return dataRegionRows[(int)sizeId] * GetSymbolAttribute(SymbolAttribute.VertDataRegions, sizeId); case SymbolAttribute.MappingMatrixCols: return dataRegionCols[(int)sizeId] * horizDataRegions[(int)sizeId]; case SymbolAttribute.InterleavedBlocks: return interleavedBlocks[(int)sizeId]; case SymbolAttribute.BlockErrorWords: return blockErrorWords[(int)sizeId]; case SymbolAttribute.BlockMaxCorrectable: return blockMaxCorrectable[(int)sizeId]; case SymbolAttribute.SymbolDataWords: return symbolDataWords[(int)sizeId]; case SymbolAttribute.SymbolErrorWords: return blockErrorWords[(int)sizeId] * interleavedBlocks[(int)sizeId]; case SymbolAttribute.SymbolMaxCorrectable: return blockMaxCorrectable[(int)sizeId] * interleavedBlocks[(int)sizeId]; default: return -1; } } } }