public String Encode(String text)
        {
            String encoded = "";

            if (Postnet.Validate(text))
            {
                text     = text + Postnet.CheckDigit(text);
                encoded += "Bw";
                for (int lcv = 0; lcv < text.Length; lcv++)
                {
                    encoded += postnet[text[lcv]];
                }
                encoded += "B";
            }
            return(encoded);
        }
Example #2
0
        protected override void OnSetRenderInfo(BarcodeConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            string toEncode = newToken.TextToEncode;
            int    encoding = newToken.EncodingType;
            bool   colorsBW = newToken.ColorsBW;

            Rectangle selection = EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt();

            ColorBgra primary;
            ColorBgra secondary;

            if (colorsBW)
            {
                primary   = Color.Black;
                secondary = Color.White;
            }
            else
            {
                primary   = EnvironmentParameters.PrimaryColor;
                secondary = EnvironmentParameters.SecondaryColor;
            }

            switch (encoding)
            {
            case CODE_39:
                barcode = Code39.CreateCode39(selection, srcArgs.Surface, toEncode, primary, secondary);
                break;

            case CODE_39_MOD_43:
                barcode = Code39.CreateCode39mod43(selection, srcArgs.Surface, toEncode, primary, secondary);
                break;

            case FULL_ASCII_CODE_39:
                barcode = Code39.CreateFullAsciiCode39(selection, srcArgs.Surface, toEncode, primary, secondary);
                break;

            case POSTNET:
                barcode = Postnet.Create(selection, srcArgs.Surface, toEncode, primary, secondary);
                break;

            case UPCA:
                barcode = UPCa.Create(selection, srcArgs.Surface, toEncode, primary, secondary);
                break;
            }
        }
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            // Set the text to encode and the encoding type
            String toEncode = ((BarcodeConfigToken)parameters).TextToEncode;
            int    encoding = ((BarcodeConfigToken)parameters).EncodingType;

            BarcodeSurface barcode   = null;
            Rectangle      selection = this.EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt();
            ColorBgra      primary   = this.EnvironmentParameters.PrimaryColor;
            ColorBgra      secondary = this.EnvironmentParameters.SecondaryColor;

            if (encoding == Barcode.CODE_39)
            {
                Code39 code39 = new Code39();
                barcode = code39.CreateCode39(selection, srcArgs.Surface, toEncode, primary, secondary);
            }
            else if (encoding == Barcode.CODE_39_MOD_43)
            {
                Code39 code39 = new Code39();
                barcode = code39.CreateCode39mod43(selection, srcArgs.Surface, toEncode, primary, secondary);
            }
            else if (encoding == Barcode.FULL_ASCII_CODE_39)
            {
                Code39 code39 = new Code39();
                barcode = code39.CreateFullAsciiCode39(selection, srcArgs.Surface, toEncode, primary, secondary);
            }
            else if (encoding == Barcode.POSTNET)
            {
                Postnet postnet = new Postnet();
                barcode = postnet.Create(selection, srcArgs.Surface, toEncode, primary, secondary);
            }

            for (int i = startIndex; i < startIndex + length; ++i)
            {
                Rectangle rect = rois[i];
                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        dstArgs.Surface[x, y] = barcode[x, y];
                    }
                }
            }
        }
 public static bool ValidateText(String text, int encoding)
 {
     if (encoding == Barcode.CODE_39)
     {
         return(Code39.ValidateCode39(text));
     }
     else if (encoding == Barcode.CODE_39_MOD_43)
     {
         return(Code39.ValidateCode39mod43(text));
     }
     else if (encoding == Barcode.FULL_ASCII_CODE_39)
     {
         return(Code39.ValidateFullAsciiCode39(text));
     }
     else if (encoding == Barcode.POSTNET)
     {
         return(Postnet.Validate(text));
     }
     else
     {
         return(false);
     }
 }
Example #5
0
        internal static bool ValidateText(string text, int encoding)
        {
            switch (encoding)
            {
            case CODE_39:
                return(Code39.ValidateCode39(text));

            case CODE_39_MOD_43:
                return(Code39.ValidateCode39mod43(text));

            case FULL_ASCII_CODE_39:
                return(Code39.ValidateFullAsciiCode39(text));

            case POSTNET:
                return(Postnet.Validate(text));

            case UPCA:
                return(UPCa.Validate(text));

            default:
                return(false);
            }
        }
Example #6
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            // Set the text to encode and the encoding type
            String toEncode = ((BarcodeConfigToken)parameters).TextToEncode;
            int encoding = ((BarcodeConfigToken)parameters).EncodingType;

            BarcodeSurface barcode = null;
            Rectangle selection = this.EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt();
            ColorBgra primary = this.EnvironmentParameters.PrimaryColor;
            ColorBgra secondary = this.EnvironmentParameters.SecondaryColor;

            if (encoding == Barcode.CODE_39)
            {
                Code39 code39 = new Code39();
                barcode = code39.CreateCode39(selection, srcArgs.Surface, toEncode, primary, secondary);
            }
            else if (encoding == Barcode.CODE_39_MOD_43)
            {
                Code39 code39 = new Code39();
                barcode = code39.CreateCode39mod43(selection, srcArgs.Surface, toEncode, primary, secondary);
            }
            else if (encoding == Barcode.FULL_ASCII_CODE_39)
            {
                Code39 code39 = new Code39();
                barcode = code39.CreateFullAsciiCode39(selection, srcArgs.Surface, toEncode, primary, secondary);
            }
            else if (encoding == Barcode.POSTNET)
            {
                Postnet postnet = new Postnet();
                barcode = postnet.Create(selection, srcArgs.Surface, toEncode, primary, secondary);
            }

            for (int i = startIndex; i < startIndex + length; ++i)
            {
                Rectangle rect = rois[i];
                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        dstArgs.Surface[x, y] = barcode[x,y];
                    }
                }
            }
        }