diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-11-03 15:08:31 -0500 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-11-03 15:08:31 -0500 |
commit | da06e60fb5a095a91c9a4f509466667878624cb3 (patch) | |
tree | cf9af9e6cc40e05cdbcf3ee7271ccc684e805f20 /core/src/fpdfapi/fpdf_font | |
parent | e0e922db5fb77df9a5a9cc802096f484ed21da1c (diff) | |
download | pdfium-da06e60fb5a095a91c9a4f509466667878624cb3.tar.xz |
Revert "Revert "Revert "Cleanup some numeric code."""
This reverts commit e0e922db5fb77df9a5a9cc802096f484ed21da1c.
Broke Windows build.
FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fxcrt\fxcrt.fx_basic_gcc.obj.rsp /c ..\..\core\src\fxcrt\fx_basic_gcc.cpp /Foobj\core\src\fxcrt\fxcrt.fx_basic_gcc.obj /Fdobj\fxcrt.cc.pdb
e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_gcc.cpp(28) : error C2220: warning treated as error - no 'object' file generated
e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_gcc.cpp(75) : see reference to function template instantiation 'T FXSYS_StrToInt<int32_t,const FX_WCHAR*>(STR_T)' being compiled
with
[
T=int32_t
, STR_T=const FX_WCHAR *
]
e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_gcc.cpp(28) : warning C4244: 'argument' : conversion from 'const FX_WCHAR' to 'char', possible loss of data
FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fpdftext\fpdftext.fpdf_text.obj.rsp /c ..\..\core\src\fpdftext\fpdf_text.cpp /Foobj\core\src\fpdftext\fpdftext.fpdf_text.obj /Fdobj\fpdftext.cc.pdb
e:\b\build\slave\windows\build\pdfium\core\src\fpdftext\fpdf_text.cpp(439) : error C2039: 'isdigit' : is not a member of 'std'
FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fxcrt\fxcrt.fx_basic_wstring.obj.rsp /c ..\..\core\src\fxcrt\fx_basic_wstring.cpp /Foobj\core\src\fxcrt\fxcrt.fx_basic_wstring.obj /Fdobj\fxcrt.cc.pdb
e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_wstring.cpp(973) : error C2220: warning treated as error - no 'object' file generated
e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_wstring.cpp(973) : warning C4244: 'argument' : conversion from 'const FX_WCHAR' to 'char', possible loss of data
e:\b\build\slave\windows\build\pdfium\core\src\fxcrt\fx_basic_wstring.cpp(981) : warning C4244: 'argument' : conversion from 'const FX_WCHAR' to 'char', possible loss of data
FAILED: ninja -t msvc -e environment.x86 -- "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\core\src\fpdftext\fpdftext.fpdf_text_int.obj.rsp /c ..\..\core\src\fpdftext\fpdf_text_int.cpp /Foobj\core\src\fpdftext\fpdftext.fpdf_text_int.obj /Fdobj\fpdftext.cc.pdb
e:\b\build\slave\windows\build\pdfium\core\src\fpdftext\fpdf_text_int.cpp(2436) : error C2039: 'isdigit' : is not a member of 'std'
e:\b\build\slave\windows\build\pdfium\core\src\fpdftext\fpdf_text_int.cpp(2440) : error C2039: 'isdigit' : is not a member of 'std'
ninja: build stopped: subcommand failed.
TBR=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1431683008 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_font')
-rw-r--r-- | core/src/fpdfapi/fpdf_font/fpdf_font.cpp | 51 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp | 44 |
2 files changed, 72 insertions, 23 deletions
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp index 2d5e9780ad..0529d3d35b 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp @@ -8,7 +8,6 @@ #include "../../../include/fpdfapi/fpdf_page.h" #include "../../../include/fpdfapi/fpdf_pageobj.h" #include "../../../include/fpdfapi/fpdf_resource.h" -#include "../../../include/fxcrt/fx_ext.h" #include "../../../include/fxge/fx_freetype.h" #include "../fpdf_page/pageint.h" #include "font_int.h" @@ -514,19 +513,32 @@ FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { const FX_CHAR* buf = str.GetCStr(); int len = str.GetLength(); - if (len == 0) + if (len == 0) { return 0; - + } int result = 0; if (buf[0] == '<') { - for (int i = 1; i < len && std::isxdigit(buf[i]); ++i) - result = result * 16 + FXSYS_toHexDigit(buf[i]); + for (int i = 1; i < len; i++) { + int digit; + if (buf[i] >= '0' && buf[i] <= '9') { + digit = buf[i] - '0'; + } else if (buf[i] >= 'a' && buf[i] <= 'f') { + digit = buf[i] - 'a' + 10; + } else if (buf[i] >= 'A' && buf[i] <= 'F') { + digit = buf[i] - 'A' + 10; + } else { + break; + } + result = result * 16 + digit; + } return result; } - - for (int i = 0; i < len && std::isdigit(buf[i]); ++i) - result = result * 10 + FXSYS_toDecimalDigit(buf[i]); - + for (int i = 0; i < len; i++) { + if (buf[i] < '0' || buf[i] > '9') { + break; + } + result = result * 10 + buf[i] - '0'; + } return result; } static CFX_WideString StringDataAdd(CFX_WideString str) { @@ -553,15 +565,26 @@ CFX_WideString CPDF_ToUnicodeMap::StringToWideString( const CFX_ByteStringC& str) { const FX_CHAR* buf = str.GetCStr(); int len = str.GetLength(); - if (len == 0) + if (len == 0) { return CFX_WideString(); - + } CFX_WideString result; if (buf[0] == '<') { int byte_pos = 0; FX_WCHAR ch = 0; - for (int i = 1; i < len && std::isxdigit(buf[i]); ++i) { - ch = ch * 16 + FXSYS_toHexDigit(buf[i]); + for (int i = 1; i < len; i++) { + int digit; + if (buf[i] >= '0' && buf[i] <= '9') { + digit = buf[i] - '0'; + } else if (buf[i] >= 'a' && buf[i] <= 'f') { + digit = buf[i] - 'a' + 10; + } else if (buf[i] >= 'A' && buf[i] <= 'F') { + digit = buf[i] - 'A' + 10; + } else { + break; + } + ch = ch * 16 + digit; + byte_pos++; if (byte_pos == 4) { result += ch; @@ -571,6 +594,8 @@ CFX_WideString CPDF_ToUnicodeMap::StringToWideString( } return result; } + if (buf[0] == '(') { + } return result; } void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp index 2d1834c096..43125d717a 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp @@ -7,7 +7,6 @@ #include "../../../include/fpdfapi/fpdf_module.h" #include "../../../include/fpdfapi/fpdf_page.h" #include "../../../include/fpdfapi/fpdf_resource.h" -#include "../../../include/fxcrt/fx_ext.h" #include "../../../include/fxge/fx_freetype.h" #include "../../../include/fxge/fx_ge.h" #include "../fpdf_cmaps/cmap_int.h" @@ -699,17 +698,30 @@ void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) { m_LastWord = word; } -// Static. FX_DWORD CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) { int num = 0; if (word.GetAt(0) == '<') { - for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i) - num = num * 16 + FXSYS_toHexDigit(word.GetAt(i)); - return num; + for (int i = 1; i < word.GetLength(); i++) { + uint8_t digit = word.GetAt(i); + if (digit >= '0' && digit <= '9') { + digit = digit - '0'; + } else if (digit >= 'a' && digit <= 'f') { + digit = digit - 'a' + 10; + } else if (digit >= 'A' && digit <= 'F') { + digit = digit - 'A' + 10; + } else { + return num; + } + num = num * 16 + digit; + } + } else { + for (int i = 0; i < word.GetLength(); i++) { + if (word.GetAt(i) < '0' || word.GetAt(i) > '9') { + return num; + } + num = num * 10 + word.GetAt(i) - '0'; + } } - - for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i) - num = num * 10 + FXSYS_toDecimalDigit(word.GetAt(i)); return num; } @@ -733,7 +745,13 @@ bool CPDF_CMapParser::CMap_GetCodeRange(CMap_CodeRange& range, for (i = 0; i < range.m_CharSize; ++i) { uint8_t digit1 = first.GetAt(i * 2 + 1); uint8_t digit2 = first.GetAt(i * 2 + 2); - range.m_Lower[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2); + uint8_t byte = (digit1 >= '0' && digit1 <= '9') + ? (digit1 - '0') + : ((digit1 & 0xdf) - 'A' + 10); + byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') + ? (digit2 - '0') + : ((digit2 & 0xdf) - 'A' + 10)); + range.m_Lower[i] = byte; } FX_DWORD size = second.GetLength(); @@ -744,7 +762,13 @@ bool CPDF_CMapParser::CMap_GetCodeRange(CMap_CodeRange& range, uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : '0'; - range.m_Upper[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2); + uint8_t byte = (digit1 >= '0' && digit1 <= '9') + ? (digit1 - '0') + : ((digit1 & 0xdf) - 'A' + 10); + byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') + ? (digit2 - '0') + : ((digit2 & 0xdf) - 'A' + 10)); + range.m_Upper[i] = byte; } return true; } |