1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef FXBARCODE_DATAMATRIX_BC_C40ENCODER_H_
8 #define FXBARCODE_DATAMATRIX_BC_C40ENCODER_H_
9 
10 #include "core/fxcrt/widestring.h"
11 #include "fxbarcode/datamatrix/BC_Encoder.h"
12 
13 class CBC_C40Encoder : public CBC_Encoder {
14  public:
15   CBC_C40Encoder();
16   ~CBC_C40Encoder() override;
17 
18   // CBC_Encoder
19   CBC_HighLevelEncoder::Encoding GetEncodingMode() override;
20   bool Encode(CBC_EncoderContext* context) override;
21 
22   static void WriteNextTriplet(CBC_EncoderContext* context, WideString* buffer);
23 
24   virtual bool HandleEOD(CBC_EncoderContext* context, WideString* buffer);
25 
26   // Returns the number of characters appended to |sb|, or 0 on failure.
27   virtual int32_t EncodeChar(wchar_t c, WideString* sb);
28 
29  private:
30   // Moves back by 1 position in |context| and adjusts |buffer| accordingly
31   // using |lastCharSize|. Returns the length of the current character in
32   // |context| after adjusting the position. If the character cannot be encoded,
33   // return -1.
34   int32_t BacktrackOneCharacter(CBC_EncoderContext* context,
35                                 WideString* buffer,
36                                 int32_t lastCharSize);
37 };
38 
39 #endif  // FXBARCODE_DATAMATRIX_BC_C40ENCODER_H_
40