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]; } } } }