From ad4deb26be690c6905e9a535e06958edef6919c8 Mon Sep 17 00:00:00 2001 From: chrox Date: Fri, 26 Oct 2012 17:16:31 +0800 Subject: [PATCH] add page margin and text wrap and contrast option in koptconfig Conflicts: koptconfig.lua koptreader.lua --- djvu.c | 8 +++-- k2pdfopt.c | 44 +++++++++++++------------- k2pdfopt.h | 9 +++--- koptconfig.lua | 85 +++++++++++++++++++++++++++++++++++++++----------- pdf.c | 16 +++++----- 5 files changed, 109 insertions(+), 53 deletions(-) diff --git a/djvu.c b/djvu.c index 18b78737d..ceff6e693 100644 --- a/djvu.c +++ b/djvu.c @@ -477,9 +477,13 @@ static int reflowPage(lua_State *L) { ddjvu_render_mode_t mode = (int) luaL_checkint(L, 3); int width = luaL_checkint(L, 4); // framebuffer size int height = luaL_checkint(L, 5); - double line_spacing = luaL_checknumber(L, 6); - double word_spacing = luaL_checknumber(L, 7); + double page_margin = luaL_checknumber(L, 6); + double line_spacing = luaL_checknumber(L, 7); + double word_spacing = luaL_checknumber(L, 8); + int text_wrap = luaL_checkint(L, 9); + double contrast = luaL_checknumber(L, 10); + k2pdfopt_set_params(width, height, page_margin, line_spacing, word_spacing, text_wrap, contrast); k2pdfopt_djvu_reflow(page->page_ref, page->doc->context, mode, page->doc->pixelformat, dc->zoom, \ width, height, line_spacing, word_spacing); k2pdfopt_rfbmp_size(&width, &height); diff --git a/k2pdfopt.c b/k2pdfopt.c index 889b92766..58de4b64c 100644 --- a/k2pdfopt.c +++ b/k2pdfopt.c @@ -218,7 +218,7 @@ static double dst_min_figure_height_in = 0.75; static int dst_fulljustify = -1; // 0 = no, 1 = yes static int dst_color = 0; static int dst_landscape = 0; -static double dst_mar = 0.06; +static double dst_mar = 0.2; static double dst_martop = -1.0; static double dst_marbot = -1.0; static double dst_marleft = -1.0; @@ -410,6 +410,7 @@ static int max_page_width_pix = 3000; static int max_page_height_pix = 4000; static double shrink_factor = 0.9; static double zoom_value = 1.0; +static double gamma_correction = 1.0; static void k2pdfopt_reflow_bmp(MASTERINFO *masterinfo, WILLUSBITMAP *src) { PAGEINFO _pageinfo, *pageinfo; @@ -471,9 +472,25 @@ static void k2pdfopt_reflow_bmp(MASTERINFO *masterinfo, WILLUSBITMAP *src) { bmp_free(srcgrey); } +void k2pdfopt_set_params(int bb_width, int bb_height, double page_margin, \ + double line_space, double word_space, \ + int wrapping, double contrast) { + dst_userwidth = bb_width; // dst_width is adjusted in adjust_params_init + dst_userheight = bb_height; + vertical_line_spacing = line_space; + word_spacing = word_space; + text_wrap = wrapping; + gamma_correction = contrast; // contrast is only used by k2pdfopt_mupdf_reflow + + dst_mar = page_margin; + dst_martop = -1.0; + dst_marbot = -1.0; + dst_marleft = -1.0; + dst_marright = -1.0; +} + void k2pdfopt_mupdf_reflow(fz_document *doc, fz_page *page, fz_context *ctx, \ - double zoom, double gamma, double rot_deg, \ - int bb_width, int bb_height, double line_space, double word_space) { + double zoom, double gamma, double rot_deg) { fz_device *dev; fz_pixmap *pix; fz_rect bounds,bounds2; @@ -481,14 +498,6 @@ void k2pdfopt_mupdf_reflow(fz_document *doc, fz_page *page, fz_context *ctx, \ fz_bbox bbox; WILLUSBITMAP _src, *src; - dst_userwidth = bb_width; // dst_width is adjusted in adjust_params_init - dst_userheight = bb_height; - vertical_line_spacing = line_space; - word_spacing = word_space; - - printf("k2pdfopt_mupdf_reflow width:%d height:%d, line space:%.2f, word space:%.2f\n", \ - bb_width,bb_height,vertical_line_spacing,word_spacing); - double dpp; double dpi = 250*zoom; do { @@ -527,8 +536,8 @@ void k2pdfopt_mupdf_reflow(fz_document *doc, fz_page *page, fz_context *ctx, \ fz_run_page(doc, page, dev, ctm, NULL); fz_free_device(dev); - if(gamma >= 0.0) { - fz_gamma_pixmap(ctx, pix, gamma); + if(gamma_correction >= 0.0) { + fz_gamma_pixmap(ctx, pix, gamma_correction); } src = &_src; @@ -542,18 +551,11 @@ void k2pdfopt_mupdf_reflow(fz_document *doc, fz_page *page, fz_context *ctx, \ } void k2pdfopt_djvu_reflow(ddjvu_page_t *page, ddjvu_context_t *ctx, \ - ddjvu_render_mode_t mode, ddjvu_format_t *fmt, double zoom, \ - int bb_width, int bb_height, double line_space, double word_space) { + ddjvu_render_mode_t mode, ddjvu_format_t *fmt, double zoom) { WILLUSBITMAP _src, *src; ddjvu_rect_t prect; ddjvu_rect_t rrect; int i, iw, ih, idpi, status; - - dst_userwidth = bb_width; // dst_width is adjusted in adjust_params_init - dst_userheight = bb_height; - vertical_line_spacing = line_space; - word_spacing = word_space; - double dpi = 250*zoom; while (!ddjvu_page_decoding_done(page)) diff --git a/k2pdfopt.h b/k2pdfopt.h index 51743b3c5..ae9bb764f 100644 --- a/k2pdfopt.h +++ b/k2pdfopt.h @@ -26,12 +26,13 @@ #include #include +void k2pdfopt_set_params(int bb_width, int bb_height, double page_margin, \ + double line_space, double word_space, \ + int wrapping, double contrast); void k2pdfopt_mupdf_reflow(fz_document *doc, fz_page *page, fz_context *ctx, \ - double zoom, double gamma, double rot_deg, int bb_width, int bb_height, \ - double line_spacing, double word_spacing); + double zoom, double gamma, double rot_deg); void k2pdfopt_djvu_reflow(ddjvu_page_t *page, ddjvu_context_t *ctx, \ - ddjvu_render_mode_t mode, ddjvu_format_t *fmt, double zoom, int bb_width, int bb_height, \ - double line_spacing, double word_spacing); + ddjvu_render_mode_t mode, ddjvu_format_t *fmt, double zoom); void k2pdfopt_rfbmp_size(int *width, int *height); void k2pdfopt_rfbmp_ptr(unsigned char** bmp_ptr_ptr); void k2pdfopt_rfbmp_zoom(double *zoom); diff --git a/koptconfig.lua b/koptconfig.lua index 64f02c605..342f5308f 100644 --- a/koptconfig.lua +++ b/koptconfig.lua @@ -3,6 +3,14 @@ require "keys" require "settings" KOPTOptions = { + { + name="page_margin", + option_text="Page Margin", + items_text={"small","medium","large"}, + current_item=2, + text_dirty=true, + marker_dirty={true, true, true}, + value={0.02, 0.06, 0.10}}, { name="line_spacing", option_text="Line Spacing", @@ -10,7 +18,7 @@ KOPTOptions = { current_item=2, text_dirty=true, marker_dirty={true, true, true}, - space={1.0, 1.2, 1.4}}, + value={1.0, 1.2, 1.4}}, { name="word_spacing", option_text="Word Spacing", @@ -18,19 +26,44 @@ KOPTOptions = { current_item=2, text_dirty=true, marker_dirty={true, true, true}, - space={0.2, 0.375, 0.5}}, + value={0.2, 0.375, 0.5}}, + { + name="text_wrap", + option_text="Text Wrap", + items_text={"fitting","reflowing"}, + current_item=2, + text_dirty=true, + marker_dirty={true, true}, + value={0, 1}}, + { + name="contrast", + option_text="Contrast", + items_text={"lightest","lighter","default","darker","darkest"}, + current_item=3, + text_dirty=true, + marker_dirty={true, true, true, true, true}, + value={0.2, 0.4, 1.0, 1.8, 2.6}}, } KOPTConfig = { -- UI constants - HEIGHT = 200, -- height + HEIGHT = 220, -- height MARGIN_BOTTOM = 20, -- window bottom margin +<<<<<<< HEAD MARGIN_HORISONTAL = 75, -- window horisontal margin OPTION_PADDING_T = 50, -- options top padding OPTION_PADDING_H = 50, -- options horisontal padding OPTION_SPACING_V = 35, -- options vertical spacing VALUE_PADDING_H = 150, -- values horisontal padding VALUE_SPACING_H = 10, -- values horisontal spacing +======= + MARGIN_HORISONTAL = 50, -- window horisontal margin + NAME_PADDING_T = 50, -- option name top padding + OPTION_SPACING_V = 35, -- options vertical spacing + NAME_ALIGN_RIGHT = 0.3, -- align name right to the window width + ITEM_ALIGN_LEFT = 0.35, -- align item left to the window width + ITEM_SPACING_H = 10, -- items horisontal spacing +>>>>>>> f4a2b5f... add page margin and text wrap and contrast option in koptconfig OPT_NAME_FONT_SIZE = 20, -- option name font size OPT_VALUE_FONT_SIZE = 16, -- option value font size @@ -42,13 +75,6 @@ KOPTConfig = { page_dirty = false, } -configurable = { - font_size = 1.0, - page_margin = 0.06, - line_spacing = 1.2, - word_spacing = 0.375, -} - function KOPTConfig:drawBox(xpos, ypos, width, hight, bgcolor, bdcolor) -- draw dialog border local r = 6 -- round corners @@ -105,9 +131,34 @@ function KOPTConfig:drawOptions(xpos, ypos, name_font, value_font, refresh) end end +<<<<<<< HEAD function KOPTConfig:config(callback, reader) local kopt_callback = callback local koptreader = reader +======= +function KOPTConfig:makeDefault() + for i=1,#KOPTOptions do + KOPTOptions[i].text_dirty = true + for j=1,#KOPTOptions[i].items_text do + KOPTOptions[i].marker_dirty[j] = true + end + end +end + +function KOPTConfig:reconfigure(configurable) + for i=1,#KOPTOptions do + option = KOPTOptions[i].name + configurable[option] = KOPTOptions[i].value[KOPTOptions[i].current_item] + end +end + +function KOPTConfig:config(callback, reader, configurable) + local kopt_callback = callback + local koptreader = reader + local configurable = configurable + + self:makeDefault() +>>>>>>> f4a2b5f... add page margin and text wrap and contrast option in koptconfig self:addAllCommands() local name_font = Font:getFace("tfont", self.OPT_NAME_FONT_SIZE) @@ -124,11 +175,11 @@ function KOPTConfig:config(callback, reader) local ev, keydef, command, ret_code while true do - configurable.line_spacing = KOPTOptions[1].space[KOPTOptions[1].current_item] - configurable.word_spacing = KOPTOptions[2].space[KOPTOptions[2].current_item] - --Debug("Line spacing:", configurable.line_spacing, "Word spacing:", configurable.word_spacing) + + self:reconfigure(configurable) + if self.page_dirty then - kopt_callback(koptreader, configurable) + kopt_callback(koptreader) self:drawBox(topleft_x, topleft_y, width, height, 3, 15) self:drawOptions(topleft_x, topleft_y, name_font, value_font, true) fb:refresh(1, topleft_x, topleft_y, width, height) @@ -150,11 +201,7 @@ function KOPTConfig:config(callback, reader) end if ret_code == "break" then ret_code = nil - if self.final_choice then - return self.readers[self.final_choice] - else - return nil - end + return nil end end -- if end -- while diff --git a/pdf.c b/pdf.c index 579dc8a02..7c38a2af0 100644 --- a/pdf.c +++ b/pdf.c @@ -515,14 +515,16 @@ static int reflowPage(lua_State *L) { PdfPage *page = (PdfPage*) luaL_checkudata(L, 1, "pdfpage"); DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); - int width = (int) luaL_checkint(L, 4); // framebuffer size - int height = (int) luaL_checkint(L, 5); - double line_spacing = luaL_checknumber(L, 6); - double word_spacing = luaL_checknumber(L, 7); + int width = luaL_checkint(L, 4); // framebuffer size + int height = luaL_checkint(L, 5); + double page_margin = luaL_checknumber(L, 6); + double line_spacing = luaL_checknumber(L, 7); + double word_spacing = luaL_checknumber(L, 8); + int text_wrap = luaL_checkint(L, 9); + double contrast = luaL_checknumber(L, 10); - //printf("reflowPage width:%d height:%d\n", width, height); - - k2pdfopt_mupdf_reflow(page->doc->xref, page->page, page->doc->context, dc->zoom, dc->gamma, 0.0, width, height, line_spacing, word_spacing); + k2pdfopt_set_params(width, height, page_margin, line_spacing, word_spacing, text_wrap, contrast); + k2pdfopt_mupdf_reflow(page->doc->xref, page->page, page->doc->context, dc->zoom, dc->gamma, 0.0); k2pdfopt_rfbmp_size(&width, &height); k2pdfopt_rfbmp_zoom(&dc->zoom);