Fix the big integer bug in PDF417.
authorBo Xu <bo_xu@foxitsoftware.com>
Mon, 29 Dec 2014 19:25:01 +0000 (11:25 -0800)
committerBo Xu <bo_xu@foxitsoftware.com>
Mon, 29 Dec 2014 19:25:01 +0000 (11:25 -0800)
Previously no big integer support in Pdfium and XFA.

The PDF417 barcode functionality could not work properly.

BUG=https://code.google.com/p/pdfium/issues/detail?id=98
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/777553002

test/barcode_test.pdf [new file with mode: 0644]
xfa/include/foxitxfa.h
xfa/src/fxbarcode/src/BC_PDF417DecodedBitStreamParser.cpp
xfa/src/fxbarcode/src/BC_PDF417HighLevelEncoder.cpp
xfa/src/fxbarcode/src/include/BC_PDF417DecodedBitStreamParser.h

diff --git a/test/barcode_test.pdf b/test/barcode_test.pdf
new file mode 100644 (file)
index 0000000..8454cd0
Binary files /dev/null and b/test/barcode_test.pdf differ
index 26ab6cd..1c54e53 100644 (file)
@@ -17,4 +17,5 @@
 #include "./fwl/fwl.h"\r
 #include "./fxjse/fxjse.h"\r
 #include "./fxfa/fxfa.h"\r
+#include "../../third_party/bigint/BigIntegerLibrary.hh"\r
 #endif\r
index cf0a149..b832ab9 100644 (file)
@@ -18,8 +18,8 @@
 #define    BEGIN_MACRO_PDF417_OPTIONAL_FIELD     923\r
 #define    MACRO_PDF417_TERMINATOR               922\r
 #define    MODE_SHIFT_TO_BYTE_COMPACTION_MODE    913\r
+\r
 FX_INT32 CBC_DecodedBitStreamPaser::MAX_NUMERIC_CODEWORDS = 15;\r
-FX_INT32 CBC_DecodedBitStreamPaser::EXP900[16] = {0};\r
 FX_INT32 CBC_DecodedBitStreamPaser::NUMBER_OF_SEQUENCE_CODEWORDS = 2;\r
 FX_INT32 CBC_DecodedBitStreamPaser::PL = 25;\r
 FX_INT32 CBC_DecodedBitStreamPaser::LL = 27;\r
@@ -40,12 +40,6 @@ FX_CHAR CBC_DecodedBitStreamPaser::MIXED_CHARS[30] = {
 };\r
 void CBC_DecodedBitStreamPaser::Initialize()\r
 {\r
-    EXP900[0] = 1;\r
-    FX_INT32 nineHundred = 900;\r
-    EXP900[1] = nineHundred;\r
-    for (FX_INT32 i = 2; i < sizeof(EXP900) / sizeof(FX_INT32); i++) {\r
-        EXP900[i] = EXP900[i - 1] * nineHundred;\r
-    }\r
 }\r
 void CBC_DecodedBitStreamPaser::Finalize()\r
 {\r
@@ -460,12 +454,12 @@ FX_INT32 CBC_DecodedBitStreamPaser::numericCompaction(CFX_Int32Array &codewords,
 }\r
 CFX_ByteString CBC_DecodedBitStreamPaser::decodeBase900toBase10(CFX_Int32Array &codewords, FX_INT32 count, FX_INT32 &e)\r
 {\r
-    FX_INT32 result = 0;\r
+    BigInteger result = 0;\r
+    BigInteger nineHundred(900);\r
     for (FX_INT32 i = 0; i < count; i++) {\r
-        result += EXP900[count - i - 1] * codewords[i];\r
+        result = result * nineHundred + BigInteger(codewords[i]);\r
     }\r
-    CFX_ByteString resultString;\r
-    resultString = resultString.FormatInteger(result);\r
+    CFX_ByteString resultString(bigIntegerToString(result).c_str());\r
     if (resultString.GetAt(0) != '1') {\r
         e =  BCExceptionFormatInstance;\r
         return ' ';\r
index ade6977..7b4701f 100644 (file)
@@ -292,20 +292,19 @@ void CBC_PDF417HighLevelEncoder::encodeBinary(CFX_ByteArray* bytes, FX_INT32 sta
 void CBC_PDF417HighLevelEncoder::encodeNumeric(CFX_WideString msg, FX_INT32 startpos, FX_INT32 count, CFX_WideString &sb)\r
 {\r
     FX_INT32 idx = 0;\r
-    CFX_WideString tmp;\r
-    FX_INT32 num900 = 900;\r
-    FX_INT32 num0 = 0;\r
+    BigInteger num900 = 900;\r
     while (idx < count - 1) {\r
+        CFX_WideString tmp;\r
         FX_INT32 len = 44 < count - idx ? 44 : count - idx;\r
-        CFX_WideString part = (FX_WCHAR)'1' + msg.Mid(startpos + idx, len);\r
-        FX_INT32 bigint = part.GetInteger();\r
+        CFX_ByteString part = ((FX_WCHAR)'1' + msg.Mid(startpos + idx, len)).UTF8Encode();\r
+        BigInteger bigint = stringToBigInteger(FX_LPCSTR(part));\r
         do {\r
-            FX_INT32 c = bigint % num900;\r
-            tmp += (FX_WCHAR) (c);\r
+            FX_INT32 c = (bigint % num900).toInt();\r
+            tmp += (FX_WCHAR)(c);\r
             bigint = bigint / num900;\r
-        } while (bigint != num0);\r
+        } while (!bigint.isZero());\r
         for (FX_INT32 i = tmp.GetLength() - 1; i >= 0; i--) {\r
-            sb += (tmp.GetAt(i));\r
+            sb += tmp.GetAt(i);\r
         }\r
         idx += len;\r
     }\r
index a612769..64ae2ae 100644 (file)
@@ -37,7 +37,6 @@ private:
     static FX_INT32 PAL;\r
     static FX_CHAR PUNCT_CHARS[29];\r
     static FX_CHAR MIXED_CHARS[30];\r
-    static FX_INT32 EXP900[16];\r
     static FX_INT32 NUMBER_OF_SEQUENCE_CODEWORDS;\r
     static FX_INT32 decodeMacroBlock(CFX_Int32Array &codewords, FX_INT32 codeIndex, CBC_PDF417ResultMetadata* resultMetadata, FX_INT32 &e);\r
     static FX_INT32 textCompaction(CFX_Int32Array &codewords, FX_INT32 codeIndex, CFX_ByteString &result);\r