/// <summary> /// Renders the specified matrix. /// </summary> /// <param name="matrix">The matrix.</param> /// <param name="format">The format.</param> /// <param name="content">The content.</param> /// <param name="options">The options.</param> /// <returns></returns> public SvgImage Render(BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options) { var result = new SvgImage(); Create(result, matrix, format, content, options); return(result); }
private static void AppendDarkCell(SvgImage image, BitMatrix matrix, int offsetX, int offSetY) { if (matrix == null) { return; } int width = matrix.Width; int height = matrix.Height; var processed = new BitMatrix(width, height); bool currentIsBlack = false; int startPosX = 0; int startPosY = 0; for (int x = 0; x < width; x++) { int endPosX; for (int y = 0; y < height; y++) { if (processed[x, y]) { continue; } processed[x, y] = true; if (matrix[x, y]) { if (!currentIsBlack) { startPosX = x; startPosY = y; currentIsBlack = true; } } else { if (currentIsBlack) { FindMaximumRectangle(matrix, processed, startPosX, startPosY, y, out endPosX); image.AddRec(startPosX + offsetX, startPosY + offSetY, endPosX - startPosX + 1, y - startPosY); currentIsBlack = false; } } } if (currentIsBlack) { FindMaximumRectangle(matrix, processed, startPosX, startPosY, height, out endPosX); image.AddRec(startPosX + offsetX, startPosY + offSetY, endPosX - startPosX + 1, height - startPosY); currentIsBlack = false; } } }
private void Create(SvgImage image, BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options) { const int quietZone = 5; if (matrix == null) { return; } int width = matrix.Width; int height = matrix.Height; image.AddHeader(); image.AddTag(0, 0, 2 * quietZone + width, 2 * quietZone + height, Background, Foreground); AppendDarkCell(image, matrix, quietZone, quietZone); image.AddEnd(); }
private void Create(SvgImage image, BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options) { if (matrix == null) { return; } const int spaceBetweenMatrixAndText = 3; int width = matrix.Width; int height = matrix.Height; var outputContent = (options == null || !options.PureBarcode) && !String.IsNullOrEmpty(content) && (format == BarcodeFormat.CODE_39 || format == BarcodeFormat.CODE_93 || format == BarcodeFormat.CODE_128 || format == BarcodeFormat.EAN_13 || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.CODABAR || format == BarcodeFormat.ITF || format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E || format == BarcodeFormat.MSI || format == BarcodeFormat.PLESSEY); if (outputContent) { var fontSize = FontSize < 1 ? DefaultFontSize : FontSize; height += fontSize + spaceBetweenMatrixAndText; } image.AddHeader(); image.AddTag(0, 0, width, height, Background, Foreground); AppendDarkCell(image, matrix, 0, 0); if (outputContent) { var fontName = String.IsNullOrEmpty(FontName) ? DefaultFontName : FontName; var fontSize = FontSize < 1 ? DefaultFontSize : FontSize; content = ModifyContentDependingOnBarcodeFormat(format, content); image.AddText(content, fontName, fontSize); } image.AddEnd(); }