summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/luapplib/pptest3.c
blob: 0b96b229ad0ac2a86b3761e51840c00557db9e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

#include <stdio.h>
//#include "ppapi.h"
#include "pplib.h"
#include "assert.h"

static int usage (const char *argv0)
{
	printf("pplib " pplib_version ", " pplib_author "\n");
	printf("usage: %s file1.pdf file2.pdf ...\n", argv0);
	return 0;
}

static void print_result_filter (ppstream *stream, int decode)
{
  ppstream_filter info;
  size_t i;

  ppstream_filter_info(stream, &info, decode);
  printf("when %s: /Filter [", decode ? "uncompressed" : "compressed");
  for (i = 0; i < info.count; ++i)
	  printf(" /%s", ppstream_filter_name[info.filters[i]]);
	printf(" ]");
	if (info.params != NULL)
	{
		printf(" /DecodeParms [");
		for (i = 0; i < info.count; ++i)
			printf(" %s", info.params[i] != NULL ? "<<...>>" : "null");
		printf(" ]");
	}
  printf("\n");
}

static void print_stream_info (ppref *ref, ppstream *stream)
{	
	size_t length;
	printf("object %lu %lu R\n", (unsigned long)ref->number, (unsigned long)ref->version);
	if (stream->flags & PPSTREAM_FILTER)
		printf("filtered ");
	else
	  printf("plain ");
	if (stream->flags & PPSTREAM_IMAGE)
	  printf("image ");
	else
	  printf("stream ");
	if (stream->flags & PPSTREAM_ENCRYPTED)
		printf("encrypted ");
	if (stream->flags & PPSTREAM_NOT_SUPPORTED)
	  printf("invalid ");
	if (!ppdict_rget_uint(stream->dict, "Length", &length))
		length = 0;
	assert(stream->length == length);
	printf("length %lu (/Length %lu)\n", (unsigned long)stream->length, (unsigned long)length);
	print_result_filter(stream, 0);
	print_result_filter(stream, 1);
	printf("\n");
}

int main (int argc, const char **argv)
{
  const char *filepath;
  int a;
  ppdoc *pdf;
  ppxref *xref;
  ppxsec *xsec;
  size_t xi;
  ppuint refnum;
  ppref *ref;

  if (argc < 2)
    return usage(argv[0]);
  for (a = 1; a < argc; ++a)
  {
    filepath = argv[a];
    printf("loading %s... ", filepath);
    pdf = ppdoc_load(filepath);
    if (pdf == NULL)
    {
      printf("failed\n");
      continue;
    }
    printf("done.\n");
		for (xref = ppdoc_xref(pdf); xref != NULL; xref = ppxref_prev(xref))
		{
			for (xi = 0, xsec = xref->sects; xi < xref->size; ++xi, ++xsec)
			{
				for (refnum = xsec->first, ref = xsec->refs; refnum <= xsec->last; ++refnum, ++ref)
				{
					if (ref->object.type != PPSTREAM)
					  continue;
					print_stream_info(ref, ref->object.stream);
				}
			}			
		}
    ppdoc_free(pdf);
  }
  return 0;
}