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_PAGE_H_
00028 #define PDF_PAGE_H_
00029
00030 #include "pdf_define.h"
00031 #include "pdf_anchor.h"
00032 #include "pdf_searcher.h"
00033 #include "pdf_observer.h"
00034
00035 namespace pdf
00036 {
00037 typedef PDFInstanceCollection<PluginRectangle> PDFRectangles;
00038
00039 class PDFRenderAttributes
00040 {
00041 public:
00042 PDFRenderAttributes()
00043 : zoom_setting(PLUGIN_ZOOM_DEFAULT)
00044 , real_zoom_value(PLUGIN_ZOOM_DEFAULT)
00045 , rotate(0)
00046 {}
00047
00048 PDFRenderAttributes(const PDFRenderAttributes &attr)
00049 : zoom_setting(attr.zoom_setting)
00050 , real_zoom_value(attr.real_zoom_value)
00051 , rotate(attr.rotate)
00052 {}
00053
00054 ~PDFRenderAttributes() {}
00055
00056 PDFRenderAttributes& operator=(const PDFRenderAttributes& right)
00057 {
00058 if (*this == right)
00059 {
00060 return *this;
00061 }
00062
00063 zoom_setting = right.zoom_setting;
00064 real_zoom_value = right.real_zoom_value;
00065 rotate = right.rotate;
00066 return *this;
00067 }
00068
00069 bool operator==(const PDFRenderAttributes &right) const
00070 {
00071 return ((fabs(this->zoom_setting - right.zoom_setting) < ZERO_RANGE) &&
00072 (fabs(this->real_zoom_value - right.real_zoom_value) < ZERO_RANGE) &&
00073 this->rotate == right.rotate);
00074 }
00075
00076 void set_zoom_setting(double z) {zoom_setting = z;}
00077 double get_zoom_setting() const {return zoom_setting;}
00078
00079 void set_rotate(int r) {rotate = r;}
00080 int get_rotate() const {return rotate;}
00081
00082 void set_real_zoom_value(double z) {real_zoom_value = z;}
00083 double get_real_zoom_value() const {return real_zoom_value;}
00084
00085 private:
00086
00087 double zoom_setting;
00088
00089
00090 double real_zoom_value;
00091
00092
00093 int rotate;
00094
00095 };
00096
00097 struct SearchWordRecord
00098 {
00099 int word_index;
00100 int start_char_index;
00101 int end_char_index;
00102
00103 SearchWordRecord()
00104 : word_index(0)
00105 , start_char_index(0)
00106 , end_char_index(0)
00107 {}
00108
00109 SearchWordRecord(int word_idx, int start_idx, int end_idx)
00110 : word_index(word_idx)
00111 , start_char_index(start_idx)
00112 , end_char_index(end_idx)
00113 {}
00114
00115 ~SearchWordRecord()
00116 {}
00117 };
00118
00119 typedef PDFInstanceCollection<SearchWordRecord> SearchWords;
00120
00121 class PDFController;
00122 class PDFRenderer;
00123 class TextWordQueue;
00124
00125 class PDFPage
00126 {
00127 public:
00128
00129
00130 typedef enum
00131 {
00132 RENDER_DONE = 0,
00133 RENDER_RUNNING,
00134 RENDER_STOP
00135 }RenderStatus;
00136
00137 public:
00138 PDFPage(int page_num, const PDFRenderAttributes &attr);
00139
00140 ~PDFPage(void);
00141
00142
00143 size_t operator()();
00144
00145
00146 bool operator == (const PDFPage &right);
00147 bool operator == (const PDFRenderAttributes &right);
00148
00149
00150 unsigned int destroy();
00151
00152
00153
00154 void lock() { b_lock = true; }
00155
00156
00157 void unlock() { b_lock = false; }
00158
00159
00160 bool locked() const { return b_lock; }
00161
00162
00163
00164
00165
00166 void set_render_attr(const PDFRenderAttributes &attr);
00167
00168
00169 const PDFRenderAttributes& get_render_attr() const { return render_attr; }
00170
00171
00172 int get_ref_id() { return ref_id; }
00173 void set_ref_id(int id) { ref_id = id; }
00174
00175 int get_page_num() const { return page_number; }
00176 int get_bitmap_width();
00177 int get_bitmap_height();
00178 int get_bitmap_row_stride();
00179 SplashBitmap* get_bitmap() const { return bitmap; }
00180 Links* get_links() const { return links; }
00181 TextPage* get_text() const { return text; }
00182 TextWordList* get_words_list();
00183 PDFController* get_doc_controller() const { return doc_controller; }
00184 void set_doc_controller(PDFController* doc) { doc_controller = doc; }
00185
00186
00187 unsigned int length();
00188
00189
00190 const unsigned char* get_bitmap_data();
00191
00192
00193 bool is_hyper_linked_page(int dst_page_num);
00194
00195
00196
00197 bool render_splash_map(PDFRenderer *renderer, void *abort_data);
00198
00199
00200 bool render_text(PDFRenderer *renderer, bool use_defalt_setting = false);
00201
00202
00203
00204
00205 SearchResult search(SearchContext &ctx, PDFSearchPage &results);
00206
00207
00208 bool get_bounding_rectangles(const string &start_anchor
00209 , const string &end_anchor
00210 , PDFRectangles &rects);
00211
00212
00213 RenderStatus get_render_status() {return render_status;}
00214
00215
00216 void get_anchor_param_from_coordinates(double x, double y, PDFAnchor ¶m);
00217
00218
00219 int get_goto_page_of_link(int link_index);
00220
00221
00222 bool get_goto_anchor_of_link(int link_index, std::string & anchor);
00223
00224
00225 bool get_range_param_by_link_index(const int link_index,
00226 PDFAnchor & start_param,
00227 PDFAnchor & end_param);
00228
00229
00230 bool get_range_param_by_word_index(const int link_index,
00231 PDFAnchor & start_param,
00232 PDFAnchor & end_param);
00233
00234
00235 bool get_text_by_range(const PDFAnchor & start_param,
00236 const PDFAnchor & end_param,
00237 std::string &result);
00238
00239
00240
00241 bool get_content_area(PDFRenderer *renderer, RenderArea &area);
00242 const RenderArea & get_content_area() const { return content_area; }
00243
00244
00245 void coordinates_dev_to_user(const double dx, const double dy,
00246 double *ux, double *uy);
00247
00248 void coordinates_user_to_dev(const double ux, const double uy,
00249 int *dx, int *dy);
00250
00251 private:
00252
00253 typedef enum
00254 {
00255 STATUS_HEADER = 0,
00256 STATUS_BODY,
00257 STATUS_TAIL,
00258 }MatchStatus;
00259
00260 private:
00261
00262 void init();
00263
00264
00265 void set_render_status(RenderStatus s);
00266
00267
00268 void update_text(TextPage *t);
00269 void update_links(Links *l);
00270 void update_bitmap(SplashBitmap *m);
00271
00272
00273 void destroy_text();
00274 unsigned int destroy_bitmap();
00275 void destroy_links();
00276
00277
00278
00279 PluginRangeImpl* search_string_forward(SearchContext &ctx,
00280 TextWordList *words);
00281
00282
00283
00284 PluginRangeImpl* search_string_backward(SearchContext &ctx,
00285 TextWordList *words);
00286
00287
00288 bool compare_string(const string &dst
00289 , const string &src
00290 , bool case_sensitive
00291 , bool match_whole_word
00292 , bool forward
00293 , bool sub_string
00294 , const int start_char_idx
00295 , int &start_result_idx
00296 );
00297
00298
00299 void generate_search_result(SearchContext &ctx
00300 , SearchWords &queue
00301 , PluginRangeImpl* &result
00302 , bool forward);
00303
00304
00305 bool get_content_from_bitmap(SplashBitmap *bitmap, PDFRectangle &rect);
00306
00307
00308 static GBool abort_render_check(void *data);
00309
00310
00311 static unsigned int try_calc_length(const double zoom_value
00312 , const double crop_width
00313 , const double crop_height);
00314
00315 private:
00316
00317 int page_number;
00318
00319
00320 PDFRenderAttributes render_attr;
00321
00322
00323 SplashBitmap *bitmap;
00324 Links *links;
00325 TextPage *text;
00326
00327
00328 PDFController *doc_controller;
00329
00330
00331 bool b_lock;
00332
00333
00334 RenderStatus render_status;
00335
00336
00337 int ref_id;
00338
00339
00340 RenderArea content_area;
00341
00342
00343 double ctm[6];
00344 double ictm[6];
00345
00346 friend class PDFRenderTask;
00347 friend class PDFSearcher;
00348 };
00349
00350 typedef PDFPage* PagePtr;
00351
00352 };
00353
00354 #endif //PDF_PAGE_H_
00355
00356