コード例 #1
0
        /// <summary>
        /// Handle "end of data" situations
        /// </summary>
        /// <param name="context">the encoder context</param>
        /// <param name="buffer">the buffer with the remaining encoded characters</param>
        private static void handleEOD(EncoderContext context, StringBuilder buffer)
        {
            try
            {
                int count = buffer.Length;
                if (count == 0)
                {
                    return; //Already finished
                }
                if (count == 1)
                {
                    //Only an unlatch at the end
                    context.updateSymbolInfo();
                    int available = context.SymbolInfo.dataCapacity - context.CodewordCount;
                    int remaining = context.RemainingCharacters;
                    if (remaining == 0 && available <= 2)
                    {
                        return; //No unlatch
                    }
                }

                if (count > 4)
                {
                    throw new InvalidOperationException("Count must not exceed 4");
                }
                int    restChars          = count - 1;
                String encoded            = encodeToCodewords(buffer, 0);
                bool   endOfSymbolReached = !context.HasMoreCharacters;
                bool   restInAscii        = endOfSymbolReached && restChars <= 2;

                if (restChars <= 2)
                {
                    context.updateSymbolInfo(context.CodewordCount + restChars);
                    int available = context.SymbolInfo.dataCapacity - context.CodewordCount;
                    if (available >= 3)
                    {
                        restInAscii = false;
                        context.updateSymbolInfo(context.CodewordCount + encoded.Length);
                        //available = context.symbolInfo.dataCapacity - context.getCodewordCount();
                    }
                }

                if (restInAscii)
                {
                    context.resetSymbolInfo();
                    context.Pos -= restChars;
                }
                else
                {
                    context.writeCodewords(encoded);
                }
            }
            finally
            {
                context.signalEncoderChange(Encodation.ASCII);
            }
        }
コード例 #2
0
ファイル: C40Encoder.cs プロジェクト: jeason0813/ZXing.Net-1
        private int backtrackOneCharacter(EncoderContext context,
                                          StringBuilder buffer, StringBuilder removed, int lastCharSize)
        {
            int count = buffer.Length;

            buffer.Remove(count - lastCharSize, lastCharSize);
            context.Pos--;
            char c = context.CurrentChar;

            lastCharSize = encodeChar(c, removed);
            context.resetSymbolInfo(); //Deal with possible reduction in symbol size
            return(lastCharSize);
        }
コード例 #3
0
ファイル: C40Encoder.cs プロジェクト: n1rvana/ZXing.NET
 private int backtrackOneCharacter(EncoderContext context,
                                   StringBuilder buffer, StringBuilder removed, int lastCharSize)
 {
    int count = buffer.Length;
    buffer.Remove(count - lastCharSize, lastCharSize);
    context.Pos--;
    char c = context.CurrentChar;
    lastCharSize = encodeChar(c, removed);
    context.resetSymbolInfo(); //Deal with possible reduction in symbol size
    return lastCharSize;
 }
コード例 #4
0
        /// <summary>
        /// Handle "end of data" situations
        /// </summary>
        /// <param name="context">the encoder context</param>
        /// <param name="buffer">the buffer with the remaining encoded characters</param>
        private static void handleEOD(EncoderContext context, StringBuilder buffer)
        {
            try
            {
                int count = buffer.Length;
                if (count == 0)
                {
                    return; //Already finished
                }
                if (count == 1)
                {
                    //Only an unlatch at the end
                    context.updateSymbolInfo();
                    int available = context.SymbolInfo.dataCapacity - context.CodewordCount;
                    int remaining = context.RemainingCharacters;
                    // The following two lines are a hack inspired by the 'fix' from https://sourceforge.net/p/barcode4j/svn/221/
                    if (remaining > available)
                    {
                        context.updateSymbolInfo(context.CodewordCount + 1);
                        available = context.SymbolInfo.dataCapacity - context.CodewordCount;
                    }
                    if (remaining <= available && available <= 2)
                    {
                        return; //No unlatch
                    }
                }

                if (count > 4)
                {
                    throw new InvalidOperationException("Count must not exceed 4");
                }
                int    restChars          = count - 1;
                String encoded            = encodeToCodewords(buffer);
                bool   endOfSymbolReached = !context.HasMoreCharacters;
                bool   restInAscii        = endOfSymbolReached && restChars <= 2;

                if (restChars <= 2)
                {
                    context.updateSymbolInfo(context.CodewordCount + restChars);
                    int available = context.SymbolInfo.dataCapacity - context.CodewordCount;
                    if (available >= 3)
                    {
                        restInAscii = false;
                        context.updateSymbolInfo(context.CodewordCount + encoded.Length);
                        //available = context.symbolInfo.dataCapacity - context.getCodewordCount();
                    }
                }

                if (restInAscii)
                {
                    context.resetSymbolInfo();
                    context.Pos -= restChars;
                }
                else
                {
                    context.writeCodewords(encoded);
                }
            }
            finally
            {
                context.signalEncoderChange((int)Encodation.ASCII);
            }
        }
コード例 #5
0
      /// <summary>
      /// Handle "end of data" situations
      /// </summary>
      /// <param name="context">the encoder context</param>
      /// <param name="buffer">the buffer with the remaining encoded characters</param>
      private static void handleEOD(EncoderContext context, StringBuilder buffer)
      {
         try
         {
            int count = buffer.Length;
            if (count == 0)
            {
               return; //Already finished
            }
            if (count == 1)
            {
               //Only an unlatch at the end
               context.updateSymbolInfo();
               int available = context.SymbolInfo.dataCapacity - context.CodewordCount;
               int remaining = context.RemainingCharacters;
               if (remaining == 0 && available <= 2)
               {
                  return; //No unlatch
               }
            }

            if (count > 4)
            {
               throw new InvalidOperationException("Count must not exceed 4");
            }
            int restChars = count - 1;
            String encoded = encodeToCodewords(buffer, 0);
            bool endOfSymbolReached = !context.HasMoreCharacters;
            bool restInAscii = endOfSymbolReached && restChars <= 2;

            if (restChars <= 2)
            {
               context.updateSymbolInfo(context.CodewordCount + restChars);
               int available = context.SymbolInfo.dataCapacity - context.CodewordCount;
               if (available >= 3)
               {
                  restInAscii = false;
                  context.updateSymbolInfo(context.CodewordCount + encoded.Length);
                  //available = context.symbolInfo.dataCapacity - context.getCodewordCount();
               }
            }

            if (restInAscii)
            {
               context.resetSymbolInfo();
               context.Pos -= restChars;
            }
            else
            {
               context.writeCodewords(encoded);
            }
         }
         finally
         {
            context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION);
         }
      }