c-如何使用Poppler进行缩放



语言C,UI库:GTK,渲染器:poppler

我是GTK/Poppler编程的新手,有点难以理解如何使用Poppler解决Zoom问题。当我使用下面的函数时,除了缩放(因此是滚动条(之外,一切都可以。

我试着从这里得到想法,但似乎,我根本不知道屏幕/文档是如何呈现的:(.

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();
}

要拥有"滚动条",您必须将查看器放在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);
这就是答案。(但我仍然不知道如何正确创建滚动条(。
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();
    }

相关内容

  • 没有找到相关文章