1
// --------------------------------------------------------------------
2
// Loading IML stream (and objects) from PDF file
3
// --------------------------------------------------------------------
6
This file is part of the extensible drawing editor Ipe.
7
Copyright (C) 1993-2004 Otfried Cheong
9
Ipe is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
As a special exception, you have permission to link Ipe with the
15
CGAL library and distribute executables, as long as you follow the
16
requirements of the Gnu General Public License in regard to all of
17
the software in the executable aside from CGAL.
19
Ipe is distributed in the hope that it will be useful, but WITHOUT
20
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
22
License for more details.
24
You should have received a copy of the GNU General Public License
25
along with Ipe; if not, you can find it at
26
"http://www.gnu.org/copyleft/gpl.html", or write to the Free
27
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32
#include "ipepdfloader_p.h"
36
// --------------------------------------------------------------------
38
IpePdfParser::IpePdfParser(IpePdfLoader &loader, IpeRepository *rep)
39
: IpeImlParser(loader, rep)
41
iXRef = loader.iDoc->getXRef();
44
IpeString IpePdfParser::PdfStream(int objNum)
47
iXRef->fetch(objNum, 0, &streamObj);
48
if (streamObj->isStream()) {
49
Stream *str = streamObj->getStream()->getBaseStream();
53
while ((ch = str->getChar()) != EOF)
60
// --------------------------------------------------------------------
62
/*! \class IpePdfLoader
63
\brief Loader for PDF files written by Ipe.
65
Create an IpePdfLoader given a file name.
66
Check that the file has been opened okay using IsOk().
67
Check that it is a file written by Ipe using IsIpeFile().
71
//! Create a loader object.
72
IpePdfLoader::IpePdfLoader(QString fname)
79
// iDoc takes ownership of GString
80
iDoc = new PDFDoc(new GString(fname.utf8()));
84
// try opening object # 1
85
iDoc->getXRef()->fetch(1, 0, &iStreamObj);
86
if (iStreamObj->isStream() && iStreamObj->streamIs("Ipe")) {
88
iStreamObj->streamReset();
93
// otherwise, use /Ipe key in /Catalog (first preview versions of Ipe 6.0)
95
iDoc->getXRef()->getCatalog(&catObj);
96
if (catObj->isNull() || !catObj->isDict("Catalog")) {
100
catObj->dictLookupNF("Ipe", &ipeRefObj);
101
if (ipeRefObj->isNull() || !ipeRefObj->isRef() ||
102
ipeRefObj->getRef().gen != 0)
105
iIpeStream = ipeRefObj->getRef().num;
106
iDoc->getXRef()->fetch(iIpeStream, 0, &iStreamObj);
107
iStreamObj->streamReset();
111
IpePdfLoader::~IpePdfLoader()
116
//! Has PDF file been opened okay?
117
bool IpePdfLoader::IsOk() const
119
return (iDoc && iDoc->isOk() && iIpeStream >= 0);
122
//! Read one character from Ipe stream in PDF document.
123
int IpePdfLoader::GetChar()
125
return iStreamObj->streamGetChar();
128
// --------------------------------------------------------------------