pdf/plugin_impl/render_result_impl.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 "render_result_impl.h"
00028 #include "render_settings_impl.h"
00029 #include "collection_impl.h"
00030
00031 #include "pdf_renderer.h"
00032 #include "pdf_doc_controller.h"
00033 #include "pdf_page.h"
00034
00035 namespace pdf
00036 {
00037
00038 utils::ObjectTable<PluginRenderResultImpl> PluginRenderResultImpl::g_instances_table;
00039
00040 PluginRenderResultImpl::PluginRenderResultImpl(const unsigned int page_num, const unsigned int id)
00041 : page(0)
00042 , page_number(page_num)
00043 , ref_id(id)
00044 , discard(false)
00045 {
00046
00047 query_interface = query_interface_impl;
00048 release = release_impl;
00049
00050
00051 get_bitmap_attributes = get_bitmap_attributes_impl;
00052 get_anchor_from_coordinates = get_anchor_from_coordinates_impl;
00053 get_bounding_rectangles_from_range = get_bounding_rectangles_from_range_impl;
00054 get_rendered_range = get_rendered_range_impl;
00055
00056
00057
00058
00059 set_zoom_factor = set_zoom_factor_impl;
00060 get_zoom_factor = get_zoom_factor_impl;
00061
00062
00063 set_rotation = set_rotation_impl;
00064 get_rotation = get_rotation_impl;
00065
00066
00067
00068 g_instances_table.add_interface<IPluginUnknown>(this);
00069 g_instances_table.add_interface<IPluginRenderResult>(this);
00070 g_instances_table.add_interface<IPluginRenderSettings>(this);
00071 g_instances_table.add_interface<IPluginZoom>(this);
00072 g_instances_table.add_interface<IPluginRotation>(this);
00073
00074 }
00075
00076 void PluginRenderResultImpl::set_page(PagePtr ptr)
00077 {
00078 if (ptr != 0)
00079 {
00080 page = ptr;
00081 page_number = static_cast<unsigned int>(page->get_page_num());
00082 ref_id = page->get_ref_id();
00083 page->lock();
00084 }
00085 }
00086
00087 PluginRenderResultImpl::~PluginRenderResultImpl(void)
00088 {
00089
00090
00091 if (page != 0)
00092 {
00093 page->unlock();
00094 }
00095
00096 g_instances_table.remove(this);
00097 }
00098
00099 PluginStatus
00100 PluginRenderResultImpl::query_interface_impl(IPluginUnknown *thiz,
00101 const UDSString *id,
00102 void **ptr )
00103 {
00104 PluginRenderResultImpl *instance = g_instances_table.get_object(thiz);
00105 if (g_instances_table.query_interface(instance, id->get_buffer(id), ptr))
00106 {
00107 return PLUGIN_OK;
00108 }
00109 return PLUGIN_FAIL;
00110 }
00111
00112 int
00113 PluginRenderResultImpl::release_impl(IPluginUnknown *thiz )
00114 {
00115 PluginRenderResultImpl *instance = g_instances_table.get_object(thiz);
00116 instance->release_signal.safe_broadcast(instance);
00117 return 0;
00118 }
00119
00120 PluginStatus
00121 PluginRenderResultImpl::get_bitmap_attributes_impl(IPluginUnknown *thiz,
00122 PluginBitmapAttributes *attributes)
00123 {
00124 PluginRenderResultImpl *instance = g_instances_table.get_object(thiz);
00125
00126 if (instance->page == 0)
00127 {
00128 return PLUGIN_FAIL;
00129 }
00130
00131 attributes->width = instance->page->get_bitmap_width();
00132 attributes->height = instance->page->get_bitmap_height();
00133 attributes->row_stride = instance->page->get_bitmap_row_stride();
00134 attributes->data = instance->page->get_bitmap_data();
00135
00136 return PLUGIN_OK;
00137 }
00138
00139 PluginStatus
00140 PluginRenderResultImpl::get_anchor_from_coordinates_impl(IPluginUnknown *thiz,
00141 const int x,
00142 const int y,
00143 UDSString *anchor )
00144 {
00145
00146 PluginRenderResultImpl *instance = g_instances_table.get_object(thiz);
00147
00148 if (instance->page == 0)
00149 {
00150 return PLUGIN_FAIL;
00151 }
00152
00153 double ux, uy;
00154
00155 instance->page->coordinates_dev_to_user(x, y, &ux, &uy);
00156
00157 PDFAnchor param;
00158 instance->page->get_anchor_param_from_coordinates(ux, uy, param);
00159
00160 anchor->assign(anchor, param.get_string().c_str());
00161
00162 return PLUGIN_OK;
00163 }
00164
00165 IPluginUnknown*
00166 PluginRenderResultImpl::get_bounding_rectangles_from_range_impl(IPluginUnknown *thiz,
00167 const PluginRange *range)
00168 {
00169 PluginRenderResultImpl *instance = g_instances_table.get_object(thiz);
00170
00171 if (instance->page == 0)
00172 {
00173 return 0;
00174 }
00175
00176 PDFRectangles *rectangles = new PDFRectangles;
00177
00178
00179 string start(range->start_anchor->get_buffer(range->start_anchor));
00180 string end(range->end_anchor->get_buffer(range->end_anchor));
00181 if (instance->page->get_bounding_rectangles(start, end, *rectangles))
00182 {
00183 PluginCollectionImpl *collection = new PluginCollectionImpl;
00184
00185 collection->set_data(rectangles);
00186
00187 return static_cast<IPluginUnknown *>(collection);
00188 }
00189
00190 return 0;
00191 }
00192
00193 float
00194 PluginRenderResultImpl::get_zoom_factor_impl(IPluginUnknown* thiz )
00195 {
00196 PluginRenderResultImpl *instance = g_instances_table.get_object(thiz);
00197
00198 if (instance->page == 0)
00199 {
00200 return static_cast<float>(PLUGIN_ZOOM_INVALID);
00201 }
00202
00203 return static_cast<float>(instance->page->get_render_attr().get_zoom_setting());
00204 }
00205
00206 PluginRotationDegree
00207 PluginRenderResultImpl::get_rotation_impl(IPluginUnknown *thiz )
00208 {
00209 PluginRenderResultImpl *instance = g_instances_table.get_object(thiz);
00210
00211 if (instance->page == 0)
00212 {
00213 return Clockwise_Degrees_0;
00214 }
00215
00216 return static_cast<PluginRotationDegree>(
00217 instance->page->get_render_attr().get_rotate());
00218 }
00219
00220 PluginStatus
00221 PluginRenderResultImpl::get_rendered_range_impl(IPluginUnknown *thiz,
00222 PluginRange *range)
00223 {
00224
00225
00226 PluginRenderResultImpl *instance = g_instances_table.get_object(thiz);
00227
00228 if (instance->page == 0)
00229 {
00230 return PLUGIN_FAIL;
00231 }
00232
00233 int page_num = instance->page->get_page_num();
00234
00235 PDFAnchor start_anchor;
00236 start_anchor.page_num = page_num;
00237
00238
00239 PDFAnchor end_anchor;
00240
00241 end_anchor.set_end_anchor();
00242
00243 range->start_anchor->assign( range->start_anchor, start_anchor.get_string().c_str() );
00244 range->end_anchor->assign( range->end_anchor, end_anchor.get_string().c_str() );
00245
00246 return PLUGIN_OK;
00247 }
00248
00249
00250 PluginStatus
00251 PluginRenderResultImpl::set_zoom_factor_impl(IPluginUnknown* thiz,
00252 const float zoom_factor )
00253 {
00254 return PLUGIN_FAIL;
00255 }
00256
00257 PluginStatus
00258 PluginRenderResultImpl::set_rotation_impl(IPluginUnknown *thiz,
00259 const PluginRotationDegree rotation )
00260 {
00261 return PLUGIN_FAIL;
00262 }
00263
00264 }
00265