summaryrefslogtreecommitdiff
path: root/src/pdf_doc.h
blob: 27a730a403ae53862d16ed7abb6435237ff318a1 (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
/*
 * Copyright 2018 Vincent Sanders <vince@netsurf-browser.org>
 *
 * This file is part of libnspdf.
 *
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 */

/**
 * \file
 * NetSurf PDF library pdf document
 */

#ifndef NSPDF__PDF_DOC_H_
#define NSPDF__PDF_DOC_H_

struct xref_table_entry;
struct page_table_entry;

/**
 * pdf document
 */
struct nspdf_doc {

    const uint8_t *start; /* start of pdf document in input stream */
    unsigned int length;

    /**
     * input data stream
     */
    struct cos_stream *stream;

    int major;
    int minor;

    /**
     * Indirect object cross reference table
     */
    uint64_t xref_table_size;
    struct xref_table_entry *xref_table;

    struct cos_object *root;
    struct cos_object *encrypt;
    struct cos_object *info;
    struct cos_object *id;

    /* page refrerence table */
    uint64_t page_table_size;
    struct page_table_entry *page_table;
};

/* byte data acessory, allows for more complex buffer handling in future */
#define DOC_BYTE(doc, offset) (doc->start[(offset)])

static inline uint8_t
stream_byte(struct cos_stream *stream, unsigned int offset)
{
    return *(stream->data + offset);
}

/* helpers in pdf_doc.c */
nspdferror nspdf__stream_skip_ws(struct cos_stream *stream, uint64_t *offset);
nspdferror doc_skip_eol(struct nspdf_doc *doc, uint64_t *offset);
nspdferror doc_read_uint(struct nspdf_doc *doc, uint64_t *offset_out, uint64_t *result_out);

/* cross reference table handlers */
/**
 * parse xref from file
 */
nspdferror nspdf__xref_parse(struct nspdf_doc *doc, uint64_t *offset_out);


/**
 * get an object dereferencing through xref table if necessary
 */
nspdferror nspdf__xref_get_referenced(struct nspdf_doc *doc, struct cos_object **cobj_out);

nspdferror nspdf__xref_allocate(struct nspdf_doc *doc, int64_t size);

nspdferror nspdf__decode_page_tree(struct nspdf_doc *doc, struct cos_object *page_tree_node, unsigned int *page_index);

/* cos stream filters */
nspdferror nspdf__cos_stream_filter(struct nspdf_doc *doc, const char *filter_name, struct cos_stream **stream_out);

#endif