blob: 2701c810fbbdcfaf45048e67a3bf5aa30a37bd66 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// 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
Dan Sinclaire7786682017-03-29 15:18:41 -04007#ifndef FXBARCODE_PDF417_BC_PDF417HIGHLEVELENCODER_H_
8#define FXBARCODE_PDF417_BC_PDF417HIGHLEVELENCODER_H_
Dan Sinclair1770c022016-03-14 14:14:16 -04009
Tom Sepez8b6186f2017-03-28 12:06:45 -070010#include <vector>
11
dsinclaira52ab742016-09-29 13:59:29 -070012#include "core/fxcrt/fx_string.h"
Dan Sinclaire7786682017-03-29 15:18:41 -040013#include "fxbarcode/pdf417/BC_PDF417Compaction.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040014
15class CBC_PDF417HighLevelEncoder {
16 public:
Ryan Harrison275e2602017-09-18 14:23:18 -040017 static WideString encodeHighLevel(WideString msg,
18 Compaction compaction,
19 int32_t& e);
Dan Sinclair1770c022016-03-14 14:14:16 -040020 static void Inverse();
21 static void Initialize();
22 static void Finalize();
23
24 private:
25 static int32_t TEXT_COMPACTION;
26 static int32_t BYTE_COMPACTION;
27 static int32_t NUMERIC_COMPACTION;
28 static int32_t SUBMODE_PUNCTUATION;
29 static int32_t LATCH_TO_TEXT;
30 static int32_t LATCH_TO_BYTE_PADDED;
31 static int32_t LATCH_TO_NUMERIC;
32 static int32_t SHIFT_TO_BYTE;
33 static int32_t LATCH_TO_BYTE;
34 static uint8_t TEXT_MIXED_RAW[];
35 static uint8_t TEXT_PUNCTUATION_RAW[];
36 static int32_t MIXED[128];
37 static int32_t PUNCTUATION[128];
Ryan Harrison275e2602017-09-18 14:23:18 -040038 static int32_t encodeText(WideString msg,
Dan Sinclair1770c022016-03-14 14:14:16 -040039 int32_t startpos,
40 int32_t count,
Ryan Harrison275e2602017-09-18 14:23:18 -040041 WideString& sb,
Dan Sinclair1770c022016-03-14 14:14:16 -040042 int32_t initialSubmode);
Tom Sepez8b6186f2017-03-28 12:06:45 -070043 static void encodeBinary(std::vector<uint8_t>* bytes,
Dan Sinclair1770c022016-03-14 14:14:16 -040044 int32_t startpos,
45 int32_t count,
46 int32_t startmode,
Ryan Harrison275e2602017-09-18 14:23:18 -040047 WideString& sb);
48 static void encodeNumeric(WideString msg,
Dan Sinclair1770c022016-03-14 14:14:16 -040049 int32_t startpos,
50 int32_t count,
Ryan Harrison275e2602017-09-18 14:23:18 -040051 WideString& sb);
Dan Sinclair812e96c2017-03-13 16:43:37 -040052 static bool isDigit(wchar_t ch);
53 static bool isAlphaUpper(wchar_t ch);
54 static bool isAlphaLower(wchar_t ch);
55 static bool isMixed(wchar_t ch);
56 static bool isPunctuation(wchar_t ch);
57 static bool isText(wchar_t ch);
Ryan Harrison275e2602017-09-18 14:23:18 -040058 static int32_t determineConsecutiveDigitCount(WideString msg,
Dan Sinclair1770c022016-03-14 14:14:16 -040059 int32_t startpos);
Ryan Harrison275e2602017-09-18 14:23:18 -040060 static int32_t determineConsecutiveTextCount(WideString msg,
Dan Sinclair1770c022016-03-14 14:14:16 -040061 int32_t startpos);
Ryan Harrison275e2602017-09-18 14:23:18 -040062 static int32_t determineConsecutiveBinaryCount(WideString msg,
Tom Sepez8b6186f2017-03-28 12:06:45 -070063 std::vector<uint8_t>* bytes,
64 int32_t startpos,
65 int32_t& e);
Dan Sinclair1770c022016-03-14 14:14:16 -040066
67 friend class PDF417HighLevelEncoder_EncodeNumeric_Test;
68 friend class PDF417HighLevelEncoder_EncodeBinary_Test;
69 friend class PDF417HighLevelEncoder_EncodeText_Test;
70 friend class PDF417HighLevelEncoder_ConsecutiveDigitCount_Test;
71 friend class PDF417HighLevelEncoder_ConsecutiveTextCount_Test;
72 friend class PDF417HighLevelEncoder_ConsecutiveBinaryCount_Test;
73};
74
Dan Sinclaire7786682017-03-29 15:18:41 -040075#endif // FXBARCODE_PDF417_BC_PDF417HIGHLEVELENCODER_H_