3
Copyright (c) 2006-2007, BBR Inc. All rights reserved.
5
Permission is hereby granted, free of charge, to any person obtaining
6
a copy of this software and associated documentation files (the
7
"Software"), to deal in the Software without restriction, including
8
without limitation the rights to use, copy, modify, merge, publish,
9
distribute, sublicense, and/or sell copies of the Software, and to
10
permit persons to whom the Software is furnished to do so, subject to
11
the following conditions:
13
The above copyright notice and this permission notice shall be included
14
in all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
pdftopdf output pdf routines
33
#include "UGooString.h"
34
#include "P2POutput.h"
35
#include "P2PObject.h"
39
void P2POutput::outputDict(Dict *dict, const char **keys,
40
P2PObject **objs, int len, P2POutputStream *str, XRef *xref)
43
int n = dict->getLength();
47
for (i = 0;i < n;i++) {
48
#ifdef HAVE_UGOOSTRING_H
49
char *key = dict->getKey(i)->getCString();
51
char *key = dict->getKey(i);
55
for (j = 0;j < len;j++) {
56
if (strcmp(keys[j],key) == 0) {
63
dict->getValNF(i,&obj);
64
outputObject(&obj,str,xref);
67
#ifdef HAVE_UGOOSTRING_H
71
for (j = 0;j < len;j++) {
75
outputName(keys[j],str);
77
objs[j]->getNum(&num,&gen);
79
objs[j]->outputRef(str);
81
objs[j]->output(str,xref);
87
void P2POutput::outputDict(Dict *dict, P2POutputStream *str, XRef *xref)
90
int n = dict->getLength();
93
for (i = 0;i < n;i++) {
94
#ifdef HAVE_UGOOSTRING_H
95
char *key = dict->getKey(i)->getCString();
97
char *key = dict->getKey(i);
103
dict->getValNF(i,&obj);
104
outputObject(&obj,str,xref);
107
#ifdef HAVE_UGOOSTRING_H
114
void P2POutput::outputStream(Stream *stream, P2POutputStream *str, XRef *xref)
120
#ifdef HAVE_GETUNDECODEDSTREAM
121
stream = stream->getUndecodedStream();
123
stream = stream->getBaseStream();
125
dict = stream->getDict();
126
/* output dictionary part */
127
outputDict(dict,str,xref);
128
str->puts("\nstream\n");
130
for (len = 0;(c = stream->getChar()) != EOF;len++) {
133
str->puts("endstream");
136
void P2POutput::outputRef(Ref *ref, P2POutputStream *str, XRef *xref)
141
if ((p2pobj = P2PObject::find(ref->num,ref->gen)) == 0) {
142
obj.initRef(ref->num, ref->gen);
143
p2pobj = new P2PObj(&obj, ref->num, ref->gen);
146
P2PXRef::put(p2pobj);
147
p2pobj->outputRef(str);
150
void P2POutput::outputArray(Array *array, P2POutputStream *str, XRef *xref,
154
int n = array->getLength();
157
for (i = 0;i < n;i++) {
160
array->getNF(i,&obj);
161
outputObject(&obj,str,xref,mapDict);
168
void P2POutput::outputName(const char *name, P2POutputStream *str, Dict *mapDict)
171
#ifdef HAVE_UGOOSTRING_H
172
UGooString nameStr(name);
174
char *nameStr = const_cast<char *>(name);
177
static const char *punctures = "()<>[]{}/%#";
179
if (mapDict != 0 && mapDict->lookupNF(nameStr,&obj) != 0) {
182
name = obj.getName();
186
for (p = name;*p != '\0';p++) {
187
if (*p >= 33 && *p <= 126 && strchr(punctures,*p) == 0) {
190
str->printf("#%02x",*p & 0xff);
196
void P2POutput::outputString(const char *s, int len, P2POutputStream *str)
202
for (i = 0;i < len;i++,p++) {
232
str->printf("\\%03o",*p & 0xff);
240
void P2POutput::outputObject(Object *obj, P2POutputStream *str, XRef *xref,
243
switch (obj->getType()) {
245
if (obj->getBool()) {
252
str->printf("%d",obj->getInt());
255
str->printf("%u",obj->getUint());
258
str->printf("%f",obj->getReal());
261
outputString(obj->getString()->getCString(),
262
obj->getString()->getLength(), str);
265
outputName(obj->getName(),str,mapDict);
271
outputArray(obj->getArray(),str,xref,mapDict);
274
outputDict(obj->getDict(),str,xref);
277
outputStream(obj->getStream(),str,xref);
281
Ref ref = obj->getRef();
283
outputRef(&ref,str,xref);
287
str->puts(obj->getCmd());
290
str->puts("<error>");