poppler/Form.cc | 71 +++++++++++++++++++++++++++++++++++++++++------- qt4/src/poppler-form.cc | 4 +- 2 files changed, 63 insertions(+), 12 deletions(-)
New commits: commit e80fd082914fe29fad7e60c321a747eb8634e413 Author: Albert Astals Cid <[email protected]> Date: Sun Apr 29 18:27:41 2012 +0200 [qt4] the qualified name may be unicode encoded diff --git a/qt4/src/poppler-form.cc b/qt4/src/poppler-form.cc index 1703784..82309ff 100644 --- a/qt4/src/poppler-form.cc +++ b/qt4/src/poppler-form.cc @@ -1,6 +1,6 @@ /* poppler-form.h: qt4 interface to poppler * Copyright (C) 2007-2008, 2011, Pino Toscano <[email protected]> - * Copyright (C) 2008, 2011, Albert Astals Cid <[email protected]> + * Copyright (C) 2008, 2011, 2012 Albert Astals Cid <[email protected]> * Copyright (C) 2011 Carlos Garcia Campos <[email protected]> * * This program is free software; you can redistribute it and/or modify @@ -115,7 +115,7 @@ QString FormField::fullyQualifiedName() const QString name; if (GooString *goo = m_formData->fm->getFullyQualifiedName()) { - name = QString::fromLatin1(goo->getCString()); + name = UnicodeParsedString(goo); } return name; } commit 251be1787a2a003862691f5a825eb3468eceb6a2 Author: Albert Astals Cid <[email protected]> Date: Sun Apr 29 18:26:42 2012 +0200 Fix getFullyQualifiedName with unicode field names Based on a patch from Mark Riedesel. Bug #49256 diff --git a/poppler/Form.cc b/poppler/Form.cc index 00c8cc1..99d7bbb 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright 2006-2008 Julien Rebetez <[email protected]> -// Copyright 2007-2011 Albert Astals Cid <[email protected]> +// Copyright 2007-2012 Albert Astals Cid <[email protected]> // Copyright 2007-2008, 2011 Carlos Garcia Campos <[email protected]> // Copyright 2007 Adrian Johnson <[email protected]> // Copyright 2007 Iñigo MartÃnez <[email protected]> @@ -13,7 +13,7 @@ // Copyright 2008 Michael Vrable <[email protected]> // Copyright 2009 Matthias Drochner <[email protected]> // Copyright 2009 KDAB via Guillermo Amaral <[email protected]> -// Copyright 2010 Mark Riedesel <[email protected]> +// Copyright 2010, 2012 Mark Riedesel <[email protected]> // //======================================================================== @@ -59,6 +59,15 @@ char* pdfDocEncodingToUTF16 (GooString* orig, int* length) return result; } +static GooString *convertToUtf16(GooString *pdfDocEncodingString) +{ + int tmp_length; + char* tmp_str = pdfDocEncodingToUTF16(pdfDocEncodingString, &tmp_length); + delete pdfDocEncodingString; + pdfDocEncodingString = new GooString(tmp_str, tmp_length); + delete [] tmp_str; + return pdfDocEncodingString; +} FormWidget::FormWidget(PDFDoc *docA, Object *aobj, unsigned num, Ref aref, FormField *fieldA) @@ -676,6 +685,7 @@ GooString* FormField::getFullyQualifiedName() { Object parent; GooString *parent_name; GooString *full_name; + GBool unicode_encoded = gFalse; if (fullyQualifiedName) return fullyQualifiedName; @@ -687,14 +697,26 @@ GooString* FormField::getFullyQualifiedName() { if (parent.dictLookup("T", &obj2)->isString()) { parent_name = obj2.getString(); - if (parent_name->hasUnicodeMarker()) { - parent_name->del(0, 2); // Remove the unicode BOM - full_name->insert(0, "\0.", 2); // 2-byte unicode period + if (unicode_encoded) { + full_name->insert(0, "\0.", 2); // 2-byte unicode period + if (parent_name->hasUnicodeMarker()) { + full_name->insert(0, parent_name->getCString() + 2, parent_name->getLength() - 2); // Remove the unicode BOM + } else { + int tmp_length; + char* tmp_str = pdfDocEncodingToUTF16(parent_name, &tmp_length); + full_name->insert(0, tmp_str + 2, tmp_length - 2); // Remove the unicode BOM + delete [] tmp_str; + } } else { full_name->insert(0, '.'); // 1-byte ascii period + if (parent_name->hasUnicodeMarker()) { + unicode_encoded = gTrue; + full_name = convertToUtf16(full_name); + full_name->insert(0, parent_name->getCString() + 2, parent_name->getLength() - 2); // Remove the unicode BOM + } else { + full_name->insert(0, parent_name); + } } - - full_name->insert(0, parent_name); obj2.free(); } obj1.free(); @@ -705,12 +727,41 @@ GooString* FormField::getFullyQualifiedName() { parent.free(); if (partialName) { - full_name->append(partialName); + if (unicode_encoded) { + if (partialName->hasUnicodeMarker()) { + full_name->append(partialName->getCString() + 2, partialName->getLength() - 2); // Remove the unicode BOM + } else { + int tmp_length; + char* tmp_str = pdfDocEncodingToUTF16(partialName, &tmp_length); + full_name->append(tmp_str + 2, tmp_length - 2); // Remove the unicode BOM + delete [] tmp_str; + } + } else { + if (partialName->hasUnicodeMarker()) { + unicode_encoded = gTrue; + full_name = convertToUtf16(full_name); + full_name->append(partialName->getCString() + 2, partialName->getLength() - 2); // Remove the unicode BOM + } else { + full_name->append(partialName); + } + } } else { int len = full_name->getLength(); // Remove the last period - if (len > 0) - full_name->del(len - 1, 1); + if (unicode_encoded) { + if (len > 1) { + full_name->del(len - 2, 2); + } + } else { + if (len > 0) { + full_name->del(len - 1, 1); + } + } + } + + if (unicode_encoded) { + full_name->insert(0, 0xff); + full_name->insert(0, 0xfe); } fullyQualifiedName = full_name;
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
