1 | /* poppler-input-stream.cc: glib interface to poppler |
2 | * |
3 | * Copyright (C) 2012 Carlos Garcia Campos <carlosgc@gnome.org> |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2, or (at your option) |
8 | * any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "config.h" |
21 | #include "poppler-input-stream.h" |
22 | |
23 | PopplerInputStream::PopplerInputStream(GInputStream *inputStreamA, GCancellable *cancellableA, Goffset startA, bool limitedA, Goffset lengthA, Object &&dictA) : BaseSeekInputStream(startA, limitedA, lengthA, std::move(dictA)) |
24 | { |
25 | inputStream = (GInputStream *)g_object_ref(inputStreamA); |
26 | cancellable = cancellableA ? (GCancellable *)g_object_ref(cancellableA) : nullptr; |
27 | } |
28 | |
29 | PopplerInputStream::~PopplerInputStream() |
30 | { |
31 | close(); |
32 | g_object_unref(object: inputStream); |
33 | if (cancellable) { |
34 | g_object_unref(object: cancellable); |
35 | } |
36 | } |
37 | |
38 | BaseStream *PopplerInputStream::copy() |
39 | { |
40 | return new PopplerInputStream(inputStream, cancellable, start, limited, length, dict.copy()); |
41 | } |
42 | |
43 | Stream *PopplerInputStream::makeSubStream(Goffset startA, bool limitedA, Goffset lengthA, Object &&dictA) |
44 | { |
45 | return new PopplerInputStream(inputStream, cancellable, startA, limitedA, lengthA, std::move(dictA)); |
46 | } |
47 | |
48 | Goffset PopplerInputStream::currentPos() const |
49 | { |
50 | GSeekable *seekable = G_SEEKABLE(inputStream); |
51 | return g_seekable_tell(seekable); |
52 | } |
53 | |
54 | void PopplerInputStream::setCurrentPos(Goffset offset) |
55 | { |
56 | GSeekable *seekable = G_SEEKABLE(inputStream); |
57 | g_seekable_seek(seekable, offset, type: G_SEEK_SET, cancellable, error: nullptr); |
58 | } |
59 | |
60 | Goffset PopplerInputStream::read(char *buffer, Goffset count) |
61 | { |
62 | return g_input_stream_read(stream: inputStream, buffer, count, cancellable, error: nullptr); |
63 | } |
64 | |