diff options
24 files changed, 274 insertions, 126 deletions
@@ -1397,6 +1397,7 @@ test("pdfium_unittests") { "core/src/fxcrt/fx_basic_bstring_unittest.cpp", "core/src/fxcrt/fx_basic_memmgr_unittest.cpp", "core/src/fxcrt/fx_basic_wstring_unittest.cpp", + "core/src/fxcrt/fx_system_unittest.cpp", "testing/fx_string_testhelpers.cpp", "testing/fx_string_testhelpers.h", "third_party/base/nonstd_unique_ptr_unittest.cpp", diff --git a/core/include/fxcrt/fx_ucd.h b/core/include/fxcrt/fx_ucd.h index fb417189a1..823b80700a 100644 --- a/core/include/fxcrt/fx_ucd.h +++ b/core/include/fxcrt/fx_ucd.h @@ -53,27 +53,37 @@ enum FX_CHARBREAKPROP { #define FX_BIDICLASSBITS 6 #define FX_BIDICLASSBITSMASK (31 << FX_BIDICLASSBITS) enum FX_BIDICLASS { - FX_BIDICLASS_ON = 0, - FX_BIDICLASS_L = 1, - FX_BIDICLASS_R = 2, - FX_BIDICLASS_AN = 3, - FX_BIDICLASS_EN = 4, - FX_BIDICLASS_AL = 5, - FX_BIDICLASS_NSM = 6, - FX_BIDICLASS_CS = 7, - FX_BIDICLASS_ES = 8, - FX_BIDICLASS_ET = 9, - FX_BIDICLASS_BN = 10, - FX_BIDICLASS_S = 11, - FX_BIDICLASS_WS = 12, - FX_BIDICLASS_B = 13, - FX_BIDICLASS_RLO = 14, - FX_BIDICLASS_RLE = 15, - FX_BIDICLASS_LRO = 16, - FX_BIDICLASS_LRE = 17, - FX_BIDICLASS_PDF = 18, + FX_BIDICLASS_ON = 0, // Other Neutral + FX_BIDICLASS_L = 1, // Left Letter + FX_BIDICLASS_R = 2, // Right Letter + FX_BIDICLASS_AN = 3, // Arabic Number + FX_BIDICLASS_EN = 4, // European Number + FX_BIDICLASS_AL = 5, // Arabic Letter + FX_BIDICLASS_NSM = 6, // Non-spacing Mark + FX_BIDICLASS_CS = 7, // Common Number Separator + FX_BIDICLASS_ES = 8, // European Separator + FX_BIDICLASS_ET = 9, // European Number Terminator + FX_BIDICLASS_BN = 10, // Boundary Neutral + FX_BIDICLASS_S = 11, // Segment Separator + FX_BIDICLASS_WS = 12, // Whitespace + FX_BIDICLASS_B = 13, // Paragraph Separator + FX_BIDICLASS_RLO = 14, // Right-to-Left Override + FX_BIDICLASS_RLE = 15, // Right-to-Left Embedding + FX_BIDICLASS_LRO = 16, // Left-to-Right Override + FX_BIDICLASS_LRE = 17, // Left-to-Right Embedding + FX_BIDICLASS_PDF = 18, // Pop Directional Format FX_BIDICLASS_N = FX_BIDICLASS_ON, }; + +extern const FX_DWORD kTextLayoutCodeProperties[]; +extern const size_t kTextLayoutCodePropertiesSize; + +extern const FX_WCHAR kFXTextLayoutVerticalMirror[]; +extern const size_t kFXTextLayoutVerticalMirrorSize; + +extern const FX_WCHAR kFXTextLayoutBidiMirror[]; +extern const size_t kFXTextLayoutBidiMirrorSize; + #define FX_CHARTYPEBITS 11 #define FX_CHARTYPEBITSMASK (15 << FX_CHARTYPEBITS) enum FX_CHARTYPE { diff --git a/core/src/fxcrt/fx_arabic.cpp b/core/src/fxcrt/fx_arabic.cpp index ab736f9769..139e9f1f48 100644 --- a/core/src/fxcrt/fx_arabic.cpp +++ b/core/src/fxcrt/fx_arabic.cpp @@ -7,7 +7,6 @@ #include "../../include/fxcrt/fx_ucd.h" #include "fx_arabic.h" -extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536]; #ifdef __cplusplus extern "C" { #endif @@ -149,19 +148,19 @@ IFX_ArabicChar* IFX_ArabicChar::Create() { } FX_BOOL CFX_ArabicChar::IsArabicChar(FX_WCHAR wch) const { FX_DWORD dwRet = - (gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK); + kTextLayoutCodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK; return dwRet >= FX_CHARTYPE_ArabicAlef; } FX_BOOL CFX_ArabicChar::IsArabicFormChar(FX_WCHAR wch) const { - return (gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & - FX_CHARTYPEBITSMASK) == FX_CHARTYPE_ArabicForm; + return (kTextLayoutCodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK) == + FX_CHARTYPE_ArabicForm; } FX_WCHAR CFX_ArabicChar::GetFormChar(FX_WCHAR wch, FX_WCHAR prev, FX_WCHAR next) const { - CFX_Char c(wch, gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]); - CFX_Char p(prev, gs_FX_TextLayout_CodeProperties[(FX_WORD)prev]); - CFX_Char n(next, gs_FX_TextLayout_CodeProperties[(FX_WORD)next]); + CFX_Char c(wch, kTextLayoutCodeProperties[(FX_WORD)wch]); + CFX_Char p(prev, kTextLayoutCodeProperties[(FX_WORD)prev]); + CFX_Char n(next, kTextLayoutCodeProperties[(FX_WORD)next]); return GetFormChar(&c, &p, &n); } FX_WCHAR CFX_ArabicChar::GetFormChar(const CFX_Char* cur, @@ -260,17 +259,17 @@ void FX_BidiClassify(const CFX_WideString& wsText, if (bWS) { for (int32_t i = 0; i < iCount; i++) { wch = *pwsStart++; - iCls = ((gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & - FX_BIDICLASSBITSMASK) >> - FX_BIDICLASSBITS); + iCls = + ((kTextLayoutCodeProperties[(FX_WORD)wch] & FX_BIDICLASSBITSMASK) >> + FX_BIDICLASSBITS); classes.SetAt(i, iCls); } } else { for (int32_t i = 0; i < iCount; i++) { wch = *pwsStart++; - iCls = ((gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & - FX_BIDICLASSBITSMASK) >> - FX_BIDICLASSBITS); + iCls = + ((kTextLayoutCodeProperties[(FX_WORD)wch] & FX_BIDICLASSBITSMASK) >> + FX_BIDICLASSBITS); classes.SetAt(i, gc_FX_BidiNTypes[iCls]); } } @@ -1070,7 +1069,7 @@ void CFX_BidiChar::SetPolicy(FX_BOOL bSeparateNeutral) { } FX_BOOL CFX_BidiChar::AppendChar(FX_WCHAR wch) { - FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; + FX_DWORD dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; int32_t iContext = 0; switch (iBidiCls) { diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp index bf3d61524e..6f17482156 100644 --- a/core/src/fxcrt/fx_basic_gcc.cpp +++ b/core/src/fxcrt/fx_basic_gcc.cpp @@ -32,30 +32,41 @@ T FXSYS_StrToInt(STR_T str) { } return neg ? -num : num; } -template <typename T, typename STR_T> + +template <typename T, typename UT, typename STR_T> STR_T FXSYS_IntToStr(T value, STR_T string, int radix) { - int i = 0; - if (value < 0) { - string[i++] = '-'; - value = -value; - } else if (value == 0) { + if (radix < 2 || radix > 16) { + string[0] = 0; + return string; + } + if (value == 0) { string[0] = '0'; string[1] = 0; return string; } + int i = 0; + UT uvalue; + if (value < 0) { + string[i++] = '-'; + // Standard trick to avoid undefined behaviour when negating INT_MIN. + uvalue = static_cast<UT>(-(value + 1)) + 1; + } else { + uvalue = value; + } int digits = 1; - T order = value / 10; + T order = uvalue / radix; while (order > 0) { digits++; - order = order / 10; + order = order / radix; } for (int d = digits - 1; d > -1; d--) { - string[d + i] = "0123456789abcdef"[value % 10]; - value /= 10; + string[d + i] = "0123456789abcdef"[uvalue % radix]; + uvalue /= radix; } string[digits + i] = 0; return string; } + #ifdef __cplusplus extern "C" { #endif @@ -72,10 +83,7 @@ int64_t FXSYS_wtoi64(const FX_WCHAR* str) { return FXSYS_StrToInt<int64_t, const FX_WCHAR*>(str); } const FX_CHAR* FXSYS_i64toa(int64_t value, FX_CHAR* str, int radix) { - return FXSYS_IntToStr<int64_t, FX_CHAR*>(value, str, radix); -} -const FX_WCHAR* FXSYS_i64tow(int64_t value, FX_WCHAR* str, int radix) { - return FXSYS_IntToStr<int64_t, FX_WCHAR*>(value, str, radix); + return FXSYS_IntToStr<int64_t, uint64_t, FX_CHAR*>(value, str, radix); } #ifdef __cplusplus } @@ -182,7 +190,7 @@ int FXSYS_wcsicmp(const FX_WCHAR* dst, const FX_WCHAR* src) { return (f - l); } char* FXSYS_itoa(int value, char* string, int radix) { - return FXSYS_IntToStr<int32_t, FX_CHAR*>(value, string, radix); + return FXSYS_IntToStr<int32_t, uint32_t, FX_CHAR*>(value, string, radix); } #ifdef __cplusplus } diff --git a/core/src/fxcrt/fx_system_unittest.cpp b/core/src/fxcrt/fx_system_unittest.cpp new file mode 100644 index 0000000000..824ed5370c --- /dev/null +++ b/core/src/fxcrt/fx_system_unittest.cpp @@ -0,0 +1,161 @@ +// Copyright 2015 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. + +#include <string> + +#include "testing/gtest/include/gtest/gtest.h" +#include "../../../testing/fx_string_testhelpers.h" +#include "../../include/fxcrt/fx_system.h" + +// Unit test covering cases where PDFium replaces well-known library +// functionality on any given platformn. + +#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + +namespace { + +const FX_CHAR kSentinel = 0x7f; + +void Check32BitBase16Itoa(int32_t input, const char* expected_output) { + const size_t kBufLen = 11; // "-" + 8 digits + NUL + sentinel. + FX_CHAR buf[kBufLen]; + buf[kBufLen - 1] = kSentinel; + FXSYS_itoa(input, buf, 16); + EXPECT_EQ(std::string(expected_output), buf); + EXPECT_EQ(kSentinel, buf[kBufLen - 1]); +} + +void Check32BitBase10Itoa(int32_t input, const char* expected_output) { + const size_t kBufLen = 13; // "-" + 10 digits + NUL + sentinel. + FX_CHAR buf[kBufLen]; + buf[kBufLen - 1] = kSentinel; + FXSYS_itoa(input, buf, 10); + EXPECT_EQ(std::string(expected_output), buf); + EXPECT_EQ(kSentinel, buf[kBufLen - 1]); +} + +void Check32BitBase2Itoa(int32_t input, const char* expected_output) { + const size_t kBufLen = 35; // "-" + 32 digits + NUL + sentinel. + FX_CHAR buf[kBufLen]; + buf[kBufLen - 1] = kSentinel; + FXSYS_itoa(input, buf, 2); + EXPECT_EQ(std::string(expected_output), buf); + EXPECT_EQ(kSentinel, buf[kBufLen - 1]); +} + +void Check64BitBase16Itoa(int64_t input, const char* expected_output) { + const size_t kBufLen = 19; // "-" + 16 digits + NUL + sentinel. + FX_CHAR buf[kBufLen]; + buf[kBufLen - 1] = kSentinel; + FXSYS_i64toa(input, buf, 16); + EXPECT_EQ(std::string(expected_output), buf); + EXPECT_EQ(kSentinel, buf[kBufLen - 1]); +} + +void Check64BitBase10Itoa(int64_t input, const char* expected_output) { + const size_t kBufLen = 22; // "-" + 19 digits + NUL + sentinel. + FX_CHAR buf[kBufLen]; + buf[kBufLen - 1] = kSentinel; + FXSYS_i64toa(input, buf, 10); + EXPECT_EQ(std::string(expected_output), buf); + EXPECT_EQ(kSentinel, buf[kBufLen - 1]); +} + +void Check64BitBase2Itoa(int64_t input, const char* expected_output) { + const size_t kBufLen = 67; // "-" + 64 digits + NUL + sentinel. + FX_CHAR buf[kBufLen]; + buf[kBufLen - 1] = kSentinel; + FXSYS_i64toa(input, buf, 2); + EXPECT_EQ(std::string(expected_output), buf); + EXPECT_EQ(kSentinel, buf[kBufLen - 1]); +} + +} // namespace + +TEST(fxcrt, FXSYS_itoa_InvalidRadix) { + FX_CHAR buf[32]; + + FXSYS_itoa(42, buf, 17); // Ours stops at 16. + EXPECT_EQ(std::string(""), buf); + + FXSYS_itoa(42, buf, 1); + EXPECT_EQ(std::string(""), buf); + + FXSYS_itoa(42, buf, 0); + EXPECT_EQ(std::string(""), buf); + + FXSYS_itoa(42, buf, -1); + EXPECT_EQ(std::string(""), buf); +} + +TEST(fxcrt, FXSYS_itoa) { + Check32BitBase16Itoa(std::numeric_limits<int32_t>::min(), "-80000000"); + Check32BitBase10Itoa(std::numeric_limits<int32_t>::min(), "-2147483648"); + Check32BitBase2Itoa(std::numeric_limits<int32_t>::min(), + "-10000000000000000000000000000000"); + + Check32BitBase16Itoa(-1, "-1"); + Check32BitBase10Itoa(-1, "-1"); + Check32BitBase2Itoa(-1, "-1"); + + Check32BitBase16Itoa(0, "0"); + Check32BitBase10Itoa(0, "0"); + Check32BitBase2Itoa(0, "0"); + + Check32BitBase16Itoa(42, "2a"); + Check32BitBase10Itoa(42, "42"); + Check32BitBase2Itoa(42, "101010"); + + Check32BitBase16Itoa(std::numeric_limits<int32_t>::max(), "7fffffff"); + Check32BitBase10Itoa(std::numeric_limits<int32_t>::max(), "2147483647"); + Check32BitBase2Itoa(std::numeric_limits<int32_t>::max(), + "1111111111111111111111111111111"); +} + +TEST(fxcrt, FXSYS_i64toa_InvalidRadix) { + FX_CHAR buf[32]; + + FXSYS_i64toa(42, buf, 17); // Ours stops at 16. + EXPECT_EQ(std::string(""), buf); + + FXSYS_i64toa(42, buf, 1); + EXPECT_EQ(std::string(""), buf); + + FXSYS_i64toa(42, buf, 0); + EXPECT_EQ(std::string(""), buf); + + FXSYS_i64toa(42, buf, -1); + EXPECT_EQ(std::string(""), buf); +}; + +TEST(fxcrt, FXSYS_i64toa) { + Check64BitBase16Itoa(std::numeric_limits<int64_t>::min(), + "-8000000000000000"); + Check64BitBase10Itoa(std::numeric_limits<int64_t>::min(), + "-9223372036854775808"); + Check64BitBase2Itoa( + std::numeric_limits<int64_t>::min(), + "-1000000000000000000000000000000000000000000000000000000000000000"); + + Check64BitBase16Itoa(-1, "-1"); + Check64BitBase10Itoa(-1, "-1"); + Check64BitBase2Itoa(-1, "-1"); + + Check64BitBase16Itoa(0, "0"); + Check64BitBase10Itoa(0, "0"); + Check64BitBase2Itoa(0, "0"); + + Check64BitBase16Itoa(42, "2a"); + Check64BitBase10Itoa(42, "42"); + Check64BitBase2Itoa(42, "101010"); + + Check64BitBase16Itoa(std::numeric_limits<int64_t>::max(), "7fffffffffffffff"); + Check64BitBase10Itoa(std::numeric_limits<int64_t>::max(), + "9223372036854775807"); + Check64BitBase2Itoa( + std::numeric_limits<int64_t>::max(), + "111111111111111111111111111111111111111111111111111111111111111"); +} + +#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ diff --git a/core/src/fxcrt/fx_ucddata.cpp b/core/src/fxcrt/fx_ucddata.cpp index 8b35f31e2b..13c5da1419 100644 --- a/core/src/fxcrt/fx_ucddata.cpp +++ b/core/src/fxcrt/fx_ucddata.cpp @@ -4,9 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "../../include/fxcrt/fx_system.h" +#include "../../include/fxcrt/fx_basic.h" +#include "../../include/fxcrt/fx_ucd.h" -extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536] = { +const FX_DWORD kTextLayoutCodeProperties[] = { 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe8ae5, 0xfffe9b5c, 0xfffe9ada, 0xfffe9b1a, 0xfffe9b5b, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, 0xfffe9a93, @@ -10931,7 +10932,11 @@ extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536] = { 0xfffe02a4, 0xfffe02a4, 0xfffe02a4, 0xfffe3013, 0xfffe3013, 0xfffe3013, 0xfffe3011, 0xfffe3022, 0xfffe1aa4, 0xfffe1aa4, }; -extern const FX_WCHAR gs_FX_TextLayout_VerticalMirror[64] = { + +const size_t kTextLayoutCodePropertiesSize = + FX_ArraySize(kTextLayoutCodeProperties); + +const FX_WCHAR kFXTextLayoutVerticalMirror[] = { 0xFE33, 0xFE32, 0xFE31, 0xFE41, 0xFE42, 0xFE43, 0xFE44, 0xFE3F, 0xFE40, 0xFE3D, 0xFE3E, 0xFE41, 0xFE42, 0xFE43, 0xFE44, 0xFE3B, 0xFE3C, 0xFE39, 0xFE3A, 0xFE34, 0xFE35, 0xFE36, 0xFE37, 0xFE38, @@ -10941,7 +10946,10 @@ extern const FX_WCHAR gs_FX_TextLayout_VerticalMirror[64] = { 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, }; -extern const FX_WCHAR gs_FX_TextLayout_BidiMirror[512] = { +const size_t kFXTextLayoutVerticalMirrorSize = + FX_ArraySize(kFXTextLayoutVerticalMirror); + +const FX_WCHAR kFXTextLayoutBidiMirror[] = { 0x0029, 0x0028, 0x003E, 0x003C, 0x005D, 0x005B, 0x007D, 0x007B, 0x00BB, 0x00AB, 0x0F3B, 0x0F3A, 0x0F3D, 0x0F3C, 0x169C, 0x169B, 0x2019, 0x2018, 0x201D, 0x201C, 0x203A, 0x2039, 0x2046, 0x2045, 0x207E, 0x207D, 0x208E, @@ -11000,3 +11008,6 @@ extern const FX_WCHAR gs_FX_TextLayout_BidiMirror[512] = { 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF, }; + +const size_t kFXTextLayoutBidiMirrorSize = + FX_ArraySize(kFXTextLayoutBidiMirror); diff --git a/core/src/fxcrt/fx_unicode.cpp b/core/src/fxcrt/fx_unicode.cpp index f05aeb5efb..67ff009513 100644 --- a/core/src/fxcrt/fx_unicode.cpp +++ b/core/src/fxcrt/fx_unicode.cpp @@ -6,41 +6,38 @@ #include "../../include/fxcrt/fx_ucd.h" -extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536]; -extern const FX_WCHAR gs_FX_TextLayout_VerticalMirror[64]; -extern const FX_WCHAR gs_FX_TextLayout_BidiMirror[512]; FX_DWORD FX_GetUnicodeProperties(FX_WCHAR wch) { - return gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; + return kTextLayoutCodeProperties[(FX_WORD)wch]; } FX_BOOL FX_IsCtrlCode(FX_WCHAR ch) { FX_DWORD dwRet = - (gs_FX_TextLayout_CodeProperties[(FX_WORD)ch] & FX_CHARTYPEBITSMASK); + (kTextLayoutCodeProperties[(FX_WORD)ch] & FX_CHARTYPEBITSMASK); return dwRet == FX_CHARTYPE_Tab || dwRet == FX_CHARTYPE_Control; } FX_BOOL FX_IsRotationCode(FX_WCHAR ch) { - return (gs_FX_TextLayout_CodeProperties[(FX_WORD)ch] & 0x8000) != 0; + return (kTextLayoutCodeProperties[(FX_WORD)ch] & 0x8000) != 0; } FX_BOOL FX_IsCombinationChar(FX_WCHAR wch) { FX_DWORD dwProps = - (gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK); + (kTextLayoutCodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK); return dwProps == FX_CHARTYPE_Combination; } FX_BOOL FX_IsBidiChar(FX_WCHAR wch) { - FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; + FX_DWORD dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; return (FX_BIDICLASS_R == iBidiCls || FX_BIDICLASS_AL == iBidiCls); } FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_BOOL bRTL, FX_BOOL bVertical) { - FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; + FX_DWORD dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; FX_DWORD dwTemp = (dwProps & 0xFF800000); if (bRTL && dwTemp < 0xFF800000) { - wch = gs_FX_TextLayout_BidiMirror[dwTemp >> 23]; - dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; + wch = kFXTextLayoutBidiMirror[dwTemp >> 23]; + dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; } if (bVertical) { dwTemp = (dwProps & 0x007E0000); if (dwTemp < 0x007E0000) { - wch = gs_FX_TextLayout_VerticalMirror[dwTemp >> 17]; + wch = kFXTextLayoutVerticalMirror[dwTemp >> 17]; } } return wch; @@ -51,13 +48,13 @@ FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_BOOL bVertical) { FX_DWORD dwTemp = (dwProps & 0xFF800000); if (bRTL && dwTemp < 0xFF800000) { - wch = gs_FX_TextLayout_BidiMirror[dwTemp >> 23]; - dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; + wch = kFXTextLayoutBidiMirror[dwTemp >> 23]; + dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; } if (bVertical) { dwTemp = (dwProps & 0x007E0000); if (dwTemp < 0x007E0000) { - wch = gs_FX_TextLayout_VerticalMirror[dwTemp >> 17]; + wch = kFXTextLayoutVerticalMirror[dwTemp >> 17]; } } return wch; diff --git a/core/src/fxge/android/fpf_skiafontmgr.cpp b/core/src/fxge/android/fpf_skiafontmgr.cpp index 521460bea3..7e7aee3c06 100644 --- a/core/src/fxge/android/fpf_skiafontmgr.cpp +++ b/core/src/fxge/android/fpf_skiafontmgr.cpp @@ -337,7 +337,7 @@ IFPF_Font* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname, m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); return pFont->Retain(); } - pFont->Release() + pFont->Release(); } return NULL; } diff --git a/core/src/fxge/android/fpf_skiamodule.cpp b/core/src/fxge/android/fpf_skiamodule.cpp index a421a0e944..fdc3398d30 100644 --- a/core/src/fxge/android/fpf_skiamodule.cpp +++ b/core/src/fxge/android/fpf_skiamodule.cpp @@ -25,9 +25,6 @@ void CFPF_SkiaDeviceModule::Destroy() { IFPF_FontMgr* CFPF_SkiaDeviceModule::GetFontMgr() { if (!m_pFontMgr) { m_pFontMgr = new CFPF_SkiaFontMgr; - if (!m_pFontMgr) { - return NULL; - } if (!m_pFontMgr->InitFTLibrary()) { delete m_pFontMgr; return NULL; diff --git a/core/src/fxge/android/fx_android_imp.cpp b/core/src/fxge/android/fx_android_imp.cpp index 43fe3b197f..073a665560 100644 --- a/core/src/fxge/android/fx_android_imp.cpp +++ b/core/src/fxge/android/fx_android_imp.cpp @@ -14,9 +14,6 @@ void CFX_GEModule::InitPlatform() { IFPF_FontMgr* pFontMgr = pDeviceModule->GetFontMgr(); if (pFontMgr) { CFX_AndroidFontInfo* pFontInfo = new CFX_AndroidFontInfo; - if (!pFontInfo) { - return; - } pFontInfo->Init(pFontMgr); m_pFontMgr->SetSystemFontInfo(pFontInfo); } diff --git a/core/src/fxge/apple/fx_mac_imp.cpp b/core/src/fxge/apple/fx_mac_imp.cpp index 07e3d02c4c..41333f8bf4 100644 --- a/core/src/fxge/apple/fx_mac_imp.cpp +++ b/core/src/fxge/apple/fx_mac_imp.cpp @@ -96,9 +96,6 @@ void* CFX_MacFontInfo::MapFont(int weight, } IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) { CFX_MacFontInfo* pInfo = new CFX_MacFontInfo; - if (!pInfo) { - return NULL; - } pInfo->AddPath("~/Library/Fonts"); pInfo->AddPath("/Library/Fonts"); pInfo->AddPath("/System/Library/Fonts"); diff --git a/core/src/fxge/dib/fx_dib_convert.cpp b/core/src/fxge/dib/fx_dib_convert.cpp index 93e741158c..3884d0fc8e 100644 --- a/core/src/fxge/dib/fx_dib_convert.cpp +++ b/core/src/fxge/dib/fx_dib_convert.cpp @@ -1094,9 +1094,6 @@ CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, return pClone; } CFX_DIBitmap* pClone = new CFX_DIBitmap; - if (!pClone) { - return NULL; - } if (!pClone->Create(m_Width, m_Height, dest_format)) { delete pClone; return NULL; diff --git a/core/src/fxge/dib/fx_dib_engine.cpp b/core/src/fxge/dib/fx_dib_engine.cpp index 33c0333788..56bb5abafa 100644 --- a/core/src/fxge/dib/fx_dib_engine.cpp +++ b/core/src/fxge/dib/fx_dib_engine.cpp @@ -840,9 +840,6 @@ FX_BOOL CFX_ImageStretcher::StartStretch() { m_pStretchEngine = new CStretchEngine(m_pDest, m_DestFormat, m_DestWidth, m_DestHeight, m_ClipRect, m_pSource, m_Flags); - if (!m_pStretchEngine) { - return FALSE; - } m_pStretchEngine->StartStretchHorz(); if (m_pSource->GetWidth() * m_pSource->GetHeight() < MAX_PROGRESSIVE_STRETCH_PIXELS) { diff --git a/core/src/fxge/dib/fx_dib_transform.cpp b/core/src/fxge/dib/fx_dib_transform.cpp index 7a33f1d9f8..d368a95c35 100644 --- a/core/src/fxge/dib/fx_dib_transform.cpp +++ b/core/src/fxge/dib/fx_dib_transform.cpp @@ -79,9 +79,6 @@ CFX_DIBitmap* CFX_DIBSource::SwapXY(FX_BOOL bXFlip, return NULL; } CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap; - if (!pTransBitmap) { - return NULL; - } int result_height = dest_clip.Height(), result_width = dest_clip.Width(); if (!pTransBitmap->Create(result_width, result_height, GetFormat())) { delete pTransBitmap; @@ -424,9 +421,6 @@ FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause) { } int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); CFX_DIBitmap* pTransformed = new CFX_DIBitmap; - if (!pTransformed) { - return FALSE; - } FXDIB_Format transformF = _GetTransformedFormat(m_Stretcher.m_pSource); if (!pTransformed->Create(m_ResultWidth, m_ResultHeight, transformF)) { delete pTransformed; diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp index e9c9d768c8..b332ffdea2 100644 --- a/core/src/fxge/ge/fx_ge_fontmap.cpp +++ b/core/src/fxge/ge/fx_ge_fontmap.cpp @@ -138,9 +138,6 @@ FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, FX_DWORD size, int face_index) { CTTFontDesc* pFontDesc = new CTTFontDesc; - if (!pFontDesc) { - return NULL; - } pFontDesc->m_Type = 1; pFontDesc->m_SingleFace.m_pFace = NULL; pFontDesc->m_SingleFace.m_bBold = weight; @@ -336,9 +333,6 @@ FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size, FX_DWORD size, int font_offset) { CTTFontDesc* pFontDesc = new CTTFontDesc; - if (!pFontDesc) { - return NULL; - } pFontDesc->m_Type = 2; pFontDesc->m_pFontData = pData; for (int i = 0; i < 16; i++) { diff --git a/core/src/fxge/ge/fx_ge_linux.cpp b/core/src/fxge/ge/fx_ge_linux.cpp index 609777fbb5..72971f7f5d 100644 --- a/core/src/fxge/ge/fx_ge_linux.cpp +++ b/core/src/fxge/ge/fx_ge_linux.cpp @@ -91,7 +91,7 @@ void* CFX_LinuxFontInfo::MapFont(int weight, } } break; case FXFONT_GB2312_CHARSET: { - for (int32_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) { + for (size_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) { auto it = m_FontList.find(g_LinuxGbFontList[i]); if (it != m_FontList.end()) { return it->second; @@ -99,7 +99,7 @@ void* CFX_LinuxFontInfo::MapFont(int weight, } } break; case FXFONT_CHINESEBIG5_CHARSET: { - for (int32_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) { + for (size_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) { auto it = m_FontList.find(g_LinuxB5FontList[i]); if (it != m_FontList.end()) { return it->second; @@ -107,7 +107,7 @@ void* CFX_LinuxFontInfo::MapFont(int weight, } } break; case FXFONT_HANGEUL_CHARSET: { - for (int32_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) { + for (size_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) { auto it = m_FontList.find(g_LinuxHGFontList[i]); if (it != m_FontList.end()) { return it->second; diff --git a/core/src/fxge/skia/fx_skia_device.cpp b/core/src/fxge/skia/fx_skia_device.cpp index d7f448ebf6..fcd8e9871e 100644 --- a/core/src/fxge/skia/fx_skia_device.cpp +++ b/core/src/fxge/skia/fx_skia_device.cpp @@ -626,4 +626,4 @@ CFX_SkiaDevice::~CFX_SkiaDevice() { delete GetBitmap(); } -#endif
\ No newline at end of file +#endif diff --git a/core/src/fxge/win32/fx_win32_dwrite.cpp b/core/src/fxge/win32/fx_win32_dwrite.cpp index 845eb14576..5a3c16c2af 100644 --- a/core/src/fxge/win32/fx_win32_dwrite.cpp +++ b/core/src/fxge/win32/fx_win32_dwrite.cpp @@ -64,7 +64,6 @@ class CDwFontFileLoader final : public IDWriteFontFileLoader { static IDWriteFontFileLoader* GetLoader() { if (instance_ == NULL) { instance_ = new CDwFontFileLoader(); - return instance_; } return instance_; } @@ -191,9 +190,6 @@ FX_BOOL CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, } *(CDwGdiTextRenderer**)renderTarget = new CDwGdiTextRenderer(pBitmap, pBitmapRenderTarget, pRenderingParams); - if (*(CDwGdiTextRenderer**)renderTarget == NULL) { - goto failed; - } SafeRelease(&pGdiInterop); SafeRelease(&pBitmapRenderTarget); SafeRelease(&pRenderingParams); diff --git a/core/src/fxge/win32/fx_win32_gdipext.cpp b/core/src/fxge/win32/fx_win32_gdipext.cpp index ce65a26301..cae6c67823 100644 --- a/core/src/fxge/win32/fx_win32_gdipext.cpp +++ b/core/src/fxge/win32/fx_win32_gdipext.cpp @@ -5,20 +5,26 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "../../../include/fxge/fx_ge.h" + #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ #include <windows.h> #include <algorithm> + namespace Gdiplus { using std::min; using std::max; } // namespace Gdiplus + #include <gdiplus.h> #include "../../../include/fxge/fx_ge_win32.h" #include "win32_int.h" + using namespace Gdiplus; using namespace Gdiplus::DllExports; + #define GdiFillType2Gdip(fill_type) \ (fill_type == ALTERNATE ? FillModeAlternate : FillModeWinding) + static CombineMode GdiCombineMode2Gdip(int mode) { switch (mode) { case RGN_AND: diff --git a/core/src/fxge/win32/fx_win32_print.cpp b/core/src/fxge/win32/fx_win32_print.cpp index de5b4c54be..18fe1eb6fa 100644 --- a/core/src/fxge/win32/fx_win32_print.cpp +++ b/core/src/fxge/win32/fx_win32_print.cpp @@ -170,12 +170,6 @@ static CFX_DIBitmap* Transform1bppBitmap(const CFX_DIBSource* pSrc, int result_width = result_rect.Width(); int result_height = result_rect.Height(); CFX_DIBitmap* pTempBitmap = new CFX_DIBitmap; - if (!pTempBitmap) { - if (pSrcBitmap != src_bitmap) { - delete pSrcBitmap; - } - return NULL; - } if (!pTempBitmap->Create(result_width, result_height, pSrc->GetFormat())) { delete pTempBitmap; if (pSrcBitmap != src_bitmap) { @@ -324,9 +318,6 @@ FX_BOOL CPSPrinterDriver::Init(HDC hDC, int pslevel, FX_BOOL bCmykOutput) { m_Height = ::GetDeviceCaps(m_hDC, VERTRES); m_nBitsPerPixel = ::GetDeviceCaps(m_hDC, BITSPIXEL); m_pPSOutput = new CPSOutput(hDC); - if (!m_pPSOutput) { - return FALSE; - } ((CPSOutput*)m_pPSOutput)->Init(); m_PSRenderer.Init(m_pPSOutput, pslevel, m_Width, m_Height, bCmykOutput); m_bCmykOutput = bCmykOutput; diff --git a/pdfium.gyp b/pdfium.gyp index 3785d38a1b..4d20f82f18 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -772,8 +772,9 @@ 'core/src/fxcrt/fx_basic_bstring_unittest.cpp', 'core/src/fxcrt/fx_basic_memmgr_unittest.cpp', 'core/src/fxcrt/fx_basic_wstring_unittest.cpp', - 'testing/fx_string_testhelpers.h', + 'core/src/fxcrt/fx_system_unittest.cpp', 'testing/fx_string_testhelpers.cpp', + 'testing/fx_string_testhelpers.h', 'third_party/base/nonstd_unique_ptr_unittest.cpp', ], 'conditions': [ diff --git a/xfa/src/fgas/src/layout/fx_linebreak.cpp b/xfa/src/fgas/src/layout/fx_linebreak.cpp index 3eef550a02..76fc222195 100644 --- a/xfa/src/fgas/src/layout/fx_linebreak.cpp +++ b/xfa/src/fgas/src/layout/fx_linebreak.cpp @@ -5,7 +5,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../fgas_base.h"
-extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536];
+
extern const FX_LINEBREAKTYPE gs_FX_LineBreak_PairTable[64][32] = {
{FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB,
FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB, FX_LBPB,
@@ -273,11 +273,11 @@ void FX_GetLineBreakPositions(const FX_WCHAR* pwsText, FX_DWORD dwCur, dwNext;
FX_WCHAR wch;
wch = *pwsText++;
- dwCur = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & 0x003F;
+ dwCur = kTextLayoutCodeProperties[(FX_WORD)wch] & 0x003F;
iLength--;
for (int32_t i = 0; i < iLength; i++) {
wch = *pwsText++;
- dwNext = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & 0x003F;
+ dwNext = kTextLayoutCodeProperties[(FX_WORD)wch] & 0x003F;
if (dwNext == FX_CBP_SP) {
pBrkType[i] = FX_LBT_PROHIBITED_BRK;
} else {
@@ -298,11 +298,11 @@ void FX_GetLineBreakPositions(const FX_WCHAR* pwsText, FX_DWORD dwCur, dwNext;
FX_WCHAR wch;
wch = *pwsText++;
- dwCur = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & 0x003F;
+ dwCur = kTextLayoutCodeProperties[(FX_WORD)wch] & 0x003F;
iLength--;
for (int32_t i = 0; i < iLength; i++) {
wch = *pwsText++;
- dwNext = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & 0x003F;
+ dwNext = kTextLayoutCodeProperties[(FX_WORD)wch] & 0x003F;
if (dwNext == FX_CBP_SP) {
eType = FX_LBT_PROHIBITED_BRK;
} else {
diff --git a/xfa/src/fgas/src/layout/fx_rtfbreak.cpp b/xfa/src/fgas/src/layout/fx_rtfbreak.cpp index a341c2574f..4e1866b8e4 100644 --- a/xfa/src/fgas/src/layout/fx_rtfbreak.cpp +++ b/xfa/src/fgas/src/layout/fx_rtfbreak.cpp @@ -7,9 +7,6 @@ #include "../fgas_base.h"
#include "fx_unicode.h"
#include "fx_rtfbreak.h"
-extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536];
-extern const FX_WCHAR gs_FX_TextLayout_VerticalMirror[64];
-extern const FX_WCHAR gs_FX_TextLayout_BidiMirror[512];
extern const FX_LINEBREAKTYPE gs_FX_LineBreak_PairTable[64][32];
IFX_RTFBreak* IFX_RTFBreak::Create(FX_DWORD dwPolicies) {
return new CFX_RTFBreak(dwPolicies);
@@ -349,7 +346,7 @@ FX_DWORD CFX_RTFBreak::AppendChar(FX_WCHAR wch) { if (m_bCharCode) {
return AppendChar_CharCode(wch);
}
- FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch];
+ FX_DWORD dwProps = kTextLayoutCodeProperties[(FX_WORD)wch];
FX_DWORD dwType = (dwProps & FX_CHARTYPEBITSMASK);
CFX_RTFCharArray& tca = m_pCurLine->m_LineChars;
CFX_RTFChar* pCurChar = tca.AddSpace();
diff --git a/xfa/src/fgas/src/layout/fx_textbreak.cpp b/xfa/src/fgas/src/layout/fx_textbreak.cpp index 05f5510ccd..461ac03d47 100644 --- a/xfa/src/fgas/src/layout/fx_textbreak.cpp +++ b/xfa/src/fgas/src/layout/fx_textbreak.cpp @@ -9,9 +9,6 @@ #include "fx_unicode.h"
#include "fx_textbreak.h"
-extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536];
-extern const FX_WCHAR gs_FX_TextLayout_VerticalMirror[64];
-extern const FX_WCHAR gs_FX_TextLayout_BidiMirror[512];
extern const FX_LINEBREAKTYPE gs_FX_LineBreak_PairTable[64][32];
IFX_TxtBreak* IFX_TxtBreak::Create(FX_DWORD dwPolicies) {
return new CFX_TxtBreak(dwPolicies);
@@ -569,7 +566,7 @@ static const FX_TxtBreak_LPFAppendChar g_FX_TxtBreak_lpfAppendChar[16] = { &CFX_TxtBreak::AppendChar_Others, &CFX_TxtBreak::AppendChar_Others,
};
FX_DWORD CFX_TxtBreak::AppendChar(FX_WCHAR wch) {
- FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch];
+ FX_DWORD dwProps = kTextLayoutCodeProperties[(FX_WORD)wch];
FX_DWORD dwType = (dwProps & FX_CHARTYPEBITSMASK);
CFX_TxtChar* pCurChar = m_pCurLine->m_pLineChars->AddSpace();
pCurChar->m_wCharCode = (FX_WORD)wch;
|