Esempio n. 1
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);
     }
 }
Esempio n. 4
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);
            }
        }
 public BarcodeSurface CreateCode39mod43(Rectangle rect, Surface source, String text, ColorBgra primaryColor, ColorBgra secondaryColor)
 {
     text = text.ToUpperInvariant();
     text = text + Code39.Mod43(text);
     return(this.Create(rect, source, text, primaryColor, secondaryColor));
 }
 public static bool ValidateCode39mod43(String text)
 {
     return(Code39.ValidateCode39(text));
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                versionLabel.Text = Version;
                imagerow.Visible  = false;

                foreach (KeyValuePair <Type, string> kvp in Utility.CodeType)
                {
                    var item = new ListItem(kvp.Value, kvp.Value, true);

                    string valueSelected = Request.Form[general_type.UniqueID];
                    if ((valueSelected == null && item.Value == "Code 39") || (valueSelected == item.Value))
                    {
                        item.Selected  = true;
                        configFor.Text = item.Value;
                    }
                    else
                    {
                        item.Selected = false;
                    }

                    general_type.Items.Add(item);
                }

                foreach (KeyValuePair <int, string> kvp in Utility.OutputType)
                {
                    var item = new ListItem(kvp.Value, kvp.Key.ToString(), true);

                    string valueSelected = Request.Form[general_output.UniqueID];
                    if ((valueSelected == null && kvp.Key == 2) || (valueSelected == item.Value))
                    {
                        item.Selected = true;
                    }
                    else
                    {
                        item.Selected = false;
                    }

                    general_output.Items.Add(item);
                }

                foreach (string font in Utility.FontType)
                {
                    var item = new ListItem(font, font, true);

                    string valueSelected = Request.Form[general_font.UniqueID];
                    if ((valueSelected == null && item.Value == "Arial") || (valueSelected == item.Value))
                    {
                        item.Selected = true;
                    }
                    else
                    {
                        item.Selected = false;
                    }

                    general_font.Items.Add(item);
                }

                string valueFont = Request.Form[general_fontsize.UniqueID];
                if (valueFont == null)
                {
                    general_fontsize.Text = "8";
                }

                if (!general_res1.Checked && !general_res2.Checked && !general_res3.Checked)
                {
                    general_res1.Checked = true;
                }

                if (string.IsNullOrEmpty(general_thickness.Text))
                {
                    general_thickness.Text = "30";
                }

                var code39 = new Code39();
                explanation.Controls.Add(new LiteralControl(code39.Explanation));
                DisplayKeys(code39.Keys, code39.SizeKeys);
                data1.Text = code39.SpecificText;
                data2.Controls.Clear();
                data2.Controls.Add(code39.SpecificValue);

                general_type.Attributes["onchange"] = string.Format("document.getElementById('{0}').value='';var obj=document.getElementById('{1}');if(obj)obj.style.display='none';", general_Text.ClientID, barcodeimage.ClientID);
            }

            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "newKey", string.Format(@"function newkey(variable){{document.getElementById('{0}').value += unescape(variable);}}", general_Text.ClientID), true);
        }