aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-01-23 23:58:23 +0100
committerJay Berkenbilt <ejb@ql.org>2021-01-24 09:27:28 +0100
commit04edfe9fade7e77342f5e4fe694ee071554a119c (patch)
treee198ad6dd5d6e4759728c333363898d41690cf6e /libqpdf
parent63e5cb533de0567612ef5ab373d02f90880a8653 (diff)
downloadqpdf-04edfe9fade7e77342f5e4fe694ee071554a119c.tar.zst
QPDFObjectHandle::newUnicodeString to uses UTF-16 only when needed
Use the first of ASCII, PDFDocEncoding, or UTF-16 that is capable of encoding the string.
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDF_String.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc
index 5558979c..8f10b977 100644
--- a/libqpdf/QPDF_String.cc
+++ b/libqpdf/QPDF_String.cc
@@ -31,7 +31,13 @@ QPDF_String::~QPDF_String()
QPDF_String*
QPDF_String::new_utf16(std::string const& utf8_val)
{
- return new QPDF_String(QUtil::utf8_to_utf16(utf8_val));
+ std::string result;
+ if (! (QUtil::utf8_to_ascii(utf8_val, result, '?') ||
+ QUtil::utf8_to_pdf_doc(utf8_val, result, '?')))
+ {
+ result = QUtil::utf8_to_utf16(utf8_val);
+ }
+ return new QPDF_String(result);
}
std::string