generateBarcodeLogic() private method

Generates the barcode logic.
private generateBarcodeLogic ( String msg, int errorCorrectionLevel ) : void
msg String the message to encode
errorCorrectionLevel int PDF417 error correction level to use
return void
        /// <summary>
        /// Takes encoder, accounts for width/height, and retrieves bit matrix
        /// </summary>
        private static BitMatrix bitMatrixFromEncoder(Internal.PDF417 encoder,
                                                      String contents,
                                                      int errorCorrectionLevel,
                                                      int width,
                                                      int height,
                                                      int margin,
                                                      int aspectRatio)
        {
            if (width >= height)
            {
                encoder.generateBarcodeLogic(contents, errorCorrectionLevel, width, height, ref aspectRatio);
            }
            else
            {
                encoder.generateBarcodeLogic(contents, errorCorrectionLevel, height, width, ref aspectRatio);
            }

            sbyte[][] originalScale = encoder.BarcodeMatrix.getScaledMatrix(1, aspectRatio);
            bool      rotated       = false;

            if ((height > width) != (originalScale[0].Length < originalScale.Length))
            {
                originalScale = rotateArray(originalScale);
                rotated       = true;
            }

            int scaleX = width / originalScale[0].Length;
            int scaleY = height / originalScale.Length;

            int scale;

            if (scaleX < scaleY)
            {
                scale = scaleX;
            }
            else
            {
                scale = scaleY;
            }

            if (scale > 1)
            {
                sbyte[][] scaledMatrix =
                    encoder.BarcodeMatrix.getScaledMatrix(scale, scale * aspectRatio);
                if (rotated)
                {
                    scaledMatrix = rotateArray(scaledMatrix);
                }
                return(bitMatrixFromBitArray(scaledMatrix, margin));
            }
            return(bitMatrixFromBitArray(originalScale, margin));
        }
Beispiel #2
0
        /// <summary>
        /// Takes encoder, accounts for width/height, and retrieves bit matrix
        /// </summary>
        private static BitMatrix bitMatrixFromEncoder(Internal.PDF417 encoder,
                                                      String contents,
                                                      int width,
                                                      int height,
                                                      int margin,
                                                      int errorCorrectionLevel,
                                                      float PREFERRED_RATIO)
        {
            encoder.generateBarcodeLogic(contents, errorCorrectionLevel, PREFERRED_RATIO);

            const int lineThickness = 2;
            const int aspectRatio   = 4;

            sbyte[][] originalScale = encoder.BarcodeMatrix.getScaledMatrix(lineThickness, aspectRatio * lineThickness);
            bool      rotated       = false;

            if ((height > width) ^ (originalScale[0].Length < originalScale.Length))
            {
                originalScale = rotateArray(originalScale);
                rotated       = true;
            }

            int scaleX = width / originalScale[0].Length;
            int scaleY = height / originalScale.Length;

            int scale;

            if (scaleX < scaleY)
            {
                scale = scaleX;
            }
            else
            {
                scale = scaleY;
            }

            if (scale > 1)
            {
                sbyte[][] scaledMatrix =
                    encoder.BarcodeMatrix.getScaledMatrix(scale * lineThickness, scale * aspectRatio * lineThickness);
                if (rotated)
                {
                    scaledMatrix = rotateArray(scaledMatrix);
                }
                return(bitMatrixFrombitArray(scaledMatrix, margin));
            }
            return(bitMatrixFrombitArray(originalScale, margin));
        }