diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-08-08 17:49:02 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-08-08 17:49:02 +0000 |
commit | 34dab07ed6e826666fd0589069f2c9b5bd2ba4dc (patch) | |
tree | 0eb30bd1c76f54890a6d365258a7157ae9972748 /xfa | |
parent | 6d9897b103aef10b369eb999a40c22011a8ae4f5 (diff) | |
download | pdfium-34dab07ed6e826666fd0589069f2c9b5bd2ba4dc.tar.xz |
Move ByteString::FromUnicode() to WideString::ToDefANSI()
Turns out that "FromUnicode" is misleading in that, on linux, it simply
removes any characters beyond 0xFF and passes the rest unchanged, so
no unicode decoding actually takes place. On Windows, it passes it into
the system function specifying FX_CODEPAGE_DefANSI, converting it into
the so-called "default ANSI code plane", passing some characters,
converting others to '?' and still others to 'A'. Either way, nothing
resembling UTF8 comes out of this, so pick a better name.
These now immediately look suspicious, so a follow-up CL will see
which ones should really be WideString::UTF8Encode() instead.
Making this a normal method on a widestring rather than a static
method on a bytestring feels more natural; this is parallel to
the UTF8Encode and UTF16LE_Encode functions.
Add a test that shows these conversions.
Change-Id: Ia7551b47199eba61b5c328a97bfe9176ac8e583c
Reviewed-on: https://pdfium-review.googlesource.com/39690
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.cpp | 3 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_gefont.cpp | 2 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_pdffontmgr.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 2 |
4 files changed, 4 insertions, 5 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 5ab91b3cc6..f173bf24ae 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -416,8 +416,7 @@ ByteString CFX_FontSourceEnum_File::GetNextFile() { } ByteString bsName; bool bFolder; - ByteString bsFolderSeparator = - ByteString::FromUnicode(WideString(kFolderSeparator)); + ByteString bsFolderSeparator = WideString(kFolderSeparator).ToDefANSI(); while (true) { if (!FX_GetNextFile(pCurHandle, &bsName, &bFolder)) { FX_CloseFolder(pCurHandle); diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp index 740504f088..b5cb7962af 100644 --- a/xfa/fgas/font/cfgas_gefont.cpp +++ b/xfa/fgas/font/cfgas_gefont.cpp @@ -76,7 +76,7 @@ bool CFGAS_GEFont::LoadFontInternal(const wchar_t* pszFontFamily, return false; ByteString csFontFamily; if (pszFontFamily) - csFontFamily = ByteString::FromUnicode(pszFontFamily); + csFontFamily = WideString(pszFontFamily).ToDefANSI(); int32_t iWeight = FontStyleIsBold(dwFontStyles) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp index 80d6196d4e..4220d4d6c5 100644 --- a/xfa/fgas/font/cfgas_pdffontmgr.cpp +++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp @@ -80,7 +80,7 @@ RetainPtr<CFGAS_GEFont> CFGAS_PDFFontMgr::GetFont( if (it != m_FontMap.end()) return it->second; - ByteString bsPsName = ByteString::FromUnicode(WideString(wsFontFamily)); + ByteString bsPsName = WideString(wsFontFamily).ToDefANSI(); bool bBold = FontStyleIsBold(dwFontStyles); bool bItalic = FontStyleIsItalic(dwFontStyles); ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 7ff205c6f4..8babe45ef3 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -214,7 +214,7 @@ RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc, pdfium::MakeRetain<CFX_MemoryStream>(pImageBuffer, iRead, false); } } else { - bsContent = ByteString::FromUnicode(wsImage); + bsContent = wsImage.ToDefANSI(); pImageFileRead = pdfium::MakeRetain<CFX_MemoryStream>( const_cast<uint8_t*>(bsContent.raw_str()), bsContent.GetLength(), false); |