diff options
-rw-r--r-- | man/feh.pre | 20 | ||||
-rw-r--r-- | src/index.c | 187 | ||||
-rw-r--r-- | src/index.h | 2 | ||||
-rw-r--r-- | src/thumbnail.c | 104 |
4 files changed, 116 insertions, 197 deletions
diff --git a/man/feh.pre b/man/feh.pre index 9922ea5..decb5f4 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -260,7 +260,7 @@ Note: This option needs to load all images to calculate the dimensions of the window, so when using it with many files it will ake a while before a .Nm window is visible. Use -.Ar --preload +.Cm --preload to get a progress bar. . .It Cm -F , --fullscreen @@ -319,7 +319,7 @@ needs to load all images to calculate the dimensions of its own window. So when using them with many files, it will take a while before a .Nm window becomes visible. Use -.Ar --preload +.Cm --preload to get a progress bar. . .It Cm --info Ar commandline @@ -585,16 +585,22 @@ This will prevent any empty space in the final montage. . .It Cm -H , --limit-height Ar pixels . -Limit the height of the montage. These options can be used together to define -the image size exactly, or separately. If only one is specified, the other is -calculated from the number of files specified and the size of the thumbnails. -The default is to limit width to 800 pixels and calculate the height as -necessary. +Limit the height of the montage, defaults to 800 pixels. . .It Cm -W , --limit-width Ar pixels . Limit the width of the montage. . +.Pp +. +If both +.Cm --limit-width No and Cm --limit-height +are specified, the montage will be exactly +.Ar width +pixels wide and up to +.Ar height +pixels high. +. .It Cm -o , --output Ar file . Save the created montage to diff --git a/src/index.c b/src/index.c index d9e068a..ba95642 100644 --- a/src/index.c +++ b/src/index.c @@ -133,116 +133,28 @@ void init_index_mode(void) info in the selected font, work out how much space we need, and calculate the size of the image we will require */ - if (opt.limit_w && opt.limit_h) { - int rec_h = 0; - + if (opt.limit_w) { w = opt.limit_w; - h = opt.limit_h; - - /* Work out if this is big enough, and give a warning if not */ - - /* Pretend we are limiting width by that specified, loop through, and - see it we fit in the height specified. If not, continue the loop, - and recommend the final value instead. Carry on and make the index - anyway. */ - - for (l = filelist; l; l = l->next) { - file = FEH_FILE(l->data); - text_area_w = opt.thumb_w; - if (opt.index_info) { - get_index_string_dim(file, fn, &fw, &fh); - if (fw > text_area_w) - text_area_w = fw; - if (fh > text_area_h) { - text_area_h = fh + 5; - tot_thumb_h = opt.thumb_h + text_area_h; - } - } - if (text_area_w > opt.thumb_w) - text_area_w += 5; - - if ((x > w - text_area_w)) { - x = 0; - y += tot_thumb_h; - } - x += text_area_w; - } - rec_h = y + tot_thumb_h; - - if (h < rec_h) { - weprintf( - "The image size you specified (%d by %d) is not large\n" - "enough to hold all the thumnails you specified (%d). To fit all\n" - "the thumnails, either decrease their size, choose a smaller font,\n" - "or use a larger image (may I recommend %d by %d?)", - opt.limit_w, opt.limit_h, filelist_len, opt.limit_w, rec_h); + index_calculate_height(fn, w, &h, &tot_thumb_h); + + if (opt.limit_h) { + if (h > opt.limit_h) + weprintf( + "The image size you specified (%dx%d) is not large\n" + "enough to hold all %d thumbnails. To fit all the thumbnails,\n" + "either decrease their size, choos e asmaller font,\n" + "or use a larger image (like %dx%d)", + opt.limit_w, opt.limit_h, filelist_len, w, h); + h = opt.limit_h; } } else if (opt.limit_h) { vertical = 1; h = opt.limit_h; - /* calc w */ - for (l = filelist; l; l = l->next) { - file = FEH_FILE(l->data); - text_area_w = opt.thumb_w; - /* Calc width of text */ - if (opt.index_info) { - get_index_string_dim(file, fn, &fw, &fh); - if (fw > text_area_w) - text_area_w = fw; - if (fh > text_area_h) { - text_area_h = fh + 5; - tot_thumb_h = opt.thumb_h + text_area_h; - } - } - if (text_area_w > opt.thumb_w) - text_area_w += 5; - - if (text_area_w > max_column_w) - max_column_w = text_area_w; - - if ((y > h - tot_thumb_h)) { - y = 0; - x += max_column_w; - max_column_w = 0; - } - - y += tot_thumb_h; - } - w = x + text_area_w; - max_column_w = 0; - } else if (opt.limit_w) { - w = opt.limit_w; - /* calc h */ - - for (l = filelist; l; l = l->next) { - file = FEH_FILE(l->data); - text_area_w = opt.thumb_w; - if (opt.index_info) { - get_index_string_dim(file, fn, &fw, &fh); - if (fw > text_area_w) - text_area_w = fw; - if (fh > text_area_h) { - text_area_h = fh + 5; - tot_thumb_h = opt.thumb_h + text_area_h; - } - } - - if (text_area_w > opt.thumb_w) - text_area_w += 5; - - if ((x > w - text_area_w)) { - x = 0; - y += tot_thumb_h; - } - x += text_area_w; - } - h = y + tot_thumb_h; + index_calculate_width(fn, &w, h, &tot_thumb_h); } - x = y = 0; - index_image_width = w; index_image_height = h + title_area_h; im_main = imlib_create_image(index_image_width, index_image_height); @@ -445,6 +357,79 @@ void init_index_mode(void) return; } +void index_calculate_height(Imlib_Font fn, int w, int *h, int *tot_thumb_h) +{ + gib_list *l; + feh_file *file = NULL; + int x = 0, y = 0; + int fw = 0, fh = 0; + int text_area_w = 0, text_area_h = 0; + + for (l = filelist; l; l = l->next) { + file = FEH_FILE(l->data); + text_area_w = opt.thumb_w; + if (opt.index_info) { + get_index_string_dim(file, fn, &fw, &fh); + if (fw > text_area_w) + text_area_w = fw; + if (fh > text_area_h) { + text_area_h = fh + 5; + *tot_thumb_h = opt.thumb_h + text_area_h; + } + } + + if (text_area_w > opt.thumb_w) + text_area_w += 5; + + if ((x > w - text_area_w)) { + x = 0; + y += *tot_thumb_h; + } + + x += text_area_w; + } + *h = y + *tot_thumb_h; +} + +void index_calculate_width(Imlib_Font fn, int *w, int h, int *tot_thumb_h) +{ + gib_list *l; + feh_file *file = NULL; + int x = 0, y = 0; + int fw = 0, fh = 0; + int text_area_w = 0, text_area_h = 0; + int max_column_w = 0; + + for (l = filelist; l; l = l->next) { + file = FEH_FILE(l->data); + text_area_w = opt.thumb_w; + /* Calc width of text */ + if (opt.index_info) { + get_index_string_dim(file, fn, &fw, &fh); + if (fw > text_area_w) + text_area_w = fw; + if (fh > text_area_h) { + text_area_h = fh + 5; + *tot_thumb_h = opt.thumb_h + text_area_h; + } + } + if (text_area_w > opt.thumb_w) + text_area_w += 5; + + if (text_area_w > max_column_w) + max_column_w = text_area_w; + + if ((y > h - *tot_thumb_h)) { + y = 0; + x += max_column_w; + max_column_w = 0; + } + + y += *tot_thumb_h; + } + *w = x + text_area_w; +} + void get_index_string_dim(feh_file *file, Imlib_Font fn, int *fw, int *fh) { int line_w, line_h; diff --git a/src/index.h b/src/index.h index 288b0ee..08ab337 100644 --- a/src/index.h +++ b/src/index.h @@ -29,5 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. char *create_index_string(feh_file *file); char *create_index_title_string(int num, int w, int h); void get_index_string_dim(feh_file *file, Imlib_Font fn, int *w, int *h); +void index_calculate_height(Imlib_Font fn, int w, int *h, int *tot_thumb_w); +void index_calculate_width(Imlib_Font fn, int *w, int h, int *tot_thumb_h); #endif diff --git a/src/thumbnail.c b/src/thumbnail.c index 42e2a82..4e32dfa 100644 --- a/src/thumbnail.c +++ b/src/thumbnail.c @@ -522,9 +522,9 @@ void feh_thumbnail_calculate_geometry(void) if (opt.verbose) fputs(PACKAGE " - No size restriction specified for index.\n" - " Using defaults (width limited to 640)\n", + " Using defaults (width limited to 800)\n", stdout); - opt.limit_w = 640; + opt.limit_w = 800; } } @@ -532,100 +532,26 @@ void feh_thumbnail_calculate_geometry(void) info in the selected font, work out how much space we need, and calculate the size of the image we will require */ - if (opt.limit_w && opt.limit_h) { - int rec_h = 0; - + if (opt.limit_w) { td.w = opt.limit_w; - td.h = opt.limit_h; - - /* Work out if this is big enough, and give a warning if not */ - /* Pretend we are limiting width by that specified, loop through, and - see it we fit in the height specified. If not, continue the loop, - and recommend the final value instead. Carry on and make the index - anyway. */ - - for (l = filelist; l; l = l->next) { - file = FEH_FILE(l->data); - td.text_area_w = opt.thumb_w; - if (opt.index_info) { - get_index_string_dim(file, td.font_main, &fw, &fh); - if (fw > td.text_area_w) - td.text_area_w = fw; - } - if (td.text_area_w > opt.thumb_w) - td.text_area_w += 5; - - if ((x > td.w - td.text_area_w)) { - x = 0; - y += td.thumb_tot_h; - } - - x += td.text_area_w; - } - rec_h = y + td.thumb_tot_h; - - if (td.h < rec_h) { - weprintf - ("The image size you specified (%d by %d) is not large\n" - "enough to hold all the thumnails you specified (%d). To fit all\n" - "the thumnails, either decrease their size, choose a smaller font,\n" - "or use a larger image (may I recommend %d by %d?)", - opt.limit_w, opt.limit_h, filelist_len, opt.limit_w, rec_h); + index_calculate_height(td.font_main, td.w, &td.h, &td.thumb_tot_h); + + if (opt.limit_h) { + if (td.h> opt.limit_h) + weprintf( + "The image size you specified (%dx%d) is not large\n" + "enough to hold all %d thumbnails. To fit all\n" + "the thumnails, either decrease their size, choose a smaller font,\n" + "or use a larger image (like %dx%d)", + opt.limit_w, opt.limit_h, filelist_len, opt.limit_w, td.h); + td.h = opt.limit_h; } } else if (opt.limit_h) { td.vertical = 1; td.h = opt.limit_h; - /* calc w */ - for (l = filelist; l; l = l->next) { - file = FEH_FILE(l->data); - td.text_area_w = opt.thumb_w; - /* Calc width of text */ - if (opt.index_info) { - get_index_string_dim(file, td.font_main, &fw, &fh); - if (fw > td.text_area_w) - td.text_area_w = fw; - } - if (td.text_area_w > opt.thumb_w) - td.text_area_w += 5; - - if (td.text_area_w > td.max_column_w) - td.max_column_w = td.text_area_w; - - if ((y > td.h - td.thumb_tot_h)) { - y = 0; - x += td.max_column_w; - td.max_column_w = 0; - } - - y += td.thumb_tot_h; - } - td.w = x + td.text_area_w; - td.max_column_w = 0; - } else if (opt.limit_w) { - td.w = opt.limit_w; - /* calc h */ - - for (l = filelist; l; l = l->next) { - file = FEH_FILE(l->data); - td.text_area_w = opt.thumb_w; - if (opt.index_info) { - get_index_string_dim(file, td.font_main, &fw, &fh); - if (fw > td.text_area_w) - td.text_area_w = fw; - } - if (td.text_area_w > opt.thumb_w) - td.text_area_w += 5; - - if ((x > td.w - td.text_area_w)) { - x = 0; - y += td.thumb_tot_h; - } - - x += td.text_area_w; - } - td.h = y + td.thumb_tot_h; + index_calculate_width(td.font_main, &td.w, td.h, &td.thumb_tot_h); } } |