summaryrefslogtreecommitdiff
path: root/xfa/fgas
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-05-19 18:07:11 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-19 18:07:11 -0700
commitfc2cdf8657534467fd807e216d50650b0e959868 (patch)
treea0642ba14ee4e438e97957825772e8dd16e347a2 /xfa/fgas
parent411f1185f44b7862a9b1c16e588407ae197752dd (diff)
downloadpdfium-fc2cdf8657534467fd807e216d50650b0e959868.tar.xz
fgas/ code cleanup.
This CL shuffles code around in the fgas/ headers, removes unused functions and adds anonymous namepaces for static methods and data. Review-Url: https://codereview.chromium.org/1992033002
Diffstat (limited to 'xfa/fgas')
-rw-r--r--xfa/fgas/crt/fgas_algorithm.cpp306
-rw-r--r--xfa/fgas/crt/fgas_algorithm.h29
-rw-r--r--xfa/fgas/crt/fgas_codepage.cpp277
-rw-r--r--xfa/fgas/crt/fgas_codepage.h28
-rw-r--r--xfa/fgas/crt/fgas_encode.cpp193
-rw-r--r--xfa/fgas/crt/fgas_memory.cpp8
-rw-r--r--xfa/fgas/crt/fgas_stream.cpp201
-rw-r--r--xfa/fgas/crt/fgas_stream.h6
-rw-r--r--xfa/fgas/crt/fgas_system.cpp36
-rw-r--r--xfa/fgas/crt/fgas_system.h6
10 files changed, 271 insertions, 819 deletions
diff --git a/xfa/fgas/crt/fgas_algorithm.cpp b/xfa/fgas/crt/fgas_algorithm.cpp
deleted file mode 100644
index ee557b10d9..0000000000
--- a/xfa/fgas/crt/fgas_algorithm.cpp
+++ /dev/null
@@ -1,306 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fgas/crt/fgas_algorithm.h"
-
-#include "core/fxcrt/include/fx_basic.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static const FX_CHAR g_FXBase64EncoderMap[64] = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
- 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
-};
-
-struct FX_BASE64DATA {
- uint32_t data1 : 2;
- uint32_t data2 : 6;
- uint32_t data3 : 4;
- uint32_t data4 : 4;
- uint32_t data5 : 6;
- uint32_t data6 : 2;
- uint32_t data7 : 8;
-};
-
-static void FX_Base64EncodePiece(const FX_BASE64DATA& src,
- int32_t iBytes,
- FX_CHAR dst[4]) {
- dst[0] = g_FXBase64EncoderMap[src.data2];
- uint32_t b = src.data1 << 4;
- if (iBytes > 1) {
- b |= src.data4;
- }
- dst[1] = g_FXBase64EncoderMap[b];
- if (iBytes > 1) {
- b = src.data3 << 2;
- if (iBytes > 2) {
- b |= src.data6;
- }
- dst[2] = g_FXBase64EncoderMap[b];
- if (iBytes > 2) {
- dst[3] = g_FXBase64EncoderMap[src.data5];
- } else {
- dst[3] = '=';
- }
- } else {
- dst[2] = dst[3] = '=';
- }
-}
-int32_t FX_Base64EncodeA(const uint8_t* pSrc, int32_t iSrcLen, FX_CHAR* pDst) {
- ASSERT(pSrc != NULL);
- if (iSrcLen < 1) {
- return 0;
- }
- if (pDst == NULL) {
- int32_t iDstLen = iSrcLen / 3 * 4;
- if ((iSrcLen % 3) != 0) {
- iDstLen += 4;
- }
- return iDstLen;
- }
- FX_BASE64DATA srcData;
- int32_t iBytes = 3;
- FX_CHAR* pDstEnd = pDst;
- while (iSrcLen > 0) {
- if (iSrcLen > 2) {
- ((uint8_t*)&srcData)[0] = *pSrc++;
- ((uint8_t*)&srcData)[1] = *pSrc++;
- ((uint8_t*)&srcData)[2] = *pSrc++;
- iSrcLen -= 3;
- } else {
- *((uint32_t*)&srcData) = 0;
- ((uint8_t*)&srcData)[0] = *pSrc++;
- if (iSrcLen > 1) {
- ((uint8_t*)&srcData)[1] = *pSrc++;
- }
- iBytes = iSrcLen;
- iSrcLen = 0;
- }
- FX_Base64EncodePiece(srcData, iBytes, pDstEnd);
- pDstEnd += 4;
- }
- return pDstEnd - pDst;
-}
-
-static const uint8_t g_FXBase64DecoderMap[256] = {
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0x3F,
- 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
- 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12,
- 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
- 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
- 0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF,
-};
-static void FX_Base64DecodePiece(const FX_CHAR src[4],
- int32_t iChars,
- FX_BASE64DATA& dst,
- int32_t& iBytes) {
- ASSERT(iChars > 0 && iChars < 5);
- iBytes = 1;
- dst.data2 = g_FXBase64DecoderMap[(uint8_t)src[0]];
- if (iChars > 1) {
- uint8_t b = g_FXBase64DecoderMap[(uint8_t)src[1]];
- dst.data1 = b >> 4;
- dst.data4 = b;
- if (iChars > 2) {
- iBytes = 2;
- b = g_FXBase64DecoderMap[(uint8_t)src[2]];
- dst.data3 = b >> 2;
- dst.data6 = b;
- if (iChars > 3) {
- iBytes = 3;
- dst.data5 = g_FXBase64DecoderMap[(uint8_t)src[3]];
- } else {
- dst.data5 = 0;
- }
- } else {
- dst.data3 = 0;
- }
- } else {
- dst.data1 = 0;
- }
-}
-int32_t FX_Base64DecodeA(const FX_CHAR* pSrc, int32_t iSrcLen, uint8_t* pDst) {
- ASSERT(pSrc != NULL);
- if (iSrcLen < 1) {
- return 0;
- }
- while (iSrcLen > 0 && pSrc[iSrcLen - 1] == '=') {
- iSrcLen--;
- }
- if (iSrcLen < 1) {
- return 0;
- }
- if (pDst == NULL) {
- int32_t iDstLen = iSrcLen / 4 * 3;
- iSrcLen %= 4;
- if (iSrcLen == 1) {
- iDstLen += 1;
- } else if (iSrcLen == 2) {
- iDstLen += 1;
- } else if (iSrcLen == 3) {
- iDstLen += 2;
- }
- return iDstLen;
- }
- FX_CHAR srcData[4];
- FX_BASE64DATA dstData;
- int32_t iChars = 4, iBytes;
- uint8_t* pDstEnd = pDst;
- while (iSrcLen > 0) {
- if (iSrcLen > 3) {
- *((uint32_t*)srcData) = *((uint32_t*)pSrc);
- pSrc += 4;
- iSrcLen -= 4;
- } else {
- *((uint32_t*)&dstData) = 0;
- *((uint32_t*)srcData) = 0;
- srcData[0] = *pSrc++;
- if (iSrcLen > 1) {
- srcData[1] = *pSrc++;
- }
- if (iSrcLen > 2) {
- srcData[2] = *pSrc++;
- }
- iChars = iSrcLen;
- iSrcLen = 0;
- }
- FX_Base64DecodePiece(srcData, iChars, dstData, iBytes);
- *pDstEnd++ = ((uint8_t*)&dstData)[0];
- if (iBytes > 1) {
- *pDstEnd++ = ((uint8_t*)&dstData)[1];
- }
- if (iBytes > 2) {
- *pDstEnd++ = ((uint8_t*)&dstData)[2];
- }
- }
- return pDstEnd - pDst;
-}
-int32_t FX_Base64DecodeW(const FX_WCHAR* pSrc, int32_t iSrcLen, uint8_t* pDst) {
- ASSERT(pSrc != NULL);
- if (iSrcLen < 1) {
- return 0;
- }
- while (iSrcLen > 0 && pSrc[iSrcLen - 1] == '=') {
- iSrcLen--;
- }
- if (iSrcLen < 1) {
- return 0;
- }
- if (pDst == NULL) {
- int32_t iDstLen = iSrcLen / 4 * 3;
- iSrcLen %= 4;
- if (iSrcLen == 1) {
- iDstLen += 1;
- } else if (iSrcLen == 2) {
- iDstLen += 1;
- } else if (iSrcLen == 3) {
- iDstLen += 2;
- }
- return iDstLen;
- }
- FX_CHAR srcData[4];
- FX_BASE64DATA dstData;
- int32_t iChars = 4, iBytes;
- uint8_t* pDstEnd = pDst;
- while (iSrcLen > 0) {
- if (iSrcLen > 3) {
- srcData[0] = (FX_CHAR)*pSrc++;
- srcData[1] = (FX_CHAR)*pSrc++;
- srcData[2] = (FX_CHAR)*pSrc++;
- srcData[3] = (FX_CHAR)*pSrc++;
- iSrcLen -= 4;
- } else {
- *((uint32_t*)&dstData) = 0;
- *((uint32_t*)srcData) = 0;
- srcData[0] = (FX_CHAR)*pSrc++;
- if (iSrcLen > 1) {
- srcData[1] = (FX_CHAR)*pSrc++;
- }
- if (iSrcLen > 2) {
- srcData[2] = (FX_CHAR)*pSrc++;
- }
- iChars = iSrcLen;
- iSrcLen = 0;
- }
- FX_Base64DecodePiece(srcData, iChars, dstData, iBytes);
- *pDstEnd++ = ((uint8_t*)&dstData)[0];
- if (iBytes > 1) {
- *pDstEnd++ = ((uint8_t*)&dstData)[1];
- }
- if (iBytes > 2) {
- *pDstEnd++ = ((uint8_t*)&dstData)[2];
- }
- }
- return pDstEnd - pDst;
-}
-
-static const uint8_t g_FXHex2DecMap[256] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
- 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12,
- 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-uint8_t FX_Hex2Dec(uint8_t hexHigh, uint8_t hexLow) {
- return (g_FXHex2DecMap[hexHigh] << 4) + g_FXHex2DecMap[hexLow];
-}
-int32_t FX_SeparateStringW(const FX_WCHAR* pStr,
- int32_t iStrLen,
- FX_WCHAR delimiter,
- CFX_WideStringArray& pieces) {
- if (pStr == NULL) {
- return 0;
- }
- if (iStrLen < 0) {
- iStrLen = FXSYS_wcslen(pStr);
- }
- const FX_WCHAR* pToken = pStr;
- const FX_WCHAR* pEnd = pStr + iStrLen;
- while (TRUE) {
- if (pStr >= pEnd || delimiter == *pStr) {
- CFX_WideString sub(pToken, pStr - pToken);
- pieces.Add(sub);
- pToken = pStr + 1;
- if (pStr >= pEnd) {
- break;
- }
- }
- pStr++;
- }
- return pieces.GetSize();
-}
-#ifdef __cplusplus
-}
-#endif
diff --git a/xfa/fgas/crt/fgas_algorithm.h b/xfa/fgas/crt/fgas_algorithm.h
index 9fefb2bc40..f68b53f8cc 100644
--- a/xfa/fgas/crt/fgas_algorithm.h
+++ b/xfa/fgas/crt/fgas_algorithm.h
@@ -11,41 +11,24 @@
#include "core/fxcrt/include/fx_basic.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t FX_Base64EncodeA(const uint8_t* pSrc, int32_t iSrcLen, FX_CHAR* pDst);
-int32_t FX_Base64DecodeA(const FX_CHAR* pSrc, int32_t iSrcLen, uint8_t* pDst);
-int32_t FX_Base64DecodeW(const FX_WCHAR* pSrc, int32_t iSrcLen, uint8_t* pDst);
-uint8_t FX_Hex2Dec(uint8_t hexHigh, uint8_t hexLow);
-int32_t FX_SeparateStringW(const FX_WCHAR* pStr,
- int32_t iStrLen,
- FX_WCHAR delimiter,
- CFX_WideStringArray& pieces);
-#ifdef __cplusplus
-};
-#endif
-
template <class baseType>
class CFX_DSPATemplate {
public:
int32_t Lookup(const baseType& find, const baseType* pArray, int32_t iCount) {
- ASSERT(pArray != NULL);
- if (iCount < 1) {
+ ASSERT(pArray);
+ if (iCount < 1)
return -1;
- }
+
int32_t iStart = 0, iEnd = iCount - 1, iMid;
do {
iMid = (iStart + iEnd) / 2;
const baseType& v = pArray[iMid];
- if (find == v) {
+ if (find == v)
return iMid;
- } else if (find < v) {
+ if (find < v)
iEnd = iMid - 1;
- } else {
+ else
iStart = iMid + 1;
- }
} while (iStart <= iEnd);
return -1;
}
diff --git a/xfa/fgas/crt/fgas_codepage.cpp b/xfa/fgas/crt/fgas_codepage.cpp
index 7362a89d30..2087cac138 100644
--- a/xfa/fgas/crt/fgas_codepage.cpp
+++ b/xfa/fgas/crt/fgas_codepage.cpp
@@ -8,7 +8,24 @@
#include "xfa/fgas/crt/fgas_codepage.h"
#include "xfa/fgas/crt/fgas_language.h"
-static const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = {
+namespace {
+
+struct FX_STR2CPHASH {
+ uint32_t uHash;
+ uint16_t uCodePage;
+};
+
+struct FX_CHARSET_MAP {
+ uint16_t charset;
+ uint16_t codepage;
+};
+
+struct FX_LANG2CPMAP {
+ uint16_t wLanguage;
+ uint16_t wCodepage;
+};
+
+const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = {
{0, 1252}, {1, 0}, {2, 42}, {77, 10000}, {78, 10001},
{79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, {84, 10004},
{85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, {89, 10007},
@@ -17,24 +34,8 @@ static const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = {
{186, 1257}, {204, 1251}, {222, 874}, {238, 1250}, {254, 437},
{255, 850},
};
-uint16_t FX_GetCodePageFromCharset(uint8_t charset) {
- int32_t iEnd = sizeof(g_FXCharset2CodePageTable) / sizeof(FX_CHARSET_MAP) - 1;
- ASSERT(iEnd >= 0);
- int32_t iStart = 0, iMid;
- do {
- iMid = (iStart + iEnd) / 2;
- const FX_CHARSET_MAP& cp = g_FXCharset2CodePageTable[iMid];
- if (charset == cp.charset) {
- return cp.codepage;
- } else if (charset < cp.charset) {
- iEnd = iMid - 1;
- } else {
- iStart = iMid + 1;
- }
- } while (iStart <= iEnd);
- return 0xFFFF;
-}
-static const FX_CHARSET_MAP g_FXCodepage2CharsetTable[] = {
+
+const FX_CHARSET_MAP g_FXCodepage2CharsetTable[] = {
{1, 0}, {2, 42}, {254, 437}, {255, 850}, {222, 874},
{128, 932}, {134, 936}, {129, 949}, {136, 950}, {238, 1250},
{204, 1251}, {0, 1252}, {161, 1253}, {162, 1254}, {177, 1255},
@@ -43,23 +44,7 @@ static const FX_CHARSET_MAP g_FXCodepage2CharsetTable[] = {
{84, 10004}, {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029},
{89, 10007},
};
-uint16_t FX_GetCharsetFromCodePage(uint16_t codepage) {
- int32_t iEnd = sizeof(g_FXCodepage2CharsetTable) / sizeof(FX_CHARSET_MAP) - 1;
- ASSERT(iEnd >= 0);
- int32_t iStart = 0, iMid;
- do {
- iMid = (iStart + iEnd) / 2;
- const FX_CHARSET_MAP& cp = g_FXCodepage2CharsetTable[iMid];
- if (codepage == cp.codepage) {
- return cp.charset;
- } else if (codepage < cp.codepage) {
- iEnd = iMid - 1;
- } else {
- iStart = iMid + 1;
- }
- } while (iStart <= iEnd);
- return 0xFFFF;
-}
+
const FX_LANG2CPMAP g_FXLang2CodepageTable[] = {
{FX_LANG_Arabic_SaudiArabia, FX_CODEPAGE_MSWin_Arabic},
{FX_LANG_Bulgarian_Bulgaria, FX_CODEPAGE_MSWin_Cyrillic},
@@ -197,24 +182,8 @@ const FX_LANG2CPMAP g_FXLang2CodepageTable[] = {
{FX_LANG_Spanish_Nicaragua, FX_CODEPAGE_MSWin_WesternEuropean},
{FX_LANG_Spanish_PuertoRico, FX_CODEPAGE_MSWin_WesternEuropean},
};
-uint16_t FX_GetDefCodePageByLanguage(uint16_t wLanguage) {
- int32_t iEnd = sizeof(g_FXLang2CodepageTable) / sizeof(FX_LANG2CPMAP) - 1;
- ASSERT(iEnd >= 0);
- int32_t iStart = 0, iMid;
- do {
- iMid = (iStart + iEnd) / 2;
- const FX_LANG2CPMAP& cp = g_FXLang2CodepageTable[iMid];
- if (wLanguage == cp.wLanguage) {
- return cp.wCodepage;
- } else if (wLanguage < cp.wLanguage) {
- iEnd = iMid - 1;
- } else {
- iStart = iMid + 1;
- }
- } while (iStart <= iEnd);
- return 0xFFFF;
-}
-static const FX_STR2CPHASH g_FXCPHashTable[] = {
+
+const FX_STR2CPHASH g_FXCPHashTable[] = {
{0xd45, 0x6faf}, {0xd46, 0x6fb0}, {0xd47, 0x6fb1},
{0xd48, 0x6fb2}, {0xd49, 0x4e6}, {0xd4d, 0x6fbd},
{0xe9e, 0x4e4}, {0xc998, 0x1b5}, {0x18ef0, 0x3a8},
@@ -301,7 +270,8 @@ static const FX_STR2CPHASH g_FXCPHashTable[] = {
{0xf3d463c2, 0x3a4}, {0xf52a70a3, 0xc42e}, {0xf5693147, 0x6fb3},
{0xf637e157, 0x478}, {0xfc213f3a, 0x2717}, {0xff654d14, 0x3b5},
};
-uint16_t FX_GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength) {
+
+uint16_t GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength) {
ASSERT(pStr != NULL);
if (iLength < 0) {
iLength = FXSYS_strlen(pStr);
@@ -326,7 +296,64 @@ uint16_t FX_GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength) {
} while (iStart <= iEnd);
return 0xFFFF;
}
-uint16_t FX_GetCodePageFormStringW(const FX_WCHAR* pStr, int32_t iLength) {
+
+} // namespace
+
+uint16_t FX_GetCodePageFromCharset(uint8_t charset) {
+ int32_t iEnd = sizeof(g_FXCharset2CodePageTable) / sizeof(FX_CHARSET_MAP) - 1;
+ ASSERT(iEnd >= 0);
+ int32_t iStart = 0, iMid;
+ do {
+ iMid = (iStart + iEnd) / 2;
+ const FX_CHARSET_MAP& cp = g_FXCharset2CodePageTable[iMid];
+ if (charset == cp.charset) {
+ return cp.codepage;
+ } else if (charset < cp.charset) {
+ iEnd = iMid - 1;
+ } else {
+ iStart = iMid + 1;
+ }
+ } while (iStart <= iEnd);
+ return 0xFFFF;
+}
+
+uint16_t FX_GetCharsetFromCodePage(uint16_t codepage) {
+ int32_t iEnd = sizeof(g_FXCodepage2CharsetTable) / sizeof(FX_CHARSET_MAP) - 1;
+ ASSERT(iEnd >= 0);
+ int32_t iStart = 0, iMid;
+ do {
+ iMid = (iStart + iEnd) / 2;
+ const FX_CHARSET_MAP& cp = g_FXCodepage2CharsetTable[iMid];
+ if (codepage == cp.codepage) {
+ return cp.charset;
+ } else if (codepage < cp.codepage) {
+ iEnd = iMid - 1;
+ } else {
+ iStart = iMid + 1;
+ }
+ } while (iStart <= iEnd);
+ return 0xFFFF;
+}
+
+uint16_t FX_GetDefCodePageByLanguage(uint16_t wLanguage) {
+ int32_t iEnd = sizeof(g_FXLang2CodepageTable) / sizeof(FX_LANG2CPMAP) - 1;
+ ASSERT(iEnd >= 0);
+ int32_t iStart = 0, iMid;
+ do {
+ iMid = (iStart + iEnd) / 2;
+ const FX_LANG2CPMAP& cp = g_FXLang2CodepageTable[iMid];
+ if (wLanguage == cp.wLanguage) {
+ return cp.wCodepage;
+ } else if (wLanguage < cp.wLanguage) {
+ iEnd = iMid - 1;
+ } else {
+ iStart = iMid + 1;
+ }
+ } while (iStart <= iEnd);
+ return 0xFFFF;
+}
+
+uint16_t FX_GetCodePageFromStringW(const FX_WCHAR* pStr, int32_t iLength) {
if (iLength < 0) {
iLength = FXSYS_wcslen(pStr);
}
@@ -339,5 +366,141 @@ uint16_t FX_GetCodePageFormStringW(const FX_WCHAR* pStr, int32_t iLength) {
*pBuf++ = (FX_CHAR)*pStr++;
}
csStr.ReleaseBuffer(iLength);
- return FX_GetCodePageFromStringA(csStr.c_str(), iLength);
+ return GetCodePageFromStringA(csStr.c_str(), iLength);
+}
+
+void FX_SwapByteOrder(FX_WCHAR* pStr, int32_t iLength) {
+ ASSERT(pStr != NULL);
+ if (iLength < 0) {
+ iLength = FXSYS_wcslen(pStr);
+ }
+ uint16_t wch;
+ if (sizeof(FX_WCHAR) > 2) {
+ while (iLength-- > 0) {
+ wch = (uint16_t)*pStr;
+ wch = (wch >> 8) | (wch << 8);
+ wch &= 0x00FF;
+ *pStr++ = wch;
+ }
+ } else {
+ while (iLength-- > 0) {
+ wch = (uint16_t)*pStr;
+ wch = (wch >> 8) | (wch << 8);
+ *pStr++ = wch;
+ }
+ }
+}
+
+void FX_UTF16ToWChar(void* pBuffer, int32_t iLength) {
+ ASSERT(pBuffer != NULL && iLength > 0);
+ if (sizeof(FX_WCHAR) == 2) {
+ return;
+ }
+ uint16_t* pSrc = (uint16_t*)pBuffer;
+ FX_WCHAR* pDst = (FX_WCHAR*)pBuffer;
+ while (--iLength >= 0) {
+ pDst[iLength] = (FX_WCHAR)pSrc[iLength];
+ }
+}
+
+void FX_WCharToUTF16(void* pBuffer, int32_t iLength) {
+ ASSERT(pBuffer != NULL && iLength > 0);
+ if (sizeof(FX_WCHAR) == 2) {
+ return;
+ }
+ const FX_WCHAR* pSrc = (const FX_WCHAR*)pBuffer;
+ uint16_t* pDst = (uint16_t*)pBuffer;
+ while (--iLength >= 0) {
+ *pDst++ = (uint16_t)*pSrc++;
+ }
+}
+
+int32_t FX_DecodeString(uint16_t wCodePage,
+ const FX_CHAR* pSrc,
+ int32_t* pSrcLen,
+ FX_WCHAR* pDst,
+ int32_t* pDstLen,
+ FX_BOOL bErrBreak) {
+ if (wCodePage == FX_CODEPAGE_UTF8) {
+ return FX_UTF8Decode(pSrc, pSrcLen, pDst, pDstLen);
+ }
+ return -1;
+}
+int32_t FX_UTF8Decode(const FX_CHAR* pSrc,
+ int32_t* pSrcLen,
+ FX_WCHAR* pDst,
+ int32_t* pDstLen) {
+ if (pSrcLen == NULL || pDstLen == NULL) {
+ return -1;
+ }
+ int32_t iSrcLen = *pSrcLen;
+ if (iSrcLen < 1) {
+ *pSrcLen = *pDstLen = 0;
+ return 1;
+ }
+ int32_t iDstLen = *pDstLen;
+ FX_BOOL bValidDst = (pDst != NULL && iDstLen > 0);
+ uint32_t dwCode = 0;
+ int32_t iPending = 0;
+ int32_t iSrcNum = 0, iDstNum = 0;
+ int32_t k = 0;
+ int32_t iIndex = 0;
+ k = 1;
+ while (iIndex < iSrcLen) {
+ uint8_t byte = (uint8_t) * (pSrc + iIndex);
+ if (byte < 0x80) {
+ iPending = 0;
+ k = 1;
+ iDstNum++;
+ iSrcNum += k;
+ if (bValidDst) {
+ *pDst++ = byte;
+ if (iDstNum >= iDstLen) {
+ break;
+ }
+ }
+ } else if (byte < 0xc0) {
+ if (iPending < 1) {
+ break;
+ }
+ iPending--;
+ dwCode |= (byte & 0x3f) << (iPending * 6);
+ if (iPending == 0) {
+ iDstNum++;
+ iSrcNum += k;
+ if (bValidDst) {
+ *pDst++ = dwCode;
+ if (iDstNum >= iDstLen) {
+ break;
+ }
+ }
+ }
+ } else if (byte < 0xe0) {
+ iPending = 1;
+ k = 2;
+ dwCode = (byte & 0x1f) << 6;
+ } else if (byte < 0xf0) {
+ iPending = 2;
+ k = 3;
+ dwCode = (byte & 0x0f) << 12;
+ } else if (byte < 0xf8) {
+ iPending = 3;
+ k = 4;
+ dwCode = (byte & 0x07) << 18;
+ } else if (byte < 0xfc) {
+ iPending = 4;
+ k = 5;
+ dwCode = (byte & 0x03) << 24;
+ } else if (byte < 0xfe) {
+ iPending = 5;
+ k = 6;
+ dwCode = (byte & 0x01) << 30;
+ } else {
+ break;
+ }
+ iIndex++;
+ }
+ *pSrcLen = iSrcNum;
+ *pDstLen = iDstNum;
+ return 1;
}
diff --git a/xfa/fgas/crt/fgas_codepage.h b/xfa/fgas/crt/fgas_codepage.h
index 15bdd74487..5d867feb8e 100644
--- a/xfa/fgas/crt/fgas_codepage.h
+++ b/xfa/fgas/crt/fgas_codepage.h
@@ -135,21 +135,12 @@
uint16_t FX_GetCodePageFromCharset(uint8_t charset);
uint16_t FX_GetCharsetFromCodePage(uint16_t codepage);
-uint16_t FX_GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength);
-uint16_t FX_GetCodePageFormStringW(const FX_WCHAR* pStr, int32_t iLength);
+uint16_t FX_GetCodePageFromStringW(const FX_WCHAR* pStr, int32_t iLength);
uint16_t FX_GetDefCodePageByLanguage(uint16_t wLanguage);
void FX_SwapByteOrder(FX_WCHAR* pStr, int32_t iLength);
-void FX_SwapByteOrderCopy(const FX_WCHAR* pSrc,
- FX_WCHAR* pDst,
- int32_t iLength);
+
void FX_UTF16ToWChar(void* pBuffer, int32_t iLength);
-void FX_UTF16ToWCharCopy(const uint16_t* pUTF16,
- FX_WCHAR* pWChar,
- int32_t iLength);
void FX_WCharToUTF16(void* pBuffer, int32_t iLength);
-void FX_WCharToUTF16Copy(const FX_WCHAR* pWChar,
- uint16_t* pUTF16,
- int32_t iLength);
int32_t FX_DecodeString(uint16_t wCodePage,
const FX_CHAR* pSrc,
int32_t* pSrcLen,
@@ -161,19 +152,4 @@ int32_t FX_UTF8Decode(const FX_CHAR* pSrc,
FX_WCHAR* pDst,
int32_t* pDstLen);
-struct FX_STR2CPHASH {
- uint32_t uHash;
- uint16_t uCodePage;
-};
-
-struct FX_CHARSET_MAP {
- uint16_t charset;
- uint16_t codepage;
-};
-
-struct FX_LANG2CPMAP {
- uint16_t wLanguage;
- uint16_t wCodepage;
-};
-
#endif // XFA_FGAS_CRT_FGAS_CODEPAGE_H_
diff --git a/xfa/fgas/crt/fgas_encode.cpp b/xfa/fgas/crt/fgas_encode.cpp
deleted file mode 100644
index b84406f642..0000000000
--- a/xfa/fgas/crt/fgas_encode.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fgas/crt/fgas_codepage.h"
-
-void FX_SwapByteOrder(FX_WCHAR* pStr, int32_t iLength) {
- ASSERT(pStr != NULL);
- if (iLength < 0) {
- iLength = FXSYS_wcslen(pStr);
- }
- uint16_t wch;
- if (sizeof(FX_WCHAR) > 2) {
- while (iLength-- > 0) {
- wch = (uint16_t)*pStr;
- wch = (wch >> 8) | (wch << 8);
- wch &= 0x00FF;
- *pStr++ = wch;
- }
- } else {
- while (iLength-- > 0) {
- wch = (uint16_t)*pStr;
- wch = (wch >> 8) | (wch << 8);
- *pStr++ = wch;
- }
- }
-}
-void FX_SwapByteOrderCopy(const FX_WCHAR* pSrc,
- FX_WCHAR* pDst,
- int32_t iLength) {
- ASSERT(pSrc != NULL && pDst != NULL);
- if (iLength < 0) {
- iLength = FXSYS_wcslen(pSrc);
- }
- uint16_t wch;
- if (sizeof(FX_WCHAR) > 2) {
- while (iLength-- > 0) {
- wch = (uint16_t)*pSrc++;
- wch = (wch >> 8) | (wch << 8);
- wch &= 0x00FF;
- *pDst++ = wch;
- }
- } else {
- while (iLength-- > 0) {
- wch = (uint16_t)*pSrc++;
- wch = (wch >> 8) | (wch << 8);
- *pDst++ = wch;
- }
- }
-}
-void FX_UTF16ToWChar(void* pBuffer, int32_t iLength) {
- ASSERT(pBuffer != NULL && iLength > 0);
- if (sizeof(FX_WCHAR) == 2) {
- return;
- }
- uint16_t* pSrc = (uint16_t*)pBuffer;
- FX_WCHAR* pDst = (FX_WCHAR*)pBuffer;
- while (--iLength >= 0) {
- pDst[iLength] = (FX_WCHAR)pSrc[iLength];
- }
-}
-void FX_UTF16ToWCharCopy(const uint16_t* pUTF16,
- FX_WCHAR* pWChar,
- int32_t iLength) {
- ASSERT(pUTF16 != NULL && pWChar != NULL && iLength > 0);
- if (sizeof(FX_WCHAR) == 2) {
- FXSYS_memcpy(pWChar, pUTF16, iLength * sizeof(FX_WCHAR));
- } else {
- while (--iLength >= 0) {
- pWChar[iLength] = (FX_WCHAR)pUTF16[iLength];
- }
- }
-}
-void FX_WCharToUTF16(void* pBuffer, int32_t iLength) {
- ASSERT(pBuffer != NULL && iLength > 0);
- if (sizeof(FX_WCHAR) == 2) {
- return;
- }
- const FX_WCHAR* pSrc = (const FX_WCHAR*)pBuffer;
- uint16_t* pDst = (uint16_t*)pBuffer;
- while (--iLength >= 0) {
- *pDst++ = (uint16_t)*pSrc++;
- }
-}
-void FX_WCharToUTF16Copy(const FX_WCHAR* pWChar,
- uint16_t* pUTF16,
- int32_t iLength) {
- ASSERT(pWChar != NULL && pUTF16 != NULL && iLength > 0);
- if (sizeof(FX_WCHAR) == 2) {
- FXSYS_memcpy(pUTF16, pWChar, iLength * sizeof(FX_WCHAR));
- } else {
- while (--iLength >= 0) {
- *pUTF16++ = (uint16_t)*pWChar++;
- }
- }
-}
-inline uint32_t FX_DWordFromBytes(const uint8_t* pStr) {
- return FXBSTR_ID(pStr[3], pStr[2], pStr[1], pStr[0]);
-}
-inline uint16_t FX_WordFromBytes(const uint8_t* pStr) {
- return (pStr[1] << 8 | pStr[0]);
-}
-int32_t FX_DecodeString(uint16_t wCodePage,
- const FX_CHAR* pSrc,
- int32_t* pSrcLen,
- FX_WCHAR* pDst,
- int32_t* pDstLen,
- FX_BOOL bErrBreak) {
- if (wCodePage == FX_CODEPAGE_UTF8) {
- return FX_UTF8Decode(pSrc, pSrcLen, pDst, pDstLen);
- }
- return -1;
-}
-int32_t FX_UTF8Decode(const FX_CHAR* pSrc,
- int32_t* pSrcLen,
- FX_WCHAR* pDst,
- int32_t* pDstLen) {
- if (pSrcLen == NULL || pDstLen == NULL) {
- return -1;
- }
- int32_t iSrcLen = *pSrcLen;
- if (iSrcLen < 1) {
- *pSrcLen = *pDstLen = 0;
- return 1;
- }
- int32_t iDstLen = *pDstLen;
- FX_BOOL bValidDst = (pDst != NULL && iDstLen > 0);
- uint32_t dwCode = 0;
- int32_t iPending = 0;
- int32_t iSrcNum = 0, iDstNum = 0;
- int32_t k = 0;
- int32_t iIndex = 0;
- k = 1;
- while (iIndex < iSrcLen) {
- uint8_t byte = (uint8_t) * (pSrc + iIndex);
- if (byte < 0x80) {
- iPending = 0;
- k = 1;
- iDstNum++;
- iSrcNum += k;
- if (bValidDst) {
- *pDst++ = byte;
- if (iDstNum >= iDstLen) {
- break;
- }
- }
- } else if (byte < 0xc0) {
- if (iPending < 1) {
- break;
- }
- iPending--;
- dwCode |= (byte & 0x3f) << (iPending * 6);
- if (iPending == 0) {
- iDstNum++;
- iSrcNum += k;
- if (bValidDst) {
- *pDst++ = dwCode;
- if (iDstNum >= iDstLen) {
- break;
- }
- }
- }
- } else if (byte < 0xe0) {
- iPending = 1;
- k = 2;
- dwCode = (byte & 0x1f) << 6;
- } else if (byte < 0xf0) {
- iPending = 2;
- k = 3;
- dwCode = (byte & 0x0f) << 12;
- } else if (byte < 0xf8) {
- iPending = 3;
- k = 4;
- dwCode = (byte & 0x07) << 18;
- } else if (byte < 0xfc) {
- iPending = 4;
- k = 5;
- dwCode = (byte & 0x03) << 24;
- } else if (byte < 0xfe) {
- iPending = 5;
- k = 6;
- dwCode = (byte & 0x01) << 30;
- } else {
- break;
- }
- iIndex++;
- }
- *pSrcLen = iSrcNum;
- *pDstLen = iDstNum;
- return 1;
-}
diff --git a/xfa/fgas/crt/fgas_memory.cpp b/xfa/fgas/crt/fgas_memory.cpp
index 9176466a61..d218f42aa4 100644
--- a/xfa/fgas/crt/fgas_memory.cpp
+++ b/xfa/fgas/crt/fgas_memory.cpp
@@ -20,6 +20,7 @@ class CFX_DefStore : public IFX_MemoryAllocator, public CFX_Target {
public:
CFX_DefStore() {}
~CFX_DefStore() override {}
+
void* Alloc(size_t size) override { return FX_Alloc(uint8_t, size); }
void Free(void* pBlock) override { FX_Free(pBlock); }
};
@@ -44,12 +45,13 @@ struct FX_STATICSTORECHUNK {
class CFX_StaticStore : public IFX_MemoryAllocator, public CFX_Target {
public:
- CFX_StaticStore(size_t iDefChunkSize = 4096);
+ CFX_StaticStore(size_t iDefChunkSize);
~CFX_StaticStore() override;
+
void* Alloc(size_t size) override;
void Free(void* pBlock) override {}
- protected:
+ private:
size_t m_iAllocatedSize;
size_t m_iDefChunkSize;
FX_STATICSTORECHUNK* m_pChunk;
@@ -74,7 +76,7 @@ class CFX_FixedStore : public IFX_MemoryAllocator, public CFX_Target {
void* Alloc(size_t size) override;
void Free(void* pBlock) override;
- protected:
+ private:
FX_FIXEDSTORECHUNK* AllocChunk();
size_t m_iBlockSize;
diff --git a/xfa/fgas/crt/fgas_stream.cpp b/xfa/fgas/crt/fgas_stream.cpp
index 73e5a02aa0..59eb99bcf0 100644
--- a/xfa/fgas/crt/fgas_stream.cpp
+++ b/xfa/fgas/crt/fgas_stream.cpp
@@ -6,6 +6,11 @@
#include "xfa/fgas/crt/fgas_stream.h"
+#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \
+ _FX_OS_ == _FX_WIN64_
+#include <io.h>
+#endif
+
#include <algorithm>
#include <memory>
@@ -299,38 +304,34 @@ class CFGAS_FileRead : public IFX_FileRead {
IFX_Stream* m_pStream;
};
-class CFX_BufferAccImp : public IFX_FileRead {
- public:
- CFX_BufferAccImp(IFX_BufferRead* pBufferRead,
- FX_FILESIZE iFileSize,
- FX_BOOL bReleaseStream);
- virtual ~CFX_BufferAccImp();
- virtual void Release() { delete this; }
- virtual FX_FILESIZE GetSize();
- virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size);
-
- protected:
- IFX_BufferRead* m_pBufferRead;
- FX_BOOL m_bReleaseStream;
- FX_FILESIZE m_iBufSize;
-};
-
-class CFGAS_FileWrite : public IFX_FileWrite {
- public:
- CFGAS_FileWrite(IFX_Stream* pStream, FX_BOOL bReleaseStream);
- virtual ~CFGAS_FileWrite();
- virtual void Release() { delete this; }
- virtual FX_FILESIZE GetSize();
- virtual FX_BOOL Flush();
- virtual FX_BOOL WriteBlock(const void* pData, size_t size);
- virtual FX_BOOL WriteBlock(const void* pData,
- FX_FILESIZE offset,
- size_t size);
+int32_t FileLength(FXSYS_FILE* file) {
+ ASSERT(file != NULL);
+#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
+ return _filelength(_fileno(file));
+#else
+ int32_t iPos = FXSYS_ftell(file);
+ FXSYS_fseek(file, 0, FXSYS_SEEK_END);
+ int32_t iLen = FXSYS_ftell(file);
+ FXSYS_fseek(file, iPos, FXSYS_SEEK_SET);
+ return iLen;
+#endif
+}
- protected:
- IFX_Stream* m_pStream;
- FX_BOOL m_bReleaseStream;
-};
+FX_BOOL FileSetSize(FXSYS_FILE* file, int32_t size) {
+ ASSERT(file != NULL);
+#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
+ return _chsize(_fileno(file), size) == 0;
+#elif _FX_OS_ == _FX_WIN32_MOBILE_
+ HANDLE hFile = _fileno(file);
+ uint32_t dwPos = ::SetFilePointer(hFile, 0, 0, FILE_CURRENT);
+ ::SetFilePointer(hFile, size, 0, FILE_BEGIN);
+ FX_BOOL bRet = ::SetEndOfFile(hFile);
+ ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN);
+ return bRet;
+#else
+ return FALSE;
+#endif
+}
} // namespace
@@ -439,7 +440,7 @@ FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName,
return FALSE;
if (dwAccess & FX_STREAMACCESS_Truncate)
- FX_fsetsize(m_hFile, 0);
+ FileSetSize(m_hFile, 0);
}
} else {
return FALSE;
@@ -469,7 +470,7 @@ FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName,
return FALSE;
}
if (dwAccess & FX_STREAMACCESS_Truncate) {
- FX_fsetsize(m_hFile, 0);
+ FileSetSize(m_hFile, 0);
}
}
} else {
@@ -482,7 +483,7 @@ FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName,
(FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) {
m_iLength = 0;
} else {
- m_iLength = FX_filelength(m_hFile);
+ m_iLength = FileLength(m_hFile);
}
return TRUE;
}
@@ -564,8 +565,8 @@ void CFX_FileStreamImp::Flush() {
}
FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) {
ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0);
- FX_BOOL bRet = FX_fsetsize(m_hFile, iLength);
- m_iLength = FX_filelength(m_hFile);
+ FX_BOOL bRet = FileSetSize(m_hFile, iLength);
+ m_iLength = FileLength(m_hFile);
return bRet;
}
CFX_FileReadStreamImp::CFX_FileReadStreamImp()
@@ -1509,131 +1510,3 @@ FX_BOOL CFGAS_FileRead::ReadBlock(void* buffer,
int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size);
return iLen == (int32_t)size;
}
-
-IFX_FileRead* FX_CreateFileRead(IFX_BufferRead* pBufferRead,
- FX_FILESIZE iFileSize,
- FX_BOOL bReleaseStream) {
- if (!pBufferRead) {
- return NULL;
- }
- return new CFX_BufferAccImp(pBufferRead, iFileSize, bReleaseStream);
-}
-CFX_BufferAccImp::CFX_BufferAccImp(IFX_BufferRead* pBufferRead,
- FX_FILESIZE iFileSize,
- FX_BOOL bReleaseStream)
- : m_pBufferRead(pBufferRead),
- m_bReleaseStream(bReleaseStream),
- m_iBufSize(iFileSize) {
- ASSERT(m_pBufferRead);
-}
-CFX_BufferAccImp::~CFX_BufferAccImp() {
- if (m_bReleaseStream && m_pBufferRead) {
- m_pBufferRead->Release();
- }
-}
-FX_FILESIZE CFX_BufferAccImp::GetSize() {
- if (!m_pBufferRead) {
- return 0;
- }
- if (m_iBufSize >= 0) {
- return m_iBufSize;
- }
- if (!m_pBufferRead->ReadNextBlock(TRUE)) {
- return 0;
- }
- m_iBufSize = (FX_FILESIZE)m_pBufferRead->GetBlockSize();
- while (!m_pBufferRead->IsEOF()) {
- m_pBufferRead->ReadNextBlock(FALSE);
- m_iBufSize += (FX_FILESIZE)m_pBufferRead->GetBlockSize();
- }
- return m_iBufSize;
-}
-FX_BOOL CFX_BufferAccImp::ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) {
- if (!m_pBufferRead) {
- return FALSE;
- }
- if (!buffer || !size) {
- return TRUE;
- }
- FX_FILESIZE dwBufSize = GetSize();
- if (offset >= dwBufSize) {
- return FALSE;
- }
- size_t dwBlockSize = m_pBufferRead->GetBlockSize();
- FX_FILESIZE dwBlockOffset = m_pBufferRead->GetBlockOffset();
- if (offset < dwBlockOffset) {
- if (!m_pBufferRead->ReadNextBlock(TRUE)) {
- return FALSE;
- }
- dwBlockSize = m_pBufferRead->GetBlockSize();
- dwBlockOffset = m_pBufferRead->GetBlockOffset();
- }
- while (offset < dwBlockOffset ||
- offset >= (FX_FILESIZE)(dwBlockOffset + dwBlockSize)) {
- if (m_pBufferRead->IsEOF() || !m_pBufferRead->ReadNextBlock(FALSE)) {
- break;
- }
- dwBlockSize = m_pBufferRead->GetBlockSize();
- dwBlockOffset = m_pBufferRead->GetBlockOffset();
- }
- if (offset < dwBlockOffset ||
- offset >= (FX_FILESIZE)(dwBlockOffset + dwBlockSize)) {
- return FALSE;
- }
- const uint8_t* pBuffer = m_pBufferRead->GetBlockBuffer();
- const FX_FILESIZE dwOffset = offset - dwBlockOffset;
- size_t dwCopySize =
- std::min(size, static_cast<size_t>(dwBlockSize - dwOffset));
- FXSYS_memcpy(buffer, pBuffer + dwOffset, dwCopySize);
- offset = dwCopySize;
- size -= dwCopySize;
- while (size) {
- if (!m_pBufferRead->ReadNextBlock(FALSE)) {
- break;
- }
- dwBlockOffset = m_pBufferRead->GetBlockOffset();
- dwBlockSize = m_pBufferRead->GetBlockSize();
- pBuffer = m_pBufferRead->GetBlockBuffer();
- dwCopySize = std::min(size, dwBlockSize);
- FXSYS_memcpy(((uint8_t*)buffer) + offset, pBuffer, dwCopySize);
- offset += dwCopySize;
- size -= dwCopySize;
- }
- return TRUE;
-}
-
-IFX_FileWrite* FX_CreateFileWrite(IFX_Stream* pBaseStream,
- FX_BOOL bReleaseStream) {
- ASSERT(pBaseStream != NULL);
- return new CFGAS_FileWrite(pBaseStream, bReleaseStream);
-}
-
-CFGAS_FileWrite::CFGAS_FileWrite(IFX_Stream* pStream, FX_BOOL bReleaseStream)
- : m_pStream(pStream), m_bReleaseStream(bReleaseStream) {
- ASSERT(m_pStream != NULL);
-}
-CFGAS_FileWrite::~CFGAS_FileWrite() {
- if (m_bReleaseStream) {
- m_pStream->Release();
- }
-}
-FX_FILESIZE CFGAS_FileWrite::GetSize() {
- return m_pStream->GetLength();
-}
-FX_BOOL CFGAS_FileWrite::Flush() {
- m_pStream->Flush();
- return TRUE;
-}
-FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData, size_t size) {
- return m_pStream->WriteData((const uint8_t*)pData, (int32_t)size) ==
- (int32_t)size;
-}
-FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData,
- FX_FILESIZE offset,
- size_t size) {
- m_pStream->Seek(FX_STREAMSEEK_Begin, offset);
- int32_t iLen = m_pStream->WriteData((uint8_t*)pData, (int32_t)size);
- return iLen == (int32_t)size;
-}
diff --git a/xfa/fgas/crt/fgas_stream.h b/xfa/fgas/crt/fgas_stream.h
index 3d644cf8b4..2da06fc7ed 100644
--- a/xfa/fgas/crt/fgas_stream.h
+++ b/xfa/fgas/crt/fgas_stream.h
@@ -14,11 +14,7 @@ class IFX_Stream;
IFX_FileRead* FX_CreateFileRead(IFX_Stream* pBaseStream,
FX_BOOL bReleaseStream = FALSE);
-IFX_FileRead* FX_CreateFileRead(IFX_BufferRead* pBufferRead,
- FX_FILESIZE iFileSize = -1,
- FX_BOOL bReleaseStream = TRUE);
-IFX_FileWrite* FX_CreateFileWrite(IFX_Stream* pBaseStream,
- FX_BOOL bReleaseStream = FALSE);
+
enum FX_STREAMACCESS {
FX_STREAMACCESS_Binary = 0x00,
FX_STREAMACCESS_Text = 0x01,
diff --git a/xfa/fgas/crt/fgas_system.cpp b/xfa/fgas/crt/fgas_system.cpp
index 3ab39268ef..43d55b108a 100644
--- a/xfa/fgas/crt/fgas_system.cpp
+++ b/xfa/fgas/crt/fgas_system.cpp
@@ -10,13 +10,6 @@
#include "core/fxcrt/include/fx_system.h"
-#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \
- _FX_OS_ == _FX_WIN64_
-#include <io.h>
-#elif _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_LINUX_Mini_
-#include <sys/times.h>
-#endif
-
namespace {
inline FX_BOOL FX_isupper(int32_t ch) {
@@ -43,35 +36,6 @@ int32_t FX_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count) {
return wch1 - wch2;
}
-int32_t FX_filelength(FXSYS_FILE* file) {
- ASSERT(file != NULL);
-#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
- return _filelength(_fileno(file));
-#else
- int32_t iPos = FXSYS_ftell(file);
- FXSYS_fseek(file, 0, FXSYS_SEEK_END);
- int32_t iLen = FXSYS_ftell(file);
- FXSYS_fseek(file, iPos, FXSYS_SEEK_SET);
- return iLen;
-#endif
-}
-
-FX_BOOL FX_fsetsize(FXSYS_FILE* file, int32_t size) {
- ASSERT(file != NULL);
-#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
- return _chsize(_fileno(file), size) == 0;
-#elif _FX_OS_ == _FX_WIN32_MOBILE_
- HANDLE hFile = _fileno(file);
- uint32_t dwPos = ::SetFilePointer(hFile, 0, 0, FILE_CURRENT);
- ::SetFilePointer(hFile, size, 0, FILE_BEGIN);
- FX_BOOL bRet = ::SetEndOfFile(hFile);
- ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN);
- return bRet;
-#else
- return FALSE;
-#endif
-}
-
FX_FLOAT FX_wcstof(const FX_WCHAR* pwsStr, int32_t iLength, int32_t* pUsedLen) {
ASSERT(pwsStr != NULL);
if (iLength < 0) {
diff --git a/xfa/fgas/crt/fgas_system.h b/xfa/fgas/crt/fgas_system.h
index d4bebcadff..a3215ffa37 100644
--- a/xfa/fgas/crt/fgas_system.h
+++ b/xfa/fgas/crt/fgas_system.h
@@ -9,15 +9,9 @@
#include "core/fxcrt/include/fx_system.h"
-#define FX_RAD2DEG(r) ((r)*180.0f / FX_PI)
-#define FX_DEG2RAD(a) ((a)*FX_PI / 180.0f)
-
FX_FLOAT FX_wcstof(const FX_WCHAR* pwsStr,
int32_t iLength = -1,
int32_t* pUsedLen = NULL);
int32_t FX_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count);
-int32_t FX_filelength(FXSYS_FILE* file);
-FX_BOOL FX_fsetsize(FXSYS_FILE* file, int32_t size);
-
#endif // XFA_FGAS_CRT_FGAS_SYSTEM_H_