From d03876e35e846d604801445285af08df775ec73c Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Fri, 22 Jul 2022 15:55:49 +0200 Subject: [PATCH] Enable disabling text functions To optionally reduce footprint. --- configure.ac | 11 +++++++++++ src/bin/imlib2_colorspace.c | 12 ++++++++++-- src/bin/imlib2_show.c | 18 ++++++++++++++++-- src/bin/imlib2_test.c | 19 +++++++++++++++---- src/lib/Makefile.am | 16 +++++++++------- src/lib/api.c | 13 +++++++++++-- src/lib/api.h | 10 +++++----- 7 files changed, 77 insertions(+), 22 deletions(-) diff --git a/configure.ac b/configure.ac index 48c8f93..4001d3b 100644 --- a/configure.ac +++ b/configure.ac @@ -233,6 +233,16 @@ if test "$enable_filters" = "yes"; then fi AM_CONDITIONAL(ENABLE_FILTERS, test "$enable_filters" = "yes") +AC_ARG_ENABLE([text], + [AS_HELP_STRING([--enable-text], [Enable text (TrueType font functions) @<:@default=yes@:>@])], + enable_text="$enableval", + enable_text="yes" +) +if test "$enable_text" = "yes"; then + AC_DEFINE(ENABLE_TEXT, 1, [Enable text functions]) +fi +AM_CONDITIONAL(ENABLE_TEXT, test "$enable_text" = "yes") + AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], [Enable debug features @<:@default=no@:>@])], [ @@ -317,6 +327,7 @@ echo "Use X86 MMX for speed.....: $mmx" echo "Use AMD64 for speed.......: $amd64" echo echo "Include filters...........: $enable_filters" +echo "Include text functions....: $enable_text" echo "Use visibility hiding.....: $enable_visibility_hiding" echo echo "Installation path.........: $prefix" diff --git a/src/bin/imlib2_colorspace.c b/src/bin/imlib2_colorspace.c index 4f5d583..a9e6ca9 100644 --- a/src/bin/imlib2_colorspace.c +++ b/src/bin/imlib2_colorspace.c @@ -12,13 +12,17 @@ Window win; int main(int argc, char **argv) { - int w, h, tw, th; + int w, h; Imlib_Image im_bg = NULL; XEvent ev; KeySym keysym; - Imlib_Font font; Imlib_Color_Range range; +#if ENABLE_TEXT + Imlib_Font font; + int tw, th; +#endif + /** * First tests to determine which rendering task to perform */ @@ -38,8 +42,10 @@ main(int argc, char **argv) /** * Start rendering */ +#if ENABLE_TEXT imlib_set_font_cache_size(512 * 1024); imlib_add_path_to_font_path(PACKAGE_DATA_DIR "/data/fonts"); +#endif imlib_context_set_display(disp); imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp))); imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp))); @@ -86,6 +92,7 @@ main(int argc, char **argv) imlib_context_set_color(0, 0, 0, 255); imlib_image_draw_rectangle(20, 20, 560, 140); imlib_image_draw_rectangle(20, 220, 560, 140); +#if ENABLE_TEXT font = imlib_load_font("notepad/15"); if (font) { @@ -101,6 +108,7 @@ main(int argc, char **argv) imlib_text_draw(300 - tw / 2, 380 - th / 2, text); imlib_free_font(); } +#endif /* Draw rectangle w/ RGBA gradient */ range = imlib_create_color_range(); diff --git a/src/bin/imlib2_show.c b/src/bin/imlib2_show.c index 3dbc654..740fb45 100644 --- a/src/bin/imlib2_show.c +++ b/src/bin/imlib2_show.c @@ -44,7 +44,6 @@ main(int argc, char **argv) struct timeval timev; double sec; const char *file = NULL; - const char *fon = NULL, *str = NULL; int root = 0; int scale = 0; @@ -72,11 +71,15 @@ main(int argc, char **argv) #endif Imlib_Color_Modifier colormod = 0; ImlibPolygon poly, poly2, poly3; + +#if ENABLE_TEXT + const char *fon = NULL, *str = NULL; int textdir = IMLIB_TEXT_TO_RIGHT; - int xfdtest = 0; int xfdcachetest = 0; char *xfdfname = NULL; int xfdloop = 1; + int xfdtest = 0; +#endif /* now we'll set the locale */ setlocale(LC_ALL, ""); @@ -115,11 +118,13 @@ main(int argc, char **argv) ("-font\t\tLoads a font. The parameter must follow the police_name/size format. Example: loading the grunge font at size 18 is : grunge/18.\n\t\tThe XFD font also can be specified. Ex. 'notepad/32,-*--24-*'.\n"); printf("-poly\t\tPerforms a poly test\n"); printf("The following options requires a file to work properly.\n"); +#if ENABLE_TEXT printf("-textdir\t\tText Direction. 0: L to R, 1: R to L\n"); printf(" 2: U to D, 3: D to U, 4: angle\n"); printf("-xfdtest\t\tXFD Font queue test.\n"); printf ("-xfdcachetest []\t\tXFD tFont cache test.\n\t\tThe file f is drawn l times\n"); +#endif printf("-blast\t\tDisplays the file.\n"); printf("-loop\t\tScales down the image.\n"); printf("-blendtest\tPerforms a blending test on the file.\n"); @@ -206,6 +211,7 @@ main(int argc, char **argv) i++; imlib_set_color_usage(atoi(argv[i])); } +#if ENABLE_TEXT else if (!strcmp(argv[i], "-font")) { i++; @@ -232,6 +238,7 @@ main(int argc, char **argv) i++; textdir = atoi(argv[i]); } +#endif else if (!strcmp(argv[i], "-rotate")) rotate = 1; #if ENABLE_FILTERS @@ -787,6 +794,8 @@ main(int argc, char **argv) int x, y; XEvent ev; KeySym keysym; + +#if ENABLE_TEXT Imlib_Font fn = NULL; struct font_hdr { int type; @@ -919,6 +928,7 @@ main(int argc, char **argv) if (!fn) fon = NULL; } +#endif /* ENABLE_TEXT */ imlib_context_set_progress_function(NULL); imlib_context_set_progress_granularity(0); @@ -960,11 +970,13 @@ main(int argc, char **argv) goto quit; break; case ButtonRelease: +#if ENABLE_TEXT if (fon) { imlib_context_set_font(fn); imlib_free_font(); } +#endif goto quit; case MotionNotify: x = ev.xmotion.x; @@ -1167,6 +1179,7 @@ main(int argc, char **argv) imlib_context_set_operation(IMLIB_OP_COPY); } +#if ENABLE_TEXT if (xfdcachetest) { int l; @@ -1284,6 +1297,7 @@ main(int argc, char **argv) cx2, cy2, cw2, ch2); } } +#endif /* ENABLE_TEXT */ imlib_context_set_blend(1); if ((px != x) || (py != y)) { diff --git a/src/bin/imlib2_test.c b/src/bin/imlib2_test.c index 4762723..ad8d4aa 100644 --- a/src/bin/imlib2_test.c +++ b/src/bin/imlib2_test.c @@ -24,9 +24,6 @@ main(int argc, char **argv) /* our virtual framebuffer image we draw into */ Imlib_Image buffer; - /* a font */ - Imlib_Font font; - /* our color range */ Imlib_Color_Range range; @@ -54,11 +51,13 @@ main(int argc, char **argv) /* set our cache to 2 Mb so it doesn't have to go hit the disk as long as */ /* the images we use use less than 2Mb of RAM (that is uncompressed) */ imlib_set_cache_size(2048 * 1024); +#if ENABLE_TEXT /* set the font cache to 512Kb - again to avoid re-loading */ imlib_set_font_cache_size(512 * 1024); /* add the ./ttfonts dir to our font path - you'll want a notepad.ttf */ /* in that dir for the text to display */ imlib_add_path_to_font_path(PACKAGE_DATA_DIR "/data/fonts"); +#endif /* set the maximum number of colors to allocate for 8bpp and less to 128 */ imlib_set_color_usage(128); /* dither for depths < 24bpp */ @@ -68,6 +67,7 @@ main(int argc, char **argv) imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp))); imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp))); imlib_context_set_drawable(win); + /* infinite event loop */ for (;;) { @@ -75,7 +75,13 @@ main(int argc, char **argv) Imlib_Image image; /* width and height values */ - int w, h, text_w, text_h; + int w, h; + +#if ENABLE_TEXT + /* a font */ + Imlib_Font font; + int text_w, text_h; +#endif /* init our updates to empty */ updates = imlib_updates_init(); @@ -116,6 +122,7 @@ main(int argc, char **argv) updates = imlib_update_append_rect(updates, mouse_x - (w / 2), mouse_y - (h / 2), w, h); +#if ENABLE_TEXT font = imlib_load_font("notepad/30"); if (font) { @@ -151,6 +158,8 @@ main(int argc, char **argv) 240 - (text_h / 2), text_w, text_h); } +#endif /* ENABLE_TEXT */ + break; default: /* any other events - do nothing */ break; @@ -239,6 +248,7 @@ main(int argc, char **argv) /* free it */ imlib_free_color_range(); +#if ENABLE_TEXT /* draw text - centered with the current mouse x, y */ font = imlib_load_font("notepad/30"); if (font) @@ -261,6 +271,7 @@ main(int argc, char **argv) /* free the font */ imlib_free_font(); } +#endif /* ENABLE_TEXT */ /* dont blend the image onto the drawable - slower */ imlib_context_set_blend(0); diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 4723b19..2492a9b 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -16,7 +16,6 @@ libImlib2_la_LIBADD = libImlib2_la_SOURCES = \ api.c api.h \ api_obsolete.c \ -api_text.c \ asm.h \ asm_c.c asm_c.h \ blend.c blend.h \ @@ -29,11 +28,6 @@ draw_line.c \ draw_polygon.c \ draw_rectangle.c \ file.c file.h \ -font.h \ -font_draw.c \ -font_load.c \ -font_main.c \ -font_query.c \ grad.c grad.h \ image.c image.h \ image_tags.c \ @@ -54,8 +48,16 @@ dynamic_filters.c dynamic_filters.h \ filter.c filter.h \ script.c script.h endif - +if ENABLE_TEXT +libImlib2_la_SOURCES += \ +api_text.c \ +font.h \ +font_draw.c \ +font_load.c \ +font_main.c \ +font_query.c libImlib2_la_LIBADD += $(FREETYPE_LIBS) +endif MMX_SRCS = \ asm_blend.S \ diff --git a/src/lib/api.c b/src/lib/api.c index cf74876..d89f9e9 100644 --- a/src/lib/api.c +++ b/src/lib/api.c @@ -35,19 +35,26 @@ typedef struct _ImlibContextItem { struct _ImlibContextItem *below; } ImlibContextItem; +#if ENABLE_TEXT +#define DefaultContext_Text \ + .direction = IMLIB_TEXT_TO_RIGHT, \ + .angle = 0.0, +#else +#define DefaultContext_Text +#endif + #define DefaultContext { \ .anti_alias = 1, \ .dither = 0, \ .blend = 1, \ .operation = (ImlibOp) IMLIB_OP_COPY, \ - .direction = IMLIB_TEXT_TO_RIGHT, \ - .angle = 0.0, \ .color.alpha = 255, \ .color.red = 255, \ .color.green = 255, \ .color.blue = 255, \ .pixel = 0xffffffff, \ .mask_alpha_threshold = 128, \ + DefaultContext_Text \ } /* A default context, only used for initialization */ @@ -131,11 +138,13 @@ __imlib_free_context(ImlibContext * context) imlib_free_image(); ctx->image = NULL; } +#if ENABLE_TEXT if (ctx->font) { imlib_free_font(); ctx->font = NULL; } +#endif if (ctx->color_modifier) { imlib_free_color_modifier(); diff --git a/src/lib/api.h b/src/lib/api.h index 24181b1..4f6c132 100644 --- a/src/lib/api.h +++ b/src/lib/api.h @@ -46,11 +46,6 @@ typedef struct { char blend; Imlib_Color_Modifier color_modifier; ImlibOp operation; -#if ENABLE_TEXT - Imlib_Font font; -#endif - Imlib_Text_Direction direction; - double angle; Imlib_Color color; uint32_t pixel; Imlib_Color_Range color_range; @@ -66,6 +61,11 @@ typedef struct { #if ENABLE_FILTERS Imlib_Filter filter; #endif +#if ENABLE_TEXT + Imlib_Font font; + Imlib_Text_Direction direction; + double angle; +#endif } ImlibContext; extern ImlibContext *ctx;