CPDFCore Class Reference

#include <PDFCore.h>

Collaboration diagram for CPDFCore:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 CPDFCore (SplashColorMode colorModeA, int bitmapRowPadA, GBool reverseVideoA, SplashColorPtr paperColorA)
 ~CPDFCore (void)
void setController (struct Controller *c)
int open (GooString *fileNameA, GooString *ownerPassword=NULL, GooString *userPassword=NULL, void *guiDataA=NULL)
int open (BaseStream *stream, GooString *ownerPassword=NULL, GooString *userPassword=NULL, void *guiDataA=NULL)
void close ()
RenderRet renderPage (CPageInfo &info, GBool useMediaBox, GBool crop, GBool doLinks, GBool(*abortCheckCbk)(void *data)=NULL, void *abortCheckCbkData=NULL)
PDFDoc * getPDFDoc ()
int getNumPages ()
double getZoomMax (const int pageNumber)
int getPageType (const int pageNumber)
double verifyZoomMax (double zoom, const int pageNumber)
double getPageWidth (const int pageNumber)
double getPageHeight (const int pageNumber)
int getPageRotate (const int pageNumber)

Protected Member Functions

void calculateLayout (CPageInfo &info)
void getPageBasicInfo (CPageInfo &info)

Private Attributes

PDFDoc * pdfdoc
SplashOutputDev * outputDev
TextOutputDev * textOut
Controllerctrl


Detailed Description

Definition at line 40 of file PDFCore.h.


Constructor & Destructor Documentation

CPDFCore::CPDFCore ( SplashColorMode  colorModeA,
int  bitmapRowPadA,
GBool  reverseVideoA,
SplashColorPtr  paperColorA 
)

Definition at line 24 of file PDFCore.cpp.

00026 {
00027     outputDev = NULL;//new SplashOutputDev(colorModeA, bitmapRowPadA, reverseVideoA, paperColorA);
00028     textOut = NULL;//new TextOutputDev(NULL, gTrue, gFalse, gFalse);
00029     pdfdoc = NULL;    
00030     ctrl   = NULL;
00031 }

CPDFCore::~CPDFCore ( void   ) 

Definition at line 33 of file PDFCore.cpp.

00034 {
00035     if (outputDev) { delete outputDev; outputDev = NULL; }
00036     if (pdfdoc) { delete pdfdoc; pdfdoc = NULL; }
00037     ctrl = NULL;
00038 }


Member Function Documentation

void CPDFCore::calculateLayout ( CPageInfo info  )  [protected]

Definition at line 195 of file PDFCore.cpp.

00196 {
00197     PV_LOGPRINTF("info.pageZoom %lg\n", info.pageZoom);
00198     info.hDPI = info.pageZoom * 0.01 * DefDPI;
00199     info.vDPI = info.pageZoom * 0.01 * DefDPI;
00200 }

void CPDFCore::getPageBasicInfo ( CPageInfo info  )  [protected]

Definition at line 91 of file PDFCore.cpp.

00092 {
00093     info.pageDx = pdfdoc->getPageCropWidth(info.pageNumber);
00094     info.pageDy = pdfdoc->getPageCropHeight(info.pageNumber);
00095     info.pageRotate = pdfdoc->getPageRotate(info.pageNumber);
00096 }

void CPDFCore::setController ( struct Controller c  )  [inline]

Definition at line 57 of file PDFCore.h.

00057 {ctrl = c; }

int CPDFCore::open ( GooString *  fileNameA,
GooString *  ownerPassword = NULL,
GooString *  userPassword = NULL,
void *  guiDataA = NULL 
)

Definition at line 41 of file PDFCore.cpp.

00043 {
00044     int ret = errNone;
00045     // already open 
00046     if (pdfdoc)
00047     {
00048         PV_LOGPRINTF("Delete old doc %p\n", pdfdoc);
00049         delete pdfdoc;
00050     }
00051 
00052     // construct a new one
00053     pdfdoc = new PDFDoc(fileNameA, ownerPassword, userPassword, guiDataA);
00054     
00055     // check result
00056     if (!pdfdoc->isOk())
00057     {
00058         ret = pdfdoc->getErrorCode();
00059         delete pdfdoc;
00060         PV_ERRORPRINTF("Open PDF document %s failed with error code %d", 
00061             fileNameA->getCString(), ret);                
00062         return errOpenFile; 
00063     }
00064     
00065     // done
00066     if (NULL == outputDev)
00067     {
00068         SplashColor     white;
00069         white[0] = 255;
00070         white[1] = 255;
00071         white[2] = 255;
00072         outputDev = new SplashOutputDev(splashModeMono8, 4, gFalse, white);
00073     }
00074     outputDev->startDoc(pdfdoc->getXRef());
00075     return ret;
00076 }

int CPDFCore::open ( BaseStream *  stream,
GooString *  ownerPassword = NULL,
GooString *  userPassword = NULL,
void *  guiDataA = NULL 
)

Definition at line 78 of file PDFCore.cpp.

00080 {
00081     return errNone;
00082 }

void CPDFCore::close (  ) 

Definition at line 85 of file PDFCore.cpp.

00086 {
00087     if (outputDev) {  delete outputDev; outputDev = NULL; }
00088     if (pdfdoc) { delete pdfdoc; pdfdoc = NULL; }
00089 }

RenderRet CPDFCore::renderPage ( CPageInfo info,
GBool  useMediaBox,
GBool  crop,
GBool  doLinks,
GBool(*)(void *data)  abortCheckCbk = NULL,
void *  abortCheckCbkData = NULL 
)

Definition at line 119 of file PDFCore.cpp.

00122 {
00123     if (NULL == pdfdoc)
00124     {
00125         PV_ERRORPRINTF("PDF document has not been opened!");    
00126         return Render_Error;
00127     }
00128 
00129     if (0 >= info.pageNumber || info.pageNumber > pdfdoc->getNumPages())
00130     {
00131         PV_ERRORPRINTF("PageNumber %d is invalid![1, %d]", 
00132             info.pageNumber,  pdfdoc->getNumPages());
00133         return Render_Error;
00134     }
00135 
00136     // get page basic information
00137     getPageBasicInfo(info);
00138 
00139     // calcuate layout
00140     calculateLayout(info);
00141 
00142     // render it now
00143 #if (PV_PROFILE_ON)
00144     int t1 = ctrl->getHighTimeStamp();
00145 #endif 
00146 
00147     RenderRet ret = Render_Error;
00148     
00149     ret = pdfdoc->displayPage(outputDev, info.pageNumber, 
00150         info.hDPI, info.vDPI, info.rotate, useMediaBox, crop, doLinks,
00151         abortCheckCbk, abortCheckCbkData);
00152     
00153     // check result
00154     if (ret == Render_Error || ret == Render_Invalid)
00155     {
00156         PV_ERRORPRINTF("Render page error!");
00157         return ret;
00158     }
00159 
00160     // bitmap has been allocated
00161     info.bitmap = outputDev->takeBitmap();
00162     if (ret == Render_Done)
00163     {
00164 #if (PV_PROFILE_ON)
00165         int t2 = ctrl->getHighTimeStamp();
00166         PV_DUMP("PDFDoc::displayPage %d uses %d\n", info.pageNumber, t2 - t1);
00167 #endif
00168             
00169         // copy ctm and ictm
00170         memcpy(info.ctm, outputDev->getDefCTM(), 6 * sizeof(double));
00171         memcpy(info.ictm, outputDev->getDefICTM(), 6 * sizeof(double));        
00172                 
00173         // take links
00174         info.links  = pdfdoc->takeLinks();
00175         
00176         // take text
00177         if (textOut)
00178         {
00179             pdfdoc->displayPage(textOut, info.pageNumber, info.hDPI, info.vDPI, info.rotate,
00180                 gFalse, gTrue, gFalse);
00181             info.text = textOut->takeText();                
00182         }
00183         return Render_Done;
00184     }
00185     else if (ret == Render_Abort)
00186     {
00187         delete info.bitmap; 
00188         info.bitmap = NULL;
00189         info.links  = NULL;
00190     }
00191     return Render_Abort;
00192 }

Here is the call graph for this function:

PDFDoc* CPDFCore::getPDFDoc (  )  [inline]

Definition at line 66 of file PDFCore.h.

00066 { return pdfdoc; }

int CPDFCore::getNumPages (  ) 

Definition at line 113 of file PDFCore.cpp.

00114 {
00115     if (NULL == pdfdoc) return -1;
00116     return pdfdoc->getNumPages();
00117 }

double CPDFCore::getZoomMax ( const int  pageNumber  ) 

Definition at line 254 of file PDFCore.cpp.

00255 {
00256     /*
00257     if (NULL == pdfdoc) 
00258     {
00259         PV_ERRORPRINTF("Try to access NULL pdfdoc pointer!");
00260         return -1;
00261     }
00262     if (pageNumber < 1 || pageNumber > pdfdoc->getNumPages()) 
00263     {
00264         PV_ERRORPRINTF("Invalid page number %d!", pageNumber);
00265         return -1;
00266     }
00267     */
00268     int pageMx = (int)pdfdoc->getPageMediaWidth(pageNumber);
00269     int pageMy = (int)pdfdoc->getPageMediaHeight(pageNumber);
00270     for(int i = 0 ; i < PageSpecSize; ++i)
00271     {
00272         if ((pageMx >= PageSpecTable[i].hISO && 
00273              pageMy >= PageSpecTable[i].wISO) ||
00274              (pageMy >= PageSpecTable[i].hISO && 
00275              pageMx >= PageSpecTable[i].wISO))
00276         {
00277             // PV_LOGPRINTF("Page type %d\n", i);
00278             return PageSpecTable[i].zoomMax;
00279         }
00280     }
00281     return ZoomMax;
00282 }

int CPDFCore::getPageType ( const int  pageNumber  ) 

Definition at line 227 of file PDFCore.cpp.

00228 {
00229     if (NULL == pdfdoc) 
00230     {
00231         PV_ERRORPRINTF("Try to access NULL pdfdoc pointer!");
00232         return -1;
00233     }
00234     if (pageNumber < 1 || pageNumber > pdfdoc->getNumPages()) 
00235     {
00236         PV_ERRORPRINTF("Invalid page number %d!", pageNumber);
00237         return -1;
00238     }
00239     int pageMx = (int)pdfdoc->getPageMediaWidth(pageNumber);
00240     int pageMy = (int)pdfdoc->getPageMediaHeight(pageNumber);
00241     for(int i = 0 ; i < PageSpecSize; ++i)
00242     {
00243         if ((pageMx >= PageSpecTable[i].hISO && 
00244              pageMy >= PageSpecTable[i].wISO) ||
00245              (pageMy >= PageSpecTable[i].hISO && 
00246              pageMx >= PageSpecTable[i].wISO))
00247         {
00248             return i;
00249         }
00250     }
00251     return -1;
00252 }

double CPDFCore::verifyZoomMax ( double  zoom,
const int  pageNumber 
)

Definition at line 287 of file PDFCore.cpp.

00288 {
00289     double tmp = getZoomMax(pageNumber);
00290     if (zoom > tmp)
00291     {
00292         return tmp;
00293     }
00294     return zoom;
00295 }

Here is the call graph for this function:

double CPDFCore::getPageWidth ( const int  pageNumber  ) 

Definition at line 98 of file PDFCore.cpp.

00099 {
00100     return pdfdoc->getPageCropWidth(pageNumber);
00101 }

double CPDFCore::getPageHeight ( const int  pageNumber  ) 

Definition at line 103 of file PDFCore.cpp.

00104 {
00105     return pdfdoc->getPageCropHeight(pageNumber);
00106 }

int CPDFCore::getPageRotate ( const int  pageNumber  ) 

Definition at line 108 of file PDFCore.cpp.

00109 {
00110     return pdfdoc->getPageRotate(pageNumber);
00111 }


Member Data Documentation

PDFDoc* CPDFCore::pdfdoc [private]

Definition at line 43 of file PDFCore.h.

SplashOutputDev* CPDFCore::outputDev [private]

Definition at line 44 of file PDFCore.h.

TextOutputDev* CPDFCore::textOut [private]

Definition at line 45 of file PDFCore.h.

Definition at line 46 of file PDFCore.h.


The documentation for this class was generated from the following files:

Generated on Wed Feb 4 18:26:12 2009 by  doxygen 1.5.6