private bool CalculateSize(ref Size currentSize) { IBarcodeEncoder enc = GetEncoder(this.BarcodeType); if (enc == null) { throw new Exception("That encoder is not implemented yet."); } IBarcodeSizer sizer = enc.Sizer; IBarcodeModularSizer mSizer = sizer as IBarcodeModularSizer; try { enc.Text = this.Data; sizer = enc.Sizer; mSizer = sizer as IBarcodeModularSizer; sizer.DPI = (float)this.Dpi.Value; } catch (ArgumentException ex) { throw ex; } BarcodeRenderMode mode = BarcodeRenderMode.None; if (this.Guarded) { mode |= BarcodeRenderMode.Guarded; } if (this.Notched) { mode |= BarcodeRenderMode.Notched; } if (this.Numbered) { mode |= BarcodeRenderMode.Numbered; } if (this.Braced) { mode |= BarcodeRenderMode.Braced; } if (this.Boxed) { mode |= BarcodeRenderMode.Boxed; } sizer.Mode = mode; if (this.Height.Value < sizer.Height) { this.Height = new Unit(sizer.Height); } Size actualSize; if (sizer.DPI == 0 || mSizer == null) { //Logical mode, or simple fixed size. actualSize = sizer.GetValidSize(new Size((int)sizer.Width, (int)Height.Value)); SetSizeDisplay(actualSize, ref currentSize); } else { actualSize = sizer.GetValidSize(new Size((int)sizer.Width, (int)Height.Value)); SetSizeDisplay(actualSize, ref currentSize); } return(true); }
private bool CalculateSize() { IBarcodeEncoder enc = GetEncoder(); if (enc == null) { return(false); } IBarcodeSizer sizer = enc.Sizer; IBarcodeModularSizer mSizer = sizer as IBarcodeModularSizer; try { //if ((enc.Flags&BarcodeEncoderFlags.Composite)!=0 || // (enc.Generator!=null && (enc.Generator.Flags & BarcodeGeneratorFlags.VariableLength)!=0)) enc.Text = _tbData.Text; //if ((enc.Flags & BarcodeEncoderFlags.Composite) != 0) { sizer = enc.Sizer; mSizer = sizer as IBarcodeModularSizer; //} sizer.DPI = (int)_nupDpi.Value; } catch (ArgumentException ex) { MessageBox.Show(ex.Message); return(false); } BarcodeRenderMode mode = BarcodeRenderMode.None; if (_cbGuarded.Checked) { mode |= BarcodeRenderMode.Guarded; } if (_cbNotched.Checked) { mode |= BarcodeRenderMode.Notched; } if (_cbNumbered.Checked) { mode |= BarcodeRenderMode.Numbered; } if (_cbBraced.Checked) { mode |= BarcodeRenderMode.Braced; } if (_cbBoxed.Checked) { mode |= BarcodeRenderMode.Boxed; } sizer.Mode = mode; //Ok, now what we do depends on the options that are set. if (_nudHeight.Value < sizer.Height) { _nudHeight.Value = sizer.Height; } Size actualSize; if (sizer.DPI == 0 || mSizer == null) { //Logical mode, or simple fixed size. actualSize = sizer.GetValidSize(new Size(sizer.Width, (int)_nudHeight.Value)); SetSizeDisplay(actualSize); } else if (_rbDesiredWidth.Checked) { //They have given a desired width. if (_nudDesiredWidth.Value == 0) { actualSize = sizer.GetValidSize(new Size(sizer.Width, (int)_nudHeight.Value)); SetSizeDisplay(actualSize); } else { float mils = BarcodeUtilities.CalculateModuleWidth(mSizer, (int)(mSizer.DPI * (float)_nudDesiredWidth.Value)); _nudModuleWidth.Value = (decimal)mils; mSizer.Module = mils; if (_nudHeight.Value < sizer.Height) { _nudHeight.Value = sizer.Height; } actualSize = sizer.GetValidSize(new Size(sizer.Width, (int)_nudHeight.Value)); SetSizeDisplay(actualSize); } } else { //rbModule checked. mSizer.Module = (float)_nudModuleWidth.Value; if (_nudHeight.Value < sizer.Height) { _nudHeight.Value = sizer.Height; } actualSize = sizer.GetValidSize(new Size(sizer.Width, (int)_nudHeight.Value)); SetSizeDisplay(actualSize); } return(true); }