diff options
author | Lei Zhang <thestig@chromium.org> | 2016-02-19 14:26:46 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2016-02-19 14:26:46 -0800 |
commit | 11d33361e95d5ea61ee43e4261fa8f53aa372731 (patch) | |
tree | df81483804ef757d6f3c6f91531e7deae1eebf42 /core/src/fpdfapi | |
parent | 84e5a12f186a00bf37a26cc13965f65c25561bd1 (diff) | |
download | pdfium-11d33361e95d5ea61ee43e4261fa8f53aa372731.tar.xz |
Get rid of CFX_CharMap instantiations.
The only thing left are a couple of static methods.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1711273002 .
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp | 54 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 18 |
2 files changed, 35 insertions, 37 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index 7c1c6b1f53..0b7a841cd4 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -426,13 +426,11 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf, return TRUE; } -CFX_WideString PDF_DecodeText(const uint8_t* src_data, - FX_DWORD src_len, - CFX_CharMap* pCharMap) { +CFX_WideString PDF_DecodeText(const uint8_t* src_data, FX_DWORD src_len) { CFX_WideString result; if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || (src_data[0] == 0xff && src_data[1] == 0xfe))) { - FX_BOOL bBE = src_data[0] == 0xfe; + bool bBE = src_data[0] == 0xfe; FX_DWORD max_chars = (src_len - 2) / 2; if (!max_chars) { return result; @@ -461,44 +459,40 @@ CFX_WideString PDF_DecodeText(const uint8_t* src_data, } } result.ReleaseBuffer(dest_pos); - } else if (!pCharMap) { + } else { FX_WCHAR* dest_buf = result.GetBuffer(src_len); - for (FX_DWORD i = 0; i < src_len; i++) { + for (FX_DWORD i = 0; i < src_len; i++) dest_buf[i] = PDFDocEncoding[src_data[i]]; - } result.ReleaseBuffer(src_len); - } else { - return (*pCharMap->m_GetWideString)( - pCharMap, CFX_ByteString((const FX_CHAR*)src_data, src_len)); } return result; } -CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, - int len, - CFX_CharMap* pCharMap) { +CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr) { + return PDF_DecodeText((const uint8_t*)bstr.c_str(), bstr.GetLength()); +} + +CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len) { if (len == -1) { len = FXSYS_wcslen(pString); } CFX_ByteString result; - if (!pCharMap) { - FX_CHAR* dest_buf1 = result.GetBuffer(len); - int i; - for (i = 0; i < len; i++) { - int code; - for (code = 0; code < 256; code++) - if (PDFDocEncoding[code] == pString[i]) { - break; - } - if (code == 256) { + FX_CHAR* dest_buf1 = result.GetBuffer(len); + int i; + for (i = 0; i < len; i++) { + int code; + for (code = 0; code < 256; code++) + if (PDFDocEncoding[code] == pString[i]) { break; } - dest_buf1[i] = code; - } - result.ReleaseBuffer(i); - if (i == len) { - return result; + if (code == 256) { + break; } + dest_buf1[i] = code; + } + result.ReleaseBuffer(i); + if (i == len) { + return result; } if (len > INT_MAX / 2 - 1) { @@ -520,6 +514,10 @@ CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, return result; } +CFX_ByteString PDF_EncodeText(const CFX_WideString& str) { + return PDF_EncodeText(str.c_str(), str.GetLength()); +} + CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) { CFX_ByteTextBuf result; int srclen = src.GetLength(); diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index 5f8b075296..c3b0ebde63 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -36,12 +36,12 @@ CPDF_String::CPDF_String(const CFX_WideString& str) : m_bHex(FALSE) { m_String = PDF_EncodeText(str); } -CFX_WideString CPDF_String::GetUnicodeText(CFX_CharMap* pCharMap) const { - return PDF_DecodeText(m_String, pCharMap); +CFX_WideString CPDF_String::GetUnicodeText() const { + return PDF_DecodeText(m_String); } -CFX_WideString CPDF_Name::GetUnicodeText(CFX_CharMap* pCharMap) const { - return PDF_DecodeText(m_Name, pCharMap); +CFX_WideString CPDF_Name::GetUnicodeText() const { + return PDF_DecodeText(m_Name); } CPDF_Array::~CPDF_Array() { @@ -256,12 +256,12 @@ CFX_ByteStringC CPDF_Dictionary::GetConstStringBy( return CFX_ByteStringC(); } -CFX_WideString CPDF_Dictionary::GetUnicodeTextBy(const CFX_ByteStringC& key, - CFX_CharMap* pCharMap) const { +CFX_WideString CPDF_Dictionary::GetUnicodeTextBy( + const CFX_ByteStringC& key) const { CPDF_Object* p = GetElement(key); if (CPDF_Reference* pRef = ToReference(p)) p = pRef->GetDirect(); - return p ? p->GetUnicodeText(pCharMap) : CFX_WideString(); + return p ? p->GetUnicodeText() : CFX_WideString(); } CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key, @@ -562,10 +562,10 @@ void CPDF_Stream::InitStreamFromFile(IFX_FileRead* pFile, } } -CFX_WideString CPDF_Stream::GetUnicodeText(CFX_CharMap* pCharMap) const { +CFX_WideString CPDF_Stream::GetUnicodeText() const { CPDF_StreamAcc stream; stream.LoadAllData(this, FALSE); - return PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); + return PDF_DecodeText(stream.GetData(), stream.GetSize()); } CPDF_StreamAcc::CPDF_StreamAcc() { |