Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow image formats to be disabled from dillorc #316

Merged
merged 2 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dillo-3.2.0 [Not released yet]
- Improve image resize logic to always try to preserve the aspect ratio.
- Reload current page on SIGUSR1 signal
- Print library versions and enabled features with dillo -v.
- Allow image formats to be ignored with the "ignore_image_formats" option.
Patches: Rodrigo Arias Mallo
+- Add primitive support for SVG using the nanosvg.h library.
- Add support for ch, rem, vw, vh, vmin and vmax CSS units.
Expand Down
6 changes: 6 additions & 0 deletions dillorc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
# menu.)
#load_images=YES

# A space separated list of image formats that will be ignored (not viewed).
# An option to download the image will be offered instead.
# Available formats: gif, png, webp, jpeg and svg.
# ignore_image_formats="webp svg"
#ignore_image_formats=""

# Change this if you want background images to be loaded initially.
# (While browsing, this can be changed from the tools/settings menu.)
#load_background_images=NO
Expand Down
28 changes: 26 additions & 2 deletions src/dicache.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@
#include "dsvg.h"

enum {
DIC_Gif,
DIC_Gif = 0,
DIC_Png,
DIC_Webp,
DIC_Jpeg,
DIC_Svg
DIC_Svg,
DIC_MAX
};

static const char *format_name[DIC_MAX] = {
[DIC_Gif] = "gif",
[DIC_Png] = "png",
[DIC_Webp] = "webp",
[DIC_Jpeg] = "jpeg",
[DIC_Svg] = "svg"
};

static int disabled_formats[DIC_MAX] = { 0 };

/**
* List of DICacheEntry. May hold several versions of the same image,
Expand Down Expand Up @@ -67,6 +77,15 @@ void a_Dicache_init(void)
{
CachedIMGs = dList_new(256);
dicache_size_total = 0;

if (prefs.ignore_image_formats) {
for (int i = 0; i < DIC_MAX; i++) {
if (dStriAsciiStr(prefs.ignore_image_formats, format_name[i])) {
disabled_formats[i] = 1;
_MSG("Image format %s disabled\n", format_name[i]);
}
}
}
}

/**
Expand Down Expand Up @@ -372,6 +391,11 @@ static void *Dicache_image(int ImgType, const char *MimeType, void *Ptr,

dReturn_val_if_fail(MimeType && Ptr, NULL);

if (ImgType >= 0 && ImgType < DIC_MAX && disabled_formats[ImgType]) {
_MSG("Ignoring image format %s\n", format_name[ImgType]);
return NULL;
}

if (!web->Image) {
web->Image =
a_Image_new_with_dw(web->bw->render_layout, NULL, web->bgColor, 0);
Expand Down
1 change: 1 addition & 0 deletions src/prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void a_Prefs_init(void)
prefs.adjust_min_width = TRUE;
prefs.adjust_table_min_width = TRUE;
prefs.load_images=TRUE;
prefs.ignore_image_formats = NULL;
prefs.load_background_images=FALSE;
prefs.load_stylesheets=TRUE;
prefs.middle_click_drags_page = TRUE;
Expand Down
1 change: 1 addition & 0 deletions src/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ typedef struct {
bool_t show_quit_dialog;
bool_t fullwindow_start;
bool_t load_images;
char *ignore_image_formats;
bool_t load_background_images;
bool_t load_stylesheets;
bool_t parse_embedded_css;
Expand Down
1 change: 1 addition & 0 deletions src/prefsparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ void PrefsParser::parse(FILE *fp)
{ "adjust_min_width", &prefs.adjust_min_width, PREFS_BOOL, 0 },
{ "adjust_table_min_width", &prefs.adjust_table_min_width, PREFS_BOOL, 0 },
{ "load_images", &prefs.load_images, PREFS_BOOL, 0 },
{ "ignore_image_formats", &prefs.ignore_image_formats, PREFS_STRING, 0 },
{ "load_background_images", &prefs.load_background_images, PREFS_BOOL, 0 },
{ "load_stylesheets", &prefs.load_stylesheets, PREFS_BOOL, 0 },
{ "middle_click_drags_page", &prefs.middle_click_drags_page,
Expand Down
4 changes: 4 additions & 0 deletions src/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ static void print_libs()

/* FLTK only offers a single number */
{
#if FL_MAJOR_VERSION == 1 && FL_MINOR_VERSION == 3 && FL_PATCH_VERSION <= 3
int fltkver = Fl::version();
#else
int fltkver = Fl::api_version();
#endif
int fltk_maj = fltkver / 10000;
int fltk_min = (fltkver / 100) % 100;
int fltk_pat = fltkver % 100;
Expand Down
Loading