Exemplo n.º 1
0
void k2file_get_overlay_bitmap(WILLUSBITMAP *bmp,double *dpi,char *filename,char *pagelist)

    {
    int i,c,c2,src_type,np;
    char mupdffilename[MAXFILENAMELEN];
    static K2PDFOPT_SETTINGS _k2settings;
    K2PDFOPT_SETTINGS *k2settings;
    WILLUSBITMAP *tmp,_tmp;

    (*dpi)=100.;
    src_type = get_source_type(filename);
    if (src_type!=SRC_TYPE_PDF && src_type!=SRC_TYPE_DJVU)
        return;
    strncpy(mupdffilename,filename,MAXFILENAMELEN-1);
    mupdffilename[MAXFILENAMELEN-1]='\0';
    k2settings=&_k2settings;
    k2pdfopt_settings_init(k2settings);
    k2settings->document_scale_factor=1.0;
    k2settings->usegs=-1;
    np=file_numpages(filename,mupdffilename,src_type,&k2settings->usegs);
    for (c=0,i=1;i<=np;i++)
        if (pagelist_includes_page(pagelist,i,np))
            c++;
#ifdef HAVE_K2GUI
    if (k2gui_active())
        {
        k2gui_overlay_set_num_pages(c);
        k2gui_overlay_set_pages_completed(0,NULL);
        }
#endif
    tmp=&_tmp;
    bmp_init(tmp);
    for (c=c2=0,i=1;i<=np;i++)
        {
        int status;

        if (!pagelist_includes_page(pagelist,i,np))
            continue;
        status=bmp_get_one_document_page(tmp,k2settings,src_type,mupdffilename,i,100.,8,NULL);
        c2++;
#ifdef HAVE_K2GUI
        if (k2gui_active())
            k2gui_overlay_set_pages_completed(c2,NULL);
#endif
        if (status)
            {
#ifdef HAVE_K2GUI
            if (k2gui_active())
                k2gui_overlay_error(filename,i,status);
#endif
            continue;
            }
        c++;
        if (c==1)
            bmp_copy(bmp,tmp);
        else
            bmp8_merge(bmp,tmp,c);
        }
    bmp_free(tmp);
    }
Exemplo n.º 2
0
/*
** Conversion thread.  This is launched as a separate thread to do the
** conversions while the dialog box displays the progress.
*/
static void k2gui_overlay_start_conversion(void *data)

    {
    void **ptrs;
    /* static char *funcname="k2gui_overlay_start_conversion"; */
    char *filename;
    char *pagelist;
    char buf[256];
    WILLUSBITMAP *bmp;

#if (WILLUSDEBUGX & 0x2000000)
k2dprintf("@k2gui_overlay_start_conversion thread.\n");
#endif
    ptrs=(void **)data;
    filename=(char *)ptrs[0];
    pagelist=(char *)ptrs[1];
    overwrite_set(1);
    k2gui_overlay_set_error_count(0);
    /* k2gui_overlay_freelist(); */
    overwrite_set(0);
    k2gui_overlay_set_num_pages(1);
    strncpy(k2gui_overlay->filename,k2gui_short_name(filename),255);
    k2gui_overlay->filename[255]='\0';
    sprintf(buf,"Creating overlay for %s...",k2gui_overlay->filename);
    k2gui_overlay_set_pages_completed(0,buf);
    bmp=&k2gui_overlay->bmp;
#if (WILLUSDEBUGX & 0x2000000)
k2dprintf("Getting overlay bitmap...\n");
#endif
    k2file_get_overlay_bitmap(bmp,&k2gui_overlay->dpi,filename,pagelist);
#if (WILLUSDEBUGX & 0x2000000)
k2dprintf("   Done overlay bitmap (ecount=%d)...\n",k2gui_overlay->error_count);
#endif
/*
printf(" = %d x %d\n",bmp->width,bmp->height);
*/
    /* If successful, size the window to the proportions of the loaded bitmap */
    if (k2gui_overlay->error_count==0 && bmp->width>0 && bmp->height>0)
        {
        WILLUSGUIRECT rect,r1,ru;
        int dw,dh,w,h,bh,bw,delw,delh,delw2,delh2;

        k2gui_overlay->converting=2;
        k2gui_overlay->successful=1;
        willusgui_window_get_rect(&k2gui_overlay->mainwin,&r1);
        willusgui_window_get_useable_rect(&k2gui_overlay->mainwin,&ru);
        delw=(r1.right-r1.left)-(ru.right-ru.left);
        delw2=delw + 10;
        delh=(r1.bottom-r1.top)-(ru.bottom-ru.top);
        delh2=delh + (int)k2gui_overlay->bf.size*2.0 + (int)k2gui_overlay->mf.size/4;
/*
printf("delw=%d, delw2=%d, delh=%d, delh2=%d\n",delw,delw2,delh,delh2);
*/
        willusgui_window_get_rect(NULL,&rect);
        dw=rect.right-rect.left+1;
        dh=rect.bottom-rect.top+1;
        h = dh*3/4;
        bh = h - delh2;
        bw = bh*bmp->width/bmp->height;
        w = bw+delw2;
        if (w > dw*3/4)
            {
            bw =  dw*3/4-delw2;
            bh =  bw*bmp->height/bmp->width;
            }
/*
printf("bw=%d, bh=%d\n",bw,bh);
*/
        w = bw+delw2;
        h = bh+delh2;
/*
printf("w=%d, h=%d\n",w,h);
*/
        rect.left=dw/2-w/2;
        rect.right=rect.left+w-1;
        rect.top=dh/2-h/2;
        rect.bottom=rect.top+h-1;
        willusgui_window_set_pos(&k2gui_overlay->mainwin,&rect);
        k2gui_overlay_update_window();
        }
    else
        bmp->width=-1;
#if (WILLUSDEBUGX & 0x2000000)
k2dprintf("   Done overlay_start_conversion..\n",k2gui_overlay->error_count);
#endif
    k2gui_overlay_conversion_thread_cleanup();
    }