summaryrefslogtreecommitdiff
path: root/poppler
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2006-01-18 22:36:01 +0000
committerAlbert Astals Cid <aacid@kde.org>2006-01-18 22:36:01 +0000
commit38c8f3a53b3eb2be1fbfa360f77285037d89b719 (patch)
tree2892e19f7d3d199c80b4cd413ae7a029afc5d295 /poppler
parentad6e7d862c8fa6e10a7dbbb3391cbb0b6c922375 (diff)
as usual i foget some files
Diffstat (limited to 'poppler')
-rw-r--r--poppler/UGooString.cc86
-rw-r--r--poppler/UGooString.h55
2 files changed, 141 insertions, 0 deletions
diff --git a/poppler/UGooString.cc b/poppler/UGooString.cc
new file mode 100644
index 00000000..17d1b514
--- /dev/null
+++ b/poppler/UGooString.cc
@@ -0,0 +1,86 @@
+//========================================================================
+//
+// UGooString.cc
+//
+// Unicode string
+//
+// Copyright 2005 Albert Astals Cid <aacid@kde.org>
+//
+//========================================================================
+
+#include <string.h>
+
+#include "goo/gmem.h"
+#include "goo/GooString.h"
+#include "PDFDocEncoding.h"
+#include "UGooString.h"
+
+UGooString::UGooString(Unicode *u, int l)
+{
+ s = u;
+ length = l;
+}
+
+UGooString::UGooString(GooString &str)
+{
+ if ((str.getChar(0) & 0xff) == 0xfe && (str.getChar(1) & 0xff) == 0xff)
+ {
+ length = (str.getLength() - 2) / 2;
+ s = (Unicode *)gmallocn(length, sizeof(Unicode));
+ for (int j = 0; j < length; ++j) {
+ s[j] = ((str.getChar(2 + 2*j) & 0xff) << 8) | (str.getChar(3 + 2*j) & 0xff);
+ }
+ } else
+ initChar(str);
+}
+
+UGooString::UGooString(const UGooString &str)
+{
+ length = str.length;
+ s = (Unicode *)gmallocn(length, sizeof(Unicode));
+ memcpy(s, str.s, length * sizeof(Unicode));
+}
+
+UGooString::UGooString(const char *str)
+{
+ GooString aux(str);
+ initChar(aux);
+}
+
+void UGooString::initChar(GooString &str)
+{
+ length = str.getLength();
+ s = (Unicode *)gmallocn(length, sizeof(Unicode));
+ for (int j = 0; j < length; ++j) {
+ s[j] = pdfDocEncoding[str.getChar(j) & 0xff];
+ }
+}
+
+UGooString::~UGooString()
+{
+ gfree(s);
+}
+
+int UGooString::cmp(UGooString *str) const
+{
+ int n1, n2, i, x;
+ Unicode *p1, *p2;
+
+ n1 = length;
+ n2 = str->length;
+ for (i = 0, p1 = s, p2 = str->s; i < n1 && i < n2; ++i, ++p1, ++p2) {
+ x = *p1 - *p2;
+ if (x != 0) {
+ return x;
+ }
+ }
+ return n1 - n2;
+}
+
+char *UGooString::getCString() const
+{
+ char *res = new char[length + 1];
+ for (int i = 0; i < length; i++) res[i] = s[i];
+ res[length] = '\0';
+ return res;
+}
diff --git a/poppler/UGooString.h b/poppler/UGooString.h
new file mode 100644
index 00000000..9161760d
--- /dev/null
+++ b/poppler/UGooString.h
@@ -0,0 +1,55 @@
+//========================================================================
+//
+// UGooString.h
+//
+// Unicode string
+//
+// Copyright 2005 Albert Astals Cid <aacid@kde.org>
+//
+//========================================================================
+
+#ifndef UGooString_H
+#define UGooString_H
+
+#include "CharTypes.h"
+
+class GooString;
+
+class UGooString
+{
+public:
+ // Create an unicode string
+ UGooString(Unicode *u, int l);
+
+ // Create a unicode string from <str>.
+ UGooString(GooString &str);
+
+ // Copy the unicode string
+ UGooString(const UGooString &str);
+
+ // Create a unicode string from <str>.
+ UGooString(const char *str);
+
+ // Destructor.
+ ~UGooString();
+
+ // Get length.
+ int getLength() const { return length; }
+
+ // Compare two strings: -1:< 0:= +1:>
+ int cmp(UGooString *str) const;
+
+ // get the unicode
+ Unicode *unicode() const { return s; }
+
+ // get the const char*
+ char *getCString() const;
+
+private:
+ void initChar(GooString &str);
+
+ int length;
+ Unicode *s;
+};
+
+#endif