Example #1
0
void k2pdfopt_reflow_bmp(KOPTContext *kctx,WILLUSBITMAP *src,int init)

    {
    static K2PDFOPT_SETTINGS _k2settings, *k2settings;
    static MASTERINFO _masterinfo, *masterinfo;
    WILLUSBITMAP _srcgrey, *srcgrey;
    BMPREGION region;
    static int pages_done=0;

    srcgrey=&_srcgrey;
    bmp_init(srcgrey);

    k2settings=&_k2settings;
    masterinfo=&_masterinfo;
    /* First call or new document call should use init =  1 */
    if (init==1)
        {
        /* Initialize settings */
        k2pdfopt_settings_init_from_koptcontext(k2settings,kctx);
        k2pdfopt_settings_sanity_check(k2settings);

        /* Init master output structure */
        masterinfo_init(masterinfo,k2settings);

        /* Init for new source doc */
        k2pdfopt_settings_new_source_document_init(k2settings);
        }

    /* Init new source bitmap */
    bmpregion_init(&region);
    masterinfo_new_source_page_init(masterinfo,k2settings,src,srcgrey,NULL,&region,0.,NULL,NULL,1,NULL);

    /* Process single source page */
    if (init)
        pages_done=0;
    bmpregion_source_page_add(&region,k2settings,masterinfo,1,pages_done++);
    bmp_free(srcgrey);

    /*
    ** Get output pages
    */ 
    {
    WILLUSBITMAP *bmp,_bmp;
    int rows,size_reduction;
    double bmpdpi;

    bmp=&_bmp;
    bmp_init(bmp);
    while ((rows=masterinfo_get_next_output_page(masterinfo,k2settings,1,bmp,
                                                 &bmpdpi,&size_reduction,NULL))>0)
        {
        /* Process output page stored in "bmp" */
        }
    bmp_free(bmp);
    }

    /* Final call should use init = -999 */
    if (init == -999)
        masterinfo_free(masterinfo,k2settings);
    }
Example #2
0
int main(int argc,char *argv[])

{
    static K2PDFOPT_SETTINGS _k2settings, *k2settings;
    static MASTERINFO _masterinfo, *masterinfo;
    WILLUSBITMAP _srcgrey, *srcgrey;
    WILLUSBITMAP _src, *src;
    BMPREGION region;
    int status;

    if (argc<2)
    {
        printf("usage:  kview <infile.bmp>\n");
        return(0);
    }
    src=&_src;
    bmp_init(src);
    srcgrey=&_srcgrey;
    bmp_init(srcgrey);
    if ((status=bmp_read(src,argv[1],NULL))<0)
    {
        printf("Error %d reading bitmap file %s.\n",status,argv[1]);
        return(10);
    }
    printf("Bitmap %s is %d x %d x %d\n",argv[1],src->width,src->height,src->bpp);

    /* Initialize settings */
    k2settings=&_k2settings;
    k2pdfopt_settings_init(k2settings);
    k2settings->use_crop_boxes=0;
    k2settings->src_rot=0;
    k2settings->erase_vertical_lines=0;
    k2settings->src_autostraighten=0;
    k2pdfopt_settings_sanity_check(k2settings);

    /* Init master output structure */
    masterinfo=&_masterinfo;
    masterinfo_init(masterinfo,k2settings);

    /* Init for new source doc */
    k2pdfopt_settings_new_source_document_init(k2settings);

    /* Init new source bitmap */
    masterinfo_new_source_page_init(masterinfo,k2settings,src,srcgrey,NULL,&region,0.,NULL,NULL,1,NULL);

    /* Process single source page */
    bmpregion_source_page_add(&region,k2settings,masterinfo,1,
                              (int)(0.25 * k2settings->src_dpi + .5));
    bmp_free(srcgrey);
    bmp_free(src);

    /*
    ** Get output pages
    */
    {
        WILLUSBITMAP *bmp,_bmp;
        int pn,rows,size_reduction;
        double bmpdpi;

        bmp=&_bmp;
        bmp_init(bmp);
        pn=0;
        while ((rows=masterinfo_get_next_output_page(masterinfo,k2settings,1,bmp,
                     &bmpdpi,&size_reduction,NULL))>0)
        {
            char filename[256];
            pn++;
            sprintf(filename,"outpage%02d.bmp",pn);
            bmp_write(bmp,filename,stdout,0);
        }
        bmp_free(bmp);
    }
    masterinfo_free(masterinfo,k2settings);
    return(0);
}
Example #3
0
void masterinfo_publish(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings,int flushall)

    {
#ifdef HAVE_MUPDF_LIB
    static WTEXTCHARS *wtcs=NULL;
    static WTEXTCHARS _wtcs;
    /* static int pageno=0; */
#endif
    WILLUSBITMAP _bmp,*bmp;
    double bmpdpi;
    int output_page_count,size_reduction;
#ifdef HAVE_OCR_LIB
    OCRWORDS *ocrwords,_ocrwords;
#else
    void *ocrwords;
#endif

/*
aprintf(ANSI_GREEN "\n   @masterinfo_publish(flushall=%d)....\n\n" ANSI_NORMAL,flushall);
*/
#ifdef HAVE_MUPDF_LIB
    if (wtcs==NULL)
        {
        wtcs=&_wtcs;
        wtextchars_init(wtcs);
        }
#endif
#ifdef HAVE_OCR_LIB
    if (k2settings->dst_ocr)
        {
        ocrwords=&_ocrwords;
        ocrwords_init(ocrwords);
        }
    else
#endif
        ocrwords=NULL;
    bmp=&_bmp;
    bmp_init(bmp);
    output_page_count=0;
    while (masterinfo_get_next_output_page(masterinfo,k2settings,flushall,bmp,
                                           &bmpdpi,&size_reduction,ocrwords)>0)
        {
/*
aprintf(ANSI_GREEN "\n   SRC PAGE %d\n\n" ANSI_NORMAL,masterinfo->pageinfo.srcpage);
*/
        output_page_count++;
        if (masterinfo->preview_bitmap!=NULL)
            {
            if (ocrwords!=NULL)
                ocrwords_free(ocrwords); /* Don't really need this, but just for insurance */
            if (!k2settings->show_marked_source
                        && abs(k2settings->preview_page)==masterinfo->published_pages)
                {
/*
printf("At preview page:  bmp = %d x %d x %d, preview(dst) = %d x %d x %d\n",
bmp->width,bmp->height,bmp->bpp,
masterinfo->preview_bitmap->width,masterinfo->preview_bitmap->height,masterinfo->preview_bitmap->bpp);
*/              bmp_copy(masterinfo->preview_bitmap,bmp);
                masterinfo->preview_captured=1;
                break;
                }
            continue;
            }

        /* v2.16, outline / bookmark check done in separate function. */
        k2publish_outline_check(masterinfo,k2settings,0);
/*
printf("use_toc=%d, outline=%p, spc=%d, srcpage=%d\n",k2settings->use_toc,masterinfo->outline,masterinfo->outline_srcpage_completed,masterinfo->pageinfo.srcpage);
*/

        /*
        ** Nothing to do inside loop if using crop boxes -- they all
        ** get written after all pages have been processed.
        */
        if (k2settings->use_crop_boxes)
            continue;
#ifdef HAVE_OCR_LIB
        if (k2settings->dst_ocr)
            {
            int flags_extra;

            flags_extra=0;
            if (k2settings->dst_ocr=='m')
                {
                flags_extra=0x20;
                /* Don't re-sort--messes up the copy/paste flow */
                /*
                if (masterinfo->ocrfilename[0]=='\0')
                    ocrwords_sort_by_pageno(ocrwords);
                */
/*
** This section no longer needed in v2.20.  The text in the ocrword boxes
** has already been determined by k2ocr_ocrwords_get_from_ocrlayer() in k2ocr.c
*/
/*
                for (i=0;i<ocrwords->n;i++)
                    {
                    static char *funcname="masterinfo_publish";

                    if (ocrwords->word[i].pageno != pageno)
                        {
                        wtextchars_clear(wtcs);
                        wtextchars_fill_from_page(wtcs,masterinfo->srcfilename,
                                                  ocrwords->word[i].pageno,"");
                        wtextchars_rotate_clockwise(wtcs,360-(int)ocrwords->word[i].rot0_deg);
                        pageno=ocrwords->word[i].pageno;
                        }
                    willus_mem_free((double **)&ocrwords->word[i].text,funcname);
                    wtextchars_text_inside(wtcs,&ocrwords->word[i].text,
                                           ocrwords->word[i].x0,
                                           ocrwords->word[i].y0,
                                           ocrwords->word[i].x0+ocrwords->word[i].w0,
                                           ocrwords->word[i].y0+ocrwords->word[i].h0);
#if (WILLUSDEBUGX & 0x400)
printf("MuPDF Word (%5.1f,%5.1f) - (%5.1f,%5.1f) = '%s'\n",
ocrwords->word[i].x0,
ocrwords->word[i].y0,
ocrwords->word[i].x0+ocrwords->word[i].w0,
ocrwords->word[i].y0+ocrwords->word[i].h0,
ocrwords->word[i].text);
#endif
                    if (ocrwords->word[i].text==NULL || ocrwords->word[i].text[0]=='\0')
                        {
                        ocrwords_remove_words(ocrwords,i,i);
                        i--;
                        }
                    }
*/
                
                }
            if (masterinfo->ocrfilename[0]!='\0')
                ocrwords_to_textfile(ocrwords,masterinfo->ocrfilename,
                                     masterinfo->published_pages>1);

#if (WILLUSDEBUGX & 0x400)
printf("Calling pdffile_add_bitmap_with_ocrwords.\n");
#endif
#if (WILLUSDEBUGX & 0x10000)
if (ocrwords!=NULL)
{
int k;
printf("flags_extra= %d\n",flags_extra);
printf("PAGE OF WORDS\n");
for (k=0;k<ocrwords->n;k++)
printf("%3d. '%s'\n",k,ocrwords->word[k].text);
}
#endif
            pdffile_add_bitmap_with_ocrwords(&masterinfo->outfile,bmp,bmpdpi,
                                             k2settings->jpeg_quality,size_reduction,
                                             ocrwords,k2settings->dst_ocr_visibility_flags
                                                        | flags_extra);
#if (WILLUSDEBUGX & 0x400)
printf("Back from pdffile_add_bitmap_with_ocrwords.\n");
#endif
/*
{
static int count=1;
char filename[MAXFILENAMELEN];
sprintf(filename,"page%04d.png",count++);
bmp_write(bmp,filename,stdout,100);
}
*/
            masterinfo->wordcount += ocrwords->n;
            ocrwords_free(ocrwords);
            }
        else
#endif
            pdffile_add_bitmap(&masterinfo->outfile,bmp,bmpdpi,
                               k2settings->jpeg_quality,size_reduction);
        }
    /*
    ** v2.16 bug fix:  If no destination output generated, we still have to call outline_check().
    */
    if (output_page_count==0)
        k2publish_outline_check(masterinfo,k2settings,1);
    bmp_free(bmp);
    }