Ejemplo n.º 1
0
void pdfapp_close(pdfapp_t *app)
{
    if (app->cache)
        fz_freeglyphcache(app->cache);
    app->cache = nil;

    if (app->page)
        pdf_droppage(app->page);
    app->page = nil;

    if (app->image)
        fz_droppixmap(app->image);
    app->image = nil;

    if (app->text)
        fz_freetextspan(app->text);
    app->text = nil;

    if (app->outline)
        pdf_dropoutline(app->outline);
    app->outline = nil;

    if (app->xref->store)
        pdf_dropstore(app->xref->store);
    app->xref->store = nil;

    pdf_closexref(app->xref);
    app->xref = nil;
}
Ejemplo n.º 2
0
void
pdf_freepage(pdf_page *page)
{
	pdf_logpage("drop page %p\n", page);
	if (page->resources)
		fz_dropobj(page->resources);
	if (page->contents)
		fz_dropbuffer(page->contents);
	if (page->list)
		fz_freedisplaylist(page->list);
	if (page->text)
		fz_freetextspan(page->text);
	if (page->links)
		pdf_freelink(page->links);
	if (page->annots)
		pdf_freeannot(page->annots);
	fz_free(page);
}
Ejemplo n.º 3
0
static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage)
{
    char buf[256];
    fz_error error;
    fz_device *idev, *tdev, *mdev;
    fz_displaylist *list;
    fz_matrix ctm;
    fz_bbox bbox;
    fz_obj *obj;

    if (loadpage)
    {
        wincursor(app, WAIT);

        if (app->page)
            pdf_droppage(app->page);
        app->page = nil;
        //code change by kakai
        kno_clearselect(app);
        //code change by kakai
        pdf_flushxref(app->xref, 0);

        obj = pdf_getpageobject(app->xref, app->pageno);
        error = pdf_loadpage(&app->page, app->xref, obj);
        if (error)
            pdfapp_error(app, error);

        sprintf(buf, "%s - %d/%d", app->doctitle,
                app->pageno, app->pagecount);
        wintitle(app, buf);
    }

    if (drawpage)
    {
        wincursor(app, WAIT);

        ctm = pdfapp_viewctm(app);
        bbox = fz_roundrect(fz_transformrect(ctm, app->page->mediabox));

        list = fz_newdisplaylist();

        mdev = fz_newlistdevice(list);
        error = pdf_runcontentstream(mdev, fz_identity(), app->xref, app->page->resources, app->page->contents);
        if (error)
            pdfapp_error(app, error);
        fz_freedevice(mdev);

        if (app->image)
            fz_droppixmap(app->image);
        app->image = fz_newpixmapwithrect(pdf_devicergb, bbox);
        fz_clearpixmap(app->image, 0xFF);
        idev = fz_newdrawdevice(app->cache, app->image);
        fz_executedisplaylist(list, idev, ctm);
        fz_freedevice(idev);

        if (app->text)
            fz_freetextspan(app->text);
        app->text = fz_newtextspan();
        tdev = fz_newtextdevice(app->text);
        fz_executedisplaylist(list, tdev, ctm);
        fz_freedevice(tdev);

        fz_freedisplaylist(list);

        //code change by kakai
        kno_allocselection(app);
        kno_applyselect(app);
        //code change by kakai

        winconvert(app, app->image);
    }

    pdfapp_panview(app, app->panx, app->pany);

    if (app->shrinkwrap)
    {
        int w = app->image->w;
        int h = app->image->h;
        if (app->winw == w)
            app->panx = 0;
        if (app->winh == h)
            app->pany = 0;
        if (w > app->scrw * 90 / 100)
            w = app->scrw * 90 / 100;
        if (h > app->scrh * 90 / 100)
            h = app->scrh * 90 / 100;
        if (w != app->winw || h != app->winh)
            winresize(app, w, h);
    }

    winrepaint(app);

    wincursor(app, ARROW);
}