pdf::PDFPage Class Reference

The page information. More...

#include <pdf_page.h>

Collaboration diagram for pdf::PDFPage:
Collaboration graph
[legend]

Public Types

enum  RenderStatus { RENDER_DONE = 0, RENDER_RUNNING, RENDER_STOP }

Public Member Functions

 PDFPage (int page_num, const PDFRenderAttributes &attr)
 ~PDFPage (void)
size_t operator() ()
 Return the size_t value based on the pagenumber.
bool operator== (const PDFPage &right)
 Comparing.
bool operator== (const PDFRenderAttributes &right)
unsigned int destroy ()
 Destroy the resource of the page.
void lock ()
void unlock ()
 Unlock the page.
bool locked () const
 Is current page be locked.
void set_render_attr (const PDFRenderAttributes &attr)
const PDFRenderAttributesget_render_attr () const
 Get the render attributes.
int get_ref_id ()
 Get/Set the reference id.
void set_ref_id (int id)
int get_page_num () const
int get_bitmap_width ()
int get_bitmap_height ()
int get_bitmap_row_stride ()
SplashBitmap * get_bitmap () const
Links * get_links () const
TextPage * get_text () const
TextWordList * get_words_list ()
PDFControllerget_doc_controller () const
void set_doc_controller (PDFController *doc)
unsigned int length ()
 Get the data length of the bitmap.
const unsigned char * get_bitmap_data ()
 Get the data of the bitmap.
bool is_hyper_linked_page (int dst_page_num)
 Estimate whether the input is hyperlink page of current page.
bool render_splash_map (PDFRenderer *renderer, void *abort_data)
 Render a splash page by render attributes passed in.
bool render_text (PDFRenderer *renderer, bool use_defalt_setting=false)
 Render a text page by render attributes passed in.
SearchResult search (SearchContext &ctx, PDFSearchPage &results)
bool get_bounding_rectangles (const string &start_anchor, const string &end_anchor, PDFRectangles &rects)
 Get the bounding rectangles in the passed-in range.
RenderStatus get_render_status ()
 Get rendering status.
void get_anchor_param_from_coordinates (double x, double y, PDFAnchor &param)
 Get the anchor of (x, y).
int get_goto_page_of_link (int link_index)
 Get the destination's page number of the link.
bool get_goto_anchor_of_link (int link_index, std::string &anchor)
 Get the destination's anchor of the link.
bool get_range_param_by_link_index (const int link_index, PDFAnchor &start_param, PDFAnchor &end_param)
 Get the range of link by link index.
bool get_range_param_by_word_index (const int link_index, PDFAnchor &start_param, PDFAnchor &end_param)
 Get the range of word by word index.
bool get_text_by_range (const PDFAnchor &start_param, const PDFAnchor &end_param, std::string &result)
 Get the text by range.
bool get_content_area (PDFRenderer *renderer, RenderArea &area)
const RenderAreaget_content_area () const
void coordinates_dev_to_user (const double dx, const double dy, double *ux, double *uy)
 Translate point from device coordination to user's.
void coordinates_user_to_dev (const double ux, const double uy, int *dx, int *dy)

Friends

class PDFRenderTask
class PDFSearcher

Detailed Description

The page information.

Definition at line 125 of file pdf_page.h.


Member Enumeration Documentation

Render status, it would be used when submitting a new render task

Enumerator:
RENDER_DONE 
RENDER_RUNNING 
RENDER_STOP 

Definition at line 130 of file pdf_page.h.

00131     {
00132         RENDER_DONE = 0,
00133         RENDER_RUNNING,
00134         RENDER_STOP
00135     }RenderStatus;


Constructor & Destructor Documentation

pdf::PDFPage::PDFPage ( int  page_num,
const PDFRenderAttributes attr 
)

Definition at line 82 of file pdf_page.cpp.

00083 {
00084     init();
00085     page_number = page_num;
00086     render_attr = attr;
00087 }

pdf::PDFPage::~PDFPage ( void   ) 

Definition at line 89 of file pdf_page.cpp.

References destroy().

00090 {
00091     destroy();
00092 }

Here is the call graph for this function:


Member Function Documentation

void pdf::PDFPage::coordinates_dev_to_user ( const double  dx,
const double  dy,
double *  ux,
double *  uy 
)

Translate point from device coordination to user's.

Definition at line 1832 of file pdf_page.cpp.

01834 {
01835   *ux = ictm[0] * dx + ictm[2] * dy + ictm[4];
01836   *uy = ictm[1] * dx + ictm[3] * dy + ictm[5];
01837 }

void pdf::PDFPage::coordinates_user_to_dev ( const double  ux,
const double  uy,
int *  dx,
int *  dy 
)

Definition at line 1839 of file pdf_page.cpp.

Referenced by get_anchor_param_from_coordinates(), and get_bounding_rectangles().

01841 {
01842   *dx = (int)(ctm[0] * ux + ctm[2] * uy + ctm[4] + 0.5);
01843   *dy = (int)(ctm[1] * ux + ctm[3] * uy + ctm[5] + 0.5);
01844 }

Here is the caller graph for this function:

unsigned int pdf::PDFPage::destroy (  ) 

Destroy the resource of the page.

Definition at line 163 of file pdf_page.cpp.

References get_render_status(), locked(), RENDER_RUNNING, and RENDER_STOP.

Referenced by pdf::PagesCache::clear_cached_bitmaps(), and ~PDFPage().

00164 {
00165     if (locked())
00166     {
00167         return 0;
00168     }
00169 
00170     if (get_render_status() == RENDER_RUNNING)
00171     {
00172         // if the page is in rendering, cannot delete it
00173         // it won't happen now, because the deleting is executed
00174         // in working thread.
00175         return 0;
00176     }
00177 
00178     // reset the render status
00179     set_render_status(RENDER_STOP);
00180 
00181     destroy_links();
00182     destroy_text();
00183     unsigned int size = destroy_bitmap();
00184 
00185     return size;
00186 }

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf::PDFPage::get_anchor_param_from_coordinates ( double  x,
double  y,
PDFAnchor param 
)

Get the anchor of (x, y).

Definition at line 1531 of file pdf_page.cpp.

References pdf::PDFAnchor::char_idx, coordinates_user_to_dev(), get_words_list(), pdf::PDFAnchor::link_idx, pdf::PDFAnchor::page_num, and pdf::PDFAnchor::word_num.

01533 {
01534     int i;
01535     // Caculate whether (x, y) inside a Link and inside which Link
01536     int link_index = -1;
01537     if (links && links->onLink(x, y))
01538     {
01539         int link_num;
01540         Link * link;
01541 
01542         link_num = links->getNumLinks();
01543         for (i = 0; i < link_num; i++)
01544         {
01545             link = links->getLink(i);
01546             if (link && link->inRect(x, y))
01547             {
01548                 link_index = i;
01549                 break;
01550             }
01551         }
01552     }
01553 
01554     // get the anchor of a screen point
01555     // now the anchor is supposed to be like "pdf:/page:8/link:0/word:12/char:06"
01556     // however, if the point is located on a object(image, shape or any thing else),
01557     // word and char cannot be retrieved.
01558     // TODO. add support to the non-text object
01559     int dx, dy;
01560     coordinates_user_to_dev(x, y, &dx, &dy);
01561 
01562     int word_index = -1, char_index = -1;
01563 
01564     TextWordList * words = get_words_list();
01565     if (words != 0)
01566     {
01567         int words_num = words->getLength();
01568         TextWord * word = 0;
01569         double x_min = 0.0, y_min = 0.0, x_max = 0.0, y_max = 0.0;
01570         for(i = 0; i < words_num; i++)
01571         {
01572             word = words->get(i);
01573             word->getBBox(&x_min, &y_min, &x_max, &y_max);
01574 
01575             if ((x_min <= dx) && (dx <= x_max) 
01576                 && (y_min <= dy) && (dy <= y_max))
01577             {
01578                 word_index = i;
01579 
01580                 int chars_num = word->getLength();
01581                 for (int j = 0; j < chars_num; j++)
01582                 {
01583 #ifdef WIN32
01584                     x_min = word->getEdge(j);
01585                     x_max = word->getEdge(j+1);
01586 #else
01587                     word->getCharBBox(j, &x_min, &y_min, &x_max, &y_max); 
01588 #endif
01589                     if ((x_min <= dx) && (dx <= x_max) 
01590                         && (y_min <= dy) && (dy <= y_max))
01591                     {
01592                         char_index = j;
01593                         break;
01594                     }
01595                 }
01596                 break;
01597             }
01598         }
01599 
01600         delete words;
01601     }
01602 
01603     // set the anchor
01604     param.page_num = page_number;
01605     param.link_idx = link_index;
01606     param.word_num = word_index;
01607     param.char_idx = char_index;
01608     //param.file_name = get_doc_controller()->name();
01609 }

Here is the call graph for this function:

SplashBitmap* pdf::PDFPage::get_bitmap (  )  const [inline]

Definition at line 179 of file pdf_page.h.

Referenced by pdf::PagesCache::clear_cached_bitmaps(), and pdf::operator<().

00179 { return bitmap; }

Here is the caller graph for this function:

const unsigned char * pdf::PDFPage::get_bitmap_data (  ) 

Get the data of the bitmap.

Definition at line 251 of file pdf_page.cpp.

00252 {
00253     if (!bitmap)
00254     {
00255         return 0;
00256     }
00257 
00258     return bitmap->getDataPtr();
00259 }

int pdf::PDFPage::get_bitmap_height (  ) 

Definition at line 210 of file pdf_page.cpp.

00211 {
00212     if (!bitmap)
00213     {
00214         return 0;
00215     }
00216 
00217     return bitmap->getHeight();
00218 }

int pdf::PDFPage::get_bitmap_row_stride (  ) 

Definition at line 241 of file pdf_page.cpp.

00242 {
00243     if (!bitmap)
00244     {
00245         return 0;
00246     }
00247 
00248     return bitmap->getRowSize();
00249 }

int pdf::PDFPage::get_bitmap_width (  ) 

Definition at line 200 of file pdf_page.cpp.

00201 {
00202     if (!bitmap)
00203     {
00204         return 0;
00205     }
00206 
00207     return bitmap->getWidth();
00208 }

bool pdf::PDFPage::get_bounding_rectangles ( const string start_anchor,
const string end_anchor,
PDFRectangles rects 
)

Get the bounding rectangles in the passed-in range.

Definition at line 1039 of file pdf_page.cpp.

References pdf::PDFInstanceCollection< T >::add(), coordinates_user_to_dev(), get_words_list(), PluginRectangle::height, pdf::PDFAnchor::link_idx, pdf::merge_rectangle(), pdf::PDFAnchor::page_num, PluginRectangle::width, pdf::PDFAnchor::word_num, PluginRectangle::x, and PluginRectangle::y.

Referenced by pdf::PDFController::get_bounding_rectangles().

01042 {
01043     PDFAnchor start_param(start_anchor);
01044     PDFAnchor end_param(end_anchor);
01045 
01046     //Cannot identify the word in seperated pages
01047     if (start_param.page_num != page_number ||
01048         start_param.page_num != end_param.page_num)
01049     {
01050         return false;
01051     }
01052 
01053     //int len = end_param.char_idx - start_param.char_idx + 1;
01054     //assert(len > 0);
01055     //assert(start_param.word_num >= 0 && end_param.word_num >= 0);
01056 
01057     // TODO. Get rectange from hyperlink (without word)
01058     PDFRectangle pdf_rect;
01059     if (start_param.word_num >= 0 && end_param.word_num >= 0)
01060     {
01061         TextWordList * words = get_words_list();
01062         for(int i = start_param.word_num; i <= end_param.word_num; ++i)
01063         {
01064             double x_min = 0.0, y_min = 0.0, x_max = 0.0, y_max = 0.0;
01065             words->get(i)->getBBox(&x_min, &y_min, &x_max, &y_max);
01066 
01067             if (!merge_rectangle(x_min, y_min, x_max, y_max, &pdf_rect))
01068             {
01069                 PluginRectangle rect;
01070                 rect.x = static_cast<int>(pdf_rect.x1);
01071                 rect.y = static_cast<int>(pdf_rect.y1);
01072                 rect.width  = static_cast<int>(pdf_rect.x2 - pdf_rect.x1) + 1;
01073                 rect.height = static_cast<int>(pdf_rect.y2 - pdf_rect.y1) + 1;
01074                 rects.add(rect);
01075 
01076                 // update the rectangle
01077                 pdf_rect.x1 = x_min;
01078                 pdf_rect.x2 = x_max;
01079                 pdf_rect.y1 = y_min;
01080                 pdf_rect.y2 = y_max;
01081             }
01082         }
01083 
01084         delete words;
01085 
01086         if (pdf_rect.isValid())
01087         {
01088             // add the last rectangle into the list
01089             PluginRectangle rect;
01090             rect.x = static_cast<int>(pdf_rect.x1);
01091             rect.y = static_cast<int>(pdf_rect.y1);
01092             rect.width  = static_cast<int>(pdf_rect.x2 - pdf_rect.x1) + 1;
01093             rect.height = static_cast<int>(pdf_rect.y2 - pdf_rect.y1) + 1;
01094             rects.add(rect);
01095         }
01096     }
01097     else if (start_param.link_idx >= 0 && end_param.link_idx >= 0)
01098     {
01099         if (links == 0)
01100         {
01101             return false;
01102         }
01103 
01104         for(int i = start_param.link_idx; i <= end_param.link_idx; ++i)
01105         {
01106             double x_min = 0.0, y_min = 0.0, x_max = 0.0, y_max = 0.0;
01107             Link *link = links->getLink(i);
01108             link->getRect(&x_min, &y_min, &x_max, &y_max);
01109             int real_x_min, real_y_min, real_x_max, real_y_max;
01110             coordinates_user_to_dev(x_min, y_min, &real_x_min, &real_y_min);
01111             coordinates_user_to_dev(x_max, y_max, &real_x_max, &real_y_max);
01112             x_min = min(real_x_min, real_x_max);
01113             x_max = max(real_x_min, real_x_max);
01114             y_min = min(real_y_min, real_y_max);
01115             y_max = max(real_y_min, real_y_max);
01116 
01117             if (!merge_rectangle(x_min, y_min, x_max, y_max, &pdf_rect))
01118             {
01119                 PluginRectangle rect;
01120                 rect.x = static_cast<int>(pdf_rect.x1);
01121                 rect.y = static_cast<int>(pdf_rect.y1);
01122                 rect.width  = static_cast<int>(pdf_rect.x2 - pdf_rect.x1) + 1;
01123                 rect.height = static_cast<int>(pdf_rect.y2 - pdf_rect.y1) + 1;
01124                 rects.add(rect);
01125 
01126                 // update the rectangle
01127                 pdf_rect.x1 = x_min;
01128                 pdf_rect.x2 = x_max;
01129                 pdf_rect.y1 = y_min;
01130                 pdf_rect.y2 = y_max;
01131             }
01132 
01133         }
01134 
01135         if (pdf_rect.isValid())
01136         {
01137             // add the last rectangle into the list
01138             PluginRectangle rect;
01139             rect.x = static_cast<int>(pdf_rect.x1);
01140             rect.y = static_cast<int>(pdf_rect.y1);
01141             rect.width  = static_cast<int>(pdf_rect.x2 - pdf_rect.x1) + 1;
01142             rect.height = static_cast<int>(pdf_rect.y2 - pdf_rect.y1) + 1;
01143             rects.add(rect);
01144         }
01145     }
01146 
01147     return true;
01148 }

Here is the call graph for this function:

Here is the caller graph for this function:

const RenderArea& pdf::PDFPage::get_content_area (  )  const [inline]

Definition at line 242 of file pdf_page.h.

00242 { return content_area; }

bool pdf::PDFPage::get_content_area ( PDFRenderer renderer,
RenderArea area 
)

Get content area of a page. The content area should be caculated by the result of a thumbnail rendering

Definition at line 1272 of file pdf_page.cpp.

References ERRORPRINTF, pdf::PDFViewAttributes::get_device_dpi_h(), pdf::PDFViewAttributes::get_device_dpi_v(), get_page_num(), pdf::PDFController::get_pdf_doc(), pdf::PDFRenderer::get_render_mutex(), pdf::PDFRenderer::get_view_attr(), RenderArea::height, pdf::is_render_area_valid(), RenderArea::width, RenderArea::x_offset, and RenderArea::y_offset.

Referenced by pdf::PDFRenderTask::execute(), and pdf::PDFController::get_page_content_area().

01273 {
01274     static const double SHRINK_ZOOM = 0.2f;
01275     static const int    EXPAND_STEP = 2;
01276 
01277     if (!is_render_area_valid(content_area))
01278     {
01279         // lock when rendering
01280         ScopeMutex m(&(renderer->get_render_mutex()));
01281 
01282         RenderRet ret = doc_controller->get_pdf_doc()->displayPage(
01283         renderer->get_thumbnail_output_dev()
01284         , get_page_num()
01285         , SHRINK_ZOOM * renderer->get_view_attr().get_device_dpi_h()
01286         , SHRINK_ZOOM * renderer->get_view_attr().get_device_dpi_v()
01287         , 0
01288         , gFalse  //useMediaBox, TODO.
01289         , gFalse  //crop, TODO.
01290         , gFalse  //doLinks, TODO.
01291         );
01292 
01293         if (ret == Render_Error || ret == Render_Invalid)
01294         {
01295             ERRORPRINTF("Error in rendering thumbnail page:%d\n", get_page_num());
01296             return false;
01297         }
01298 
01299         SplashBitmap *thumb_map = renderer->get_thumbnail_output_dev()->takeBitmap();
01300         PDFRectangle content_rect;
01301         bool succeed = get_content_from_bitmap(thumb_map, content_rect);
01302         // calculate the render area by the rectangle
01303         double page_width = thumb_map->getWidth();
01304         double page_height = thumb_map->getHeight();
01305         delete thumb_map;
01306         if (!succeed)
01307         {
01308             // set the content area to be the page area
01309             content_rect.x1 = content_rect.y1 = 0;
01310             content_rect.x2 = page_width;
01311             content_rect.y2 = page_height;
01312         }
01313         else
01314         {
01315             // expand the content area to avoid content covering
01316             double inc_x2 = 0;
01317             double inc_y2 = 0;
01318 
01319             // expand x1
01320             if (content_rect.x1 > EXPAND_STEP)
01321             {
01322                 content_rect.x1 -= EXPAND_STEP;
01323                 inc_x2 = EXPAND_STEP;
01324             }
01325             else
01326             {
01327                 inc_x2 = content_rect.x1;
01328                 content_rect.x1 = 0;
01329             }
01330 
01331             // expand y1
01332             if (content_rect.y1 > EXPAND_STEP)
01333             {
01334                 content_rect.y1 -= EXPAND_STEP;
01335                 inc_y2 = EXPAND_STEP;
01336             }
01337             else
01338             {
01339                 inc_y2 = content_rect.y1;
01340                 content_rect.y1 = 0;
01341             }
01342 
01343             // expand x2
01344             content_rect.x2 += (inc_x2 + 1);
01345             if (content_rect.x2 > page_width)
01346             {
01347                 content_rect.x2 = page_width;
01348             }
01349 
01350             // expand y2
01351             content_rect.y2 += (inc_y2 + 1);
01352             if (content_rect.y2 > page_height)
01353             {
01354                 content_rect.y2 = page_height;
01355             }
01356         }
01357 
01358         content_area.x_offset = static_cast<float>(content_rect.x1 / page_width);
01359         content_area.y_offset = static_cast<float>(content_rect.y1 / page_height);
01360 
01361         content_area.width =
01362             static_cast<float>((content_rect.x2 - content_rect.x1) / page_width);
01363         content_area.height =
01364             static_cast<float>((content_rect.y2 - content_rect.y1) / page_height);
01365 
01366         if (content_area.width > 1.0f)
01367         {
01368             content_area.x_offset = 0.0f;
01369             content_area.width    = 1.0f;
01370         }
01371         if (content_area.height > 1.0f)
01372         {
01373             content_area.y_offset = 0.0f;
01374             content_area.height   = 1.0f;
01375         }
01376     }
01377 
01378     area = content_area;
01379 
01380     return true;
01381 }

Here is the call graph for this function:

Here is the caller graph for this function:

PDFController* pdf::PDFPage::get_doc_controller (  )  const [inline]

Definition at line 183 of file pdf_page.h.

Referenced by pdf::operator<().

00183 { return doc_controller; }

Here is the caller graph for this function:

bool pdf::PDFPage::get_goto_anchor_of_link ( int  link_index,
std::string &  anchor 
)

Get the destination's anchor of the link.

Definition at line 1816 of file pdf_page.cpp.

References get_goto_page_of_link(), pdf::PDFAnchor::get_string(), and pdf::PDFAnchor::page_num.

01817 {
01818     // Get the anchor of destination for this link.
01819     int page_num = get_goto_page_of_link(link_index);
01820     if (page_num > 0)
01821     {
01822         PDFAnchor param;
01823         param.page_num = page_num;
01824         //param.file_name = get_doc_controller()->name();
01825         anchor = param.get_string();
01826         return true;
01827     }
01828 
01829     return false;
01830 }

Here is the call graph for this function:

int pdf::PDFPage::get_goto_page_of_link ( int  link_index  ) 

Get the destination's page number of the link.

Definition at line 1739 of file pdf_page.cpp.

References action, ERRORPRINTF, and pdf::PDFController::get_pdf_doc().

Referenced by get_goto_anchor_of_link(), and is_hyper_linked_page().

01740 {
01741     if (links == 0)
01742     {
01743         return 0;
01744     }
01745 
01746     //assert(link_index >= 0 && link_index < links->getNumLinks());
01747     if (link_index < 0 || link_index >= links->getNumLinks())
01748     {
01749         ERRORPRINTF("Error Link Index");
01750         return 0;
01751     }
01752 
01753     Link *link = links->getLink(link_index);
01754     int page_num = 0;
01755     if (link != 0)
01756     {
01757         LinkAction *action = link->getAction();
01758         LinkActionKind kind = action->getKind();
01759         if (kind == actionGoTo)
01760         {
01761             // Caculate the page number of destination of this link.
01762 #ifdef WIN32
01763             UGooString *named_dest = 0;
01764 #else
01765             GooString *named_dest = 0;
01766 #endif
01767             PDFDoc *doc = doc_controller->get_pdf_doc();
01768 
01769             LinkDest *dest = ((LinkGoTo *)action)->getDest();
01770             named_dest = ((LinkGoTo *)action)->getNamedDest();
01771 
01772             if (dest && dest->isPageRef())
01773             {
01774                 Ref pageRef = dest->getPageRef();
01775                 page_num = doc->findPage(pageRef.num, pageRef.gen);
01776             }
01777             else if (named_dest)
01778             {
01779                 dest = doc->findDest(named_dest);
01780                 if (dest)
01781                 {
01782                     Ref pageRef = dest->getPageRef();
01783                     page_num = doc->findPage(pageRef.num, pageRef.gen);
01784                 }
01785             }
01786         }
01787     }
01788     return page_num;
01789 }

Here is the call graph for this function:

Here is the caller graph for this function:

Links* pdf::PDFPage::get_links (  )  const [inline]

Definition at line 180 of file pdf_page.h.

00180 { return links; }

int pdf::PDFPage::get_page_num (  )  const [inline]

Definition at line 175 of file pdf_page.h.

Referenced by get_content_area(), pdf::operator<(), render_splash_map(), and pdf::PluginRenderResultImpl::set_page().

00175 { return page_number; }

Here is the caller graph for this function:

bool pdf::PDFPage::get_range_param_by_link_index ( const int  link_index,
PDFAnchor start_param,
PDFAnchor end_param 
)

Get the range of link by link index.

Definition at line 1697 of file pdf_page.cpp.

References ERRORPRINTF, pdf::PDFAnchor::link_idx, and pdf::PDFAnchor::page_num.

01700 {
01701     if (links)
01702     {
01703         //assert(link_index >= 0 && link_index < links->getNumLinks());
01704         if (link_index < 0 || link_index >= links->getNumLinks())
01705         {
01706             ERRORPRINTF("Error Link Index");
01707             return false;
01708         }
01709 
01710         // Link * link = links->getLink(link_index);
01711 
01712         // Disable the area check
01713         // Do we really need the area check for hyperlinks?
01714         // In most of the PDF documents, hyperlinks are indicated by a rectangle.
01715         // We can just return the index of hyperlink
01716 
01717         /*double x_min = 0.0f, y_min = 0.0f, x_max = 0.0f, y_max = 0.0f, y = 0.0f;
01718         link->getRect(&x_min, &y_min, &x_max, &y_max);
01719 
01720         // calculate the middle point
01721         y = (y_min + y_max) / 2;
01722 
01723         get_anchor_param_from_coordinates(x_min, y, start_param);
01724         get_anchor_param_from_coordinates(x_max, y, end_param);*/
01725 
01726         start_param.page_num = page_number;
01727         start_param.link_idx = link_index;
01728         //start_param.file_name = get_doc_controller()->name();
01729 
01730         end_param.page_num = page_number;
01731         end_param.link_idx = link_index;
01732         //end_param.file_name = get_doc_controller()->name();
01733         return true;
01734     }
01735 
01736     return false;
01737 }

bool pdf::PDFPage::get_range_param_by_word_index ( const int  link_index,
PDFAnchor start_param,
PDFAnchor end_param 
)

Get the range of word by word index.

Definition at line 1611 of file pdf_page.cpp.

References pdf::PDFAnchor::char_idx, get_words_list(), pdf::PDFAnchor::page_num, and pdf::PDFAnchor::word_num.

01614 {
01615     TextWordList * words = get_words_list();
01616     bool ret = false;
01617     if (words != 0)
01618     {
01619         int words_num = words->getLength();
01620         if (word_index >= 0 && word_index < words_num)
01621         {
01622             TextWord * word = words->get(word_index);
01623 
01624             start_param.page_num = page_number;
01625             start_param.word_num = word_index;
01626             start_param.char_idx = 0;
01627             //start_param.file_name = get_doc_controller()->name();
01628 
01629             end_param.page_num = page_number;
01630             end_param.word_num = word_index;
01631             end_param.char_idx = word->getLength();
01632             //end_param.file_name = get_doc_controller()->name();
01633 
01634             ret = true;
01635         }
01636         delete words;
01637     }
01638     return ret;
01639 }

Here is the call graph for this function:

int pdf::PDFPage::get_ref_id (  )  [inline]

Get/Set the reference id.

Definition at line 172 of file pdf_page.h.

Referenced by pdf::PluginRenderResultImpl::set_page().

00172 { return ref_id; }

Here is the caller graph for this function:

const PDFRenderAttributes& pdf::PDFPage::get_render_attr (  )  const [inline]

Get the render attributes.

Definition at line 169 of file pdf_page.h.

Referenced by pdf::PDFRenderTask::execute(), and pdf::PDFRenderer::post_render_task().

00169 { return render_attr; }

Here is the caller graph for this function:

RenderStatus pdf::PDFPage::get_render_status (  )  [inline]

Get rendering status.

Definition at line 213 of file pdf_page.h.

Referenced by destroy(), pdf::PDFRenderTask::execute(), pdf::PDFRenderer::post_render_task(), and render_splash_map().

00213 {return render_status;}

Here is the caller graph for this function:

TextPage* pdf::PDFPage::get_text (  )  const [inline]

Definition at line 181 of file pdf_page.h.

00181 { return text; }

bool pdf::PDFPage::get_text_by_range ( const PDFAnchor start_param,
const PDFAnchor end_param,
std::string &  result 
)

Get the text by range.

Definition at line 1641 of file pdf_page.cpp.

References ERRORPRINTF, pdf::get_std_string_from_text_word(), get_words_list(), pdf::PDFAnchor::is_end_anchor(), pdf::PDFAnchor::page_num, and pdf::PDFAnchor::word_num.

Referenced by pdf::PDFController::get_text_from_range().

01644 {
01645     if (!end_param.is_end_anchor() && start_param.page_num != end_param.page_num)
01646     {
01647         // start anchor and end anchor point to different pages, quit
01648         return false;
01649     }
01650 
01651     TextWordList * words = get_words_list();
01652     result.clear();
01653     if (words != 0)
01654     {
01655         int words_num = words->getLength();
01656         int start_index = start_param.word_num;
01657         int end_index = end_param.is_end_anchor() ? words_num : end_param.word_num;
01658 
01659         // Get each word in the range.
01660 
01661         TextWord * word;
01662         string text;
01663 
01664         for (int idx = start_index; idx < end_index; ++idx)
01665         {
01666             word = words->get(idx);
01667             if (word == 0)
01668             {
01669                 // the word is NULL
01670                 ERRORPRINTF("Null word in search");
01671                 break;
01672             }
01673 
01674             get_std_string_from_text_word(word, text);
01675             result += text;
01676             // Append the seperator " "
01677             result += " ";
01678         }
01679 
01680         // Append the last word.
01681         if (start_index <= end_index)
01682         {
01683             word = words->get(end_index);
01684             if (word)
01685             {
01686                 get_std_string_from_text_word(word, text);
01687                 result += text;
01688             }
01689         }
01690 
01691         delete words;
01692     }
01693 
01694     return true;
01695 }

Here is the call graph for this function:

Here is the caller graph for this function:

TextWordList * pdf::PDFPage::get_words_list (  ) 

Definition at line 188 of file pdf_page.cpp.

Referenced by get_anchor_param_from_coordinates(), get_bounding_rectangles(), get_range_param_by_word_index(), get_text_by_range(), and search().

00189 {
00190     TextWordList *words = 0;
00191 
00192     if (text)
00193     {
00194         words = text->makeWordList(gFalse);
00195     }
00196 
00197     return words;
00198 }

Here is the caller graph for this function:

bool pdf::PDFPage::is_hyper_linked_page ( int  dst_page_num  ) 

Estimate whether the input is hyperlink page of current page.

Definition at line 1791 of file pdf_page.cpp.

References get_goto_page_of_link().

01792 {
01793     if (links == 0)
01794     {
01795         return false;
01796     }
01797 
01798     int link_num = links->getNumLinks();
01799     if (link_num <= 0)
01800     {
01801         return false;
01802     }
01803 
01804     for (int i = 0; i < link_num; ++i)
01805     {
01806         if (dst_page_num == get_goto_page_of_link(i))
01807         {
01808             return true;
01809         }
01810     }
01811 
01812     return false;
01813 }

Here is the call graph for this function:

unsigned int pdf::PDFPage::length ( void   ) 

Get the data length of the bitmap.

Definition at line 220 of file pdf_page.cpp.

Referenced by pdf::PDFRenderTask::execute(), and render_splash_map().

00221 {
00222     if (!bitmap)
00223     {
00224         return 0;
00225     }
00226     return bitmap->getHeight() * bitmap->getRowSize();
00227 }

Here is the caller graph for this function:

void pdf::PDFPage::lock ( void   )  [inline]

Lock the page so that it has the highest priority(cannot be removed until UDS unlocks it)

Definition at line 154 of file pdf_page.h.

Referenced by pdf::PluginRenderResultImpl::set_page().

00154 { b_lock = true; }

Here is the caller graph for this function:

bool pdf::PDFPage::locked (  )  const [inline]

Is current page be locked.

Definition at line 160 of file pdf_page.h.

Referenced by pdf::PagesCache::clear_cached_bitmaps(), destroy(), pdf::operator<(), and render_splash_map().

00160 { return b_lock; }

Here is the caller graph for this function:

size_t pdf::PDFPage::operator() ( void   ) 

Return the size_t value based on the pagenumber.

Definition at line 107 of file pdf_page.cpp.

00108 {
00109     return static_cast<size_t>(page_number);
00110 }

bool pdf::PDFPage::operator== ( const PDFRenderAttributes right  ) 

Definition at line 118 of file pdf_page.cpp.

00119 {
00120     return (this->render_attr == right);
00121 }

bool pdf::PDFPage::operator== ( const PDFPage right  ) 

Comparing.

Definition at line 112 of file pdf_page.cpp.

00113 {
00114     return ((this->page_number == right.page_number) &&
00115             this->render_attr == right.render_attr);
00116 }

bool pdf::PDFPage::render_splash_map ( PDFRenderer renderer,
void *  abort_data 
)

Render a splash page by render attributes passed in.

Definition at line 1150 of file pdf_page.cpp.

References pdf::PDFViewAttributes::get_device_dpi_h(), pdf::PDFViewAttributes::get_device_dpi_v(), get_page_num(), pdf::PDFController::get_pdf_doc(), pdf::PDFRenderAttributes::get_real_zoom_value(), pdf::PDFRenderer::get_render_mutex(), get_render_status(), pdf::PDFRenderAttributes::get_rotate(), pdf::PDFRenderer::get_view_attr(), length(), locked(), LOGPRINTF, RENDER_RUNNING, RENDER_STOP, and unlock().

Referenced by pdf::PDFRenderTask::execute().

01151 {
01152     if (locked())
01153     {
01154         if (get_render_status() == RENDER_STOP)
01155         {
01156             // the previous rendering stopped by some reason
01157             // reset the lock
01158             unlock();
01159         }
01160         else
01161         {
01162             // cannot render when the page is locked
01163             LOGPRINTF("Locked, Cannot render\n");
01164             return false;
01165         }
01166     }
01167 
01168     // destroy the pre-rendered results
01169     destroy_links();
01170     doc_controller->update_memory_usage((-1) * destroy_bitmap());
01171 
01172     // set the status to rendering
01173     set_render_status(RENDER_RUNNING);
01174 
01175     // second render the page
01176     RenderRet ret = Render_Error;
01177     SplashBitmap *b = 0;
01178     Links *l = 0;
01179 
01180     // lock when rendering
01181     ScopeMutex m(&(renderer->get_render_mutex()));
01182 
01183     ret = doc_controller->get_pdf_doc()->displayPage(
01184         renderer->get_splash_output_dev()
01185         , page_number
01186         , render_attr.get_real_zoom_value() * 0.01 * renderer->get_view_attr().get_device_dpi_h()
01187         , render_attr.get_real_zoom_value() * 0.01 * renderer->get_view_attr().get_device_dpi_v()
01188         , render_attr.get_rotate()
01189         , gFalse //useMediaBox, TODO.
01190         , gTrue  //crop, TODO.
01191         , gTrue  //doLinks, TODO.
01192         , abort_render_check
01193         , abort_data
01194     );
01195 
01196     if (ret == Render_Error || ret == Render_Invalid)
01197     {
01198         LOGPRINTF("1. Error in rendering page:%d\n", get_page_num());
01199         return false;
01200     }
01201 
01202     // take bitmap
01203     b = renderer->get_splash_output_dev()->takeBitmap();
01204 
01205     // take hyperlinks
01206 #ifdef WIN32
01207     l = doc_controller->get_pdf_doc()->takeLinks();
01208 #else
01209     l = doc_controller->get_pdf_doc()->getLinks(page_number);
01210 #endif
01211 
01212     if (ret == Render_Done)
01213     {
01214         update_bitmap(b);
01215         update_links(l);
01216 
01217         // retrieve ctm and ictm
01218         memcpy(ctm, renderer->get_splash_output_dev()->getDefCTM(), 6 * sizeof(double));
01219         memcpy(ictm, renderer->get_splash_output_dev()->getDefICTM(), 6 * sizeof(double)); 
01220 
01221         doc_controller->update_memory_usage(length());
01222         LOGPRINTF("Rendering of page:%d Done! Length:%d\n", get_page_num(), length());
01223         return true;
01224     }
01225     else if (ret == Render_Abort)
01226     {
01227         // MUST remove the temporary render results
01228         delete b;
01229         delete l;
01230         set_render_status(RENDER_STOP);
01231         LOGPRINTF("Rendering of page:%d is aborted! Task:%p\n", get_page_num(), abort_data);
01232         return false;
01233     }
01234 
01235     LOGPRINTF("2. Error in rendering page:%d\n", get_page_num());
01236     return false;
01237 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool pdf::PDFPage::render_text ( PDFRenderer renderer,
bool  use_defalt_setting = false 
)

Render a text page by render attributes passed in.

Definition at line 1244 of file pdf_page.cpp.

References pdf::PDFViewAttributes::get_device_dpi_h(), pdf::PDFViewAttributes::get_device_dpi_v(), pdf::PDFController::get_pdf_doc(), pdf::PDFRenderAttributes::get_real_zoom_value(), pdf::PDFRenderer::get_render_mutex(), pdf::PDFRenderAttributes::get_rotate(), and pdf::PDFRenderer::get_view_attr().

Referenced by pdf::PDFRenderTask::execute().

01245 {
01246     static const double DEFAULT_ZOOM = 0.2f;
01247 
01248     destroy_text();
01249     // currently, the text rendering cannot be aborted
01250 
01251     // lock when rendering
01252     ScopeMutex m(&(renderer->get_render_mutex()));
01253 
01254     doc_controller->get_pdf_doc()->displayPage(
01255         renderer->get_text_output_dev()
01256         , page_number
01257         , (use_defalt_setting ? DEFAULT_ZOOM : render_attr.get_real_zoom_value() * 0.01) *
01258           renderer->get_view_attr().get_device_dpi_h()
01259         , (use_defalt_setting ? DEFAULT_ZOOM : render_attr.get_real_zoom_value() * 0.01) *
01260           renderer->get_view_attr().get_device_dpi_v()
01261         , render_attr.get_rotate()
01262         , gFalse
01263         , gTrue
01264         , gFalse
01265         );
01266 
01267     update_text(renderer->get_text_output_dev()->takeText());
01268 
01269     return true;
01270 }

Here is the call graph for this function:

Here is the caller graph for this function:

SearchResult pdf::PDFPage::search ( SearchContext ctx,
PDFSearchPage results 
)

Search in the current PDFPage. Make sure the text page is rendered before searching

Definition at line 291 of file pdf_page.cpp.

References pdf::PDFCollection< T >::add(), pdf::SearchContext::forward, get_words_list(), pdf::RES_ERROR, pdf::RES_NOT_FOUND, pdf::RES_OK, pdf::SearchContext::search_all, and pdf::SearchContext::word_cursor.

00293 {
00294     if (!text)
00295     {
00296         return RES_ERROR;
00297     }
00298 
00299     TextWordList *words = get_words_list();
00300     PluginRangeImpl *result = 0;
00301     SearchResult ret = RES_NOT_FOUND;
00302 
00303     int count = 0;
00304 
00305     // the search operation would update the index of start word
00306     // in the context    
00307     if (ctx.forward)
00308     {
00309         if (ctx.word_cursor < 0)
00310         {
00311             // set the start word to be the first one
00312             ctx.word_cursor = 0;
00313         }
00314 
00315         // search forward
00316         result = search_string_forward(ctx, words);
00317         if (ctx.search_all)
00318         {    
00319             while(result != 0)
00320             {
00321                 results.add(result);
00322                 count++;
00323                 result = search_string_forward(ctx, words);
00324             }
00325         }
00326         else
00327         {
00328             if (result)
00329             {
00330                 results.add(result);
00331                 count++;
00332             }
00333         }
00334 
00335     }
00336     else
00337     {
00338         if (ctx.word_cursor < 0)
00339         {
00340             // set the start word to be the last one
00341             ctx.word_cursor = words->getLength() - 1;
00342         }
00343 
00344         //search backward
00345         result = search_string_backward(ctx, words);
00346         if (ctx.search_all)
00347         {
00348             while(result != 0)
00349             {
00350                 results.add(result);
00351                 count++;
00352                 result = search_string_backward(ctx, words);
00353             }
00354         }
00355         else
00356         {
00357             if (result)
00358             {
00359                 results.add(result);
00360                 count++;
00361             }
00362         }
00363     }
00364 
00365     if (count > 0)
00366     {
00367         ret = RES_OK;
00368     }
00369 
00370     delete words;
00371     return ret;
00372 }

Here is the call graph for this function:

void pdf::PDFPage::set_doc_controller ( PDFController doc  )  [inline]

Definition at line 184 of file pdf_page.h.

Referenced by pdf::PDFRenderer::gen_page().

00184 { doc_controller = doc; }

Here is the caller graph for this function:

void pdf::PDFPage::set_ref_id ( int  id  )  [inline]

Definition at line 173 of file pdf_page.h.

Referenced by pdf::PDFRenderTask::execute(), and pdf::PDFRenderer::post_render_task().

00173 { ref_id = id; }

Here is the caller graph for this function:

void pdf::PDFPage::set_render_attr ( const PDFRenderAttributes attr  ) 

Set the render attributes return true means setting succeed, or there is no change return false means the page is in rendering, cannot change the setting now

Definition at line 123 of file pdf_page.cpp.

Referenced by pdf::PDFRenderTask::execute().

00124 {
00125     if (render_attr == attr)
00126     {
00127         return;
00128     }
00129 
00130     render_attr = attr;
00131 }

Here is the caller graph for this function:

void pdf::PDFPage::unlock ( void   )  [inline]

Unlock the page.

Definition at line 157 of file pdf_page.h.

Referenced by render_splash_map(), and pdf::PluginRenderResultImpl::~PluginRenderResultImpl().

00157 { b_lock = false; }

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class PDFRenderTask [friend]

Definition at line 346 of file pdf_page.h.

friend class PDFSearcher [friend]

Definition at line 347 of file pdf_page.h.


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208