pdf_render_task.cpp
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 #include "log.h"
00028
00029 #include "pdf_render_task.h"
00030 #include "pdf_library.h"
00031
00032 namespace pdf
00033 {
00034
00035 PDFRenderTask::PDFRenderTask(int page_num, const PDFRenderAttributes &attr
00036 , PDFController *ctrl, PluginRenderResultImpl *render_res
00037 , int id)
00038 : page(0)
00039 , page_number(page_num)
00040 , page_render_attr(attr)
00041 , doc_ctrl(ctrl)
00042 , ref_id(id)
00043 , render_result(render_res)
00044 {
00045 type = TASK_RENDER;
00046 }
00047
00048 PDFRenderTask::PDFRenderTask(PagePtr p, const PDFRenderAttributes &attr
00049 , PDFController *ctrl, PluginRenderResultImpl *render_res
00050 , int id)
00051 : page(p)
00052 , page_number(page->get_page_num())
00053 , page_render_attr(attr)
00054 , doc_ctrl(ctrl)
00055 , ref_id(id)
00056 , render_result(render_res)
00057 {
00058 type = TASK_RENDER;
00059 }
00060
00061 PDFRenderTask::~PDFRenderTask()
00062 {
00063 }
00064
00065 void PDFRenderTask::execute()
00066 {
00067
00068 if (is_page_out_of_date())
00069 {
00070 return;
00071 }
00072
00073 PDFRenderer *renderer = doc_ctrl->get_renderer();
00074
00075
00076
00077
00078
00079 if (page == 0)
00080 {
00081 page = doc_ctrl->get_page(page_number);
00082
00083 if (page == 0)
00084 {
00085 page = renderer->gen_page(page_number, page_render_attr);
00086 }
00087 }
00088
00089
00090 if (page == 0)
00091 {
00092 ERRORPRINTF("Cannot Create New Page");
00093 return;
00094 }
00095
00096
00097
00098
00099
00100 page->set_ref_id(ref_id);
00101
00102
00103
00104 double real_zoom = page_render_attr.get_real_zoom_value();
00105 if (real_zoom == PLUGIN_ZOOM_TO_CROP_BY_PAGE ||
00106 real_zoom == PLUGIN_ZOOM_TO_CROP_BY_WIDTH)
00107 {
00108 RenderArea content_area;
00109 if (!page->get_content_area(renderer, content_area))
00110 {
00111 ERRORPRINTF("Cannot get content area of page:%d", page_number);
00112 return;
00113 }
00114 PDFRenderAttributes origin_attr = page_render_attr;
00115 renderer->calc_real_zoom(page_number, origin_attr, page_render_attr);
00116 real_zoom = page_render_attr.get_real_zoom_value();
00117 }
00118
00119
00120
00121
00122
00123 int page_len = static_cast<int>(page->length());
00124
00125 page_len = static_cast<int>(PDFPage::try_calc_length(real_zoom,
00126 doc_ctrl->get_page_crop_width(page_number),
00127 doc_ctrl->get_page_crop_height(page_number))) -
00128 page_len;
00129
00130 PDFPage::RenderStatus cur_status = page->get_render_status();
00131 if (!(page->get_render_attr() == page_render_attr))
00132 {
00133
00134
00135
00136
00137 cur_status = PDFPage::RENDER_STOP;
00138 }
00139
00140 bool render_done = true;
00141
00142
00143 if (cur_status != PDFPage::RENDER_DONE)
00144 {
00145 LOGPRINTF("Task, Render Page:%d, Ref ID:%d, Current Task:%p", page_number, ref_id, this);
00146
00147
00148
00149
00150
00151 if (page_len > 0 &&
00152 !PDFLibrary::instance().make_enough_memory(doc_ctrl,
00153 page_number,
00154 page_len))
00155 {
00156 WARNPRINTF("Cannot make enough memory to implement rendering");
00157
00158
00159
00160 renderer->handle_page_ready(render_result, page, TASK_RENDER_OOM);
00161 return;
00162 }
00163
00164
00165 page->set_render_status(cur_status);
00166
00167
00168 page->set_render_attr(page_render_attr);
00169
00170 render_done = page->render_splash_map(renderer
00171 , static_cast<void*>(this));
00172
00173
00174 if (render_done)
00175 {
00176 page->render_text(renderer);
00177 }
00178 }
00179
00180 if (render_done)
00181 {
00182
00183 page->set_render_status(PDFPage::RENDER_DONE);
00184
00185 if (render_result != 0)
00186 {
00187
00188 render_result->set_page(page);
00189 }
00190
00191
00192 renderer->handle_page_ready(render_result, page, TASK_RENDER_DONE);
00193 }
00194 else
00195 {
00196 if (render_result != 0 && is_aborted())
00197 {
00198
00199 render_result->set_discard(true);
00200 }
00201 else
00202 {
00203 renderer->handle_page_ready(render_result, page, TASK_RENDER_OOM);
00204 }
00205 }
00206
00207 }
00208
00209 bool PDFRenderTask::is_page_out_of_date()
00210 {
00211
00212 bool out_of_date = !(doc_ctrl->get_prerender_policy()->get_requests().contains(
00213 page_number));
00214
00215 if (out_of_date)
00216 {
00217 return out_of_date;
00218 }
00219
00220 PDFRenderer *renderer = doc_ctrl->get_renderer();
00221
00222 if (page_render_attr.get_zoom_setting() !=
00223 renderer->get_render_attr().get_zoom_setting() ||
00224 page_render_attr.get_rotate() !=
00225 renderer->get_render_attr().get_rotate())
00226 {
00227 out_of_date = true;
00228 }
00229
00230 return out_of_date;
00231 }
00232
00233 void* PDFRenderTask::get_user_data()
00234 {
00235 return doc_ctrl;
00236 }
00237
00238 unsigned int PDFRenderTask::get_id()
00239 {
00240 return ref_id;
00241 }
00242
00243 }
00244