home *** CD-ROM | disk | FTP | other *** search
- //========================================================================
- //
- // PDFDoc.cc
- //
- // Copyright 1996 Derek B. Noonburg
- //
- //========================================================================
- //
- // Ported to EPOC by Sander van der Wal
- //
- // $Log: PDFDoc.cpp $
- // Revision 1.2 2000-09-17 13:38:21+02 svdwal
- // Ported
- //
-
- #ifdef __GNUC__
- #pragma implementation
- #endif
-
- #ifndef __E32DEF_H__
- #include <e32base.h> // remove warning about NULL redefinition
- #endif
-
- #include "GString.h"
-
- #include "config.h"
- #include "Page.h"
- #include "Catalog.h"
- #include "XRef.h"
- #include "Link.h"
- #include "OutputDev.h"
- #include "Error.h"
- #include "PDFDoc.h"
-
- #include "Pdf.rsg"
-
- //------------------------------------------------------------------------
- // PDFDoc
- //------------------------------------------------------------------------
-
- void PDFDoc::ConstructL(RFs& aFsSession, const TFileName& aFileName)
- {
- FileStream *str;
- RAutoObject catObj;
- RAutoObject obj;
-
- ok = gFalse;
-
- fileName = aFileName;
-
- TInt err = file.Open(aFsSession, fileName, EFileRead|EFileStream|EFileShareReadersOnly);
- switch (err) {
- case KErrNone:
- break;
- case KErrNoMemory:
- User::LeaveNoMemory(); break;
- default:
- error(-1, R_COULDN_T_OPEN_FILE___S_, (const char*)fileName.Ptr());
- return;
- }
-
- // create stream
-
- obj.initNull();
- str = new(ELeave) FileStream(file, 0, -1, &obj);
- CleanupStack::PushL(str);
-
- // check header
- str->checkHeader();
-
- // read xref table
- xref = new(ELeave) XRef();
- xref->ConstructL(str);
- CleanupStack::PopAndDestroy(); // delete str;
- if (!xref->isOk()) {
- error(-1, R_COULDN_T_READ_XREF_TABLE);
- return;
- }
-
- // read catalog
- catalog = new(ELeave) Catalog();
- catalog->ConstructL(xref->getCatalogL(&catObj));
- catObj.free();
- if (!catalog->isOk()) {
- error(-1, R_COULDN_T_READ_PAGE_CATALOG);
- return;
- }
-
- // done
- ok = gTrue;
- }
-
-
- PDFDoc::~PDFDoc() {
- delete catalog;
- delete xref;
- file.Close();
- delete links;
- }
-
- void PDFDoc::displayPageL(OutputDev *out, int page, int zoom, int rotate,
- GBool doLinks) {
-
- #ifndef __SYMBIAN32__
- if (printCommands)
- printf("***** page %d *****\n", page);
- #endif
-
- if (doLinks)
- getLinksL(page);
- catalog->getPage(page)->displayL(out, zoom, rotate);
- if (doLinks)
- DisplayLinks(out, page);
-
- }
-
-
- void PDFDoc::DisplayLinks(OutputDev *out, int /* page */) {
- Link *link;
- double x1, y1, x2, y2;
- double w;
- int i;
-
- for (i = 0; i < links->getNumLinks(); ++i) {
- link = links->getLink(i);
- link->getBorder(&x1, &y1, &x2, &y2, &w);
- if (w > 0)
- out->drawLinkBorder(x1, y1, x2, y2, w);
- }
- out->dump();
- }
-
-
- void PDFDoc::displayPagesL(OutputDev *out, int firstPage, int lastPage,
- int zoom, int rotate) {
- Page *p;
- int page;
-
- for (page = firstPage; page <= lastPage; ++page) {
- #ifndef __SYMBIAN32__
- if (printCommands)
- printf("***** page %d *****\n", page);
- #endif
- p = catalog->getPage(page);
- p->displayL(out, zoom, rotate);
- }
- }
-
-
- #if 0
- GBool PDFDoc::saveAs(GString *name) {
- char buf[256];
- int n;
- FILE *f = fopen(name->getCString(), "wb");
- if (!f) {
- error(-1, R_COULDN_T_OPEN_FILE___S_, name->getCString());
- return gFalse;
- }
- rewind(file);
- while ((n = fread(buf, 1, sizeof(buf), file)) > 0)
- fwrite(buf, 1, n, f);
- fclose(f);
- return gTrue;
- }
- #endif
-
-
- void PDFDoc::getLinksL(int page) {
- RAutoObject obj;
-
- // cleanup-safe way of creating new links
- Links* l = new(ELeave) Links();
- CleanupStack::PushL(l);
- l->ConstructL(catalog->getPage(page)->getAnnotsL(&obj),
- catalog->getBaseURI());
- CleanupStack::Pop(); // l
- obj.free();
-
- delete links;
- links = l;
- }
-