~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/cpp/poppler-embedded-file.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009-2010, Pino Toscano <pino@kde.org>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2, or (at your option)
 
7
 * any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "poppler-embedded-file.h"
 
20
 
 
21
#include "poppler-embedded-file-private.h"
 
22
#include "poppler-private.h"
 
23
 
 
24
#include "Object.h"
 
25
#include "Stream.h"
 
26
#include "Catalog.h"
 
27
 
 
28
using namespace poppler;
 
29
 
 
30
embedded_file_private::embedded_file_private(EmbFile *ef)
 
31
    : emb_file(ef)
 
32
{
 
33
}
 
34
 
 
35
embedded_file_private::~embedded_file_private()
 
36
{
 
37
    delete emb_file;
 
38
}
 
39
 
 
40
embedded_file* embedded_file_private::create(EmbFile *ef)
 
41
{
 
42
    return new embedded_file(*new embedded_file_private(ef));
 
43
}
 
44
 
 
45
/**
 
46
 \class poppler::embedded_file poppler-embedded-file.h "poppler/cpp/poppler-embedded-file.h"
 
47
 
 
48
 Represents a file embedded in a PDF %document.
 
49
 */
 
50
 
 
51
 
 
52
embedded_file::embedded_file(embedded_file_private &dd)
 
53
    : d(&dd)
 
54
{
 
55
}
 
56
 
 
57
/**
 
58
 Destroys the embedded file.
 
59
 */
 
60
embedded_file::~embedded_file()
 
61
{
 
62
    delete d;
 
63
}
 
64
 
 
65
/**
 
66
 \returns whether the embedded file is valid
 
67
 */
 
68
bool embedded_file::is_valid() const
 
69
{
 
70
    return d->emb_file->isOk();
 
71
}
 
72
 
 
73
/**
 
74
 \returns the name of the embedded file
 
75
 */
 
76
std::string embedded_file::name() const
 
77
{
 
78
    return std::string(d->emb_file->name()->getCString());
 
79
}
 
80
 
 
81
/**
 
82
 \returns the description of the embedded file
 
83
 */
 
84
ustring embedded_file::description() const
 
85
{
 
86
    return detail::unicode_GooString_to_ustring(d->emb_file->description());
 
87
}
 
88
 
 
89
/**
 
90
 \note this is not always available in the PDF %document, in that case this
 
91
       will return \p -1.
 
92
 
 
93
 \returns the size of the embedded file, if known
 
94
 */
 
95
int embedded_file::size() const
 
96
{
 
97
    return d->emb_file->size();
 
98
}
 
99
 
 
100
/**
 
101
 \returns the time_t representing the modification date of the embedded file,
 
102
          if available
 
103
 */
 
104
time_type embedded_file::modification_date() const
 
105
{
 
106
    return detail::convert_date(d->emb_file->modDate()->getCString());
 
107
}
 
108
 
 
109
/**
 
110
 \returns the time_t representing the creation date of the embedded file,
 
111
          if available
 
112
 */
 
113
time_type embedded_file::creation_date() const
 
114
{
 
115
    return detail::convert_date(d->emb_file->createDate()->getCString());
 
116
}
 
117
 
 
118
/**
 
119
 \returns the checksum of the embedded file
 
120
 */
 
121
byte_array embedded_file::checksum() const
 
122
{
 
123
    GooString *cs = d->emb_file->checksum();
 
124
    const char *ccs = cs->getCString();
 
125
    byte_array data(cs->getLength());
 
126
    for (int i = 0; i < cs->getLength(); ++i) {
 
127
        data[i] = ccs[i];
 
128
    }
 
129
    return data;
 
130
}
 
131
 
 
132
/**
 
133
 \returns the MIME type of the embedded file, if available
 
134
 */
 
135
std::string embedded_file::mime_type() const
 
136
{
 
137
    return std::string(d->emb_file->mimeType()->getCString());
 
138
}
 
139
 
 
140
/**
 
141
 Reads all the data of the embedded file.
 
142
 
 
143
 \returns the data of the embedded file
 
144
 */
 
145
byte_array embedded_file::data() const
 
146
{
 
147
    if (!is_valid()) {
 
148
        return byte_array();
 
149
    }
 
150
 
 
151
    Stream *stream = d->emb_file->streamObject().getStream();
 
152
    stream->reset();
 
153
    byte_array ret(1024);
 
154
    size_t data_len = 0;
 
155
    int i;
 
156
    while ((i = stream->getChar()) != EOF) {
 
157
        if (data_len == ret.size()) {
 
158
            ret.resize(ret.size() * 2);
 
159
        }
 
160
        ret[data_len] = (char)i;
 
161
        ++data_len;
 
162
    }
 
163
    ret.resize(data_len);
 
164
    return ret;
 
165
}