summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuigi Scarso <luigi.scarso@gmail.com>2014-10-07 22:45:05 +0200
committerAlbert Astals Cid <aacid@kde.org>2014-10-07 22:45:05 +0200
commitb8810703ca76f0bbc8185ab87679cf18eb006d52 (patch)
tree9cb75f1c57b6bc1086d8346c47632f6f73895e36
parent96a04336c7a6331727724125686a0d6f42f19f46 (diff)
Make Attribute::getName() work when UTF-16BE is used
Contains some ideas by me Bug #84722
-rw-r--r--goo/GooString.h9
-rw-r--r--poppler/StructElement.cc17
-rw-r--r--poppler/StructElement.h7
3 files changed, 21 insertions, 12 deletions
diff --git a/goo/GooString.h b/goo/GooString.h
index 5932be99..c6fb100e 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -17,7 +17,7 @@
//
// Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
-// Copyright (C) 2008-2010, 2012 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2008-2010, 2012, 2014 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2012-2014 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2013 Jason Crain <jason@aquaticape.us>
//
@@ -47,6 +47,10 @@
class GooString {
public:
+ // a special value telling that the length of the string is not given
+ // so it must be calculated from the strings
+ static const int CALC_STRING_LEN = -1;
+
// Create an empty string.
GooString();
@@ -171,9 +175,6 @@ private:
// results in sizeof(GooString) be a multiple of 16.
// 24 makes sizeof(GooString) to be 32.
static const int STR_STATIC_SIZE = 24;
- // a special value telling that the length of the string is not given
- // so it must be calculated from the strings
- static const int CALC_STRING_LEN = -1;
int roundedSize(int len);
diff --git a/poppler/StructElement.cc b/poppler/StructElement.cc
index 8e064a04..b1aaca8a 100644
--- a/poppler/StructElement.cc
+++ b/poppler/StructElement.cc
@@ -5,6 +5,8 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2013, 2014 Igalia S.L.
+// Copyright 2014 Luigi Scarso <luigi.scarso@gmail.com>
+// Copyright 2014 Albert Astals Cid <aacid@kde.org>
//
//========================================================================
@@ -677,11 +679,11 @@ static StructElement::Type nameToType(const char *name)
// Attribute
//------------------------------------------------------------------------
-Attribute::Attribute(const char *nameA, Object *valueA):
+Attribute::Attribute(const char *nameA, int nameLenA, Object *valueA):
type(UserProperty),
owner(UserProperties),
revision(0),
- name(nameA),
+ name(nameA, nameLenA),
value(),
hidden(gFalse),
formatted(NULL)
@@ -789,10 +791,13 @@ Attribute *Attribute::parseUserProperty(Dict *property)
{
Object obj, value;
const char *name = NULL;
+ int nameLen = GooString::CALC_STRING_LEN;
- if (property->lookup("N", &obj)->isString())
- name = obj.getString()->getCString();
- else if (obj.isName())
+ if (property->lookup("N", &obj)->isString()) {
+ GooString *s = obj.getString();
+ name = s->getCString();
+ nameLen = s->getLength();
+ } else if (obj.isName())
name = obj.getName();
else {
error(errSyntaxError, -1, "N object is wrong type ({0:s})", obj.getTypeName());
@@ -807,7 +812,7 @@ Attribute *Attribute::parseUserProperty(Dict *property)
return NULL;
}
- Attribute *attribute = new Attribute(name, &value);
+ Attribute *attribute = new Attribute(name, nameLen, &value);
value.free();
obj.free();
diff --git a/poppler/StructElement.h b/poppler/StructElement.h
index 51fd83da..cd89a970 100644
--- a/poppler/StructElement.h
+++ b/poppler/StructElement.h
@@ -5,6 +5,8 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2013, 2014 Igalia S.L.
+// Copyright 2014 Luigi Scarso <luigi.scarso@gmail.com>
+// Copyright 2014 Albert Astals Cid <aacid@kde.org>
//
//========================================================================
@@ -74,7 +76,7 @@ public:
Attribute(Type type, Object *value);
// Creates an UserProperty attribute, with an arbitrary name and value.
- Attribute(const char *name, Object *value);
+ Attribute(const char *name, int nameLen, Object *value);
GBool isOk() const { return type != Unknown; }
@@ -86,7 +88,8 @@ public:
Object *getValue() const { return &value; }
static Object *getDefaultValue(Type type);
- const char *getName() const { return type == UserProperty ? name.getCString() : getTypeName(); }
+ // The caller gets the ownership of the return GooString and is responsible of deleting it
+ GooString *getName() const { return type == UserProperty ? name.copy() : new GooString(getTypeName()); }
// The revision is optional, and defaults to zero.
Guint getRevision() const { return revision; }