Skip to content

Commit

Permalink
update k2pdfopt to version 1.64a
Browse files Browse the repository at this point in the history
  • Loading branch information
chrox committed Jan 23, 2013
1 parent f31e2a8 commit 90ce6b4
Show file tree
Hide file tree
Showing 17 changed files with 4,964 additions and 50,224 deletions.
5 changes: 3 additions & 2 deletions k2pdfoptlib/devprofile.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
** devprofile.c Handle device profiles.
**
** Copyright (C) 2012 http://willus.com
** Copyright (C) 2013 http://willus.com
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
Expand All @@ -20,11 +20,12 @@

#include "k2pdfopt.h"

static DEVPROFILE devprof[4] =
static DEVPROFILE devprof[5] =
{
{"Kindle 2","k2",560,735,167,0,1,{0,0,3,4}},
{"Nook Simple Touch","nookst",552,725,167,0,1,{0,0,0,0}},
{"Kindle DX","dx",800,1180,167,0,1,{0,0,0,0}},
{"Kindle Paperwhite","kpw",758,1024,212,0,1,{0,0,3,4}},
{"","",0,0,167,0,1,{0,0,0,0}}
};

Expand Down
11 changes: 7 additions & 4 deletions k2pdfoptlib/k2file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
** k2file.c K2pdfopt file handling and main file processing
** function (k2pdfopt_proc_one()).
**
** Copyright (C) 2012 http://willus.com
** Copyright (C) 2013 http://willus.com
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -486,6 +486,9 @@ static double k2pdfopt_proc_one(K2PDFOPT_SETTINGS *k2settings,char *filename,dou
(double)srcgrey->height/k2settings->src_dpi,rotstr);
fflush(stdout);

/* Insert gap between source pages if requested */
if (pages_done>0 && k2settings->dst_break_pages<-1)
masterinfo_add_gap(masterinfo,k2settings,(-1-k2settings->dst_break_pages)/1000.);
/* Parse the source bitmap for viewable regions */
bmpregion_source_page_add(&region,k2settings,masterinfo,1,
pages_done==0. ? 0. : (int)(0.25*k2settings->src_dpi+.5));
Expand All @@ -499,7 +502,7 @@ static double k2pdfopt_proc_one(K2PDFOPT_SETTINGS *k2settings,char *filename,dou
if (k2settings->show_marked_source)
mark_source_page(k2settings,NULL,0,0xf);
if (k2settings->dst_fit_to_page!=-2)
masterinfo_publish(masterinfo,k2settings,k2settings->dst_break_pages);
masterinfo_publish(masterinfo,k2settings,k2settings->dst_break_pages>0 ? 1 : 0);
if (k2settings->show_marked_source)
publish_marked_page(mpdf,k2settings->dst_color ? marked : src,k2settings->src_dpi);
printf("%d new pages saved.\n",masterinfo->published_pages-pw);
Expand Down Expand Up @@ -538,7 +541,7 @@ static double k2pdfopt_proc_one(K2PDFOPT_SETTINGS *k2settings,char *filename,dou
filelist_free(fl);
return(0.);
}
if (!k2settings->dst_break_pages && k2settings->dst_fit_to_page!=-2)
if (k2settings->dst_break_pages<=0 && k2settings->dst_fit_to_page!=-2)
masterinfo_flush(masterinfo,k2settings);
{
char cdate[128],author[256],title[256];
Expand Down Expand Up @@ -579,7 +582,7 @@ printf(" sr=%5.1f, dr=%5.1f\n\n",box->srcrot_deg,box->dstrot_deg);
}
#endif
#ifdef HAVE_MUPDF_LIB
wmupdf_remake_pdf(mupdffilename,dstfile,&masterinfo->pageinfo,stdout);
wmupdf_remake_pdf(mupdffilename,dstfile,&masterinfo->pageinfo,1,stdout);
#endif
}
if (k2settings->show_marked_source)
Expand Down
7 changes: 3 additions & 4 deletions k2pdfoptlib/k2master.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
** k2master.c Functions to handle the main (master) k2pdfopt output bitmap.
**
** Copyright (C) 2012 http://willus.com
** Copyright (C) 2013 http://willus.com
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -29,7 +29,6 @@ static void masterinfo_add_cropbox(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2s
#endif
static void bmp_pad_and_mark(WILLUSBITMAP *dst,WILLUSBITMAP *src,K2PDFOPT_SETTINGS *k2settings,
int ltotheight,double bmpdpi,void *ocrwords);
static void masterinfo_add_gap(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings,double inches);
static void bmp_fully_justify(WILLUSBITMAP *jbmp,WILLUSBITMAP *src,
K2PDFOPT_SETTINGS *k2settings,int jbmpwidth,
int whitethresh,int just,int dpi);
Expand Down Expand Up @@ -170,7 +169,7 @@ int masterinfo_new_source_page_init(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2
masterinfo->bgcolor=white;
masterinfo->fit_to_page = k2settings->dst_fit_to_page;
/* Set destination size (flush output bitmap if it changes) */
k2pdfopt_settings_set_margins_and_devsize(k2settings,region,masterinfo);
k2pdfopt_settings_set_margins_and_devsize(k2settings,region,masterinfo,0);
return(1);
}

Expand Down Expand Up @@ -923,7 +922,7 @@ static void bmp_pad_and_mark(WILLUSBITMAP *dst,WILLUSBITMAP *src,K2PDFOPT_SETTIN
}


static void masterinfo_add_gap(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings,double inches)
void masterinfo_add_gap(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings,double inches)

{
int n,bw;
Expand Down
80 changes: 76 additions & 4 deletions k2pdfoptlib/k2menu.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
** k2menu.c Interactive user menu for k2pdfopt.c.
**
** Copyright (C) 2012 http://willus.com
** Copyright (C) 2013 http://willus.com
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -290,8 +290,24 @@ int k2pdfopt_menu(K2PDFOPT_SETTINGS *k2settings,int filecount,
status=userinput_string("Break output pages at end of each input page",ansyesno,k2settings->dst_break_pages?"y":"n");
if (status<0)
return(status);
k2settings->dst_break_pages=!status;
strbuf_sprintf(usermenu,"-bp%s",k2settings->dst_break_pages?"":"-");
k2settings->dst_break_pages=(status==0) ? 1 : 0;
if (!k2settings->dst_break_pages)
{
double x;
x=0.;
status=userinput_float("Gap between source pages (inches)",x,&x,1,0.0,100.,NULL);
if (status<0)
return(status);
if (x>0.)
{
k2settings->dst_break_pages=-1-(int)(1000.*x+.5);
strbuf_sprintf(usermenu,"-bp %g",x);
}
else
strbuf_sprintf(usermenu,"-bp-");
}
else
strbuf_sprintf(usermenu,"-bp");
status=userinput_integer("Fit-to-page value",k2settings->dst_fit_to_page,&k2settings->dst_fit_to_page,
-2,999);
if (status<0)
Expand Down Expand Up @@ -617,7 +633,11 @@ int k2pdfopt_menu(K2PDFOPT_SETTINGS *k2settings,int filecount,
#ifdef HAVE_OCR_LIB
else if (!stricmp(buf,"oc"))
{
static char *ocropts[]={"Tesseract","Gocr","None",""};
static char *ocropts[]={
#ifdef HAVE_TESSERACT_LIB
"Tesseract",
#endif
"Gocr","None",""};

status=userinput_string("OCR choice",ocropts,k2settings->dst_ocr=='t'?"t":(k2settings->dst_ocr=='g')?"g":"n");
if (status<0)
Expand All @@ -630,6 +650,58 @@ int k2pdfopt_menu(K2PDFOPT_SETTINGS *k2settings,int filecount,
}
else
strbuf_sprintf(usermenu,"-ocr %c",k2settings->dst_ocr);
#ifdef HAVE_TESSERACT_LIB
if (k2settings->dst_ocr=='t' && getenv("TESSDATA_PREFIX")!=NULL)
{
FILELIST *fl,_fl;
char tdir1[512];
char tdir[512];

fl=&_fl;
wfile_fullname(tdir1,getenv("TESSDATA_PREFIX"),"tessdata");
wfile_fullname(tdir,tdir1,"*.traineddata");
filelist_init(fl);
filelist_fill_from_disk_1(fl,tdir,0,0);
if (fl->n>1)
{
int i;
char base1[512];
char base[512];

filelist_sort_by_date(fl);
for (i=1;i<=fl->n;i++)
{
wfile_basespec(base1,fl->entry[fl->n-i].name);
wfile_newext(base,base1,"");
aprintf(TTEXT_BOLD "%2d" TTEXT_NORMAL ". %s\n",i,base);
}
while (1)
{
char buf[16];
aprintf(TTEXT_BOLD2 "Enter language selection (def=1): " TTEXT_NORMAL);
fgets(buf,15,stdin);
clean_line(buf);
if (buf[0]=='\0')
{
i=1;
break;
}
i=atoi(buf);
if (!is_an_integer(buf) || i<1 || i>fl->n)
{
aprintf("\n" TTEXT_WARN " ** Please enter a number in the range 1 - %d. **" TTEXT_NORMAL "\n\n",fl->n);
continue;
}
break;
}
wfile_basespec(base1,fl->entry[fl->n-i].name);
wfile_newext(base,base1,"");
strncpy(k2settings->dst_ocr_lang,base,15);
k2settings->dst_ocr_lang[15]='\0';
strbuf_sprintf(usermenu,"-ocrlang %s",k2settings->dst_ocr_lang);
}
}
#endif
if (k2settings->dst_ocr)
{
status=userinput_float("Max OCR word height (in)",k2settings->ocr_max_height_inches,
Expand Down
27 changes: 24 additions & 3 deletions k2pdfoptlib/k2parsecmd.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
** k2cmdparse.c Parse command-line options for k2pdfopt.
**
** Copyright (C) 2012 http://willus.com
** Copyright (C) 2013 http://willus.com
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -375,8 +375,25 @@ int parse_cmd_args(K2PDFOPT_SETTINGS *k2settings,STRBUF *env,STRBUF *cmdline,
}
if (!stricmp(cl->cmdarg,"-bp") || !stricmp(cl->cmdarg,"-bp-"))
{
if (setvals==1)
k2settings->dst_break_pages=(cl->cmdarg[3]=='-') ? 0 : 1;
if (cl->cmdarg[3]=='-')
{
if (setvals==1)
k2settings->dst_break_pages=0;
continue;
}
if (cmdlineinput_next(cl)==NULL)
break;
if (is_a_number(cl->cmdarg))
{
if (setvals==1)
k2settings->dst_break_pages= -1 - (int)(atof(cl->cmdarg)*1000.+.5);
}
else
{
if (setvals==1)
k2settings->dst_break_pages=1;
readnext=0;
}
continue;
}
if (!strnicmp(cl->cmdarg,"-fc",3))
Expand Down Expand Up @@ -1109,6 +1126,10 @@ static void set_value_with_units(char *s,double *val,int *units)
(*units)=UNITS_INCHES;
else if (tolower(s[i])=='c')
(*units)=UNITS_CM;
else if (tolower(s[i])=='s')
(*units)=UNITS_SOURCE;
else if (tolower(s[i])=='t')
(*units)=UNITS_TRIMMED;
else
(*units)=UNITS_PIXELS;
}
Expand Down
7 changes: 5 additions & 2 deletions k2pdfoptlib/k2pdfopt.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
** k2pdfopt.h Main include file for k2pdfopt source modules.
**
** Copyright (C) 2012 http://willus.com
** Copyright (C) 2013 http://willus.com
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -107,6 +107,8 @@
#define UNITS_PIXELS 0
#define UNITS_INCHES 1
#define UNITS_CM 2
#define UNITS_SOURCE 3
#define UNITS_TRIMMED 4

#define DEFAULT_WIDTH 560
#define DEFAULT_HEIGHT 735
Expand Down Expand Up @@ -462,7 +464,7 @@ void k2pdfopt_settings_fit_column_to_screen(K2PDFOPT_SETTINGS *k2settings,
double column_width_inches);
void k2pdfopt_settings_set_region_widths(K2PDFOPT_SETTINGS *k2settings);
void k2pdfopt_settings_set_margins_and_devsize(K2PDFOPT_SETTINGS *k2settings,
BMPREGION *region,MASTERINFO *masterinfo);
BMPREGION *region,MASTERINFO *masterinfo,int trimmed);


/* breakinfo.c */
Expand Down Expand Up @@ -514,6 +516,7 @@ void masterinfo_add_bitmap(MASTERINFO *masterinfo,WILLUSBITMAP *src,
int justification_flags,int whitethresh,int nocr,int dpi);
void masterinfo_add_gap_src_pixels(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings,
int pixels,char *caller);
void masterinfo_add_gap(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings,double inches);
void masterinfo_remove_top_rows(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings,int rows);
int masterinfo_get_next_output_page(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings,
int flushall,WILLUSBITMAP *bmp,double *bmpdpi,
Expand Down
35 changes: 34 additions & 1 deletion k2pdfoptlib/k2proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
** columns, rows of text, and individual words, and laying out the
** output pages.
**
** Copyright (C) 2012 http://willus.com
** Copyright (C) 2013 http://willus.com
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -128,6 +128,15 @@ void bmpregion_source_page_add(BMPREGION *region,K2PDFOPT_SETTINGS *k2settings,
if (srcregion->r1<0)
srcregion->r1=0;
}
/* Set device width/height to trimmed size if requested */
if (k2settings->dst_userwidth_units==UNITS_TRIMMED
|| k2settings->dst_userheight_units==UNITS_TRIMMED)
{
if (k2settings->src_trim)
bmpregion_trim_margins(srcregion,k2settings,colcount,rowcount,0xf);
k2pdfopt_settings_set_margins_and_devsize(k2settings,srcregion,masterinfo,1);
}
/* Process this part of the grid */
bmpregion_vertically_break(srcregion,k2settings,masterinfo,
k2settings->fit_columns?-2.0:-1.0,colcount,rowcount,0,2*level);
if (masterinfo->fit_to_page==-2)
Expand Down Expand Up @@ -267,6 +276,17 @@ void bmpregion_source_page_add(BMPREGION *region,K2PDFOPT_SETTINGS *k2settings,
level+1,colgap_pixels);
else
{
/* Check for dynamic adjustment of output page to trimmed source region */
if ((k2settings->vertical_break_threshold<-1.5
|| k2settings->dst_fit_to_page==-2)
&& (k2settings->dst_userwidth_units==UNITS_TRIMMED
|| k2settings->dst_userheight_units==UNITS_TRIMMED))
{
/* Set device width/height to trimmed size if requested */
if (k2settings->src_trim)
bmpregion_trim_margins(newregion,k2settings,colcount,rowcount,0xf);
k2pdfopt_settings_set_margins_and_devsize(k2settings,newregion,masterinfo,1);
}
bmpregion_vertically_break(newregion,k2settings,masterinfo,
k2settings->fit_columns?-2.0:-1.0,colcount,rowcount,
colgap_pixels,2*level);
Expand All @@ -288,6 +308,17 @@ void bmpregion_source_page_add(BMPREGION *region,K2PDFOPT_SETTINGS *k2settings,
newregion->c1 = -1-newregion->c1;
/* masterinfo_add_gap_src_pixels(masterinfo,k2settings,newregion->r1-r2,"Col level"); */
colgap_pixels = newregion->r1-r2;
/* Check for dynamic adjustment of output page to trimmed source region */
if ((k2settings->vertical_break_threshold<-1.5
|| k2settings->dst_fit_to_page==-2)
&& (k2settings->dst_userwidth_units==UNITS_TRIMMED
|| k2settings->dst_userheight_units==UNITS_TRIMMED))
{
/* Set device width/height to trimmed size if requested */
if (k2settings->src_trim)
bmpregion_trim_margins(newregion,k2settings,colcount,rowcount,0xf);
k2pdfopt_settings_set_margins_and_devsize(k2settings,newregion,masterinfo,1);
}
bmpregion_vertically_break(newregion,k2settings,masterinfo,
(k2settings->fit_columns && (level>1)) ? -2.0:-1.0,
colcount,rowcount,colgap_pixels,level);
Expand Down Expand Up @@ -978,6 +1009,8 @@ lec++;
pageregion[(*npr)]=column[1];
(*npr)=(*npr)+1;
colheight = breakinfo->textrow[ibottom].r2-region->r1+1;
willus_mem_free((double **)&pixel_count_array,funcname);
willus_dmem_free(5,(double **)&rowmin,funcname);
breakinfo_free(101,breakinfo);
/*
printf("Returning %d divider column = %d - %d\n",region->r2-region->r1+1,newregion->c1,newregion->c2);
Expand Down
Loading

0 comments on commit 90ce6b4

Please sign in to comment.