~ubuntu-branches/ubuntu/quantal/cups-filters/quantal-proposed

« back to all changes in this revision

Viewing changes to filter/pdftopdf.old/UGooString.cxx

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2012-08-20 14:53:42 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20120820145342-bddzpwqv0klmt84d
Tags: 1.0.22-1
* New upstream release
   - pdftopdf filter replaced by new QPDF-based filter from Tobias
     Hoffmann's Google Summer of Code project. The former Poppler-based
     pdftopdf duplicated a lot of Poppler's code. The old filter is
     still in the package as pdftopdf.old with source code in
     filter/pdftopdf.old. It will be removed in a later release.
   - bannertopdf: Page duplication routine fixed.
   - bannertopdf: Fixed invalid output of a direct stream object.
   - Added most recent contributors to AUTHORS and COPYING files.
* debian/control: Added build dependency on libqpdf-dev.
* debian/copyright: Updated for the addition of the new pdftopdf filter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// UGooString.cc
 
4
//
 
5
// Unicode string
 
6
//
 
7
// Copyright 2005 Albert Astals Cid <aacid@kde.org>
 
8
//
 
9
//========================================================================
 
10
 
 
11
#include <string.h>
 
12
 
 
13
#include "goo/gmem.h"
 
14
#include "goo/GooString.h"
 
15
#include "PDFDocEncoding.h"
 
16
#include "UGooString.h"
 
17
 
 
18
UGooString::UGooString(Unicode *u, int l)
 
19
{
 
20
  s = u;
 
21
  length = l;
 
22
}
 
23
 
 
24
UGooString::UGooString(GooString &str)
 
25
{
 
26
  if ((str.getChar(0) & 0xff) == 0xfe && (str.getChar(1) & 0xff) == 0xff)
 
27
  {
 
28
    length = (str.getLength() - 2) / 2;
 
29
    s = (Unicode *)gmallocn(length, sizeof(Unicode));
 
30
    for (int j = 0; j < length; ++j) {
 
31
      s[j] = ((str.getChar(2 + 2*j) & 0xff) << 8) | (str.getChar(3 + 2*j) & 0xff);
 
32
    }
 
33
  } else
 
34
    initChar(str);
 
35
}
 
36
 
 
37
UGooString::UGooString(const UGooString &str)
 
38
{
 
39
  length = str.length;
 
40
  s = (Unicode *)gmallocn(length, sizeof(Unicode));
 
41
  memcpy(s, str.s, length * sizeof(Unicode));
 
42
}
 
43
 
 
44
UGooString::UGooString(const char *str)
 
45
{
 
46
  GooString aux(str);
 
47
  initChar(aux);
 
48
}
 
49
 
 
50
void UGooString::initChar(GooString &str)
 
51
{
 
52
  length = str.getLength();
 
53
  s = (Unicode *)gmallocn(length, sizeof(Unicode));
 
54
  bool anyNonEncoded = false;
 
55
  for (int j = 0; j < length && !anyNonEncoded; ++j) {
 
56
    s[j] = pdfDocEncoding[str.getChar(j) & 0xff];
 
57
    if (!s[j]) anyNonEncoded = true;
 
58
  }
 
59
  if ( anyNonEncoded )
 
60
  {
 
61
    for (int j = 0; j < length; ++j) {
 
62
      s[j] = str.getChar(j);
 
63
    }
 
64
  }
 
65
}
 
66
 
 
67
UGooString::~UGooString()
 
68
{
 
69
  gfree(s);
 
70
}
 
71
 
 
72
int UGooString::cmp(UGooString *str) const
 
73
{
 
74
  int n1, n2, i, x;
 
75
  Unicode *p1, *p2;
 
76
 
 
77
  n1 = length;
 
78
  n2 = str->length;
 
79
  for (i = 0, p1 = s, p2 = str->s; i < n1 && i < n2; ++i, ++p1, ++p2) {
 
80
    x = *p1 - *p2;
 
81
    if (x != 0) {
 
82
      return x;
 
83
    }
 
84
  }
 
85
  return n1 - n2;
 
86
}
 
87
 
 
88
char *UGooString::getCString() const
 
89
{
 
90
  char *res = new char[length + 1];
 
91
  for (int i = 0; i < length; i++) res[i] = s[i];
 
92
  res[length] = '\0';
 
93
  return res;
 
94
}