setDisableEci() private method

Sets the disable eci.
private setDisableEci ( bool disabled ) : void
disabled bool if set to true don't add an ECI segment for different encodings than default.
return void
Ejemplo n.º 1
0
      /// <summary>
      /// </summary>
      /// <param name="contents">The contents to encode in the barcode</param>
      /// <param name="format">The barcode format to generate</param>
      /// <param name="width">The preferred width in pixels</param>
      /// <param name="height">The preferred height in pixels</param>
      /// <param name="hints">Additional parameters to supply to the encoder</param>
      /// <returns>
      /// The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white)
      /// </returns>
      public BitMatrix encode(String contents,
                              BarcodeFormat format,
                              int width,
                              int height,
                              IDictionary<EncodeHintType, object> hints)
      {
         if (format != BarcodeFormat.PDF_417)
         {
            throw new ArgumentException("Can only encode PDF_417, but got " + format);
         }

         var encoder = new Internal.PDF417();
         var margin = WHITE_SPACE;
         var errorCorrectionLevel = DEFAULT_ERROR_CORRECTION_LEVEL;

         if (hints != null)
         {
            if (hints.ContainsKey(EncodeHintType.PDF417_COMPACT) && hints[EncodeHintType.PDF417_COMPACT] != null)
            {
               encoder.setCompact(Convert.ToBoolean(hints[EncodeHintType.PDF417_COMPACT].ToString()));
            }
            if (hints.ContainsKey(EncodeHintType.PDF417_COMPACTION) && hints[EncodeHintType.PDF417_COMPACTION] != null)
            {
               Compaction compactionEnum;
               if (Enum.TryParse(hints[EncodeHintType.PDF417_COMPACTION].ToString(), out compactionEnum))
                  encoder.setCompaction(compactionEnum);
            }
            if (hints.ContainsKey(EncodeHintType.PDF417_DIMENSIONS))
            {
               var dimensions = (Dimensions) hints[EncodeHintType.PDF417_DIMENSIONS];
               encoder.setDimensions(dimensions.MaxCols,
                                     dimensions.MinCols,
                                     dimensions.MaxRows,
                                     dimensions.MinRows);
            }
            if (hints.ContainsKey(EncodeHintType.MARGIN) && hints[EncodeHintType.MARGIN] != null)
            {
               margin = Convert.ToInt32(hints[EncodeHintType.MARGIN].ToString());
            }
            if (hints.ContainsKey(EncodeHintType.ERROR_CORRECTION) && hints[EncodeHintType.ERROR_CORRECTION] != null)
            {
               var value = hints[EncodeHintType.ERROR_CORRECTION];
               if (value is PDF417ErrorCorrectionLevel ||
                   value is int)
               {
                  errorCorrectionLevel = (int)value;
               }
               else
               {
                  PDF417ErrorCorrectionLevel errorCorrectionLevelEnum;
                  if (Enum.TryParse(value.ToString(), out errorCorrectionLevelEnum))
                     errorCorrectionLevel = (int)errorCorrectionLevelEnum;
               }
            }
            if (hints.ContainsKey(EncodeHintType.CHARACTER_SET))
            {
#if !SILVERLIGHT || WINDOWS_PHONE
               var encoding = (String)hints[EncodeHintType.CHARACTER_SET];
               if (encoding != null)
               {
                  encoder.setEncoding(encoding);
               }
#else
               // Silverlight supports only UTF-8 and UTF-16 out-of-the-box
               encoder.setEncoding("UTF-8");
#endif
            }
            if (hints.ContainsKey(EncodeHintType.DISABLE_ECI) && hints[EncodeHintType.DISABLE_ECI] != null)
            {
               encoder.setDisableEci(Convert.ToBoolean(hints[EncodeHintType.DISABLE_ECI].ToString()));
            }
         }

         return bitMatrixFromEncoder(encoder, contents, errorCorrectionLevel, width, height, margin);
      }
Ejemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="contents">The contents to encode in the barcode</param>
        /// <param name="format">The barcode format to generate</param>
        /// <param name="width">The preferred width in pixels</param>
        /// <param name="height">The preferred height in pixels</param>
        /// <param name="hints">Additional parameters to supply to the encoder</param>
        /// <returns>
        /// The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white)
        /// </returns>
        public BitMatrix Encode(string contents,
                                BarcodeFormat format,
                                int width,
                                int height,
                                Mode mode     = null,
                                int quietZone = 4,
                                IDictionary <EncodeHintType, object> hints = null)
        {
            if (format != BarcodeFormat.PDF_417)
            {
                throw new ArgumentException("Can only encode PDF_417, but got " + format);
            }

            var encoder = new Internal.PDF417();
            var margin  = WHITE_SPACE;
            var errorCorrectionLevel = DEFAULT_ERROR_CORRECTION_LEVEL;
            var aspectRatio          = DEFAULT_ASPECT_RATIO;

            if (hints != null)
            {
                if (hints.ContainsKey(EncodeHintType.PDF417_COMPACT) && hints[EncodeHintType.PDF417_COMPACT] != null)
                {
                    encoder.setCompact(Convert.ToBoolean(hints[EncodeHintType.PDF417_COMPACT].ToString()));
                }
                if (hints.ContainsKey(EncodeHintType.PDF417_COMPACTION) && hints[EncodeHintType.PDF417_COMPACTION] != null)
                {
                    if (Enum.IsDefined(typeof(Compaction), hints[EncodeHintType.PDF417_COMPACTION].ToString()))
                    {
                        var compactionEnum = (Compaction)Enum.Parse(typeof(Compaction), hints[EncodeHintType.PDF417_COMPACTION].ToString(), true);
                        encoder.setCompaction(compactionEnum);
                    }
                }
                if (hints.ContainsKey(EncodeHintType.PDF417_DIMENSIONS))
                {
                    var dimensions = (Dimensions)hints[EncodeHintType.PDF417_DIMENSIONS];
                    encoder.setDimensions(dimensions.MaxCols,
                                          dimensions.MinCols,
                                          dimensions.MaxRows,
                                          dimensions.MinRows);
                }
                if (hints.ContainsKey(EncodeHintType.MARGIN) && hints[EncodeHintType.MARGIN] != null)
                {
                    margin = Convert.ToInt32(hints[EncodeHintType.MARGIN].ToString());
                }
                if (hints.ContainsKey(EncodeHintType.PDF417_ASPECT_RATIO) && hints[EncodeHintType.PDF417_ASPECT_RATIO] != null)
                {
                    var value = hints[EncodeHintType.PDF417_ASPECT_RATIO];
                    if (value is PDF417AspectRatio ||
                        value is int)
                    {
                        aspectRatio = (int)value;
                    }
                    else
                    {
                        if (Enum.IsDefined(typeof(PDF417AspectRatio), value.ToString()))
                        {
                            var aspectRatioEnum = (PDF417AspectRatio)Enum.Parse(typeof(PDF417AspectRatio), value.ToString(), true);
                            aspectRatio = (int)aspectRatioEnum;
                        }
                    }
                }
                if (hints.ContainsKey(EncodeHintType.PDF417_IMAGE_ASPECT_RATIO) && hints[EncodeHintType.PDF417_IMAGE_ASPECT_RATIO] != null)
                {
                    var value = hints[EncodeHintType.PDF417_IMAGE_ASPECT_RATIO];
                    try
                    {
                        encoder.setDesiredAspectRatio(Convert.ToSingle(value));
                    }
                    catch
                    {
                        // User passed in something that wasn't convertible to single.
                    }
                }
                if (hints.ContainsKey(EncodeHintType.ERROR_CORRECTION) && hints[EncodeHintType.ERROR_CORRECTION] != null)
                {
                    var value = hints[EncodeHintType.ERROR_CORRECTION];
                    if (value is PDF417ErrorCorrectionLevel ||
                        value is int)
                    {
                        errorCorrectionLevel = (int)value;
                    }
                    else
                    {
                        if (Enum.IsDefined(typeof(PDF417ErrorCorrectionLevel), value.ToString()))
                        {
                            var errorCorrectionLevelEnum = (PDF417ErrorCorrectionLevel)Enum.Parse(typeof(PDF417ErrorCorrectionLevel), value.ToString(), true);
                            errorCorrectionLevel = (int)errorCorrectionLevelEnum;
                        }
                    }
                }
                if (hints.ContainsKey(EncodeHintType.CHARACTER_SET))
                {
                    var encoding = (string)hints[EncodeHintType.CHARACTER_SET];
                    if (encoding != null)
                    {
                        encoder.setEncoding(encoding);
                    }
                }
                if (hints.ContainsKey(EncodeHintType.DISABLE_ECI) && hints[EncodeHintType.DISABLE_ECI] != null)
                {
                    encoder.setDisableEci(Convert.ToBoolean(hints[EncodeHintType.DISABLE_ECI].ToString()));
                }

                // Check for PDF417 Macro options
                if (hints.ContainsKey(EncodeHintType.PDF417_MACRO_META_DATA))
                {
                    encoder.setMetaData((PDF417MacroMetadata)hints[EncodeHintType.PDF417_MACRO_META_DATA]);
                }
            }

            return(BitMatrixFromEncoder(encoder, contents, errorCorrectionLevel, width, height, margin, aspectRatio));
        }