diff options
-rw-r--r-- | goo/GooString.h | 2 | ||||
-rw-r--r-- | poppler/Form.cc | 14 | ||||
-rw-r--r-- | poppler/PDFDocEncoding.h | 4 | ||||
-rw-r--r-- | qt5/src/poppler-private.cc | 10 | ||||
-rw-r--r-- | qt5/src/poppler-private.h | 2 |
5 files changed, 21 insertions, 11 deletions
diff --git a/goo/GooString.h b/goo/GooString.h index 5d17c4e5..11baa8ae 100644 --- a/goo/GooString.h +++ b/goo/GooString.h @@ -173,7 +173,9 @@ public: bool endsWith(const char *suffix) const; bool hasUnicodeMarker() const { return size() >= 2 && (*this)[0] == '\xfe' && (*this)[1] == '\xff'; } + static bool hasUnicodeMarker(const std::string& s) { return s.size() >= 2 && s[0] == '\xfe' && s[1] == '\xff'; } bool hasUnicodeMarkerLE() const { return size() >= 2 && (*this)[0] == '\xff' && (*this)[1] == '\xfe'; } + static bool hasUnicodeMarkerLE(const std::string& s) { return s.size() >= 2 && s[0] == '\xff' && s[1] == '\xfe'; } bool hasJustUnicodeMarker() const { return size() == 2 && hasUnicodeMarker(); } void prependUnicodeMarker(); diff --git a/poppler/Form.cc b/poppler/Form.cc index 2a8d5df6..60226223 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -59,12 +59,12 @@ #include "Lexer.h" //return a newly allocated char* containing an UTF16BE string of size length -char* pdfDocEncodingToUTF16 (const GooString* orig, int* length) +char* pdfDocEncodingToUTF16 (const std::string& orig, int* length) { //double size, a unicode char takes 2 char, add 2 for the unicode marker - *length = 2+2*orig->getLength(); + *length = 2+2*orig.size(); char *result = new char[(*length)]; - const char *cstring = orig->c_str(); + const char *cstring = orig.c_str(); //unicode marker result[0] = '\xfe'; result[1] = '\xff'; @@ -80,7 +80,7 @@ char* pdfDocEncodingToUTF16 (const GooString* orig, int* length) static GooString *convertToUtf16(GooString *pdfDocEncodingString) { int tmp_length; - char* tmp_str = pdfDocEncodingToUTF16(pdfDocEncodingString, &tmp_length); + char* tmp_str = pdfDocEncodingToUTF16(pdfDocEncodingString->toStr(), &tmp_length); delete pdfDocEncodingString; pdfDocEncodingString = new GooString(tmp_str, tmp_length); delete [] tmp_str; @@ -877,7 +877,7 @@ GooString* FormField::getFullyQualifiedName() { full_name->insert(0, parent_name->c_str() + 2, parent_name->getLength() - 2); // Remove the unicode BOM } else { int tmp_length; - char* tmp_str = pdfDocEncodingToUTF16(parent_name, &tmp_length); + char* tmp_str = pdfDocEncodingToUTF16(parent_name->toStr(), &tmp_length); full_name->insert(0, tmp_str + 2, tmp_length - 2); // Remove the unicode BOM delete [] tmp_str; } @@ -901,7 +901,7 @@ GooString* FormField::getFullyQualifiedName() { full_name->append(partialName->c_str() + 2, partialName->getLength() - 2); // Remove the unicode BOM } else { int tmp_length; - char* tmp_str = pdfDocEncodingToUTF16(partialName, &tmp_length); + char* tmp_str = pdfDocEncodingToUTF16(partialName->toStr(), &tmp_length); full_name->append(tmp_str + 2, tmp_length - 2); // Remove the unicode BOM delete [] tmp_str; } @@ -1189,7 +1189,7 @@ FormFieldText::FormFieldText(PDFDoc *docA, Object &&dictObj, const Ref refA, For } else if (obj1.getString()->getLength() > 0) { //non-unicode string -- assume pdfDocEncoding and try to convert to UTF16BE int tmp_length; - char* tmp_str = pdfDocEncodingToUTF16(obj1.getString(), &tmp_length); + char* tmp_str = pdfDocEncodingToUTF16(obj1.getString()->toStr(), &tmp_length); content = new GooString(tmp_str, tmp_length); delete [] tmp_str; } diff --git a/poppler/PDFDocEncoding.h b/poppler/PDFDocEncoding.h index 1d6080e1..7df3e8cb 100644 --- a/poppler/PDFDocEncoding.h +++ b/poppler/PDFDocEncoding.h @@ -24,12 +24,14 @@ #ifndef PDFDOCENCODING_H #define PDFDOCENCODING_H +#include <string> + #include "CharTypes.h" class GooString; extern const Unicode pdfDocEncoding[256]; -char* pdfDocEncodingToUTF16 (const GooString* orig, int* length); +char* pdfDocEncodingToUTF16 (const std::string& orig, int* length); #endif diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc index 81af2bed..cb5bf8f1 100644 --- a/qt5/src/poppler-private.cc +++ b/qt5/src/poppler-private.cc @@ -97,12 +97,16 @@ namespace Debug { } QString UnicodeParsedString(const GooString *s1) { - if ( !s1 || s1->getLength() == 0 ) + return (s1) ? UnicodeParsedString(s1->toStr()) : QString(); + } + + QString UnicodeParsedString(const std::string& s1) { + if ( s1.empty() ) return QString(); - if ( s1->hasUnicodeMarker() || s1->hasUnicodeMarkerLE() ) + if ( GooString::hasUnicodeMarker(s1) || GooString::hasUnicodeMarkerLE(s1) ) { - return QString::fromUtf16(reinterpret_cast<const ushort *>(s1->c_str()), s1->getLength() / 2); + return QString::fromUtf16(reinterpret_cast<const ushort *>(s1.c_str()), s1.size() / 2); } else { diff --git a/qt5/src/poppler-private.h b/qt5/src/poppler-private.h index 9131dba6..c6161364 100644 --- a/qt5/src/poppler-private.h +++ b/qt5/src/poppler-private.h @@ -71,6 +71,8 @@ namespace Poppler { POPPLER_QT5_EXPORT QString UnicodeParsedString(const GooString *s1); + POPPLER_QT5_EXPORT QString UnicodeParsedString(const std::string& s1); + POPPLER_QT5_EXPORT GooString *QStringToUnicodeGooString(const QString &s); POPPLER_QT5_EXPORT GooString *QStringToGooString(const QString &s); |