pdf_renderer.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_RENDERER_H_
00028 #define PDF_RENDERER_H_
00029
00030 #include "goo/GooList.h"
00031 #include "poppler/Object.h"
00032 #include "poppler/SplashOutputDev.h"
00033 #include "splash/SplashTypes.h"
00034 #include "render_result_impl.h"
00035
00036 #include "mutex.h"
00037 #include "pdf_page.h"
00038 #include "pdf_collection.h"
00039 #include "pdf_prerender_policy.h"
00040
00041 namespace pdf
00042 {
00043
00044 class PDFViewAttributes
00045 {
00046 public:
00047 PDFViewAttributes()
00048 : display_width(200)
00049 , display_height(200)
00050 , color_depth(8)
00051 , device_dpi_v(72.0)
00052 , device_dpi_h(72.0)
00053 {}
00054
00055 PDFViewAttributes(const PDFViewAttributes &attr)
00056 : display_width(attr.display_width)
00057 , display_height(attr.display_height)
00058 , color_depth(attr.color_depth)
00059 , device_dpi_v(attr.device_dpi_v)
00060 , device_dpi_h(attr.device_dpi_h)
00061 {}
00062
00063 ~PDFViewAttributes() {}
00064
00065 PDFViewAttributes& operator=(const PDFViewAttributes& right)
00066 {
00067 if (*this == right)
00068 {
00069 return *this;
00070 }
00071
00072 display_width = right.display_width;
00073 display_height = right.display_height;
00074 color_depth = right.color_depth;
00075 device_dpi_v = right.device_dpi_v;
00076 device_dpi_h = right.device_dpi_h;
00077
00078 return *this;
00079 }
00080
00081 bool operator==(const PDFViewAttributes &right)
00082 {
00083 return (this->display_width == right.display_width
00084 && this->display_height == right.display_height
00085 && this->color_depth == right.color_depth
00086 && this->device_dpi_v == right.device_dpi_v
00087 && this->device_dpi_h == right.device_dpi_h);
00088 }
00089
00090 void set_device_dpi_h(double h) {device_dpi_h = h;}
00091 double get_device_dpi_h() const {return device_dpi_h;}
00092 void set_device_dpi_v(double v) {device_dpi_v = v;}
00093 double get_device_dpi_v() const {return device_dpi_v;}
00094
00095 void set_display_width(const int w) {display_width = w;}
00096 int get_display_width() const {return display_width;}
00097 void set_display_height(const int h) {display_height = h;}
00098 int get_display_height() const {return display_height;}
00099
00100 void set_color_depth(const unsigned int c) {color_depth = c;}
00101 unsigned int get_color_depth() const {return color_depth;}
00102
00103 private:
00104
00105 int display_width;
00106 int display_height;
00107
00108
00109 unsigned int color_depth;
00110
00111
00112 double device_dpi_v;
00113
00114
00115 double device_dpi_h;
00116 };
00117
00118
00119 typedef enum RenderStatus_
00120 {
00121 TASK_RENDER_DONE = 0,
00122 TASK_RENDER_OOM,
00123 TASK_RENDER_INVALID_PAGE
00124 } RenderStatus;
00125
00126 class PDFController;
00127 class PDFRenderTask;
00128
00129 class PDFRenderer
00130 {
00131 public:
00132 PDFRenderer();
00133 virtual ~PDFRenderer(void);
00134
00135
00136 bool initialize(PDFController* doc);
00137
00138
00139 void destroy();
00140
00141
00142 void post_render_task(int page_num,
00143 const PDFRenderAttributes &render_attr,
00144 PluginRenderResultImpl *render_res,
00145 const unsigned int ref_id = PRERENDER_REF_ID);
00146
00147
00148
00149
00150
00151
00152
00153 void handle_page_ready(RenderResultPtr render_res,
00154 PagePtr page,
00155 RenderStatus stat);
00156
00157
00158 PDFViewAttributes& get_view_attr() { return view_attr; }
00159
00160
00161 const PDFRenderAttributes& get_render_attr() { return cur_render_attr; }
00162
00163
00164 PagePtr gen_page(int page_num, const PDFRenderAttributes &attr);
00165
00166
00167 PagePtr gen_page(int page_num);
00168
00169
00170 Mutex & get_render_mutex() { return render_mutex; }
00171
00172
00173 bool render_cover_page(const int width,
00174 const int height,
00175 PluginBitmapAttributes *output);
00176 public:
00177 static SplashColor background_color;
00178
00179 private:
00180
00181 PDFRenderTask* gen_render_task(int page_num,
00182 const PDFRenderAttributes &page_attr,
00183 PluginRenderResultImpl *render_res = 0,
00184 int ref_id = PRERENDER_REF_ID);
00185
00186
00187 PDFRenderTask* gen_render_task(PagePtr page,
00188 const PDFRenderAttributes &page_attr,
00189 PluginRenderResultImpl *render_res = 0,
00190 int ref_id = PRERENDER_REF_ID);
00191
00192
00193
00194 void init_pages_index_table();
00195
00196
00197 void init_start_time();
00198
00199 void calc_real_zoom(int page_number,
00200 const PDFRenderAttributes &origin_attr,
00201 PDFRenderAttributes &real_attr);
00202
00203
00204 SplashOutputDev* get_splash_output_dev() const { return splash_output_dev; }
00205 SplashOutputDev* get_thumbnail_output_dev() const { return thumbnail_output_dev; }
00206 TextOutputDev* get_text_output_dev() const { return text_output_dev; }
00207
00208
00209 void post_prerender_task(const size_t page_number,
00210 const PDFRenderAttributes &page_attr);
00211
00212
00213 void post_prerender_hyperlinks_task(PagePtr page);
00214
00215 private:
00216
00217 PDFController *doc_controller;
00218
00219
00220 SplashOutputDev *splash_output_dev;
00221
00222
00223 TextOutputDev *text_output_dev;
00224
00225
00226 SplashOutputDev *thumbnail_output_dev;
00227
00228
00229 PDFViewAttributes view_attr;
00230
00231
00232 PDFRenderAttributes cur_render_attr;
00233
00234
00235 Mutex render_mutex;
00236
00237 friend class PDFRenderTask;
00238 friend class PDFPage;
00239 };
00240
00241 };
00242
00243 #endif //PDF_RENDERER_H_
00244