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_ENCODERCONTEXT_H_
8 #define FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_
9 
10 #include "core/fxcrt/unowned_ptr.h"
11 #include "core/fxcrt/widestring.h"
12 #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
13 
14 class CBC_SymbolInfo;
15 
16 class CBC_EncoderContext {
17  public:
18   explicit CBC_EncoderContext(const WideString& msg);
19   ~CBC_EncoderContext();
20 
21   void setSkipAtEnd(int32_t count);
22   wchar_t getCurrentChar();
23   wchar_t getCurrent();
24   void writeCodewords(const WideString& codewords);
25   void writeCodeword(wchar_t codeword);
26   size_t getCodewordCount();
27   void SignalEncoderChange(CBC_HighLevelEncoder::Encoding encoding);
28   void ResetEncoderSignal();
29   bool hasMoreCharacters();
30   size_t getRemainingCharacters();
31   bool UpdateSymbolInfo();
32   bool UpdateSymbolInfo(size_t len);
33   void resetSymbolInfo();
34 
HasCharactersOutsideISO88591Encoding()35   bool HasCharactersOutsideISO88591Encoding() const {
36     return m_bHasCharactersOutsideISO88591Encoding;
37   }
38 
39   WideString m_msg;
40   WideString m_codewords;
41   size_t m_pos = 0;
42   CBC_HighLevelEncoder::Encoding m_newEncoding =
43       CBC_HighLevelEncoder::Encoding::UNKNOWN;
44   UnownedPtr<const CBC_SymbolInfo> m_symbolInfo;
45 
46  private:
47   size_t getTotalMessageCharCount();
48 
49   bool m_bAllowRectangular = false;  // Force square when false.
50   bool m_bHasCharactersOutsideISO88591Encoding = false;
51   size_t m_skipAtEnd = 0;
52 };
53 
54 #endif  // FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_
55