diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2012-08-28 22:16:34 +0930 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2012-08-30 22:32:36 +0200 |
commit | ce8a579f339507da3fd7802e1531fbf6849c0c98 (patch) | |
tree | 608160d55d6b63cb5313d4da60b7905e2953e1f9 /utils | |
parent | cac13e782cf4413703cfd1fa23e76133dfbe5ef9 (diff) |
Move text to unicode conversion into a separate function
This also ensures UTF-16 ActualText strings are converted to UCS-4
before calling addChar.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/pdfinfo.cc | 37 |
1 files changed, 6 insertions, 31 deletions
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc index cdc5375d..d1c077bc 100644 --- a/utils/pdfinfo.cc +++ b/utils/pdfinfo.cc @@ -48,7 +48,7 @@ #include "PDFDocFactory.h" #include "CharTypes.h" #include "UnicodeMap.h" -#include "PDFDocEncoding.h" +#include "UTF.h" #include "Error.h" #include "DateInfo.h" @@ -379,41 +379,16 @@ static void printInfoString(Dict *infoDict, const char *key, const char *text, UnicodeMap *uMap) { Object obj; GooString *s1; - GBool isUnicode; - Unicode u, u2; + Unicode *u; char buf[8]; - int i, n; + int i, n, len; if (infoDict->lookup(key, &obj)->isString()) { fputs(text, stdout); s1 = obj.getString(); - if ((s1->getChar(0) & 0xff) == 0xfe && - (s1->getChar(1) & 0xff) == 0xff) { - isUnicode = gTrue; - i = 2; - } else { - isUnicode = gFalse; - i = 0; - } - while (i < obj.getString()->getLength()) { - if (isUnicode) { - u = ((s1->getChar(i) & 0xff) << 8) | - (s1->getChar(i+1) & 0xff); - i += 2; - if (u >= 0xd800 && u <= 0xdbff && i < obj.getString()->getLength()) { - // surrogate pair - u2 = ((s1->getChar(i) & 0xff) << 8) | - (s1->getChar(i+1) & 0xff); - i += 2; - if (u2 >= 0xdc00 && u2 <= 0xdfff) { - u = 0x10000 + ((u - 0xd800) << 10) + (u2 - 0xdc00); - } - } - } else { - u = pdfDocEncoding[s1->getChar(i) & 0xff]; - ++i; - } - n = uMap->mapUnicode(u, buf, sizeof(buf)); + len = TextStringToUCS4(s1, &u); + for (i = 0; i < len; i++) { + n = uMap->mapUnicode(u[i], buf, sizeof(buf)); fwrite(buf, 1, n, stdout); } fputc('\n', stdout); |