Skip to content

Commit

Permalink
update k2pdfopt to version 2.02
Browse files Browse the repository at this point in the history
  • Loading branch information
chrox committed Sep 17, 2013
1 parent c26527f commit 7518581
Show file tree
Hide file tree
Showing 25 changed files with 590 additions and 501 deletions.
12 changes: 6 additions & 6 deletions k2pdfopt.c
Expand Up @@ -187,11 +187,12 @@ int main(int argc,char *argv[])
static void k2pdfopt_launch_gui(K2PDFOPT_CONVERSION *k2conv,STRBUF *env,STRBUF *cmdline)

{
/*
printf("\n\nNEED TO FIX IF STATEMENT IN k2pdfopt_launch_gui()...\n\n");
#if (WILLUSDEBUGX & 0x4000)
printf("\n\nNEED TO TURN OFF WILLUSDEBUGX FOR FINAL COMPILE...\n\n");
if (0)
*/
#else
if (k2conv->k2settings.gui!=2 && (!win_has_own_window() || !k2conv->k2settings.guimin))
#endif
{
char exename[512];
char *buf;
Expand Down Expand Up @@ -225,10 +226,9 @@ if (0)
HINSTANCE hinst;
/* Free console and launch the GUI window */
hinst=GetModuleHandle(NULL);
/*
printf("\n\nNEED TO FREE CONSOLE!\n\n");
*/
#if (!(WILLUSDEBUGX & 0x4000))
FreeConsole();
#endif
k2gui_main(k2conv,hinst,NULL,env,cmdline);
}
}
Expand Down
26 changes: 20 additions & 6 deletions k2pdfoptlib/bmpregion.c
Expand Up @@ -696,20 +696,34 @@ fprintf(out,"lcheight=%d\n",region->bbox.lcheight);
textrow=&region->bbox;
textrow->hyphen.ch = -1;
textrow->hyphen.c2 = -1;
// it seems that textrows.n is always less than 1 and it will never detect hyphen
//if (region->textrows.n<1)
//return;
if (textrow->type == REGION_TYPE_FIGURE)
return;
// detect hyphen when hyphen_detect is not 0
/*
** Deleted checks for number of text rows and whether region is a figure.
** (Since only called from wrapbmp, region must be text.)
*/
/* Was incorrect before v2.02--had this: if (hyphen_detect) */
if (!hyphen_detect)
{
#if (WILLUSDEBUGX & 16)
printf(" hyphen_detect is off.\n");
#endif
return;
}
if (textrow->c2<0 || textrow->c1<0 || textrow->r1<0 || textrow->r2<0
|| textrow->rowbase<0 || textrow->capheight<0 || textrow->lcheight<0)
{
#if (WILLUSDEBUGX & 16)
printf(" bad c1,c2,r1,r2,rowbase.\n");
#endif
return;
}
width=textrow->c2-textrow->c1+1;
if (width<2)
{
#if (WILLUSDEBUGX & 16)
printf(" width < 2.\n");
#endif
return;
}
willus_dmem_alloc_warn(27,(void **)&r0,sizeof(int)*4*width,funcname,10);
r1=&r0[width];
r2=&r1[width];
Expand Down
58 changes: 0 additions & 58 deletions k2pdfoptlib/bmpregions.c

This file was deleted.

3 changes: 2 additions & 1 deletion k2pdfoptlib/devprofile.c
Expand Up @@ -25,7 +25,8 @@ static DEVPROFILE devprof[7] =
{
{"Kindle 1-5","k2",560,735,167,0,1,{0,0,3,4}},
{"Kindle DX","dx",800,1180,167,0,1,{0,0,0,0}},
{"Kindle Paperwhite","kpw",758,1024,212,0,1,{0,0,3,4}},
/* v2.02: Changed kpw to 658 x 889 based on e-mail feedback, 9-15-13 */
{"Kindle Paperwhite","kpw",658,889,212,0,1,{0,0,3,4}},
{"Nook Simple Touch","nookst",552,725,167,0,1,{0,0,0,0}},
{"Kobo Touch","kbt",600,730,167,0,1,{0,0,3,4}},
{"Kobo Glo","kbg",758,942,213,0,1,{0,0,3,4}},
Expand Down
66 changes: 59 additions & 7 deletions k2pdfoptlib/k2gui.c
Expand Up @@ -37,6 +37,7 @@ static void k2gui_winposition_save(void);
static void k2gui_cmdline_to_settings(K2PDFOPT_SETTINGS *k2settings,STRBUF *cmdline);
*/
static void k2gui_init(void);
static void k2gui_close(void);
static void k2gui_background_bitmap_fill(void);
static void bmp_gradient_fill(WILLUSBITMAP *bmp);
/*
Expand Down Expand Up @@ -112,6 +113,7 @@ printf("@k2gui_main, k2conv=%p, k2settings=%p\n",k2conv0,&k2conv0->k2settings);
status=k2gui_osdep_window_proc_messages(&k2gui->mainwin,NULL,NULL);
k2gui->active=0;
strbuf_free(&k2gui->cmdxtra);
k2gui_close();
willusgui_close();
return(status);
}
Expand Down Expand Up @@ -348,6 +350,7 @@ static void k2gui_init(void)

k2gui->mainwin.handle=NULL;
willusgui_font_init(&k2gui->font);
k2gui->preview_processing=0;
k2gui->started=0;
k2gui->active=0;
/*
Expand All @@ -362,11 +365,24 @@ static void k2gui_init(void)
for (i=0;i<8;i++)
k2gui->prevthread[i]=NULL;
bmp_init(&k2gui->pbitmap);
bmp_init(&k2gui->pworking);
k2gui_preview_bitmap_message(&k2gui->pworking,728,840,0.1,"WORKING...");
bmp_init(&k2gui->pviewbitmap);
k2gui_preview_bitmap_message(&k2gui->pviewbitmap,728,840,0.1,"PREVIEW\n\nWINDOW");
k2gui->pbitmap.width=k2gui->pbitmap.height=0;
k2gui->pbitmap.bpp=24;
}


static void k2gui_close(void)

{
bmp_free(&k2gui->pviewbitmap);
bmp_free(&k2gui->pworking);
bmp_free(&k2gui->pbitmap);
}


int k2gui_active(void)

{
Expand Down Expand Up @@ -900,19 +916,27 @@ printf("settings->src_trim=%d\n",k2settings->src_trim);
k2gui_cbox_do_conversion(k2gui);
k2gui_cbox_freelist();
/* Clear file list if everything converted okay. */
/*
** v2.02--don't clear the file list anymore in case user
** wants to try some different cmd-line options for
** the conversion.
*/
/*
if (k2gui_cbox_conversion_successful())
k2pdfopt_files_clear(&k2gui->k2conv->k2files);
*/
filebox_populate();
flcontrol=k2gui_control_by_name("file list");
willusgui_control_close(flcontrol);
k2gui_update_controls();
}
}
else if (!stricmp(control->name,"pre&view"))
else if (!stricmp(control->name,"pre&view") || !stricmp(control->name,"Cancel"))
{
if (k2gui->k2conv->k2files.n<=0)
if (!k2gui->preview_processing && k2gui->k2conv->k2files.n<=0)
k2gui_messagebox(0,"Convert","No files selected for conversion.");
k2gui_preview_start();
k2gui_update_controls();
}
else if (!stricmp(control->name,"restore"))
{
Expand Down Expand Up @@ -1953,9 +1977,12 @@ printf("settings->s='%s'\n",settings->s);
control->parent=&k2gui->mainwin;
strcpy(control->label,"");
/* Before creating, need bmp assigned. */
if (k2gui->pbitmap.width==0)
k2gui_preview_bitmap_message(&k2gui->pbitmap,728,840,0.1,"PREVIEW\n\nWINDOW");
control->obmp=&k2gui->pbitmap;
if (k2gui->preview_processing)
control->obmp=&k2gui->pworking;
else if (k2gui->pbitmap.width==0)
control->obmp=&k2gui->pviewbitmap;
else
control->obmp=&k2gui->pbitmap;
/*
printf("Calling control_create() for previewwin.\n");
*/
Expand Down Expand Up @@ -2032,11 +2059,11 @@ printf(" control->handle=%p\n",control->handle);
control->font.size=k2gui->font.size;
willusgui_font_get(&control->font);
control->type=WILLUSGUICONTROL_TYPE_BUTTON;
control->color=0xffd0ff;
strcpy(control->name,"Pre&view");
control->label[0]='\0';
control->parent=&k2gui->mainwin;
}
control->color=k2gui->preview_processing?0x806080:0xffd0ff;
strcpy(control->name,k2gui->preview_processing?"Cancel":"Pre&view");
if (already_drawn)
willusgui_control_redraw(control,0);
else
Expand Down Expand Up @@ -2625,7 +2652,17 @@ static void k2gui_preview_start(void)

{
if (!k2gui_preview_done())
{
k2gui_preview_terminate();
k2gui->pbitmap.width=0;
k2gui->preview_processing=0;
willusgui_set_cursor(0);
k2gui_preview_refresh();
return;
}
k2gui->preview_processing=1;
willusgui_set_cursor(1);
k2gui_preview_refresh();
if (k2gui->k2conv->k2files.n<1)
{
k2gui_preview_fail(1);
Expand All @@ -2646,6 +2683,15 @@ static void k2gui_preview_start(void)
k2gui->prevthread[0]=NULL;
k2gui_preview_fail(3);
}
/*
** This small delay seems to prevent a weird bug where the preview
** occasionally fails, resulting in a fail with status=4, or a complete
** crash with some errors reported by the PNG library. I can't get
** seem to get the crash to occur with this delay. -- 4 Sep 2013, v2.01
*/
#if (defined(WIN32) || defined(WIN64))
win_sleep(100);
#endif
}


Expand Down Expand Up @@ -2732,7 +2778,11 @@ static void k2gui_preview_cleanup(int statuscode)
if (statuscode>0)
k2gui_preview_fail(statuscode);
else
{
k2gui->preview_processing=0;
willusgui_set_cursor(0);
k2gui_preview_refresh();
}
if (k2gui->prevthread[0]!=NULL)
{
willusgui_semaphore_release(k2gui->prevthread[0]);
Expand Down Expand Up @@ -2783,6 +2833,8 @@ static void k2gui_preview_fail(int statuscode)
statuscode=0;
sprintf(buf,"Preview failed.\n\n%s.",err[statuscode]);
k2gui_preview_bitmap_message(&k2gui->pbitmap,700,950,0.07,buf);
k2gui->preview_processing=0;
willusgui_set_cursor(0);
k2gui_preview_refresh();
}

Expand Down
13 changes: 11 additions & 2 deletions k2pdfoptlib/k2gui_cbox.c
Expand Up @@ -695,7 +695,7 @@ int k2gui_cbox_vprintf(FILE *f,char *fmt,va_list args)
static char *funcname="k2gui_cbox_vprintf";
char prbuf[1024];
char *buf;
int i,j,status;
int i,j,status,nlines;

if (k2gui_cbox==NULL || k2gui_cbox->control[0].handle==NULL || k2gui_cbox->ncontrols<1)
return(-1);
Expand Down Expand Up @@ -728,13 +728,22 @@ int k2gui_cbox_vprintf(FILE *f,char *fmt,va_list args)
}
buf[j]='\0';
strbuf_sprintf(&k2gui_cbox->buf,"%s",buf);
willusgui_control_set_text(&k2gui_cbox->control[0],k2gui_cbox->buf.s);
nlines=willusgui_control_nlines(&k2gui_cbox->control[0]);
willusgui_control_set_text(&k2gui_cbox->control[0],strbuf_lineno(&k2gui_cbox->buf,-nlines));
willusgui_control_scroll_to_bottom(&k2gui_cbox->control[0]);
willus_mem_free((double **)&buf,funcname);
return(status);
}


void k2gui_cbox_final_print(void)

{
willusgui_control_set_text(&k2gui_cbox->control[0],k2gui_cbox->buf.s);
willusgui_control_scroll_to_bottom(&k2gui_cbox->control[0]);
}


/* Clean up */
void k2gui_cbox_terminate_conversion(void)

Expand Down

0 comments on commit 7518581

Please sign in to comment.