语言 C, UI库: GTK,渲染器: poppler
我是GTK / Poppler编程的新手,并且有点了解如何使用poppler解决缩放问题。 当我使用下面的功能时,一切都很好,除了缩放(因此 - 滚动条)。
我试图从here获得这些想法,但看起来,我根本不了解屏幕/文档的呈现方式:(。
PopplerPage *ppage_P2 = NULL;
PopplerDocument *document_P2 = NULL;
cairo_surface_t *surface_P2 = NULL;
/* pdf_doc__view_page
* page - page number;
* zoom - floating nomber, 1.0 is 'no zoom'
*/
void pdf_doc__view_page (int page, float _zoom){
int err;
int w, h;
double width, height;
cairo_t *cr;
if(document_P2==NULL) /
return;
ppage_P2 = poppler_document_get_page (document_P2, page);
if(ppage_P2==NULL)
return;
poppler_page_get_size (ppage_P2, &width, &height);
w = (int) ceil(width);
h = (int) ceil(height);
if(surface_P2)
cairo_surface_destroy (surface_P2);
surface_P2 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w*zoom_P2, h*zoom_P2);
cr = cairo_create (surface_P2);
poppler_page_render (ppage_P2, cr);
cairo_destroy (cr);
if(drawarea_P2==NULL)
return;
gtk_widget_set_size_request (drawarea_P2, w*zoom_P2, h*zoom_P2);
gtk_widget_queue_draw (drawarea_P2);
// self.SetScrollbars(u, u, (self.width*self.scale)/u, (self.height*self.scale)/u)
update_statusbar();
}
答案 0 :(得分:0)
这就是答案。 (但我仍然没有得到如何正确创建滚动条。)
cr = cairo_create (surface_P2);
cairo_scale(cr, zoom_P1 , zoom_P1);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_paint(cr);
poppler_page_render(ppage_P2, cairo);
cairo_destroy(cr);
cairo_surface_destroy(surface_P2);
g_object_unref(G_OBJECT(ppage_P2));
if(drawarea_P2==NULL)
return;
gtk_widget_set_size_request (drawarea_P2, w, h);
gtk_widget_queue_draw (drawarea_P2);
// self.SetScrollbars(u, u, (self.width*self.scale)/u, (self.height*self.scale)/u)
update_statusbar();
}
答案 1 :(得分:0)
要拥有“滚动条”,您必须将查看器放入GtkScrolledWindow,我怀疑您已经这样做了。
要让它们实际工作,一旦poppler呈现页面,您可以向poppler询问渲染的大小,然后将查看器设置为该大小。在此之前,滚动条不知道绘图的大小:
viewer_page = poppler_document_get_page(viewer_doc, 0);
// add a test to see if page was rendered correctly
poppler_page_get_size(viewer_page, &width, &height);
gtk_widget_set_size_request(viewer.drawingarea, (int)width, (int)height);