pdf_doc_controller.h

Go to the documentation of this file.
00001 /*
00002  * File Name: pdf_doc_controller.h
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-pdf.
00007  *
00008  * uds-plugin-pdf is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-pdf is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
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 /// The document class.
00043 class PDFController
00044 {
00045 public:
00046     /// Page has been rendered signal
00047     Signal<void, RenderResultPtr, RenderStatus> sig_page_ready;
00048 
00049     /// Search results have been generated signal
00050     Signal<void, SearchResult, PDFRangeCollection*, unsigned int>
00051         sig_search_results_ready;
00052 
00053 public:
00054     PDFController(void);
00055     ~PDFController(void);
00056 
00057     /// Open a pdf document
00058     /// TODO. Return error code : PluginStatus, take the password into account
00059     PluginStatus open(const string &path);
00060 
00061     /// Close and release all allocated resource.
00062     bool close();
00063 
00064     /// Check whether the document has been opened.
00065     bool is_open() { return (pdf_doc && pdf_doc->isOk()); }
00066 
00067     /// Get the TOC
00068     PDFToc * get_toc(void);
00069 
00070     /// Get the file name
00071     const string& name() const { return file_name; }
00072 
00073     /// The pages number
00074     unsigned int page_count();
00075 
00076     /// Get current page
00077     int  get_cur_page_num() const { return current_page_num; }
00078 
00079     /// Get the anchor by page number
00080     bool get_anchor_of_page(const unsigned int page_number, 
00081                             string &anchor);
00082 
00083     /// Is the anchor in current document
00084     bool is_anchor_in_current_document(const string &anchor);
00085 
00086     /// Get the page number by anchor
00087     unsigned int get_page_number_of_anchor(const string &anchor);
00088 
00089     /// Compare the anchor object.
00090     int compare_anchor(const string &first,
00091                        const string &second);
00092 
00093     /// Get all of the hyperlinks from a given range
00094     PDFCollectionBase* get_hyperlinks_from_range(const string &start,
00095                                                  const string &end);
00096 
00097     /// Get the text from a given range
00098     bool get_text_from_range(const PDFAnchor &start,
00099                              const PDFAnchor &end,
00100                              string &result);
00101 
00102     /// Anchor iteraotr: retrieve the previous anchor.
00103     bool get_prev_page_anchor(string &anchor);
00104 
00105     /// Anchor iteraotr: retrieve the next anchor.
00106     bool get_next_page_anchor(string &anchor);
00107 
00108     /// Get the crop width/height of a page by anchor
00109     bool get_page_crop_width(const string &anchor, double &width);
00110     bool get_page_crop_height(const string &anchor, double &height);
00111 
00112     /// Get the content area of a page by anchor
00113     bool get_page_content_area(const string &anchor, RenderArea &area);
00114 
00115 
00116     /// Get the crop width/height of a page by number
00117     double get_page_crop_width(const int page_num);
00118     double get_page_crop_height(const int page_num);
00119 
00120     /// Get current display size
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     /// Get the original rotation of a page
00125     PluginRotationDegree get_page_original_rotation(const int page_num);
00126     PluginRotationDegree get_page_original_rotation(const string &anchor);
00127 
00128     /// Get the PDFPage by page number
00129     PagePtr get_page(const int page_num);
00130 
00131     /// Search for the next record
00132     bool search_next(const PDFSearchCriteria &criteria
00133                      , const string &from_anchor
00134                      , unsigned int search_id);
00135 
00136     /// Search all of the matched words
00137     bool search_all(const PDFSearchCriteria &criteria
00138                     , unsigned int search_id);
00139 
00140     /// Abort a search task
00141     bool abort_search(unsigned int search_id);
00142 
00143     /// Get the characters rectangle of the range
00144     bool get_bounding_rectangles(const string &start_anchor
00145                                  , const string &end_anchor
00146                                  , PDFRectangles &rects);
00147 
00148     /// Get the renderer
00149     PDFRenderer* get_renderer() { return &renderer; }
00150 
00151     /// Get the prerender policy
00152     PDFPrerenderPolicy* get_prerender_policy() { return prerender_policy; }
00153 
00154     // Get the poppler PDF document
00155     PDFDoc* get_pdf_doc() {return pdf_doc;}
00156 
00157     /// Set/get the memory limitation value to the cache
00158     bool set_memory_limit(const unsigned int bytes);
00159     unsigned int get_memory_limit();
00160 
00161     /// Clear all of the cached pages
00162     void clear_cache() { pages_cache.clear(); }
00163 
00164 private:
00165     // Compare between two anchor parameters
00166     int compare_anchor_param(const PDFAnchor & first_param,
00167                              const PDFAnchor & second_param);
00168 
00169     // Get the hyperlinks in a page
00170     bool get_hyperlinks_in_page(int page_num,
00171                                 PDFAnchor *start_param,
00172                                 PDFAnchor *end_param,
00173                                 PDFRangeCollection &results);
00174 
00175     // Remove the old pages in cache to make enough memory
00176     bool make_enough_memory(const int page_num, const int length);
00177 
00178     // Clear all cached pages but the locked one
00179     void clear_cached_bitmaps();
00180 
00181     // Update the memory usage by adding the length of page
00182     void update_memory_usage(const int length);
00183 
00184     // Set the current page number
00185     void set_cur_page_num(const int page_num) { current_page_num = page_num; }
00186 
00187     // Get the pages cache
00188     PagesCache & get_pages_cache() { return pages_cache; }
00189 
00190 private:
00191     // The pages cache
00192     PagesCache pages_cache;
00193 
00194     // The PDFDoc instance
00195     PDFDoc *pdf_doc;
00196 
00197     // The TOC instance of PDFDoc
00198     PDFToc toc;
00199 
00200     // The PDF renderer
00201     // Shall the renderer be maitained in document?
00202     PDFRenderer renderer;
00203 
00204     // The current page number
00205     int current_page_num;
00206 
00207     // The pdf searcher
00208     PDFSearcher searcher;
00209 
00210     // File name
00211     string file_name;
00212 
00213     // prerender policy
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 
Generated by  doxygen 1.6.2-20100208