pdf_doc_controller.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef PDF_DOC_CONTROLLER_H_
00028 #define PDF_DOC_CONTROLLER_H_
00029 
00030 #include "pdf_define.h"
00031 #include "pdf_page.h"
00032 #include "pdf_renderer.h"
00033 #include "pdf_searcher.h"
00034 #include "pdf_observer.h"
00035 #include "pdf_toc.h"
00036 #include "pdf_pages_cache.h"
00037 #include "pdf_collection.h"
00038 
00039 namespace pdf
00040 {
00041 
00042 
00043 class PDFController
00044 {
00045 public:
00046 
00047     Signal<void, RenderResultPtr, RenderStatus> sig_page_ready;
00048 
00049 
00050     Signal<void, SearchResult, PDFRangeCollection*, unsigned int>
00051         sig_search_results_ready;
00052 
00053 public:
00054     PDFController(void);
00055     ~PDFController(void);
00056 
00057 
00058 
00059     PluginStatus open(const string &path);
00060 
00061 
00062     bool close();
00063 
00064 
00065     bool is_open() { return (pdf_doc && pdf_doc->isOk()); }
00066 
00067 
00068     PDFToc * get_toc(void);
00069 
00070 
00071     const string& name() const { return file_name; }
00072 
00073 
00074     unsigned int page_count();
00075 
00076 
00077     int  get_cur_page_num() const { return current_page_num; }
00078 
00079 
00080     bool get_anchor_of_page(const unsigned int page_number, 
00081                             string &anchor);
00082 
00083 
00084     bool is_anchor_in_current_document(const string &anchor);
00085 
00086 
00087     unsigned int get_page_number_of_anchor(const string &anchor);
00088 
00089 
00090     int compare_anchor(const string &first,
00091                        const string &second);
00092 
00093 
00094     PDFCollectionBase* get_hyperlinks_from_range(const string &start,
00095                                                  const string &end);
00096 
00097 
00098     bool get_text_from_range(const PDFAnchor &start,
00099                              const PDFAnchor &end,
00100                              string &result);
00101 
00102 
00103     bool get_prev_page_anchor(string &anchor);
00104 
00105 
00106     bool get_next_page_anchor(string &anchor);
00107 
00108 
00109     bool get_page_crop_width(const string &anchor, double &width);
00110     bool get_page_crop_height(const string &anchor, double &height);
00111 
00112 
00113     bool get_page_content_area(const string &anchor, RenderArea &area);
00114 
00115 
00116 
00117     double get_page_crop_width(const int page_num);
00118     double get_page_crop_height(const int page_num);
00119 
00120 
00121     int get_display_width() { return renderer.get_view_attr().get_display_width(); }
00122     int get_display_height() { return renderer.get_view_attr().get_display_height(); }
00123 
00124 
00125     PluginRotationDegree get_page_original_rotation(const int page_num);
00126     PluginRotationDegree get_page_original_rotation(const string &anchor);
00127 
00128 
00129     PagePtr get_page(const int page_num);
00130 
00131 
00132     bool search_next(const PDFSearchCriteria &criteria
00133                      , const string &from_anchor
00134                      , unsigned int search_id);
00135 
00136 
00137     bool search_all(const PDFSearchCriteria &criteria
00138                     , unsigned int search_id);
00139 
00140 
00141     bool abort_search(unsigned int search_id);
00142 
00143 
00144     bool get_bounding_rectangles(const string &start_anchor
00145                                  , const string &end_anchor
00146                                  , PDFRectangles &rects);
00147 
00148 
00149     PDFRenderer* get_renderer() { return &renderer; }
00150 
00151 
00152     PDFPrerenderPolicy* get_prerender_policy() { return prerender_policy; }
00153 
00154     
00155     PDFDoc* get_pdf_doc() {return pdf_doc;}
00156 
00157 
00158     bool set_memory_limit(const unsigned int bytes);
00159     unsigned int get_memory_limit();
00160 
00161 
00162     void clear_cache() { pages_cache.clear(); }
00163 
00164 private:
00165     
00166     int compare_anchor_param(const PDFAnchor & first_param,
00167                              const PDFAnchor & second_param);
00168 
00169     
00170     bool get_hyperlinks_in_page(int page_num,
00171                                 PDFAnchor *start_param,
00172                                 PDFAnchor *end_param,
00173                                 PDFRangeCollection &results);
00174 
00175     
00176     bool make_enough_memory(const int page_num, const int length);
00177 
00178     
00179     void clear_cached_bitmaps();
00180 
00181     
00182     void update_memory_usage(const int length);
00183 
00184     
00185     void set_cur_page_num(const int page_num) { current_page_num = page_num; }
00186 
00187     
00188     PagesCache & get_pages_cache() { return pages_cache; }
00189 
00190 private:
00191     
00192     PagesCache pages_cache;
00193 
00194     
00195     PDFDoc *pdf_doc;
00196 
00197     
00198     PDFToc toc;
00199 
00200     
00201     
00202     PDFRenderer renderer;
00203 
00204     
00205     int current_page_num;
00206 
00207     
00208     PDFSearcher searcher;
00209 
00210     
00211     string file_name;
00212 
00213     
00214     PDFPrerenderPolicy *prerender_policy;
00215 
00216     friend class PDFRenderer;
00217     friend class PDFSearcher;
00218     friend class PDFPage;
00219     friend class PDFLibrary;
00220 };
00221 
00222 };
00223 
00224 #endif //PDF_DOC_CONTROLLER_H_
00225